PIT periodic interrupt timer on TEENSY 4.1

Fred_B

Member
Hello every body,

I would like to use the PIT of a TEENSY 4 to send periodic trame of pulses.
It works fine BUT, for debug reason I added some "serial.println" in code and when I remove them It doesn't work.
Here below an simple example
Code:
#include <Arduino.h>

void pit_test()
{
    PIT_TFLG0 = 1;              
    Serial.println(micros());             //<--- when I remove this line I can't see the LED blinking anymore
    digitalToggle(LED_BUILTIN);
}

void setup()
{
    pinMode(LED_BUILTIN, OUTPUT);

    PIT_LDVAL0 = 12000000 - 1; // 1/2 seconde
    PIT_TCTRL0 = 0x00000003;   // timer 0 enable et interrupt enable

    attachInterruptVector(IRQ_PIT, pit_test);

    NVIC_SET_PRIORITY(IRQ_PIT, 0);
    NVIC_ENABLE_IRQ(IRQ_PIT);
    
}

void loop()
{
}
I'm pretty sure that's a story of interrupts unable or something like that but I'm running dry !!

Thank you for reading.
Fred
 
Try adding
Code:
asm volatile("dsb");
at the end of your ISR or simply use an IntervalTimer.
 
Thank you Luni,
It's working now :)

It was under my eyes but not sure I have to use it.
Due to the clock frequency difference between CPU and
peripheral, in some corner case, peripheral interrupt flag may
not be really cleared before CPU exit ISR. In such case, user
should add DSB instruction right after instruction to clear
interrupt flag.

Could you explain me, in few words, what does mean DSB ?
Thx
Fred
 
The timer flag ist part of the timer peripheral. It takes some time until the change propagates to the peripheral. For very short ISRs the flag is not yet reset at the end and the ISR is called twice. The DSB Waits until everything is synced.
 
Back
Top