Evaluation Type: Evaluation Boards
Did you receive all parts the manufacturer stated would be included in the package?: True
What other parts do you consider comparable to this product?: The MA732 rivals optical encoders from Avago and Bourns in many aspects. The MA732 is vastly lower-cost.
What were the biggest problems encountered?: Due to the large kit, it was a bit tricky finding all the relevant datasheets. However, I really appreciated the RoadTest guide document that MPS created, it helped a lot.
How does the MA732 Sensor work?
Assembling the Motion Generating feature
Assembling the Sensing Feature
Motor Speed Measurement
Angle Measurement Granularity and Accuracy
Quadrature Rotary Encoder Output
Synchronous Serial Interface (SSI) Output
Getting Started with the MA732
Often there is a need to determine angle or speed or shaft rotations with a high degree of granularity and precision. One typical sensor is called an optical rotary encoder. The sensor contains LEDs and photodiodes and a precisely cut optical disk. Such rotary encoders are expensive and have a number of drawbacks. There is a risk of dirt getting into the encoder. The encoder’s own shaft requires coupling to the shaft that is to be measured, and doing that reliably is costly from a mechanical point of view. The cost of optical encoders means that they are used in industrial applications, and, instead, mechanical non-optical encoders get used everywhere else; they suffer from a reduced operating life and contact bounce, but at least are cheap.
I was skeptical in the past that a magnetic sensor could offer a decent alternative to an optical rotary encoder. However, when this RoadTest was launched for a magnetic sensor from Monolithic Power Systems (MPS), I read a little about how the sensor worked and was really interested to know how it would perform in practice.
The breadth of applications is immense. If the sensor works well, then it could be useful for astronomy, radio antenna positioning applications, robotics, CNC positioning and readouts, and so on. The sensor is very low-cost; under £3.50 in quantities of 25, and is very high-resolution (up to 14 bits). The sensor uses a neat signal processing technique to achieve this, and I was keen to try it out.
Testing a magnet sensor for properties like angle and speed measurements requires a way to generate precise rotary motion, and for this RoadTest, MPS kindly provided a very comprehensive kit that not only allowed for sensor measurement, but also for motion generation, using a special motor (servo motor).
How Does the MA732 Sensor Work?
The technique used is very novel. The problem that the technique solves is this: If you take a non-moving shaft with a magnet on the end (note that the magnet would be diametrically magnetized as opposed to axially magnetized; see the diagram for an explanation), and wished to sense its angle, you could measure the magnetic field strength and the strength of it would be related to the angle, however, that wouldn’t be very accurate because the value would be dependant on the distance between the magnet and the sensor, plus, the value could also drift.
If instead, you could spin the sensor really fast (assume the magnet in the diagram above is still stationary), you would get a sinewave output because the magnetic field strength of that diametrically-magnetized end varies in a sine wave depending on the angle. You could measure the time between the beginning angle of the sensor spin cycle and the sensor output (at say the peak, or instead the zero-crossing point) repeatedly, and the time would be directly related to the angle! It would not be affected by the vertical distance between the sensor and the magnet, because even though the overall output level may change, the peaks and zero crossing points would still occur at the same time regardless of the distance; it’s purely related to the rotation angle, and not the vertical distance from the sensor. It’s hard to physically spin a sensor, so the MPS solution is to place many sensors on a chip, in a formation like orange segments, and electronically select them in sequence rapidly. The end result is no different from if there were a single sensor being spun!
The MPS solution switches the sensors in the circle at extremely high speed, and this means that the shaft can rotate at a very reasonable rate (up to 60,000 RPM) and the MA732 can still resolve the position and allow for shaft speed determination too.
The next question is how does the MA732 precisely measure the time period, or, alternatively, the phase difference? That is implementation-specific inside the chip, and I don't know the detail. Perhaps the device might be performing synchronous demodulation to determine that, but it’s not documented (it may be proprietary). In any case, once the time period or phase is determined, it is made available to the user through several interfaces – SPI, SSI, PWM, and A/B quadrature outputs that toggle like a normal optical or mechanical rotary encoder! This means that it is really easy to integrate the MA732 into both new circuits, as well as retrofit.
Incidentally, the Monolithic Power Systems (MPS) solution also works with the sensor at the side of the magnet instead of end-on, however then the orthogonal sine wave internal measurements for X and Y have very differing amplitudes, and that means a phase or angle error; to correct that, there are registers within the MA732. For end-on magnets, there is no need for such correction (provided the magnet is reasonably well-centered, as will be shown in the review).
Yet another interesting capability is the detection of overall magnetic field strength exceeding a configurable threshold. This could come in handy for user interfaces; a completely electronic rotary knob with push-button could be implemented, with no mechanical contacts!
MPS went to town to supply a decent test kit. It’s very comprehensive – a load of equipment to try out the sensor. I really appreciated this, because it made my life a lot easier.
In summary, the kit does two main things: Firstly, it provides the sensor itself (with a way of attaching it to a PC for monitoring), let’s call all of that the Sensing Feature for want of a better name.
Secondly, it provides a motor that can generate precise speeds or angles, again under the control of a computer; let's call it the Motion Generating Feature.
Using the two features, you can instruct the motor to run at a specific speed or to move and halt at the desired angle, and then you can observe what the sensor makes of it.
In essence, the kit provides a shaft with a magnet, and an MA732 sensor, already attached to a special motor called a digital servo motor, along with adapter boards to control the motor from a PC and to monitor the output from the MA732 sensor from a PC. The supplied parts are based on kit EVKT-MSM942038-24 (PDF datasheet) but MPS has added the MA732 sensor and an Arduino Mega for this review.
The point of all of that is, that the special motor can be rotated to desired angles, and spun at desired speeds, all under precise PC control, and the MA732 output can be observed.
The diagram above shows how the kit can be used. The kit breaks down into the mechanics (motor and the magnet), as well as the control and sensing portions. The motor control is done using an Arduino connected to the digital servo motor through an RS-485 adapter (RS-485 is similar to UART, but uses two wires with different voltage levels). The sensor output is read by an NXP microcontroller board and sent to the PC, where it can be displayed using MPS-supplied software called Macom.
To summarize, the kit allows the user to spin the motor at precise speeds (and to precisely position the shaft) using the Arduino, and then the MA732 sensor output can be observed.
I won't go into more detail on the individual kit components here, but if you're interested, see the RoadTest unboxing blog post.
Assembling the Motion Generating Feature
An important part of the testbed is to be able to generate stimulus motion for the sensor, and this section describes how I did it. MPS supplied an Arduino board to help with this, but I used a Pi Pico instead. The diagram below shows all the connections needed between the Pi Pico and the RS485 board and the Servo motor:
The Pico was set up with the MicroPython environment, and code called mps_motor.py was written and uploaded to the Pico. When connected to the PC, it is possible to issue Python commands to control the motor as shown on the left side in the diagram above. For instance, typing m.set_velocity(400) will set the motor rotation speed to 400 RPM. The benefit of the MicroPython environment is that it provides a very powerful command line, so that the user can type instructions on-the-fly to test things, without needing code compilation each time.
Assembling the Sensing Feature
One main function of the kit is to allow the measurements from the MA732 sensor to be monitored or logged. The sensor was attached to the PC, via the supplied NXP board with its pre-installed software, which talks to the PC using an MPS Windows app called Macom. The photo below shows how it was set up.
With all this set up together with the motion generating capability discussed earlier, I now had a complete setup to test the sensor!
Motor Speed Measurements
The sensor is very suitable for shaft rotation speed measurements. I set up the motion generating feature to spin the motor at 2500 RPM, by typing the following instructions at the Pico’s Python prompt:
import mps_motor as m
The Macom app on the PC provided information from the sensor. The screenshot below from the app shows the shaft angle changing from 0 to 360 degrees, in a straight line, indicating constant rotary speed.
What’s really cool is that you can see the angle error and speed ripple across the 360-degree rotation too, so you can get a very good idea of the sensor performance in shaft speed monitoring use cases. The Macom app computes that by looking at the endpoints (since it is clear when the shaft has rotated 360 degrees, and it assumes that the shaft is rotating at constant speed) and then looking at the non-linearity of the measurements versus a straight line.
As you can see from the screenshots below, the angle error and speed ripple have a pattern to them; there are four quadrants in time. I believe the majority of this is due to the sensor, and it is within spec. The datasheet specifies a maximum angle error (it is specified as an integral non-linearity or INL in the datasheet) of +-0.7 degrees.
The Macom app dashboard also provides a load of stats:
From the above stats, it can be seen that the sensor and app correctly measured the motor speed to be 2500 RPM, and the app computed the non-linearity (i.e. the ripple visible on the Angle Error chart) to be +- 0.448 degrees, and that this resulted in a speed ripple of just +-35 RPM at 2500 RPM actual speed. Note that this is based on the servo motor providing a constant, and accurate speed, which is an assumption I will live with for now : )
The Macom app can be used to show the angle of the shaft. To test this, I set the motor to a fixed position by typing the following at the Pico’s Python command prompt:
import mps_motor as m
Now it was possible to rotate to any angle (relative to the current position) by typing (say):
m.set_position(m.CW, m.ZERO_TURNS, 10)
The above command slowly rotates the shaft clockwise by 10 degrees.
It is possible to rotate by 370 degrees (i.e. one complete 360 degree turn and an additional 10 degrees) by typing:
m.set_position(m.CW, 1, 10)
It was fascinating seeing the precise angle displayed on the Macom app : ) The animated GIF shows an example where the shaft is no longer rotating. The ‘Raw Input’ value shows the computed angle. There is some noise on it, but if slow measurements are needed, then it is possible to filter the data (the MA732 chip can do that automatically, with a register setting).
In the animated GIF above, the value underneath the text Resolution is related to the internal filtering that the MA732 chip performs; the cut-off frequency is 370 Hz according to the datasheet.
The Macom app allows for data export, but it is limited to 2000 samples. I plotted those samples, to get a better idea of the noise:
There is a chart in the MA732 datasheet that shows that (for a certain magnetic field strength) the noise is about 0.4 thousands of a degree per root Hertz, and is almost flat to 10 Hz, and then drops off, but there is still noise density of 0.08 thousandths of a degree per root Herts present at around 100 Hz. The power spectrum in the chart above shows a similar thing. For static measurements, it would be good to filter the data further. Even just filtering at 100 Hz, will reduce the noise down to one-fiftieth of a degree with the sampled data displayed above. However, the MA732 can be configured to perform the filtering. By changing a Filter Window register value, the effective resolution was increased to approximately 13.5 bits (for anyone wanting to replicate this, the FW register value was changed from the default 119 to 187). The animated GIF below shows the result (I set the shaft position to approximately zero degrees just for clarity). Now the observable noise is down to a few hundredths of a degree (see the animated image):
The chart below shows the captured data, which I decided to sample at 1 kHz. The noise is very low as you can see from the y-axis : )
Angle Measurement Granularity and Accuracy
The noise on angle measurements was investigated above. However, another question that could be important depending on the use-case, is just how granular is the measurement?
I had a motor with harmonic drive, which might be accurate to perhaps 0.05 degrees. Such a testbed would require me to obtain a suitable magnet, attach it to the harmonic drive, and find a way of positioning the sensor board in front of the magnet. This is not too dissimilar to the work that would be involved in using the sensor for any commercial project development, so I decided to give it a shot.
The MA732 board is nicely laid out, so there was no need to build a custom PCB. I used the dimensions above to build a sensor mount, using sheet plastic and engineer’s Lego (also known as hex spacers). I had to make a custom mount for the magnet. I went with an e-bay magnet, 6 mm diameter, and 1 mm thick. It needs to be diametrically magnetized as mentioned earlier.
The connections to the board require 8-way 1.27 mm ribbon cable and a Wurth 690157000872 plug.
I learned from the exercise that if you’re doing R&D with the MA732, it’s highly recommended to purchase a 3D printer if you don’t already have one. I spent most of one day manually building the mount for the magnet and the sensor, and I regretted not having a 3D printer.
Anyway, I used what I had, and the setup worked well!
I think this shows, that even without the most optimal magnet, and without the accuracy of CNC or precision moldings, it is still possible to get very decent results with the MA732 for a prototype.
That’s not to say no care should be taken of course. I used calipers to check things, a low-cost milling machine to get holes vertical and centered, and took my time trying to keep the tolerances in the setup as low as possible and to try to keep the magnet flat and in line with the motor rotation axis. I took a guess and positioned the magnet 1 mm off the surface of the MA732. The great thing is that it all worked the first time, with zero tweaks. I was not expecting that! I didn’t have to trim anything at all. Once I bolted it all together, I saw no need to loosen the screws and readjust.
The photo below shows how the motor can be controlled (I used a Leadshine DM556 stepper motor controller module visible at the right of the photo). The DM556 accepts step pulses which can be sent from any microcontroller (I used a Pi Pico). I used the Macom app to read the sensor measurements from the USB connection to the NXP sensor interface board (incidentally, I then removed the NXP board to use my own code, there is more detail on that in a section further below).
Although there is no register that reports magnetic field strength, there are a couple of threshold registers, and from looking at the alarm flags using the Macom app, I can tell that the strength is not so low to trigger the low-strength alarm, and it is not so high to trigger the high-strength alarm. That gave me confidence that the magnet and its positioning were good, although, in a real design, you could either measure the magnetic field with a suitable gaussmeter and probe, or you could use a known suitable magnet intended for the sensor (they are available from the sensor manufacturer). However, the Amazon magnet works fine! : )
I wrote a script to automate things. In brief, the script records the current sensor angle, and then the harmonic drive motor is stepped by 0.03 degrees (further micro-stepping could reduce this further). After a short pause to eliminate vibrations, the sensor measurement is recorded, and then the motor is rotated by 0.03 degrees again. After 12,000 steps, a complete 360 turn has been achieved. I repeated for 6 turns so that I could examine repeatability. At a rate of just over three pulses per second, it took about one hour per 360-degree revolution.
The sensor performance was pretty stunning. The chart below shows (in different colors) the error for each complete rotation (Note: the assumption is that the motor with harmonic drive has no error, but of course, this is a limitation of my testbed, I cannot distinguish between that error and the sensor error). The chart shows that the maximum error was about 1 degree, and I believe this will partially or almost entirely be caused by the magnet not being precisely in-line with the motor rotation axis. Still, this goes to show that even using manual techniques to make the sensor and magnet mount, and an Amazon-source magnet, can still provide very good results with no adjustment. The error is repeatable, and that means that it would be easy to calibrate out, provided that the mechanism can be stepped precisely, or if the mechanism can be rotated at a constant speed. With such calibration, the error could have been at least one order of magnitude lower.
Some smaller ripples can be seen on the error. I don’t know if it is due to the harmonic drive, or due to the sensor. From the chart below, there are around 62 ripples per 360 degrees (but again this could be calibrated out).
Using the data from the first motor revolution as the calibration data, the chart below shows the error that could not be calibrated out. The y-axis shows that the error was typically under +-0.1 degrees.
Further averaging (by taking 16 repeated measurements at each step, and averaging them) improves things a little further as shown in the chart below, but there are diminishing returns. Temperature changes will also make a difference (the environment was a room where the temperature may have changed by 5 degrees or so during the six hours it took for the six revolutions).
I wanted to see what would happen if the sensor or magnet was deliberately off-centered slightly. The testbed has little slack in it since I originally wished to have things as centered as possible! For the next test, I merely applied a bit of sideways force to the blue plastic sensor mount. I did that by slipping a coin under the plastic, and putting a small weight (a few hundred grams) onto the motor. I tried that against the adjacent side too. I ran the test speeded up a hundred-fold (steps of 3 degrees instead of 0.03 degrees). The results show negligible difference; I cannot see anything significant. A real deployment wouldn’t use long thin brass spacers as I did (they were 30 mm long) to support the sensor, I think a real deployment would have stiffer shorter mouldings even if they were plastic rather than brass, so it was good to see that it’s not a difficult barrier to achieve a sufficiently rigid solution for the MA372.
The MA732 has a PWM output pin, that can output a signal with no microcontroller or any configuration required; the output is always present, so you could use it to (say) provide a longer distance communication method, instead of using SPI. The PWM is at approximately 1 kHz (I measured 980 Hz), and it’s pretty accurate and stable. The output positive duty cycle as a percentage is angle/360 * 100. You could use this to drive dimmer circuits for lighting since many dimmer modules accept PWM at this frequency range.
The screenshot below shows the output at 40 degrees rotation.
If the zero position angle is not ideal for the use-case, then the MA732 can be configured (via SPI) to set the zero position to any arbitrary angle.
Quadrature Rotary Encoder Output
The MA732 has quadrature outputs that could be handy for retrofitting it into systems that previously used optical or mechanical rotary encoders. The output is noise-free, unlike mechanical encoders. The screenshot below shows the output when the shaft is rotated at a slow approximate 5 degrees per second (I know this because I set the stepper motor spinning slowly, and timed 360 degrees of rotation with a stop-watch, for an approximate value; I could have used the servo motor supplied with the kit for setting a very precise speed, but it was unnecessary for this test). Since the default number of pulses per turn is 1024, I expect to see a frequency of about (5/360)*1024 which is what the ‘scope shows.
Incidentally, the number of pulses per turn can be configured using SPI, to any value up to 1024. Also, all registers are non-volatile, so there’s no need for a microcontroller after it has been initially configured.
Synchronous Serial Interface (SSI) Output
The MA732 supports yet another output protocol! called SSI. The interface provides a high-speed clocked serial output that is used with industrial controllers. I have no equipment which supports it, and I didn’t try it. If you’re interested in extending the distance between the sensor and the monitoring system, then SSI is worth investigating.
Getting Started with MA732
If you’re interested in using the MA732, then it's very low-cost to do so. The sensor board costs about £10. Beyond that, all that’s needed is a bit of ribbon cable and a Wurth 690157000872 connector (or just solder-tack wires to the pads since they are well-spaced). I attached normal 0.1” header sockets on the other end, so that I can easily connect it to a microcontroller.
No microcontroller is needed if you’re OK with the PWM or quadrature rotary encoder outputs.
I used a Pi Pico and Python to interface using SPI, and the source code can be easily inspected and adapted if you wish to use a different microcontroller. From a software perspective the MA732 is one of the easiest sensors to code for. There are only a handful of registers.
I really liked that I didn’t need to do anything special to store configuration; the MA732 automatically writes to its internal non-volatile memory (NVRAM). Also, I liked that there was no need to implement averaging in the code; the MA732 automatically does that as well. Plus, any computations for handling off-axis magnets are all done by the MA732 too; there is a register that is tweaked (it sets a bias current to make the two internal orthogonal outputs of similar amplitude as mentioned earlier), and the MA732 outputs the angle, it’s as simple as that.
In summary with just these handful of parts and quite simple code, and a magnet (it needs to be diametrically magnetized as mentioned earlier), the MA732 can be evaluated. A 3D printer is recommended to allow the creation of custom mounts more advanced than what I achieved.
The code is on GitHub. To use it, the MA732 board can be connected to the Pi Pico as shown here:
Install the latest MicroPython on the Pico, and then use the Thonny app to upload any of the Python files at the GitHub link onto the Pico, and you can interact with the Python command prompt using Thonny too.
To use the code, type:
import ma732 as sensor
The sensor.read() command will display the current measured angle.
You can read or write any registers using the sensor.read_reg(regname) and sensor.write(regname, val) instructions, where regname can be an integer register number, or a register name such as sensor.MA732_REG_FW
The sensor names are listed in the code with a brief comment explanation (refer to the MA732 datasheet for detail).
If you also have a servo motor from MPS, then you can control it from the Pico as mentioned earlier in this review.
The screenshot below shows some example interactions with the sensor:
The MA732 provides pretty stunning performance. I had not expected that about 1-degree accuracy could be achieved directly from the sensor with no external calibration, and a hand-made sensor and magnet mount, but that’s what was achievable. With a more accurate machined mount, perhaps 3D printed, even better results should be directly possible. With calibration, I saw the typical error drop massively, down to circa 0.05 degrees with the hand-made setup.
The MA732 costs about £3.50 in quantities of 100, whereas an optical encoder would cost five times as much nowadays. In practice, the optical encoder would cost many times that figure yet again, because it is not easy interfacing them (the shaft needs special coupling) whereas the MA732 can handle some misalignment.
I liked that the MA732 is easy to get going with, and it has a large range of outputs to be able to fit it into many diverse designs. I’m going to be recommending this product to friends/colleagues who are interested in rotary position sensing for astronomy solutions, whereas ordinarily, I would not have considered anything other than an optical encoder.
Optical encoders are not always reliable. I have a radio receiver with an optical encoder, that might benefit from an MA732 upgrade one day. The optical encoder was badly specified for this radio because it has a brass bearing, and over the years it has worn out, making the knob have play and knock against its bearing when turning it from one direction to the other – it’s a really irritating problem in an otherwise good radio. The mechanical encoders still work funnily enough – it’s the optical one that has the problem because that knob is spun hundreds of thousands of times on the radio.
The encoder is a Bourns type. It's several decades old. There is also a NiCd battery visible in the photo below! Rare to see those : )
I hope the review was useful. Special thanks to element14 and MPS for providing a very comprehensive RoadTest kit, and a setup document.
Thanks for reading.
Yes, I think so. +- 0.1 degree is very feasible once the non-linearity is removed as shown, and it removes any slight off-axis magnet impact. Then, +- 0.1 degree should be feasible provided the temperature isn't changed dramatically (my test lasted 6 hours and the temperature changed by around 5 degrees during that time). But you can also see that +- 0.05 degree is almost attainable in the results, it was close!
I think the MA732 is excellent for replacing an optical encoder in many scenarios, (and in many scenarios the optical encoder may have less resolution anyway, e.g. 1000 or 2000 counts per turn) but for the ultimate repeatability and precision out-of-the-box then the far more expensive optical encoder and mounting mechanism could be needed. I have a couple of optical encoders which I have struggled to use simply because of the mechanical mounting complexity. The MA732 is much easier in that respect.
Thanks shabaz for your very nice review! I especially liked the test you did with your stepper+ harmonic gear. Initially when I learned about these magnetic angle sensors, I was impressed by the resolution (12-14bits across sensors from various manufacturers), however, I soon realized that in terms of accuracy, the non-linearity is usually much much bigger than the precision. Think of using the sensors on a long-range PTZ gimbal, for example, where a +-1 degree of non-linearity will be a much bigger issue than the14 bit precision. I did think about calibration but didn't know how much that will improve things. Your test gives a good practical overview of how much improvement to expect. You mentioned that after calibration the error was below 0.1 degrees. So 360/0.1 = 3600. This translates to ~11bits of angle accuracy after calibration. So, it looks like if the angle accuracy is very important, we can expect to lose 3-4 bits even after calibration for this type of sensors. Did i get this right?
Thanks DAB for this question; something that I've been wondering about for some time, and thanks shabaz for finally answering it for me. After reading your answer, I guess it makes sense as, like you mentioned, the magnet is much much closer to the sensor compared to any external magnetic fields, including those generated by the motor coils themselves.
Nicely done. Looks like a very good sensor.
A very informative review. The background info is a great learning experience. Thank you.
Good question. It doesn't seem to be affected by earth's magnetic field (I rotated the device), and I don't think I will have any magnet sufficiently strong at a distance compared to the small disc magnet spaced just 1 mm away. There may be a slight difference with extreme fields perhaps, but these sensors are designed for use on shafts near motors so they can handle magnetic fields found in typical expected environments I guess.
Very good review.
I am curious, what would happen if you put a very powerful magnet near the sensor?
Would it interfere with its ability to track position?
Interesting kit and good review!