做一个电机相关项目,我打算用TIM0的更新中断设置为TRG去触发AD0采样,
TIMER_CTL1(TIMER0) |= 2<<4; // 更新事件触发其他模块。
但更新中断标志TRG的标志有反应,但TRG的标志一直没反应。
看了两天质料还是没找到原因。
配置的代码是从灵动(仿ST)的工程移植过来的,在灵动的芯片上是可以触发的。
请大神指点一下。附件为芯片配置的工程。void Tim0_Center_Aligned_init(void)
{
/*使能TIM1时钟,默认时钟源为PCLK2(PCLK2未分频时不倍频,否则由PCLK2倍频输出),可选其它时钟源*/
RCU_APB2EN |= RCU_APB2EN_TIMER0EN;
TIMER_CAR(TIMER0) = 3600 - 1; //设定计数器自动重装值108M--- 15K
TIMER_PSC(TIMER0) = 0; //预分频器设置
TIMER_CTL0(TIMER0) |= TIMER_CTL0_CAM;
TIMER_SMCFG(TIMER0) |= TIMER_SMCFG_MSM;
TIMER_CTL1(TIMER0) |= 2<<4; // 更新事件触发其他模块,用TIM7的更新
TIMER_CHCTL0(TIMER0) |= (6<<4)|(6<<12);// PWM模式0
TIMER_CHCTL1(TIMER0) |= (6<<4);
// 互补输出使能
TIMER_CHCTL2(TIMER0) |= TIMER_CHCTL2_CH0EN|TIMER_CHCTL2_CH0NEN|TIMER_CHCTL2_CH1EN|TIMER_CHCTL2_CH1NEN|TIMER_CHCTL2_CH2EN|TIMER_CHCTL2_CH2NEN;
TIMER_CH0CV(TIMER0) = 0;//3600 - 1;//
TIMER_CH1CV(TIMER0) = 0;//3600 - 1;//
TIMER_CH2CV(TIMER0) = 0;//3600 - 1;//
// TIMER_CCHP(TIMER0) = 162;//108
// DTCFG [7:5] =3’b 10x: DTvalue = (64+DTCFG [5:0])xtDT, tDT =tDTS*2
TIMER_CCHP(TIMER0) = 0xa1;
//使能输出 和 刹车
TIMER_CCHP(TIMER0) |= TIMER_CCHP_POEN;
TIMER_CCHP(TIMER0) |= TIMER_CCHP_BRKEN;
//TIM1->RCR = 3;
TIMER_CREP(TIMER0) = 1;
TIMER_CTL0(TIMER0) |= TIMER_CTL0_CEN; //使能定时器1
// 使能刹车中断检测短路过流
TIMER_DMAINTEN(TIMER0) |= TIMER_DMAINTEN_BRKIE;
NVIC_EnableIRQ(TIMER0_BRK_IRQn);
//NVIC_SetPriority(TIMER0_BRK_IRQn, 1); //优先级设置有问题,会进不了中断
TIMER_DMAINTEN(TIMER0) |= TIMER_DMAINTEN_TRGIE;
NVIC_EnableIRQ(TIMER0_TRG_CMT_IRQn);
}
|