Skip to main content
xpp07
Associate III
September 13, 2018
Question

Reading a speed sensor on L432KC Nucleo

  • September 13, 2018
  • 6 replies
  • 1089 views

I'm using a reed switch (a pulse per revolution) to measure the speed of a wheel. The sensor output is connected to PA12 which is TIM1_ETR pin. I connected it there by mistake in my final PCB. I would have to tweak the PCB if I want to change timer channel.

Is there a way that I can measure speed on this pin?

    This topic has been closed for replies.

    6 replies

    Tesla DeLorean
    Guru
    September 13, 2018

    Configure TIM1 in External Count mode, using TIM1_ETR.

    Set counter in maximal mode (TIM1->ARR = 0xFFFF), and then read the counter TIM1->CNT once a second, and subtract out the count from the prior read. Do the math using uint16_t variables.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    xpp07
    xpp07Author
    Associate III
    September 13, 2018

    Sorry for this question .. but I forgot to mention that channel 1 from Timer1 (PA8) is used as PWM generation. Does this affect what you explain above? I'm just starting to get involved with STM32 and CubeMx

    Tesla DeLorean
    Guru
    September 13, 2018

    So if you can't use it as a TIM input, consider using PA12 as an EXTI, generating an interrupt for each pulse.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    xpp07
    xpp07Author
    Associate III
    September 13, 2018

    So I think that I can set PA12 as an EXTI and update a variable each time the pulse is given. But I would need the time elapsed between pulses. Is there a way to find it out?

    Tesla DeLorean
    Guru
    September 13, 2018

    To what accuracy?

    You could have TIM2 counting elapsed microseconds.

    Or frankly just have the EXTI increment a counter you check every second or millisecond.

    Sorry you don't mention a range of speeds/frequencies involved. ​

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    xpp07
    xpp07Author
    Associate III
    September 13, 2018

    It's low RPM application. The reed switch is located in a treadmill. I don't have the exact range of speed, but motors I'm using are around 3000 RPM max. Of course, this limit is not reached in treadmill applications