cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Reciprocal Counter

Posted on June 24, 2014 at 09:04

I'm trying to make reciprocal counter on STM32F4-Discovery.

Concept:

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.

#stm32-reciprocal-counter
2 REPLIES 2
Posted on June 24, 2014 at 16:40

Consider using PWM Input rather than Input Capture.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
galizin
Associate
Posted on November 26, 2014 at 17:55

Two timers: Tin for input frequency, Tref - reference frequency. Tin is clocked  by EXTF, Tref - internal.

Tin is master and generate trigger by OC1REF. Tref is slave in gate mode.

CC module 1set up to one pulse PWM mode with impulse raise by compare with CCR and fail by ARR. ARR=0xFFFFFFFF. CCR=1;

Enable Tref and Tin.

In 0.5 second for example the timer Tin value is read. Change ARR=(Tin + 1) * 2. This is the estimation of the measure end.

In 1 second get Tin, Tref and calculate input frequency.

Original idea http://radiokot.ru/forum/viewtopic.php?p=1495961#p1495961