2008-03-27 02:12 AM
Timer usage
2011-05-17 03:27 AM
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 Kasper2011-05-17 03:27 AM
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.