have small question , i am using the snvs HP rtc and its alarm feature of imxrt1050 . which can give interrupt in seconds is it possible to get alarm in milliseconds.
Hi Venu ,
You can use the below function to generate millisecond delay
void delay_ms(uint32_t delay)
{
PIT->CHANNEL[kPIT_Chnl_0].LDVAL = 24000*delay;
PIT_StartTimer(PIT, kPIT_Chnl_0);
while(!PIT_GetStatusFlags(PIT, kPIT_Chnl_0));
PIT_ClearStatusFlags(PIT, kPIT_Chnl_0, kPIT_TimerFlag);
PIT_StopTimer(PIT, kPIT_Chnl_0);
}
if you need a alarm for every milli second , then enable the interrupt .
void Enable_Timer_Interrupt(pit_chnl_t channel)
{
PIT_EnableInterrupts(PIT, channel, kPIT_TimerInterruptEnable);
EnableIRQ(PIT_IRQn);
}
Check below , i have configured Timers to generate interrupt every 500ms , 1 second and 2 seconds .
PIT_SetTimerPeriod(PIT, kPIT_Chnl_1, 12000000); // 24,000,000 is for 1 sec 24,000 for 1ms
Enable_Timer_Interrupt(kPIT_Chnl_1);
PIT_StartTimer(PIT, kPIT_Chnl_1);
PIT_SetTimerPeriod(PIT, kPIT_Chnl_2, 24000000); // 24,000,000 is for 1 sec 24,000 for 1ms
Enable_Timer_Interrupt(kPIT_Chnl_2);
PIT_StartTimer(PIT, kPIT_Chnl_2);
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, 48000000); // 24,000,000 is for 1 sec 24,000 for 1ms
Enable_Timer_Interrupt(kPIT_Chnl_3);
PIT_StartTimer(PIT, kPIT_Chnl_3);
Hope this will help .
Hello,
To work with millisecond interrupts I would suggest you use either the General Purpose Timer or the Quad Timer. You can refer to the SDK to see the example projects of these two timers to see how to make the proper configurations.
Best Regards,
Victor