0
votes

I have F401RB nucleo board Timer4 configured with these values enter image description here

The PWM output varies considerably , frequency between 40kHz and 41.67 kHz and the duty Cycle between 50% and 52%. enter image description here Is there a way to achieve better stablity

With due respect to Sealese logic, is it the LA that lags in capturing real output ?

1

1 Answers

6
votes

You are attempting to read a 40 KHz signal at a 1 MHz sampling rate, in other words there are only 25 samples per cycle of your signal. If there is a +/-1 error in reading a particular cycle (and there will always be a possibility of such an error, due to the complete lack of synchronization between the signal and the sampling), the displayed frequency will be off by a factor of 1/25 - either 38461 Hz or 41667 Hz.

If you wanted to determine the exact frequency to within 1% (for example), you'd need a sampling rate 100 times greater than the signal frequency.