PWM on Teensy 4.0?

Status
Not open for further replies.
I guess I'm trying to figure out, if I know the frequency I want to pulse, and the duty cycle, what do I need to call in order to make that happen using analogWrite()? I want to use PWM to pulse a Stepper Motor driver.
 
RE p#1 : PWM on those pins with analogWrite and associated functions of Freq and Res should work as expected.
 
Thanks. That page doesn't indicate the PWM clock / prescalar for T4, though. Where can I find that?

It looks like the formula for PWM clock frequency (F_BUS_ACTUAL aka IPG_CLK_ROOT in the docs [Table 13-4]) as given in clockspeed.c is essentially:

Code:
F_BUS_ACTUAL = F_CPU_ACTUAL / min(4, floor((F_CPU_ACTUAL + 149999999) / 150000000))

where the maximum frequency is 150 MHz (as listed for IPG_CLK_ROOT in the docs [Table 13-5])

@PaulStoffregen, is there any reason that the formula for div_ipg in clockspeed.c doesn't try to maximize F_BUS_ACTUAL? For instance, for the following frequencies of F_CPU_ACTUAL you get these values for F_BUS_ACTUAL:

CPU -> BUS
600 -> 150 MHz
500 -> 125 MHz
400 -> 100 MHz
300 -> 100 MHz
200 -> 100 Mhz
100 -> 50 MHz
50 -> 50 MHz

But if div_ipg were set to 2 and 1 when CPU is 300 and 100 MHz respectively, then BUS would be 150 and 100 MHz instead. Is there a reason not to do this?

Also, since the BUS (IPG) clock is derived from the CPU (AHB) clock, and the clockspeed is dynamic, how do you ensure that you get a stable PWM frequency? I probably misunderstood something here!
 
To add to this discussion. Is the bit resolution 16 bit for all frequencies on the Teensy 4? I have looked through the chip specs and cannot tell definitively, but it looks like it always has 16 bit counter.
 
Status
Not open for further replies.
Back
Top