大家好,我遇到一个非常棘手的问题,在制作一个电调实验中,需要用TIM1的1/2/3通道输出PWM,而用4通道去触发中断,使得单片机能够一直在PWM的中点触发中断,但是现在在较小占空比时,中断的触发时钟延迟PWM的上升沿一个较大的延时,恨头疼啊,不知各位大侠有没有遇到过类似的问题,谢谢!定时器的初始化程序如下
void ISR_Tim1_Init()
{
// 16M系统时钟经预分频f=fck/(PSCR+1)
// f=16M每个计数周期0.0625U
TIM1_CR1_bit.CEN = 0; //stop tim1
TIM1_PSCRH = 0;
TIM1_PSCRL = 0;
//设定重装载时的寄存器值,255是最大值
TIM1_ARRH = (16000 / Fpwm) / 256; // fpwm = 150hz
TIM1_ARRL = (16000 / Fpwm) % 256; //
//设置刹车寄存器
TIM1_BKR|= 0X80;
//PWM1模式,TIM1_CNT<TIM1_CCR1时有效
TIM1_CCMR1 = 0x6C;
TIM1_CCMR2 = 0x6C;
TIM1_CCMR3 = 0x6C;
TIM1_CCMR4 = 0x08;
//PWM 占空比 清0
TIM1_CCR1H = 0x00; // B相上管
TIM1_CCR1L = 0x00;
TIM1_CCR2H = 0x00; // C相上管
TIM1_CCR2L = 0x00;
TIM1_CCR3H = 0x00; // C相上管
TIM1_CCR3L = 0x00;
//允许比较4中断
TIM1_IER |= 0X10;
//输出到对应管脚 1 有效
TIM1_CCER1 |= 0X11;
TIM1_CCER2 = 0X01;
TIM1_EGR = 0X01; //UG = 1 ;初始化计数器 预装载载入影子寄存器中
TIM1_CNTRH = 0; //计数器清0
TIM1_CNTRL = 0;
TIM1_CR1 |= 0X01; //计数器使能,开始计数
}
|