Skip to main content
Visitor II
March 5, 2024
Solved

Nucleo-f401RE frequency measuring using timer

  • March 5, 2024
  • 2 replies
  • 2014 views

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? 

    This topic has been closed for replies.
    Best answer by mƎALLEm

    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

    2 replies

    ST Employee
    March 5, 2024

    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. 

     

    mƎALLEmAnswer
    Technical Moderator
    March 5, 2024

    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