cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo-f401RE frequency measuring using timer

DSimp.1
Associate III

Hello, I am trying to create a simple frequency measuring device using 1 optical encoder and NUCLEO-F401RE board. I want to capture frequency (or period) of impulse, so I was thinking to use input capture mode and capture rising edge of impulses and see Counter value. I don't want to use interrupts or any other method to reset Counter. Ideally, it should be done on hardware and when I need, frequency could be retrieved and read. How I imagine this should works is liek this: Counter starts counting after start function somewhere on main, after impulse positive edge comes it saves the value and resets counter, when next impulse comes, it overwrites the value and again resets the counter. At any time I can  read  saved value and get current frequency. Is this possible to do without any interruptions in program? 

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

Hello,

Refer to this example from STM32CubeF4 package on Github. But you need to use the interrupt to read CCRX values to compute the frequency and the duty cycle:

https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F401RE-Nucleo/Examples/TIM/TIM_PWMInput

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
Sarra.S
ST Employee

Hello @DSimp.1

The frequency measurement can be done with "PWM input mode" which is a particular case of input capture mode, according to section "17.3.7 PWM input mode" in RM0090, This can measure the period (frequency) (in TIMx_CCR1 register) and duty cycle (in TIMx_CCR2 register) of the signal. 

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

SofLit
ST Employee

Hello,

Refer to this example from STM32CubeF4 package on Github. But you need to use the interrupt to read CCRX values to compute the frequency and the duty cycle:

https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F401RE-Nucleo/Examples/TIM/TIM_PWMInput

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.