Teensy 4, analogWriteFrequency, constraints?

Status
Not open for further replies.

PaulS

Well-known member
While testing the FreqCount feature in another thread with high frequencies [50-75 MHz], I probably ran into a limitation/constraint of the analogWriteFrequency() function.
This code produces a 75MHz signal on pin 8:
Code:
void setup() {
  analogWriteFrequency(8, 75000000);
  analogWrite(8, 128);
}

void loop() {
}

But apparently I don't understand analogWriteFrequency very well: when I set the frequency to 60000000 or 62500000 or 65000000, it also outputs 75 MHz. Setting the frequency 55000000 outputs 50 MHz.
I read this page, but I'm probably missing something.

Perhaps someone on this forum can shine a light on this?

Thanks,
Paul
 
Sorry not much of an expert here, but maybe can walk through it...
Pin 8: {1, M(1, 3), 1, 6}, // FlexPWM1_3_A 8 // B1_00

So it is a FlexPWM timer pin.
So it calls off to: flexpwmFrequency(flexpwm, info->module & 0x03, info->channel, frequency);

In there if you look:
uint32_t newdiv = (uint32_t)((float)F_BUS_ACTUAL / frequency + 0.5f);
I believe F_BUS_ACTUAL defaults to 150mhz, so
newdiv would equal 2...
for 75mhz...

So yes 75mhz would go to 75mhz At some point divisor would go to 3 or 50mhz...
 
Hi Kurt, that makes sense. It's all there in \cores\teensy4\pwm.c ...

Thanks,
Paul
 
Status
Not open for further replies.
Back
Top