Hello,
My goal is to generate a waveform with LPIT of S32K144, the LPIT initial and interrupt handler as below:
//-------------------------------------------------------------
LPIT_DRV_Init(INST_LPIT1, &lpit1_InitConfig);
LPIT_DRV_InitChannel(INST_LPIT1, LPIT_CHANNEL, &lpit1_ChnConfig0);
INT_SYS_InstallHandler(LPIT0_Ch0_IRQn, &lpit_level_ctl, (isr_t *) 0);
INT_SYS_SetPriority(LPIT0_Ch0_IRQn, 3U);
INT_SYS_EnableIRQ(LPIT0_Ch0_IRQn);
//-------------------------------------------------------------
static void lpit_level_ctl(void) //timer period is 2us
{
PINS_DRV_WritePin(PTA,0,levelA[counter]); //levelA is waveform data array
counter++;
if(counter == data_len) { //the data_len is a global varible , and data_len is equal to 100
counter = 0;
LPIT_DRV_StopTimerChannels(INST_LPIT1, 1U << LPIT_CHANNEL);
}
LPIT_DRV_ClearInterruptFlagTimerChannels(INST_LPIT1, 1 << LPIT_CHANNEL);
}
//-------------------------------------------------------------
And PE LPIT configuration : Timer period is 2us (need 500k frequency)

Clock configuration: Core clock is 48MHz

At this, I have encountered a problem, in lpit_level_ctl() function, if the data_len variable is used, then waveform timing generated will be incorrect; But I used a constant (such as 100) instead of the data_len, and waveform is good.
I would like to know the reason for this issue? How to solve it that ensure a frequency of 500k?
Thank you for your help!
Best regards,
fedora