Hall effect Quadrature Encoder bug

Thread Starter

elpidiovaldez5

Joined Mar 9, 2016
4
I am mystified by a problem with a quadrature encoder on a DC motor. The quadrature encoder and motor are connected to an Arduino. I get reasonable speed readings when the motor runs forwards (although a few backward moves are detected. When the motor runs backwards the readings still show mostly forward motion. I have an identical motor which works perfectly, so this can't be a software issue.

On an oscilloscope the problem becomes clearer - the q1 and q2 channels are almost exact inverses of each other. As a result both channels transition at almost exactly the same time and maybe a little jitter has a big effect. Both channels show sharp, clear square waves. Since they are inverses there can be no short circuit between the channels.

It would appear that both Hall sensors are working. I turned the magnetic wheel by hand and saw that the channels do indeed switch in anti-phase.

I tried switching the Hall sensors manually by holding a neodymium magnet by each one. I found either channel could be switched independently from low to high by a magnet held behind it (so the channels are not connected via an inverter). However I found that if I used the North pole of the neodymium magnet I could switch q1 by placing the magnet behind its sensor, but q2 would not change state when the North pole was held behind its sensor. If I used the South pole of the neodymium magnet the reverse was true - I could cause q2 to switch but not q1.

So what is going wrong here ? Could the sensors be inserted the wrong way round ? Could the magnetic wheel have its poles organised incorrectly. The failure mode seems bizarre.

The sensor documentation claims 11 signals per motor rotation (I guess that means 6 poles around the magnetic wheel). It came with this motor:
Motor link
 

MaxHeadRoom

Joined Jul 18, 2013
21,402
Very rare these days to see a quadrature encoder with magnetic detection.
Is this a DC brushed motor? This detection is normally reserved for a BLDC commutation.
Although I see from the link it shows DC .
It would seem something has changed with either the magnet or the sensor to change from the normal 90° phase shift.
I would expect the two magnet/sensors to be quite separated to avoid any interaction.
Max.
 

mcardoso

Joined May 19, 2020
152
If you are seeing A and B phases perfectly opposite eachother (inverse) then what you describe doesn't surprise me. You are NOT getting a proper quadrature signal. This would look like two square waves 90 degrees out of phase with eachother. This creates 4 unique states and a mechanical/electrical directionality to the signal. See the image below:

1600181688203.png

I'd have to assume the product was made incorrectly. You can get a new one, or you can try to repair it. Your goal will be to get two signals that transition on-off at different times. It doesn't matter so mach that they are perfectly evenly spaced, although your speed measurement accuracy will suffer if they are not.

@MaxHeadRoom, I think these cheap hobby motors are sold with integral quadrature encoders to allow people to add position/distance/speed measurement to their robots. They aren't high resolution, but it doesn't matter.

Also as an aside, the only way to effectively measure this signal with a microcontroller is to use two independent hardware pin change interrupts. You can also offload the measurement to an external encoder counter chip if needed.
 

MaxHeadRoom

Joined Jul 18, 2013
21,402
The OP has a 'scope, so it should be very easy to confirm what appears to be an error in either the read head spacing or the magnet placing, it would be interesting to know the method they are using, presumably the magnets are carried by the disc past a stationary pair of proximity magnetic sensors.
Which in that case, there must be a method to position the sensors to the correct 90°.
Max.
 

Thread Starter

elpidiovaldez5

Joined Mar 9, 2016
4
@MaxHeadRoom They are indeed cheapo brushed DC motors. I want to get the bad one working because I built an entire 3D printed design around using these motors. If I change the motor, I'll need to redo a ton of work. I could just try to get another. from China, but I cannot rely on the same type being available, and they will take weeks to arrive.

The sensors are soldered in position on a small,circular circuit board , mounted on the back of the motor. There is no way to adjust the position. That is why I find the problem bewildering. My 'scope shows clean square waves on both channels in exact antiphase. Neither channel is stuck at 0 or 1. I considered that one channel was being derived erroneously from the other, but my experiment with a neodymium magnet shows both sensors can be switched separately. The only conclusion is that the magnets in the axle mounted disk are wrong, but that seems so unlikely....

@mcardoso certainly the phase of the signals is totally incorrect. There is no evident placement error in the sensors. It is not easy to see what is going on with the rotating magnet. I still have not been willing to use enough force to pull it off motor. The antiphase signal also explains the readings from the microcontroller, as the data channel is switching state at the same time as the clock edge. The result is a largely random result influenced mostly by noise.

Thanks to both of you for taking the trouble to help.
 

MaxHeadRoom

Joined Jul 18, 2013
21,402
If you wanted a sub, there are a few dual-opto isolator versions on ebay that will give you a quadrature count, also easy to make your own, especially for that coarse a resolution.
Max.
 
Top