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;
}
}
}