Migrating T3.6 to T4 - interval timers recommendation

rvh

Well-known member
I have code developed on T3.6 that I would like to migrate to T4.0 / 4.1. In that code I use 3 interval timers, one at 10ms, one at 1ms, and one at a variable audio sampling rate up to about 40-50kHz. They increase in priority in that order.

I read that the interval timer by default uses the PIT timers, which in T4 no longer have independent interrupts, and presumably(?) would cause my assigned interrupt priorities not to work. What would be the recommended way to migrate my timers? I looked at the TeensyTimerTool but am not clear how I could replicate the priority structure I currently have with that tool. I couldn't see for example how to assign priorities using the Periodic timers. It's probably a straight-forward procedure, but I'm having trouble finding what it is. Thanks!
 
I read that the interval timer by default uses the PIT timers, which in T4 no longer have independent interrupts, and presumably(?) would cause my assigned interrupt priorities not to work.

That's true. The T3.6 had 4 PIT modules with one channel each. The T4.x have 1 PIT module with 4 channels. Interrupt priorities can be assigned per module only.

I looked at the TeensyTimerTool but am not clear how I could replicate the priority structure I currently have with that tool. I couldn't see for example how to assign priorities using the Periodic timers.

Of course the TimerTool can't work around the hardware limitations (one interrupt per PIT module) but it provides easy access to other timers. E.g. you can use the PIT module for your audio timing, and GPT1 / GPT2 for your 1 and 10ms timers. If the GPTs are used in your application you can also use two of the four TMR modules. I don't know your accuracy requirements, but, if they are not too high you can also think of using one of the Software timers (TCK) for the lowest priority 10ms timing. Here more information about the available timers: https://github.com/luni64/TeensyTimerTool/wiki/Supported-Timers. Also check the chapter about which timers are used for PWM to avoid clashes https://github.com/luni64/TeensyTimerTool/wiki/Avoid-PWM-timer-clashes

The timer tool (currently) doesn't provide priority settings. But you can simply use NVIC_SET_PRIORITY to do so.
Code:
NVIC_SET_PRIORITY (IRQ_GPT1, 32);
would set the priority of the GPT1 module to 32. The IRQ constants are defined here: https://github.com/PaulStoffregen/cores/blob/master/teensy4/imxrt.h. Here a copy of the timer IRQs (QTIMER = TMR)
Code:
IRQ_GPT1 =              100,
IRQ_GPT2 =              101,
IRQ_PIT =               122,
IRQ_QTIMER1 =           133,
IRQ_QTIMER2 =           134,
IRQ_QTIMER3 =           135,
IRQ_QTIMER4 =           136,

Hope that helps
 
Thanks very much, that's exactly what I need.

That's true. The T3.6 had 4 PIT modules with one channel each. The T4.x have 1 PIT module with 4 channels. Interrupt priorities can be assigned per module only.

Of course the TimerTool can't work around the hardware limitations (one interrupt per PIT module) but it provides easy access to other timers. E.g. you can use the PIT module for your audio timing, and GPT1 / GPT2 for your 1 and 10ms timers. If the GPTs are used in your application you can also use two of the four TMR modules. I don't know your accuracy requirements, but, if they are not too high you can also think of using one of the Software timers (TCK) for the lowest priority 10ms timing. Here more information about the available timers: https://github.com/luni64/TeensyTimerTool/wiki/Supported-Timers. Also check the chapter about which timers are used for PWM to avoid clashes https://github.com/luni64/TeensyTimerTool/wiki/Avoid-PWM-timer-clashes

The timer tool (currently) doesn't provide priority settings. But you can simply use NVIC_SET_PRIORITY to do so.
Code:
NVIC_SET_PRIORITY (IRQ_GPT1, 32);
would set the priority of the GPT1 module to 32. The IRQ constants are defined here: https://github.com/PaulStoffregen/cores/blob/master/teensy4/imxrt.h. Here a copy of the timer IRQs (QTIMER = TMR)
Code:
IRQ_GPT1 =              100,
IRQ_GPT2 =              101,
IRQ_PIT =               122,
IRQ_QTIMER1 =           133,
IRQ_QTIMER2 =           134,
IRQ_QTIMER3 =           135,
IRQ_QTIMER4 =           136,

Hope that helps
 
Back
Top