PWM Measurement Accuracy
Hi,
I am trying to measure the duty cycle and the frequency of a standard servo PWM signal (50Hz and 5% to 10% duty cycle) using STM32F446. I have configured the timers to be in PWM input mode, and I can read both the frequency and duty cycle. The measurement is very accurate with the 32 bit timers (TIM2 and TIM5) down to sub uS for pulse length. However, with the 16 bit timers the frequency and the duty cycle measurement is very inaccurate. I believe this is due to the prescaler I used. I had to use a prescaler greater than 50 with the 16 bit timers to avoid overflow. However with the 32 bit timer I used a prescaler of 0. Interestingly, it is also very inaccurate when I used the same prescaler on the 32bit that I had to use for the 16 bit timer. Below are some tests I did to measure 50Hz and 2000uS pulse length, the clock frequency to the timer is 84MHz.
- 50 Prescaler -> 51.5Hz; 1960.714uS
- 75 Presclaer -> 50.667Hz,1973.214uS
- 100 Prescaler -> 50.49Hz, 1979.76uS
- 500 Prescaler -> 50.1Hz,19940.476uS
- 1000 Prescaler -> 50.05Hz, 19880.09uS
Interestingly, a higher prescaler increases accuracy to a point. I thought a lower prescaler would increase the accuracy as it is a smaller step size. Is the accuracy a limitation of the STM32? Is there any way I can make the measurements more accurate?
Thank you in advance for any help.
