AnsweredAssumed Answered

STM32F405rg pulse counter

Question asked by Quigley.Robert.001 on Mar 18, 2015
Latest reply on Mar 19, 2015 by Quigley.Robert.001
Hi


I'm using a STM32F405RG  in a fan controller, I've two fans tacho outputs connected via opto-isolators to Pins, I wish to count the number of falling edges per second.


PA5 (Tim2 CH1 ext clock source mode 1, trigger on TI1FP1) all other Tim2 pins disabled
PB6 (Tim4 CH1 ext clock source mode 1, trigger on TI1FP1)  all other Tim4 pins disabled


both have interrupts enabled for Trigger event TIMx_DIER = 0x0040
on a falling edge as this is cleaner than rising edge, TIMx_SMCR = 0x8057
Timers are running in interrupt mode (HAL_TIM_Start_IT(&htimX))



A third timer reads the htimX.Instance->CNT once a second and returns a value in Hz.


The problem is that this value is unreliable, a 10Hz square wave input mimics an expected input. 
5Hz reads as 293.
1Hz reads as 1.
10Hz reads as 4698.

My understanding is that in ext Time mode 1, an interrupt is generated for each edge detected, 
I've tried using the filter setting to reduce the likelihood of multiple triggers per edge
but to no avail. Using a timer to disable the interrupt for 200uS after an edge also proved unfruitful.

Page 590 of the reference doc RM0090 describes the feature I'm trying to use.

Any help would be appreciated.

Outcomes