AnsweredAssumed Answered

STM32F3 skips one period of input signal

Question asked by krivetskov.dmitr.001 on Nov 8, 2015
Hi, all!

Does anyone faced with a skipping one period of input signal without ovrcapture flag setting?
The setup is:
* STM32F3 Discovery board with STM32F303 MCU.
* TIM2 used for input / capture the input signal from external source.
* input / capture interrupt generation is enabled.
* MCU & TIM frequency is 48 MHz,
* input signal - sqare wave near 50%, frequency from 3 kHz to 63 kHz - result is the same.
I use TIM2 to accurate input frequency measurement, and found that about one period per 10K - 100K measurement has been lost (means that I got 12000 timer cycles per measurement instead of normal 6000, for example).
This looks very strange, because I don't get overcapture flag for this time!
I tried to:
* increase interrupt priority to highest (althought it is not requried in theory for this frequences)
* disable all another interrupts
* reduce timer handler code to minimun.
And all this steps can't help.
Here is a reduced TIM2 handler code:

void TIM2_IRQHandler(void)
    uint32_t readval;
    static uint32_t readval_old = 0;
    if (__HAL_TIM_GET_FLAG(&htim2, TIM_FLAG_CC4) != RESET && __HAL_TIM_GET_ITSTATUS(&htim2, TIM_IT_CC4) != RESET)
        __HAL_TIM_CLEAR_IT(&htim2, TIM_IT_CC4);
        readval = HAL_TIM_ReadCapturedValue(&htim2, TIM_CHANNEL_4);
        if (tim_meas_cb.ic_counter > 2)
            //!!! period skip test
            if ((readval - readval_old) < 500 || (readval - readval_old) > 1000)
        readval_old = readval;
        if (tim_meas_cb.ic_counter < 100)
        //!!! overcapture test
        if(__HAL_TIM_GET_FLAG(&htim2, TIM_FLAG_CC4OF) != RESET)
            __HAL_TIM_CLEAR_FLAG(&htim2, TIM_FLAG_CC4OF);

Have any ideas?