用新唐M0有一段时间了。发现新唐的数据手册真的是博大精深啊。其中,关于pwm捕获的内容比较少,不过其中还是提到了高低脉宽的计算方式。在英文版的227页上写了
In this case, the CNR is 8:
1. The PWM counter will be reloaded with CNRx when a capture interrupt flag (CAPIFx) is set.
2. The channel low pulse width is (CNR + 1 – CRLR).
3. The channel high pulse width is (CNR + 1 – CFLR).
即 CRLR和CFLR可以认为保存了高低电平的时间。然后,官方给的demo中却是这样
- while(u32i < 4)
- {
- /* Wait for Capture Falling Indicator */
- while(PWM_GetCaptureIntFlag(PWM, u32Ch) < 2);
- /* Clear Capture Falling and Rising Indicator */
- PWM_ClearCaptureIntFlag(PWM, u32Ch, PWM_CAPTURE_INT_FALLING_LATCH | PWM_CAPTURE_INT_RISING_LATCH);
- /* Get Capture Falling Latch Counter Data */
- u32Count[u32i++] = PWM_GET_CAPTURE_FALLING_DATA(PWM, u32Ch);
- /* Wait for Capture Rising Indicator */
- while(PWM_GetCaptureIntFlag(PWM, u32Ch) < 2);
- /* Clear Capture Rising Indicator */
- PWM_ClearCaptureIntFlag(PWM, u32Ch, PWM_CAPTURE_INT_RISING_LATCH);
- /* Get Capture Rising Latch Counter Data */
- u32Count[u32i++] = PWM_GET_CAPTURE_RISING_DATA(PWM, u32Ch);
- }
- u16RisingTime = u32Count[1];
- u16FallingTime = u32Count[0];
- <font color="#ff0000"> u16HighPeroid = u32Count[1] - u32Count[2];</font>
- <font color="#ff0000"> u16LowPeroid = 0x10000 - u32Count[1];</font>
- u16TotalPeroid = 0x10000 - u32Count[2];
完全搞不懂了,我到底是要以文档为主呢,还是以demo为主了。重点是,这些都是从官方下载的,都是亲生的 ╮(╯_╰)╭
|