@yagohoffmann
I don't think you're doing quite what I suggested - It looks like you're doing the ADC conversion inside the PIT Timer IRQ rather than checking the PIT Timer value with the ADC outside the PIT IRQ.
I just tried my way and found that ADC operation (on a K22 running at 120MHz, which should be similar to your K64) was around 38-40us - in the code below, the difference in "runTimeCounter" is 19 or 20 between when I start the ADC Operation (my ADC16_SetChannelConfig call) and after the ADC16_GetChannelConversionValue method returns in my ADC IRQ. I'm running FreeRTOS, so I think that explains why I'm returning a value that's a bit larger than yours.
I've can cut down my PIT code that I think is relevant to you:
PIT Global Counter Variable:
uint32_t volatile runTimeCounter = 0;
PIT Timer 0 Initialization:
PIT_GetDefaultConfig(&pitConfig);
/* Init pit module */
PIT_Init(PIT
, &pitConfig);
/* Set timer period for channel 0 */
PIT_SetTimerPeriod(PIT
, kPIT_Chnl_0
, USEC_TO_COUNT(2U
, PIT_SOURCE_CLOCK));
/* Enable timer interrupts for channel 0 */
PIT_EnableInterrupts(PIT
, kPIT_Chnl_0
, kPIT_TimerInterruptEnable);
/* Enable at the NVIC */
EnableIRQ(PIT_IRQ_ID);
/* Start channel 0 */
PIT_StartTimer(PIT
, kPIT_Chnl_0);
PIT IRQ:
void PIT_RUNTASK_HANDLER(void) {
PIT_ClearStatusFlags(PIT
, kPIT_Chnl_0
, kPIT_TimerFlag);
++runTimeCounter;
/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}And then, to read the "RTOS_RunTimeCounter", I use the inline method:
inline static uint32_t readRunTimeCounter() {
extern uint32_t runTimeCounter;
return runTimeCounter;
}
2us PIT Timer interval was the shortest I could do with my system remaining stable.
I guess it's up to the NXP engineers to explain what's happening here - for my product, 40us or so converstion time is acceptable but I thought it was under 1us (as I think you do).