1、设置捕获的时钟预分频值请修改下面函数的第二个参数,
/* If input minimum frequency is 250Hz, user can calculate capture settings by follows.
Capture clock source frequency = __HXT = 12000000 in the sample code.
(CNR+1) = Capture clock source frequency/prescaler/clock source divider/minimum input frequency
= 12000000/2/1/250 = 24000
(Note: CNR is 16 bits, so if calculated value is larger than 65536, user should increase prescale value.)
CNR = 0xFFFF
(Note: In capture mode, user should set CNR to 0xFFFF to increase capture frequency range.)
*/
Capture unit time = 1/(Capture clock source frequency/prescaler)
166ns = 1/(12000000/2)
PWM_ConfigCaptureChannel(PWMB, PWM_CH2, 166, 0);
2、为何CalPeriodTime函数里连清两次下降沿中断?
程序设置的是下降沿捕获时会清除计数器重新计数。
两次清除下降沿是为了定位一个测量的起点。比如刚进入此函数时有可能刚发生下降沿中断,也可能发生完下降沿+上升沿,所以这个中断忽略对应A段;
等到下一个下降沿发生时,把它当作测量的起点,所以B点的中断标志也清除掉,开始正事测试。 |