Teensy PWM ideal frequency

The PWM hardware runs from the peripheral clock. The hardware is only capable of adjusting the pulse width by integer number of steps of the peripheral clock.

At those ideal frequencies the PWM period is exactly 2^N cycles of the peripheral clock. You always get a direct 1-to-1 mapping of values written by analogWrite() to the actual PWM pulse width. Each incremental increase in PWM pulse width is always the same.

At any other frequency, the number of PWM pulse widths is not a perfect mapping. For example, if you have 375 kHz and the peripheral clock is 150 MHz (CPU at 600 MHz), the PWM total cycle is 400 steps of the peripheral clock. So if you write 8 bit numbers to analogWrite(), it will have to map the 256 numbers onto those 400 steps. Sometimes when you increase the PWM by 1, you'll get at increase in pulse width of 1/400th, but other times you'll get an increase of 1/200th (2 steps).
 
Back
Top