Generating a 20MHz Clock Wave

Drodru

Member
How can I generate a 20MHz clock wave (50% duty cycle) with PWM using Teensy 4.1. I don't understand at all the Pulse Width Modulation page.
Thank you.
 
Normally you can't get exactly 20 MHz because the timers run at 150 MHz and they can only create waveforms that are an integer division of 150 MHz. And to get exactly 50% duty cycle, that integer must be an even number, because you need the same number of clock cycles high and low. The closest you could get is 150 ÷ 8 = 18.75 MHz.

But if you're willing to stray from the well-worn "normally" path, there is a way to configure clock speed different than 150 MHz. It was discussed recently on this other thread:


If you were to configure the CPU to run at 480 MHz, that would give you a peripheral clock at 120 MHz. Then you could get 120 ÷ 6 = 20 MHz.
 
Last edited:
Back
Top