cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a speed sensor on L432KC Nucleo

xpp07
Senior

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?

6 REPLIES 6

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
Up vote any posts that you find helpful, it shows what's working..
xpp07
Senior

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

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
Up vote any posts that you find helpful, it shows what's working..
xpp07
Senior

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?

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
Up vote any posts that you find helpful, it shows what's working..
xpp07
Senior

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