Teensy 4.1 available PWM frequencies

Status
Not open for further replies.

edmundsj

New member
Hello,

I am wondering what the possible PWM frequencies are on the Teensy 4.1. I am hoping to use 50% duty-cycled PWM or some other hardware timer based method (ideally no load on the CPU) to generate a 1.0MHz clock for an external ADC. On the teensy website https://www.pjrc.com/teensy/td_pulse.html there is a table of frequencies and the corresponding resolution, but are those *all* the available frequencies? Internally, is there some clock divider / PLL doing the work to generate them, and what are the available divider ratios?

If others have alternative suggestions for how to generate a 1.0MHz clock on any output pin (I have flexibility), I'm certainly open to those.
 
I have a related question - what is the fastest possible clock rate? Ideally for the GPT.
 
In most cases like this you need to look at the sources... and manual:

PWM: Depends on which pin... Some are FlexPWM and others are Quad timers.

I believe the default F_BUS_ACTUAL is 150000000

And the computation that FlexPWM does:
Code:
void flexpwmFrequency(IMXRT_FLEXPWM_t *p, unsigned int submodule, uint8_t channel, float frequency)
{
	uint16_t mask = 1 << submodule;
	uint32_t olddiv = p->SM[submodule].VAL1;
	uint32_t newdiv = (uint32_t)((float)F_BUS_ACTUAL / frequency + 0.5f);
	uint32_t prescale = 0;
	//printf(" div=%lu\n", newdiv);
	while (newdiv > 65535 && prescale < 7) {
		newdiv = newdiv >> 1;
		prescale = prescale + 1;
	}

So if you pass in 1000000 I think the code will compute 150 which should work...

Would need to look at quad...
 
I am hoping to use 50% duty-cycled PWM or some other hardware timer based method (ideally no load on the CPU) to generate a 1.0MHz clock for an external ADC.

Use this:

Code:
void setup() {
  analogWriteFrequency(2, 1000000);
  analogWrite(2, 128);
}

void loop() {
}

file.png

I have a related question - what is the fastest possible clock rate? Ideally for the GPT.

The FlexPWM runs from the 150 MHz peripheral clock (when the CPU is 600 MHz or any multiple of 150 MHz), so 75 MHz is the fastest PWM output.

Code:
void setup() {
  analogWriteFrequency(2, 75000000);
  analogWrite(2, 128);
}

void loop() {
}

file2.png

My oscilloscope has only 200 MHz bandwidth, so this is the best image I can capture with my limited equipment...
 
Status
Not open for further replies.
Back
Top