The electric motor is the fundamental building block of almost all robotic projects but, without some form of feedback, it lacks the precise positional control required for the task. Small servos from the modelling world will often use a potentiometer to sense where they are on their travel, while more accomplished motors will employ some form of shaft encoder.
Commercial shaft encoders use magnets and Hall-effect sensors, or optical sensors and encoder discs. But these can be quite expensive, so [Hello1024] hacked together an alternative in an afternoon. It uses another motor as the encoder, taking advantage of the minute changes in inductance as the magnet passes each of its coils. It’s a technique that works better with cheaper motors, as their magnets are more imperfect than those on their expensive cousins.
The sensing is rather clever in its economy, sending a pulse to the motor through an off the shelf motor controller and measuring the time it takes to decay through the body diode of the driving MOSFET. It requires a calibration procedure before first use, and it is stressed that the whole thing is very much still in beta, but it’s a very impressive hack nevertheless. He’s posted a video demonstration which you can see below the break.
We’ve covered one or two home-made encoders in the past, in some cases rather primitive ones but others have been more sophisticated. You might also find our recent guide to coding for one on an mbed to be of interest.
17 thoughts on “Use A Brushless Motor As A Rotary Encoder”
hmm, looks very much like what i got on my bench right now. but i will not use it as an encoder..
Mine is a Hobbypower 30A encoder, bought from ebay 2 weeks ago for $10 with a free motor.
Yours looks like a slightly different revision of the same design (the sense resistors, middle right, are laid out differently)
Mine was the cheapest 30A ESC i could find on ebay a few months ago, are currently trying to modify SimonK to be better suitable for robotics applications. what i am planning to do is to use a logic analyzer to collect the backEMF signals or rather almost all I/O so i can write a little “motor simulator”. with that i might be able to get some good development environment up and running with simavr.
Why work on a live system, fearing to release the magic smoke when you can spend weeks on trying to get a simulated environment up and running?
My solution to that was to add a 10 ohm resistor to the power supply…
Motors behave nearly the same, yet any accidental shorting of MOSFETs will not lead to magic smoke.
Before you go too far on that model of ESC, beware that the high side mosfet drivers are rather rubbish. They switch on after a 500 nanosecond delay, and they switch slowly (generating lots of heat in the process). That means either you loose lots of energy in the body diodes, or you switch the mosfets to have both on at once (ie. negative deadtime). The driver also has a restriction that you must switch all pmos mosfets on at least once every few seconds due to leakage across the npn drive transistors.
You might think the delay isn’t an issue, but watch the waveforms and you’ll see that the default PWM frequency of 10KHz is far too low for reasonable low speed efficiency (the motor current drops to zero between PWM pulses), and more like 100kHz is required.
ah, thanks! that is good to know. I have ordered an Storm32 from aliexpress that i also will evaluate. 3x motor control and a stm32, its a bit different from the 8bit avr controllers. but then you won’t get the same power to the motors..
at least its not 100% assembly as simonK ;)
Can someone explin how this is better than just using the motors back-emf like is usuay done? It seems like a lot of complication for not a lot of gains…
I think that only works when there’s enough speed already.
All of this is of course only precise for magnetic rotations in the brushless motor.
BTW great idea, I like how those motors even being mechanically so simple can be generators, motors, encoders or tachometers. And all of this with basically off the shelf ESCs, only depending on the firmware.
Back emf can’t tell you the angle when the motor is stationary. That’s critical for fine control like in 3d printers or robotic arms.
If you just want a motor for a quadcopter, this sort of control isn’t necessary.
been trying to piece together how to do this exact thing with stepper motors, CD-ROM/hard-disk spindle-motors, and more for quite some time. Was under the impression that applying an external magnetic field to an inductor has no effect unless the magnet is moving. Yet, couldn’t we move the electrons through the winding, which, to them, would appear as though they’re moving WRT the magnet? *Many* searches said no. And yet, here it (allegedly) is.
I am not sure exactly what you are trying to do, but this method doesn’t have anything to do with magnets or their motion. Most pm motors have a rotor made with magnets and iron. The permeability of a magnet is basically the same as air and the permeability of iron is very high. Therefore the coil will have a different inductance based on the rotors position ( there will be more or less iron in the magnetic path). So this method just measures the inductance of the coil and likely uses a look up table to relate that to rotor position. It is measuring the inductance by sending high frequency current pulses through the coil and measuring the reaction.
Ah, so the inductance is changing because of the iron, not the magnets… that makes sense from what I’d gathered… [Hello1024] basically made a three-coil metal-detector.
This’d probably work with steppers, then, but less-likely with hard-disk/CD-motors, as they usually have a circular/cylindrical magnet that lines the entire cylindrical/circular “can” which would provide little to no change in Iron vs. any winding’s “magnetic path”…
So I don’t see how this system’s different than those, looking at the video, unless you’re suggesting that the magnet is interfering with the “detection” of the iron behind it, and the magnets themselves, in a case like this, are not cylindrical. (Or due to the holes in the top of the “can”?)
As far as moving the electrons in the stationary magnetic field: by running a current through the winding, the current would create a magnetic field, when the polarity of that field matches that of the magnet, the sources of the two magnetic fields would repel, causing it to be harder to drive that current through it. When the polarity of the field opposes that of the magnet, they would attract, causing it to be easier to drive that current through it… Sounds like a change in inductance, to me… and certainly measurable, despite all my readings.
You have to make sure you have a Salient rotor, which you likely do not. Just means there isn’t a significant change in the impedance of the magnetic path based on rotor position. If you google salient rotor, you should understand what I am talking about. Also playing around in FEMM might help as well.
Basically if the iron/magnets don’t have any breaks or voids in them the rotor looks the same to the coils no matter what position it is in, particularly when it is not moving.
Also you can give this a read, specifically the low speed position detection to see how TI is doing this. (PDF WARNING) http://www.edn.com/Pdf/ViewPdf?contentItemId=4439393
So the point is in measuring the reaction of the coil – essentially feeling whether there’s a magnet aligned with the pole and by how much.
And the actual angle sensing relies on the fact that the magnets are not uniformly strong, so you can track the absolute position around the perimeter by finding the weakest or strongest effect.
Not exactly no. It uses the fact that the magnets have a magnetic permeability similar to air and iron has a very high permeability. This changes the inductance seen by the stator coils based on the position of the rotor. Only motors with significant saliency can use this method. The magnets don’t even need to be installed in the motor for this to work! It’s a great way to grab zero-low speed position information. In most applications people switch away from using this method (high frequency injection) at a rather low speed. It’s not the most accurate method and is likely susceptible to the switching noise of the inverter.
Methods that rely on the magnets are sensing the back emf of the motor and cannot sense zero speed as the motor does not produce a bemf while it is not moving. Magnetic fields don’t induce any voltage or current in a coil unless they are changing.
Resolver, not encoder
This works much the same way as Texas Instrument’s proprietary FAST observer, or at least the low-speed mode. Maybe some more tricks can be found from the few papers they have published on it and some external documents that talk about it.
Please be kind and respectful to help make the comments section excellent. (Comment Policy)