Looking further into the code of the IntervalTimer library and the documentation of the processor, I found out that all four channels of the IntervalTimer trigger the same interrupt and therefore must have the same priority.
I solved my problem having two periodic tasks using one of the General Purpose Timers that are available on the Teensy 4. I looked into the reference manual of the processor and some code, that I found on this forum to produce the following:
Code:
void setup()
{
Serial.begin(1);
uint32_t us = 1000;
CCM_CCGR1 |= CCM_CCGR1_GPT(CCM_CCGR_ON); //enable clock for General Purpose Timer 1
GPT1_CR = 0;
GPT1_PR = 0;
GPT1_SR = 0x3F; // clear all prior status
GPT1_IR = GPT_IR_OF1IE; // enable GPT1 COMPARE 1 Interrupt
GPT1_CR = GPT_CR_EN | GPT_CR_CLKSRC(1); // sets timer clock to 24 MHz (Teensy 4)
GPT1_OCR1 = 24000000 / 1000000 * us; // set compare value
attachInterruptVector(IRQ_GPT1, timer_test);
NVIC_SET_PRIORITY(IRQ_GPT1, 0);
NVIC_ENABLE_IRQ(IRQ_GPT1);
}
void timer_test()
{
GPT1_SR = GPT_SR_OF1; //clear the compare flag, the timer resets automatically
Serial.println(micros());
}
void loop()
{
}
This way I have a different interrupt (GPT1_IRQ), that I can assign a different priority to. This allows the IntervalTimer to interrupt or be interrupted by the other task.
Is this the way you would do it, or has the General Purpose Timer (GPT) some drawbacks in comparison to the Periodic Interrupt Timer (PIT) that is used in the IntervalTimer library? Should I use the PIT for the faster Task where timing needs to be more accurate or is there no difference?