Hall Effect Module Knows Where Your Motor Is

If you have a motor and you’d like to know where the shaft position is, you are likely to turn to an optical encoder scheme. However, as [lingib] points out, you can also use a magnet and a magnetometer. You can see how it works in the video below.

The MLX90393 is a 3-axis hall effect device and, with a magnet on the shaft, the X and Y outputs of the spinning magnet will form a quadrature output that you can easily read.

The magnet is strong enough that the Earth’s magnetic field becomes negligible. Post-processing involves scaling the two inputs to the same amplitude and shifting them so they are centered on zero. Then the angle in radians is the atan2 function of the X and Y coordinates.

We are always entertained by how many ways there are to measure any particular physical quantity. If you want to know more about the hall effect, we have you covered. In addition to magnetic and optical, mechanical encoders are also common.

22 thoughts on “Hall Effect Module Knows Where Your Motor Is

  1. Some advantages of this are no additional moving parts, and even if you are reading at a low rate, you’ll never miss a step (in measurement) since the reading is absolute rather than relative.

  2. So at first glance this is a fun article – until you realize that this is … A very common problem to solve.
    Actually, it’s so common that it is very easy to buy stepper motors that have an extended shaft from the rear side to mount the magnet on. Even better, you can buy stepper modules that have a built-in hall effect rotation encoder, and use it to drive the stepper in FOC.

    Using a 3-axis magnetometer instead of a hall effect rotational encoder, and perhaps a properly mounted magnet on the backside shaft, would yield much better results with less fiddling.

    But to each their own, I suppose.

      1. This *IS* a common task with many solutions.

        Any two hall bipolar sensors aligned at right angles can be used for this. This can be individual bipolar sensors mounted at right angles, or a dual axis sensor made by several manufacturers (TI, AMS, others). The third angle, if present (z-axis) is irrelevant. Even front panel control knobs are offered that can replace optical- or mechanical-shaft encoders.

  3. Unless I’m looking at completely the wrong part the MLX90393 does not output any sort of quadrature output, but is a spi/i2c interface. Which is a shame as quadrature output is a fairly common standard input on a lot of industrial equipment.

    1. That would depend on your definition or interpretation of what ‘quadrature output’ is.

      If you’re looking for a digital output that you might get from an optical or other rotary encoder, then no, it does not (though, ironically, other similar chips to this sensor do have a ‘simulate quadrature encoder’ mode).

      If you want “normalized sine and cosine outputs taking values -1 to +1 as the input rotates through 2pi radians”, then this device also fails.

      However, this does produce a digitized representation of the X and Y components of the magnetic field. If you can do your own offset adjustment and normalization, and calibration if you’re picky, it qualifies as a quadrature shaft angle sensor. As shown in the mercifully short video.

  4. I’m not sure what is novel about this. Magnetic encoders such as AS5047P have been used for BLDC motor control for a while now. The MLX90393 seems very similar albeit 3 axis instead of just 2, but the video does not seem to be using the Z axis anyway.

  5. I have used these Melexis sensors before and they work rather well. However, there is a trap for young players – you can’t use any sort of flat magnet – it must be diametrically magnetized. I.e. not the usual one pole at one end and the other pole at the other.

    Otherwise the sensor won’t be able to sense the orientation of the shaft – it needs to “see” both the north and the south pole at the same time for that.

    Such magnets are not hard to find but unless you are working with magnetic encoders already it is not likely you have one in your junk box.

    1. Yay, it’s Frank! I think Hackaday should feature your tool changer but they didn’t take my tip at the time. Much cooler than the E3D effort in my opinion. Joshua Vasquez would love it!

  6. The AS5600 boards are exceedingly common from Chinese sites at the moment very cheap. They have an analogue output which can be configured as PWM or voltage. They also have an i2c bus where exact rotational position can be gained as a two byte value of 0-4096.
    No “decoding” of quadrature outputs is needed as you just get the accurate rotational position.

    1. The 0-4095 output version is like something someone from 9th grade thought up. It’s naive and nearly useless except for a knob application that is constrained not to rotate 360 degrees.

      Handling the 0-4095 wrap *generally* is actually darned difficult without making a lot of assumptions, special cases, and time-wasting decisions. It’s almost impossible to filter in real time without a bunch of heuristics to handle real-life noise and reversals.

      No, give me the well-behaved sin and cos output any day over the naive, hare-brained and simplistic ramp output.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.