cancel
Showing results for 
Search instead for 
Did you mean: 

Wheel speed using hall effect sensor and STM32F446 - count 'teeth' rather than period.

AGust.1
Associate II

Hello,

I'm new to all this, first-year uni student and still learning java. I'm working on someone else's code for the uni motorsport club in c++ and the original coder has left.

Currently, we detect the wheel speed using a hall effect sensor and capturing the period when the code is run (every 50ms). This is creating very messy data.

I was wondering if there's a way to just straight up count the number of 'teeth' rather than determine the period with Input Capture?

We want to grab the number of 'teeth' from the register, then use that to determine how many times the wheel has turned (distance travelled), plus how many counts of the clock from the last time we calculated and determine the speed as distance/time.

I hope this makes sense, I'm still learning my way around the STM32s.

7 REPLIES 7

> This is creating very messy data.

Maybe you should start with finding out, why. What would be the reason for the period not being consistently measurable? If the period measurement is unreliable, why would measurement of multiple periods be any better?

Observe the exact waveform using logic analyzer, or maybe better using oscilloscope. Is the signal clean? Aren't there oscillations at the edges? Isn't there any noise induced from outside?

> I was wondering if there's a way to just straight up count the number of 'teeth' rather than determine the period with Input Capture?

If the connection is to timer's CH1 or CH2, you set the Slave-mode controller in timer to input from given channel, and then use External Clock Mode 1. Read the TIM chapter in RM, focus on TIMx_SMCR register description.

But you can have both the time and the count. Maybe the easiest way to achieve it is to use DMA to transfer the captured values to memory. The number of transferred values gives you the count, and you will have all the transitions times available for analysis.

JW

AGust.1
Associate II

Hello,

One reason for the messy data that I know of is that there's a wobble to the disk the hall effect sensor is reading but I've been told there's nothing they can do about that.

Thank you for your response, I'll share it with the team.

TDK
Guru

A hall effect sensor gives an analog output. Looks like you're looking for a digital output from something like an encoder wheel. Can you describe more in detail how things work? Are you reading an ADC value from the hall effect sensor?

If you feel a post has answered your question, please click "Accept as Solution".

> A hall effect sensor gives an analog output

.. except of those, which are integrated with comparator/discriminator and output logic levels, e.g. https://www.allegromicro.com/en/products/sense/magnetic-speed/general-purpose-speed-sensor-ics/a17201

I believe, this type is prevalent in the motor/engine control field.

> ... wobble to the disk the hall effect sensor is reading

Measuring over a larger number of teeth may or may not help with this problem. Measure the signal with a LA and analyze it before attempting to do anything with the microcontroller.

JW

TDK
Guru

> which are integrated with comparator/discriminator and output logic levels,

So it's an encoder implemented using hall effect technology. Haven't seen that before.

Wobble will affect the reading a small amount, but counting edges a JW suggests should be much much more accurate than just reading the period of a single pulse. And the long term average will be exactly correct, so you could filter the value if needed.

If you feel a post has answered your question, please click "Accept as Solution".
raptorhal2
Lead

This is a bit off topic, but a hardware design to eliminate wobble is to use two alternating polarity rare earth magnets around the circimference and a latching Hall sensor. That produces one clean on and off pulse per revolution with no wobble effect. Timer register captures then produce accurate speed results.

Cheers, Hal

There's a hall effect sensor reading cut-outs on a metal disc on the tire. I'll have to ask my classmate who's the tech lead of our club these other questions. Really appreciate everyone's responses, thank you.