AnsweredAssumed Answered

K64F timing issue

Question asked by Cesar Hoyos on Mar 21, 2017
Latest reply on Mar 23, 2017 by Butcher

Hello everybody,

I am working with FRDM K64F developer platform.

I am using K64F in order to interface some sensors with my PC.

These sensors work in one of the following frequencies: 400Hz and 10kHz. Also I want a higher frequency in order to have a "clock" for my system (1MHz) counting one by one microsecond, being the time mark for data register.

I programmed three PITs in order to read sensors and get this timing:

    #define PIT_SOURCE_CLOCK CLOCK_GetBusClkFreq()
    #define FEQ_SENS 400U
    #define FEQ_SENS_2 10000U
    #define FEQ_CLOCK 1000000U
    pit_config_t pit_config;
    PIT_GetDefaultConfig(&pit_config);
    pit_config.enableRunInDebug = true;

    //PIT_Deinit(PIT);
    PIT_Init(PIT, &pit_config);

    PIT_SetTimerPeriod(PIT, kPIT_Chnl_0, PIT_SOURCE_CLOCK/(FEQ_SENS)-1);
    PIT_SetTimerPeriod(PIT, kPIT_Chnl_1, PIT_SOURCE_CLOCK/(FEQ_SENS_2)-1);
    PIT_SetTimerPeriod(PIT, kPIT_Chnl_2, PIT_SOURCE_CLOCK/(FEQ_CLOCK)-1);
    PIT_EnableInterrupts(PIT, kPIT_Chnl_0, kPIT_TimerInterruptEnable);
    PIT_EnableInterrupts(PIT, kPIT_Chnl_1, kPIT_TimerInterruptEnable);
    PIT_EnableInterrupts(PIT, kPIT_Chnl_2, kPIT_TimerInterruptEnable);

    EnableIRQ(PIT0_IRQn);
    EnableIRQ(PIT1_IRQn);
    EnableIRQ(PIT2_IRQn);

    PIT_StartTimer(PIT, kPIT_Chnl_0);
    PIT_StartTimer(PIT, kPIT_Chnl_1);
    PIT_StartTimer(PIT, kPIT_Chnl_2);

With all this, then in execution time, I have been looking the number of data that have been registered in 10sec (measured with 1MHz PIT) and there are more data than there should be. If there should be 100k data, there are 101052 (constantly each 10sec).

 

Also, I have done some proofs toggling digital pins out, and watching square signals in oscilloscope:

- For 400Hz there are not deviation.

- For 10kHz there are little deviation, but there are not problematic (most of measures indicates 10kHz, and a few indicates 9'99804kHz).

- For 1MHz the deviation is bigger. Oscilloscope indicates 983'63kHz and some times is rise to 983'632kHz.

 

The point is, is there any limitation of use of this PIT module? How much is this error? Could it be fixed by some method?

 

If there is a frequency limitation, I would be fine by using this limitation as clock of my system. Else, could you recommend another method to solve my timing issue?

 

Thanks for your attention.

Outcomes