having trouble setting up TIM1 to measure input period and detecting no input
I need to measure the rpm of a tachometer signal from a fan. I want to measure the period. I also need to know when the fan is stopped (i.e. the signal stops changing).
I am trying to use TIM1 for what seems to me to be a simple setup. I want an input signal edge to save the counter in a capture register (CCR1), reset the counter, and generate an interrupt so I can save the measured count. If the counter overflows then I will know the input stopped and I can record the rpm as zero. Does this seem like a good plan?
So I need interrupts on CCR1 capturing and on counter overflow. I am trying this setup. I think the following pseudo-code shows the pertinent registers. (I am programming registers directly. I personally hate any HAL like the peripheral library).
TIM1_SMCR_TS, Trigger Selection, is input source TI1
TIM1_SMCR_SMS, Slave Mode Selection mask, is trigger reset mode
TIM1_IER_TIE, input trigger interrupt, is enabled
TIM1_IER_UIE, overflow interrupt, is enabled
TIM1_CCMR_CC1S, Capture/Compare Selection, is TI1FP1
TIM1_CCER1_CC1E, Capture/Compare Enable, is enabled
TIM1_ARR, auto-reload register, is set to 0xffff
Other things like counter-enable and pre-scaler are set also.
The problem is that I'm getting overflow interrupts and no input trigger interrupts. I'm thinking maybe I'm confusing CCR capturing with the trigger reset mode. The two can be used at the same time, right?
