Dear Sir,
Recently, I start to use RT1050 EVK, based on SDK PIT driver example I plan to make a time delay function(with PIT). I found there is a problem on the delay function.
1. if I want to delay 1us, I will get the nearly 2 us delay, that is OK because there is interrupt head.
2. if I want to delay 480us, I will get the around 160us delay (check with scope).
3. when I set the delay as 5000us, I got 1800us delay.
The attached is the project source file(MCUXpresso project). Please advise me what is the problem to use PIT.
Thanks.
Hi Shen,
As the demo as-is provides a properly 1-second delay, it should be an issue with the adaption to the delay_us function. You could try checking the following:
PIT_clock_peroid=PIT_SOURCE_CLOCK/1000000U;
PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, 1000000U*PIT_clock_peroid);
PIT_SetTimerPeriod(PIT, kPIT_Chnl_1, 1000U*PIT_clock_peroid);
Hope this will be useful for you.
Best regards!
/Carlos
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi
Based on PIT driver example, I set the PIT channel0's period as 1000000us (one second, toggle led on/off), and channel2's period as 1us, 2us,...step with 1us (toggle GPIO: GPIO_AD_B0_01). According to the example that the PIT source clock is kCLOCK_OscClk=24Mhz. I found that led on/off is like 1 second, but GPIO toggle is like 1/3us step (on scope). So I set the period based on 72Mhz, the channel2 look like step on 1us(but in within 10us, the period is random.). Is PIT clock 72MHz?
Using similar code on KF64, the PIT period is correct, which interrupt overhead period is fixed round 3us. Does PIT have a bug on RT1050?
here is the code:
j=1;
while (true)
{
/* Check whether occur interupt and toggle LED */
if (true == pitIsrFlag)
{
PRINTF("\r\n Channel No.%d interrupt is occured !",j);
LED_TOGGLE();
pitIsrFlag = false;
// check channel 2 for delay
GPIO_PinWrite(OW_GPIO_PORT, OW_GPIO_PIN, 0U);
US_delay(j);
GPIO_PinWrite(OW_GPIO_PORT, OW_GPIO_PIN, 1U);
j++;
}
}
void US_delay(uint32_t us){
PIT_SetTimerPeriod(PIT, kPIT_Chnl_2, us*3*PIT_clock_peroid); // assume source is 72Mhz
PIT_StartTimer(PIT, kPIT_Chnl_2);
while(PIT->CHANNEL[kPIT_Chnl_2].TCTRL & PIT_TCTRL_TEN_MASK);
}
void PIT_LED_HANDLER(void)
{
pit_chnl_t i;
/* Clear interrupt flag.*/
for(i=kPIT_Chnl_0;i<4;i++){
if(PIT_GetStatusFlags(PIT, i)){
PIT_ClearStatusFlags(PIT, i, kPIT_TimerFlag);
switch(i){
case kPIT_Chnl_0:
pitIsrFlag = true;
break;
case kPIT_Chnl_1:
break;
case kPIT_Chnl_2:
PIT_StopTimer(PIT, kPIT_Chnl_2);
break;
case kPIT_Chnl_3:
break;
}
break;
}
}
}