40 cent magnetic angle sensing technique

Hello Everyone,

I’m currently working on a project that needs very cheap contactless angular position sensing, and I ended up trying to develop a custom solution. SimpleFOC provided a convenient platform for prototyping the concept, so I thought it would be nice to write a sensor driver for this technique to let other people use it easily.

You can have a look at a rough draft for the documentation here if you want a detailed explanation, but this is the TLDR:

Two analog linear hall sensors placed very specifically around the outer edge of a bldc motor can pick up a non-symmetrical waveform from the motor’s own magnets, that the microcontroller can sample and use to find relative shaft angle

Pros:

  • ~20 cents per sensor in single quantity, no cost for magnets
  • Off-axis from the motor’s axle

Cons:

  • Specific sensor location for each motor part number (note: not each individual motor though)
  • Requires fast and frequent analog sampling
  • Requires a computationally expensive trig function
  • Many factors can degrade performance of the sensor

Here are some pictures of the setup:

Note the two sot23-3 packages on the perfboard suspended right above the motor, these are the two hall sensors


An oscilloscope trace of the raw analog output signals from the hall sensors

The digitized readings, converted to shaft angle (in degrees) of a motor spinning at constant velocity

Currently working on some pull requests, which can be found:
Here for some tweaks to SimpleFOC base code + sensor calibration routine
Here for the actual sensor driver code

I think the main functionality is roughly all implemented, but now it is time to test a bit, clean up the code, and write some documentation.

Cheers,
nano

8 Likes

That’s very cool indeed! Could potentially be useful for portable wind turbine project down the line.

2 Likes

and with a montage like this

74LS148

Interesting. Can you do absolute angle? How do you find the initial starting angle w.r.t. 0 degree ?

The sensor can only tell absolute angle within one electrical revolution, due to the way it uses the motor’s own magnets. This is not good enough for absolute shaft angle, so at best it acts exactly the same way as e.g. an incremental optical encoder does when interacting with SimpleFOC, which means a calibration routine upon every power-on.

How is this any different than from factory (built inside the coils) hall sensored motors then?

I definitely don’t have as much experience with brushless motors as some of the people here, so anyone who knows more can feel free to chime in. But the impression I get is that a vast majority of the brushless motors that have integrated sensing use digital hall sensors, which give you something like six counts per electrical revolution. This is great for trapezoidal commutation, as the hall signal can be used to define both the timing and the step number of the next step in the commutation sequence, even at very low speeds, but it’s practically useless for FOC commutation. Using linear analog hall sensors like above gives much finer angular resolution, which is much better suited for FOC.

2 Likes

I’m not sure I understand, are you suggesting to use the 74LS148 as an analog to digital converter?

I forgot this detail “relative shaft angle”
I will continue the evolution of my progress on the position that I have already opened
Hall effect sensors encoder

I don’t have much experience either, but I would like to be able to do without the initialization at the start and to be able to work with a hollow shaft motor

1 Like

yes, with input comparators and for initialization, I want to do an analog reading of the two sensors, I would not have an absolute angle, but personally it does not bother me for my use

Interpolation

Welcome to the community!

Awesome work, I think you have here one of the cheapest solutions that are good enough for position control. I think a lot of people here will find this work valuable and we’ll find it implemented in some projects soon. :smiley:

1 Like

Awesome! This may actually be less trouble in terms of sensor placement than digital hall sensors, since you don’t have to worry about the angular position of the sensors relative to the stator. Plus two sensors is two thirds the work soldering tiny wires and capacitors :slight_smile: EDIT: Even better, it looks like 49e hall sensors don’t even need filtering capacitors.

There are ways to do fast atan2 approximation to reduce CPU load, which should be plenty accurate for this. Here’s a good one with max error 0.28 degrees: How to Find a Fast Floating-Point atan2 Approximation - Nic Taylor

And you could switch to 8-bit ADC when the motor gets above a certain speed so you can use higher ADC clock rate to reduce the reading time. Lower precision values, but higher accuracy since less time delay means the values you have are closer to the actual rotor position.

3 Likes

If anyone needs sensors, let me know. I bought a pack of 100 on ebay because it was little more expensive than buying 10. It will take a couple weeks to get here though.

I found an older post on the forum about a DJI gimbal. It seems like it were utilizing this technique:

1 Like