I am using the PIT for a delay function. It sets up the timer based on the delay passed in and polls for the interrupt flag, stops the timer and exits. This has been working great. But then I set up a pin interrupt triggering on both rising and falling edges and then I call my delay function inside that interrupt. And It seems like if I write anything to the PIT registers it causes an exception. Goes to the defaultISR.
void usDelay(uint32_t us) {
uint8_t i = 0;
uint32_t count = (US_FREQ_BUS*us);
//PIT_HAL_ClearIntFlag(g_pitBaseAddr[US_DELAY_INSTANCE], US_DELAY_CHAN);
PIT_TFLG0 = 0x01;
if(count > US_DELAY_TRIM) {
PIT_DRV_SetTimerPeriodByCount(US_DELAY_INSTANCE, US_DELAY_CHAN, count - US_DELAY_TRIM);
count = count - US_DELAY_TRIM;
} else {
PIT_DRV_SetTimerPeriodByCount(US_DELAY_INSTANCE, US_DELAY_CHAN, count);
}
PIT_HAL_StartTimer(g_pitBaseAddr[US_DELAY_INSTANCE], US_DELAY_CHAN);
while(!PIT_HAL_IsIntPending(g_pitBaseAddr[US_DELAY_INSTANCE], US_DELAY_CHAN));
PIT_HAL_StopTimer(g_pitBaseAddr[US_DELAY_INSTANCE], US_DELAY_CHAN);
}
In the debugger, the line PIT_TFLG0 = 0x01; executes and then the next operation (does not matter what it is) causes the exception. But this only happens when I call this delay function from an interrupt.
Solved! Go to Solution.
Hello Matt Lang:
What MCU target are you using? And what IDE (KDS, IAR, Keil)?
The problem sounds like if the PIT clock gate was not enabled, but if it fails only when calling your delay function from the ISR then that should not be the cause.
If possible please share your project in a zip file to take a look at it.
Regards!
Jorge Gonzalez
Hello Matt Lang:
What MCU target are you using? And what IDE (KDS, IAR, Keil)?
The problem sounds like if the PIT clock gate was not enabled, but if it fails only when calling your delay function from the ISR then that should not be the cause.
If possible please share your project in a zip file to take a look at it.
Regards!
Jorge Gonzalez