cancel
Showing results for 
Search instead for 
Did you mean: 

Timer usage

kjepsen9
Associate II
Posted on March 27, 2008 at 10:12

Timer usage

2 REPLIES 2
kjepsen9
Associate II
Posted on May 17, 2011 at 12:27

Hello

I am trying to measre the speed of a fan, i first thought i could use the input compare register as a register for counting my input pulses, but that is not made this way

then i can use the input and latch the value on positive and negative edge and reset the counter once and i have the pulse time or i can get the periode time, but if i want to connect 4 fans on the same timer it seems defficult.

another way is just to use the i/o pin as interupt and count up a register, but it will happen 3000 times/min * 4 fans..

Anyone haveing a better suggestion, i am a litle stuck

Kasper

lanchon
Associate III
Posted on May 17, 2011 at 12:27

3000 rpm is 50 Hz. 4 timers give 200 Hz interrupt rate which is very easily handled by the stm32. but the precision will not be as good as it could.

you can use a timer: count up with ARR = 0xFFFF (period 0x10000) and capture and interrupt on one edge. in the int handler subtract previous from current capture (and cast result to unsigned 16 bit integer) to find the period for last revolution. you can prescale inputs /1 to /8 to interrupt with less frequency, giving better accuracy. or when turning fast, you can selectively add several revolutions to keep precision high independent of speed.

to detect stalls you can use the update event interrupt to check whether no interrupts of a particular channel were triggered during the last (or last ''N'') counter period(s).

you can link two counters for 32 bit precision.