作者: admin 时间: 2022-5-19 16:35
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点的中断标志也清除掉,开始正事测试。作者: admin 时间: 2022-5-19 16:36
3、循环里发生下降沿中断后,为何同时清除上下沿中断标志?
因为例程是选择的先记录下降沿,从B处的下降沿到0位置时,中间必定会先发生上升沿,所以此时应该要将上下沿标志都清除。作者: admin 时间: 2022-5-19 16:36