Download PDF version
By Alex Latham and Wade Bussing,
Allegro MicroSystems, LLC
This application note is a guide through the design process for using angle sensor ICs for linear position sensing, including magnet choice and orientation, output linearization, and using sensor IC arrays for extending the measurement range. Test data from a number of magnets and sensing lengths is also provided to show how well the theoretical and real-world accuracy of these solutions match.
Accurate, low-cost, and non-contact linear position sensing is often accomplished using a bar magnet and a magnetic sensor IC or array of sensor ICs. The magnet is attached to the moving object, and the sensor is positioned such that the magnet slides by it. The typical configuration and fields seen are shown in Figure 1. As the magnet slides by in the x direction, the field in the y direction looks like a sine wave with the magnetic field versus position being linear around x = 0.
There are a few challenges to this approach of linear position sensing, including:
All three of these issues are addressed by measuring the angle of the magnetic field versus position.
The Allegro A1335 magnetic angle sensor IC is wellsuited for linear position sensing using the Angle Method described above, as it provides advanced features beyond accurate angle measurement, such as:
The A1335 is available in a TSSOP-14 package (or dual-die TSSOP-24 for systems needing redundancy) and measures the angle of the magnetic field in plane with the package. This means that for linear position sensing, the IC needs to be oriented perpendicular to the magnet motion, as shown in Figure 4. The effective air gap is the distance from the center of the magnetic sensing array (Circular Vertical Hall sensor) to the edge of the magnet. The CVH is off-center in the A1335, so that can be used to help increase or decrease the air gap in the system as needed.
The appropriate magnet size and nominal air gap must be chosen for the stroke length being measured to create a system with the desired accuracy. Mainly, the system needs to be designed such that:
While this seems like a lot to balance, there are a wide range of magnetic systems which will work for a particular application, and each variable in the magnetic system has a specific impact on the accuracy, allowing adjustments to be made quickly to improve performance, reduce cost, etc.
Overall, for a given stroke length, LS, a reasonable design to start with is:
L = LS × 0.65
d = D = 0.4 × L
From there, these parameters can be increased or descreased in order to meet the goals of the application.
To determine whether the system will meet the design goals, the magnetic fields need to be modeled. While using advanced 3D magnetic modeling software will yield the most accurate result, it is not necessary in most cases. Fields can be modeled accurately enough using free 2D simulation software available online. Alternatively, the fields can be fairly easily computed in the case where a cylindrical magnet is used, and a MATLAB function for doing this is provided in the Appendix. A bar magnet of similar size will result in nearly identical fields. Figure 7 shows the theoretical angle versus air gap for a cylindrical magnet using these equations, as well as the experimental results using the A1335— the two match well.
Depending on the needs of the system, different linearization or calibration methods may be used. Here, a method for linearizing the output of the A1335 versus position using the Allegro A1335 Samples Programmer is described. This method can be applied to every system, or the results can be used from one system and apply the found coefficients to all the other systems to get similar performance with less impact to test time in production.
An example of a linearized sensor output is shown in Figure 8. Here, the position was changed 2 mm for each linearization point, mmstep = 2. This means that Cpmm = 256/2 = 128 codes/mm, which is the slope of the sensor output after linearization, as seen in Figure 8. Also, at position X = 0, the sensor outputs 2048.
Linearization results are provided below for three different magnets over different stroke lengths. The key values for each magnet used are given in the table below (all magnets are Neodymium):
|1||6.4 mm||15.9 mm||25 mm||2 mm|
|2||9.5 mm||19 mm||30 mm||3 mm|
|3||12.7 mm||38.1 mm||50 mm||4 mm|
The plots below for each magnet show the output angle versus position and the error in the measured position versus position over multiple air gaps. The error is based on the ideal sensor output, which should be:
Rearranging this shows how to convert from the sensor output of the A1335 to an X position.
The error is then just the difference between the actual X position and the calculated X position from the sensor IC output. For Magnet 1, this error is shown in Figure 9.
One of the main benefits of using the Angle Method for sensing linear position is that it is highly accurate over both air gap and temperature. The previous sections all dealt with accuracy over air gap. Accuracy over temperature is mainly dependent on the angle accuracy of the sensor used.
The accuracy of the A1335 over temperature is around ±1.3 degrees; however, this must be converted to millimeters in the system. As the angle error is relative to the nonlinearized angle output, the raw angles being swept, which is around 180 degrees over the full stroke, must be considered. This can be seen in Figure 2. The error in position measurement can then be calculated as:
For a 25 mm stroke, LS = 25, the error over temperature would be ±0.18 mm. The position resolution can be calculated using essentially the same method. For the A1335, the angle resolution is 0.8 degrees (3 sigma). This means that the position resolution for a 25 mm stroke will be 0.8 / 180 × LS = 0.11 mm. Of course, if internal filtering of the A1335 is enabled or number of readings are averaged, this resolution will be improved.
Extending the sensing range can be done either by increasing the magnet size, following the guidelines above, or by adding more sensor ICs to the system. As the desired stroke length gets larger, the cost and size of the larger magnet will drive the solution towards using multiple sensors. A configuration using multiple sensors is shown in Figure 14. Here, three sensor ICs are used, but this can be extended to n sensor ICs.
The desired stroke length, LS, is divided by n (3 in the case of Figure 14) in order to have an effective stroke length, Lseff, of:
The magnetic system is then designed around Lseff, using the methodologies described above, and the n sensors are spaced Lseff, away from each other, center to center. Besides making the magnet smaller, this also results in lower error over temperature, as LS is reduced:
As the magnet passes beyond the range of one sensor, it enters the range of the next sensor. Determining which sensor IC to read the position from is fairly simple with the A1335. During normal operation where the position is periodically measured, if the position reading from the sensor currently being used goes beyond Lseff / 2 in either direction, switch to the next sensor over. To avoid switching back and forth between two sensors a lot right at Lseff / 2, some hysteresis can be added to this switchover, waiting for the position to go a little beyond Lseff / 2 before switching. At startup, or after a long period of not reading the position, it may be necessary to determine which one out of the n sensors to use for reading the position. The challenge here is that if n is large, some of the sensors may not have enough field on them to give a valid output. Here, the low field error register of the A1335 can be used to determine which sensor outputs to ignore. Then, of the sensors which are giving valid outputs, the one giving an angle output closest to 180 degrees should be chosen as the active sensor.
Overall, magnetic angle sensor ICs work significantly better for linear position sensing than single-axis magnetic sensor ICs. The Allegro line of CVH-based angle sensor ICs, such as the A1335, are well-suited for these applications, providing advanced features, such as piecewise linear (PWL) linearization and addressable SENT, I2C, or SPI, which help extend the usable sensing range from a magnet, and simplifying and reducing the cost of the total system.
function [Bz,Br] = cyl_field(B,L,Radius,z,r)
% Bz and Br are the Z and Radial direction of the field from a cylindrical magnet
% where B is the residual inductance of the material, L is the length of the
% magnet, and Radius is the radius of the magnet.
% z is the distance from the center of the magnet along the z axis, and r
% is the distance from the magnet in the radial direction.
bz = @(R,phi,z,L,r) R.*(L/2-z)./((R.^2+(L/2-z).^2+r.^2-2*R.*r.*cos(phi)).^(3/2))...
br = @(R,phi,z,L,r) -R./2.*(2.*r-2.*R.*cos(phi))./((R.^2+(L/2-z).^2+r.^2-2.*R.*r.*cos(phi)).^(3/2))...
% Fix the field calculation value if one is inside the magnet
if (z <= L/2*1.01) && (z > -L/2*1.01) && (abs(r) <= Radius*1.01)
Bz = B/2;
Br = 0;
Bz = -B./(4*pi)*integral2(@(R,phi)bz(R,phi,z,L,r),0,Radius,0,2*pi);
Br = -B./(4*pi)*integral2(@(R,phi)br(R,phi,z,L,r),0,Radius,0,2*pi);