2018-09-12 7:44 PM
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?
2018-09-12 8:12 PM
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.
2018-09-12 8:56 PM
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
2018-09-12 9:26 PM
So if you can't use it as a TIM input, consider using PA12 as an EXTI, generating an interrupt for each pulse.
2018-09-12 10:13 PM
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?
2018-09-13 4:49 AM
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.
2018-09-13 9:53 AM
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
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.