Application Note – AN222
Electronic Compass Calibration
ABSTRACT
A lot of mis-perceptions have been circling around the idea of calibration for electronic compasses. New engineers
coming to the task of compass integration believe that calibration will fix all the problems of inaccurate heading in
electronic compasses. In reality, judicious system engineering along with the right amount of calibration routines will
provide a good solution for most customers. This application note will address the need for calibration, why calibration is
the solution, and calibration methodologies for both factory and end users.
THE NEED FOR CALIBRATION
Not knowing any better, many design engineers receiving electronic compass integrated circuits or compassing modules
will attempt a calibration before getting familiar with other aspects of compass usage. With complete compass solutions,
Honeywell always factory calibrates every electronic compass product in a clean magnetic environment before the
product ships to customers. In many cases, this factory calibration is likely to be the best calibration available and no
further calibration maybe needed for the life of the product. If non-zero calibration offset values are stored in your device,
it may be wise to record these values prior to starting a new calibration to have a baseline. For partial compass solutions,
the compass IC provides the raw magnetic vectors, and the designer must code a calibration routine into a digital
processor as part of the routines converting raw data to finalized compass headings.
The question often asked is, “When should I re-calibrate the compass?” The answer appeals to common sense when the
compass seems not be reporting accurate headings, or not changing heading output appropriate with the required
mechanical change in direction, or showing a limited range of heading readings when a full zero to 359 degrees is
expected. Even with these indications, be aware that the compass assembly may not recover when a re-calibration is
performed. If you suspect that the compass has been exposed to high magnetic fields like permanent magnets or
energized coils, a demagnetizing wand may be needed to erase the magnetic upset before re-calibration. While the
magnetic sensors can de-gauss themselves after high field exposure, the surrounding components and assemblies do not
have built-in demagnetizing coils and the demagnetizing wand is the next logical process to remove stray magnetization
from ferrous metals near the compass circuits.
CALIBRATION INSTANCES
When calibration capability is required, many different types of calibration can be performed. The first calibration is
typically a factory calibration, and which may be a simple insertion of factory standard calibration offset values that were
found during early builds of the product. Most factories do not spend the time or labor to individually calibrate compass
circuitry unless the wiring harness or build layout changes from unit to unit. Of those factories that have consistent
hardware test location and factory calibrate the compass, most will see fairly repeatable calibration offset values and will
normally discontinue the practice. Most factory calibrations are done under reasonably clean magnetic field conditions,
with no need for special magnetic test apparatus like Helmholtz coil sets or zero gauss shielded chambers.
The other type of calibration is called end-user calibration. These calibrations are added to the stored factory calibration
data to handle the magnetic anomalies that the user incorporates in the mounting of the product with the compass
integrated. A classic example is an automotive wireless phone cradle, in which factory calibration typically is good enough
for hand-held use of the phone, but another calibration would be appropriate for the cradle location to calibrate out the
magnetic influences of the automobile and the phone cradle. Normally hand held applications do not require periodic re-
calibrations as most users do not contain any significant body structure that distorts the earth’s magnetic field.
It is very important to understand that calibrations can not remove the magnetic effects of larger environmental items that
do not move with the compass. While it is possible to calibrate out compass mounts like cars, planes, and ships;
calibrations can not remove effects of non-mobile structure like buildings, furniture, concrete reinforcing steel, and
electrical wiring.
AN220
2 www.honeywell.com
HOW AN ELECTRONIC COMPASS WORKS
Just like a mechanical needle compass, an electronic compass responds to the earth’s magnetic field which is about 0.5
gauss in strength. Because a compass desires the earth’s field direction as the output, two kinds of problems can occur to
cause errors in compass heading accuracy. The first problem type is nearby ferrous metals distorting the earth’s field
direction by being in proximity to the compass. The second problem type is stray magnetic fields coming from non-earth
sources that combine with the desired earth’s magnetic fields to cause heading errors. A typical needle compass can not
correct for these errors, and makes a good detector of field distortions from these problems.
In a simple 2-axis electronic compass, two directional sensors are placed orthogonal to each other in a level plane and
described as X and Y sensors. Typically the X sensor is defined as the north reference sensor on the product, so that the
product pointed in the north direction provides maximum positive voltage from the X sensor. It is expected that both
sensors have a bi-polar output so that a south direction provides a similar negative voltage from the X sensor with near
zero volts output at the east and west directions. Given that the Y sensor points orthogonally east when the X sensor
points north, the compass heading equation is:
Heading = Azimuth = arctan (Y/X) in degrees ( 0 to 359)
Figure 1 shows these plots as cosine (for X) and negative sine (for Y) as compass magnetic sensors are rotated
clockwise from north. Figure 2 shows an ideal plot of output if X and Y outputs are plotted two dimensionally with rotation.
Figure 1
Plot of X and Y Sensor Outputs with Rotation
Figure 2
Plot of X Versus Y with Rotation
-100
-80
-60
-40
20
40
60
80
100
Direction (degree)
O
ut
pu
t (
%
FS
)
X Y
-20
0
30 60 90 12
0
15
0
18
0
21
0
24
0
27
0
30
0
33
0
36
0
AN220
www.honeywell.com 3
Typically a compass calibration routine for a 2-axis electronic compass involves a flat, level, rotation in which X and Y
data is collected at a rapid rate, and the information is acted on upon the completion of the rotation. The speed of the
rotation depends on the data collection rate and amount points on the circle the designer requires for a good quality
calibration. It is common that one data point per degree of rotation is desired, so that a ten updates per second electronic
compass would require about a 36 second rotation to gather all the directional data. If a slow consistent speed rotation is
not likely, multiple faster rotations could be used to statistically gather the same data.
CALIBRATION FOR 3-AXIS COMPASSES
For 3-axis compasses, the third axis magnetic data is used with additional tilt angle data from MEMS accelerometers to
create a tilt-compensated compass heading output. Compass headings are two-dimensional by definition, and tilted
compasses would indicate errors in heading if not corrected by gimbaling, either mechanically or mathematically. To
convert the XYZ magnetic data and pitch and roll angles, to tilt-corrected X’ and Y’ data for the arctangent solution; two
“flattening” equations need to be solved for 3-D to 2-D conversion. These are:
X’ = X cos φ + Y sin θ sin φ – Z cos θ sin φ
Y’ = Y cos θ + Z sin θ
With φ being the pitch angle in degrees, and θ being the roll angle in degrees.
Just like the 2-axis calibration routine, a flat, level, (yaw) rotation should be done to collect the best X and Y data. Ideally
two additional pitch and roll angle rotations should be done to collect ZX and YZ circle data. However, in many instances,
quality rotations can not be done at all, or only an upside down measurement for the Z-axis calibration offsets. Obviously
hand held products can be oriented in most any fashion, but compasses mounted to cars, boats, and aircraft can not
perform severe tilt data collection. In these cases, the z-axis offset data is left at zero value for the next best calibration
acceptance. To see an end-user perform these manual rotations, especially while standing, many observers may call the
rotary calibration routine the “chicken dance” in reference to folk music dancing.
CALIBRATION ROUTINE TYPES
Electronic compass calibration is done to eliminate two kinds of distortion of the earth’s magnetic field. Hard-Iron distortion
is described a man-made stray magnetic fields that are combined with the earth’s magnetic field. These stray fields may
come from permanent magnets, solenoid coils with currents flowing, and by ferrous metals with inadvertent magnetization
applied by previous proximity to magnets. Soft-Iron distortion is caused by proximity to ferrous metals that attract the
earth’s magnetic field (flux) and bend into the metals. Because the ferrous metals have lower magnetic “reluctance” than
the surrounding non-magnetic materials, all magnetic fields tend to concentrate in lower reluctance materials and de-
concentrate in surrounding higher reluctance materials. This “stealing” of fields creates localized bending of the magnetic
fields which leads to erroneous heading indications by compasses. A classic example is a steel-hulled ship in which the
earth’s south-to-north magnetic field bends into the steel if nearby. Figure 3 shows typical hard and soft-iron effects on
plots of compass calibration circles.
Figure 3
Distortion Effects on Compasses
AN220
4 www.honeywell.com
CALIBRATION FOR HARD-IRON DISTORTIONS
In practice, many soft-iron distortions can be designed out of compass assemblies, leaving only hard-iron distortion effects
to be calibrated out. By just offering a hard-iron calibration routine, many products will have sufficient goodness of
performance with just hard-iron distortion compensation. Since hard-iron distortion comes from man-made magnetic flux
sources, these stray sources are additive with the desired earth’s magnetic field. When plotted linearly, the data shows a
single cycle error when compared to a perfect plot. When viewed on the X versus Y rotational plot, the stray field pushes
the perfect circle of the earth’s field off from origin of the axis. Calibration routines for hard-iron distortion require complete
rotational data collection, or just a couple of orthogonal data points to derive the amount of offset the circle needs to be
pushed to re-center on the axis origin. Figure 4 shows pictorially what needs to happen.
Figure 4
Hard-Iron Distortion Calibration
In hard-iron calibration routines, the simplest methods are to cue the user to begin the rotation or change in position while
collecting the XYZ data and storing the minimum (min) and maximum (max) values and discarding values within the min
and max range. As the user cues the processor at the end of the rotation, the min and max values of the X, Y, and Z axis
are processed for span and mean values. Basic hard-iron correction will only use the mean values as calibration offset
correction numbers to slide future raw magnetic vector data back towards the origin, removing the stray field effects.
Simple equations for the offsets are:
X offset = Xmean = Xmax + Xmin
Y offset = Ymean = Ymax + Ymin
Z offset = Zmean = Zmax + Zmin
Since the min values are typically negative signed numbers, the addition creates the mean values. When applying these
offset calibration values, the raw data just has the offsets subtracted to create the calibration compensated values such
as:
X = Xraw – Xoffset
Y = Yraw – Yoffset
Z = Zraw – Zoffset
Because some stray fields may interact with the sensors in a non-linear fashion, some “oval-ization” could occur and
would need to be removed. To detect this, the span values for X, Y, and Z would need to be calculated from the min and
max values. These would be:
AN220
www.honeywell.com 5
Xspan = Xmax – Xmin
Yspan = Ymax – Ymin
Zspan = Zmax – Zmin
With the min values nominally negative signed, the numeric distance or span is computed for all the magnetic vectors.
Given floating point processor capability, the largest span value is noted and defined as the numerator for expansion
equations provided below to correct the mean or offset values of the other vectors. This is shown as:
MAXspan = the largest of Xspan, Yspan, or Zspan
Xoffset’ = Xmean * (MAXspan / Xspan)
Yoffset’ = Ymean * (MAXspan / Yspan)
Zoffset’ = Zmean * (MAXspan / Zspan)
These new offsets are then applied against the raw data before heading computation. Beware that the Z axis data should
be truly rotational if the Zmin and Zmax values are to be trusted. While right-side-up and upside-down two-point
collections of the Z-axis could be used, the values must be acquired with the compass reasonably flat.
EXCESSIVE HARD-IRON DISTORTION
While some amount of stray field correction is possible using the hard-iron calibration routine, overly large stray fields can
not be electrically handled without significant loss of compass accuracy. For most automobiles with compasses, the
manufacturer designs the compass magnetic dynamic range for +/-2 gauss so that the earth’s magnetic field range of
about +/-0.5 gauss can be added up to +/-1.5 gauss of stray fields from vehicle chassis or engine. Fields beyond the
magnetic dynamic range are likely to be “clipped” by the analog-to-digital converter (ADC). This clipping will show up as
excessive heading errors during a portion of the compass rotation. Figure 5 shows this phenomenon.
Figure 5
Excess Hard-Iron Causing Clipping
The obvious cures for clipping are to reduce the sensor gain to increase the magnetic field range, or to reduce the amount
of stray fields pushing the circular plot into clipping. While gain reduction sounds appealing, reducing the ADC counts per
milli-gauss means decreased resolution and decreased accuracy. For low resolution automotive compasses, this is an
acceptable solution, but precision compass applications like location based services and pedestrian navigation requires
uncompromised resolution and accuracy. In general, excess hard-iron (stray fields) is a designer issue, and better
containment of stray fields is the correct solution. This usually means the use of shielded speakers, motors with better
housing shields, and smaller pellet magnets on slider or flip-phones.
AN220
6 www.honeywell.com
CALIBRATION FOR SOFT-IRON DISTORTIONS
If correcting for hard-iron distortions is not good enough, soft-iron calibration may be required to correct for modest
bending of the earth’s magnetic field. When plotted linearly, soft-iron distortion shows a two-cycle error when compared to
a perfect plot. As shown in Figure 3, most soft-iron effects are the classic tilted ellipse that is centered at the origin. There
are occasions in which an offending ferrous metal contains both hard and soft-iron distortions, and the hard-iron routine
must be done first to re-center the data set before soft-iron correction can be applied. Figure 6 shows a typical soft-iron
distortion on a XY rotary plot.
Figure 6
Soft-Iron Distortion Calibration
Unlike hard-iron calibration, a more rigorous collection of XYZ data points must be captured and stored. This is because a
mean value of magnetic vector must be computed from either 2-axis or 3-axis plot points. As each data set is captured,
the radius from the origin is computed and min and max radii are stored during the rotational calibration. At the completion
of the rotations, the mean radius is computed and used as expansion/compression value to the XYZ magnetic vectors to
re-circularize the tilted ellipse.
To apply a soft-iron calibration correction, all successive captured magnetic vector data is first hard-iron corrected by
subtracting the hard-iron offsets (Xoffset, Yoffset, Zoffset) from the raw data vectors. With the results now centered on the
origin, the dataset radius is computed by the equation:
R = [sqrt(X^2 + Y^2 + Z^2) / 3]
Note that we showing floating-point type computations, which means simple microcontroller ICs will not be able to execute
soft-iron calibration routines.
Since this dataset radius is likely between the minimum radius (Rmin) and maximum radius (Rmax), the XYZ values are
now compressed or expanded to match the mean radius (Rmean) computed by the soft-iron calibration routine. These
equations are:
X’’ = X * (Rmean / R)
Y’’ = Y * (Rmean / R)
Z’’ = Z * (Rmean / R)
After the compression/expansion equations, the magnetic vectors are ready for the heading computation routine. For 2-
axis soft-iron calibration, the Z term is removed and the radii equation becomes:
R = [sqrt(X^2 + Y^2) / 2]
These radius computation equations are used during the rotational part of the soft-iron calibration routine to collect the
min and max radii to compute the mean. Note that soft-iron corrections could be applied to cross-axis sensor errors, but
Honeywell AMR sensors are designed with very small cross-field sensitivities and do not require this correction.
AN220
www.honeywell.com 7
ALTERNATIVE SOFT-IRON CALIBRATION MATH
When encountering soft-iron distortions, a majority of the tilted ellipses are plotted with a near perfect 45 degree tilt on the
rotary plot. If you have the complete calibration datasets stored, the resulting plot could be rotated 45 degrees and
processed just like a hard-iron span correction. Then the data could be un-rotated back to the original position. The
downside to this method, is that all succeeding datasets must go through this rotation and un-rotation process to
compress or expand the magnetic vectors.
Other more complex soft-iron routines do exist, and most involve matrix math solutions and floating point processing to
solve for calibration coefficients to be applied to the raw magnetic vectors. Honeywell acknowledges these methods, and
we shall not detail these routines and leave them pr
本文档为【AN222_20090729】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。