1.同时打开3个定时器,TIM2,TIM4输出的定时时间很准,但TIM1的TIM1_CH4的PWM频率不准(采用外部16MHZ晶振,不分频,即fmaster=16MHZ),当我想输出100K(占空比为50%)时,TIM1_CH4脚却输出90.91K,占空比为45.45%,相差太远了.
2.测得高电平的时间是5us(与下面的代码的设计符合),但PWM周器却变为11us(正确应该是10us),导致输出的PWM频率不准,请高手分析一下.
void PWM_INIT()
{
TIM1_IER = 0X00; //不允许中断
TIM1_PSCRH =0;
TIM1_PSCRL =15; //分频系数是16
TIM1_ARRH = 0; //PWM周期(PWM频率为100K)
TIM1_ARRL = 10;
TIM1_CCR4H = 0; //PWM占空比(50%)
TIM1_CCR4L = 5;
TIM1_CCMR4 = 0X60; //配置通道4,PWM模式1
TIM1_CCER2 = 0X10; //通道4输出,高电平有效
TIM1_OISR = 0X01; //空闲状态为高
TIM1_CR1 =0X01; //打开定时器1(向上计数,边沿对齐)
TIM1_BKR =0X80; //使能PWM输出
} |