I was checking out PIT recently on teensy 4.0.
Although you can setup 4 different timers. It seems that you can use only one interrupt out of four PIT timers. you can change PIT_LDVALx = (Required time period * Timer Frequency) - 1.
According to readings i got Timer Frequency is roughly 25Mhz.
This is the code I used:
Code:
volatile uint32_t curr = 0, prev = 0;
void setup() {
Serial.begin(115200);
PIT_SETUP();
}
void loop() {
}
void PIT_SETUP() {
PIT_MCR = 0; //Enable PIT
PIT_LDVAL0 = 2499;// for 100 micro seconds
PIT_TCTRL0 = PIT_TCTRL_TIE;// PIT Interrupt enable for Timer0
PIT_TCTRL0 |= PIT_TCTRL_TEN;// start Timer0
attachInterruptVector(IRQ_PIT, TIM0);// attach TIM0(isr) to Timer0 PIT interrupt
NVIC_ENABLE_IRQ(IRQ_PIT);
}
inline void TIM0() {
PIT_TFLG0 |= PIT_TFLG_TIF;// to enable interrupt again
curr = micros();
Serial.println(curr - prev);
prev = curr;
}