2024-03-05 03:00 AM
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?
Solved! Go to Solution.
2024-03-05 06:43 AM
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:
2024-03-05 04:50 AM
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.
2024-03-05 06:43 AM
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: