中级会员
- 积分
- 379
- 威望
- 207
- 贡献
- 102
- 兑换币
- 109
- 注册时间
- 2012-10-27
- 在线时间
- 35 小时
|
3#
楼主 |
发表于 2013-3-16 19:40:11
|
只看该作者
李增杰 发表于 2013-3-16 19:18
没见程序不知道情况
//=============================================
//函数名:FTM1_pwm_ch0_init
//参数:void
//返回:无
//说明:初始化FTM1,输出PWM
// ch0: frequency = 50Hz,duty_cycle = 0.075
//=============================================
void FTM1_pwm_ch0_init(void)
{
//period = 1 / frequency;
SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK;
PORTA_PCR12 = PORT_PCR_MUX(3) | PORT_PCR_DSE_MASK; //channel 2
SIM_SCGC6 |= SIM_SCGC6_FTM1_MASK; //加载FTM0时钟
FTM1_MODE |= FTM_MODE_WPDIS_MASK; //写保护禁止
//FTM1_MODE |= FTM_MODE_FTMEN_MASK;
/************** 设置为ePWM *****************/
FTM1_C0SC |= FTM_CnSC_MSB_MASK; //1
FTM1_C0SC |= FTM_CnSC_MSA_MASK; //1
FTM1_C0SC |= FTM_CnSC_ELSB_MASK; //1
FTM1_C0SC &= ~FTM_CnSC_ELSA_MASK; //0
FTM1_SC &= ~FTM_SC_CPWMS_MASK; //0
FTM1_SC |= FTM_SC_CLKS(1); //system clock
FTM1_SC |= FTM_SC_PS(5); //预分频为32
//FTM1_MODE &= ~1; //FTMEN = 0
FTM1_OUTMASK = 0xfe; //only channel 0 is not masked
FTM1_COMBINE = 0;
FTM1_EXTTRIG = 0;
FTM1_POL = 0;
FTM1_INVCTRL = 0;
FTM1_SWOCTRL = 0; //
FTM1_PWMLOAD = 0;
/************** 设置周期 *******************/
FTM1_CNTIN = 0;
FTM1_MOD = 30000;
FTM1_C0V = 2250;
FTM1_CNT = 0;
/************** 打开中断 *******************/
//FTM1_C0SC |= FTM_CnSC_CHIE_MASK; //使能通道中断
//FTM1_SC |= FTM_SC_TOIE_MASK; //
}
void isr_ftm1(void)
{
run_counter1++;
FTM1_SC &= ~FTM_SC_TOF_MASK; //清除中断标志
if(run_counter1 == 20)
{
run_counter1 = 0;
BSET(22,GPIOB_PTOR); //
}
}
|
|