AnsweredAssumed Answered

STM32 Reciprocal Counter

Question asked by Kyb.Ivan on Jun 24, 2014
Latest reply on Nov 26, 2014 by Galizin.Oleg
I'm trying to make reciprocal counter on STM32F4-Discovery.
0. Input signal connected to TIM1_Ch1 (PA8) and TIM4_ETR (PE0);
1. TIM1 is clocked from HSE 168MHz,
              configured to start from external trigger channel1,
              counts time base;
2. TIM4 is counting input singnal rising fronts - number of Signal pulses.

When Signal rises TIM1 starts counting internal pulses (timebase), TIM4 counts external rising fronts. When TIM1_Update occures, enable TIM1_CC1 interrupt - waiting the next rising front. When TIM1_IT_CC1 occures, stop counting and calculate freqency:
          freq = pulses / (time in TIM1 pulses) * TIM1_frequency;
          freq = (TIM4->CNT) / (TIM1->CCR1 + TIM1->ARR) * HClkFreq.
Reset counters.

And now I have some troubles - unstable Frequency result. I think it's becouse I'm using interrupts and stop timers by software.
Is there any way to stop timer automatically with input front?
I understand the way to get best results is to make minimunim software operations, ideal - only one calculation.