AN2272 PSoC 1 Sensing - Magnetic Compass with Tilt Compensation.pdf

Sensing – Magnetic Compass with Tilt Compensation
Author: Vadym Grygorenko
Associated Project: Yes
Associated Part Family: CY8C27xxx, CY8C29xxx
Software Version: PSoC ® Designer™ 5.1 (SP1.1)
Related Application Notes: None
To get the latest version of this application note, or the associated project file, please visit
AN2272 presents a low-cost, digital 3-axis magnetic compass based on the Honeywell HMC1043 Magneto Resistive
Sensor. A dual-axis accelerometer is used to provide tilt sensing for heading correction. Several full-featured and
simplified design versions are also described.
Introduction ....................................................................... 1
Magnetic Compass Background ....................................... 1
Device Design Basis ......................................................... 3
PSoC Implementation ........................................................ 5
Software Description ......................................................... 6
Compass Calibration ......................................................... 8
Testing Results ................................................................. 9
Simplified Compass Versions .......................................... 10
Summary ......................................................................... 11
Appendix A: Device Schematics ..................................... 12
Worldwide Sales and Design Support ............................. 15
This design implements a 3-axis, magneto resistive
sensor-based digital compass with tilt compensation.
Minimal external components are used, which allows for
low-cost and compact implementation.
Main features of the presented design include:
High precision and resolution up to 0.25 degrees.
Ability to transmit data to a PC via RS-232 interface
for debug and other purposes.
Wide range tilts compensation.
Procedures to store calibration data in the internal
Magnetic Compass Background
All electronic compasses are based on the measurements
of the Earth’s magnetic field. The Earth can be considered
a magnetic dipole with poles located near the geographic
North Pole and South Pole (see Figure 1).
Document No. 001-32379 Rev. *C
Sensing – Magnetic Compass with Tilt Compensation
Figure 1. Earth’s Magnetic Field
Figure 2. Magnetic Field Inclination Angle
X (forward)
Y (right)
Z (down)
It is easy to observe that the magnetic field vector is
parallel to the surface near the equator. In the Northern
Hemisphere, that vector points down toward the North
Pole, as shown in Figure 2.
The angle between the magnetic vector and the horizontal plane, XY, is called the dip or inclination angle ( α in Figure 2). This
angle is mainly dependent on the geographical latitude (see Figure 3).
Figure 3. Magnetic Vector Inclination Angle Map From
Document No. 001-32379 Rev. *C
Sensing – Magnetic Compass with Tilt Compensation
A common approach used to estimate the heading is to
measure two orthogonal components of the magnetic
vector (Hx and Hy according to Figure 2) and calculate the
heading as the arctangent of their ratio:
Heading = arctan
 Hx
Figure 4. Pitch and Roll Description
Equation 1
This equation is correct only when the magnetic sensor is
precisely leveled. If some tilt is present, the measured
values Hx and Hy change and the resultant heading is not
This error is enhanced by the vertical component of the
magnetic vector. For instance, if the inclination angle is
about 60 degrees and the compass is tilted at 5 degrees
to level, the azimuth measurement error will be up to 8
To avoid tilt error, a 3-axis magnetic sensor with an
additional tilt measurement circuit can be used. A 3-axis
sensor provides the Earth’s magnetic vector coordinates
relative to a compass local coordinate frame. These
values are not enough to calculate the true heading.
Additional information about the compass space
orientation is necessary.
This information is obtained from the tilt sensor, similar to
an accelerometer. If the compass is not accelerating, the
tilt sensor measures the angles between the compass and
the gravity vector. Based on the tilt sensor values, the
locally measured vector coordinates Hx, Hx and Hz are
converted to a reference coordinate and the heading is
calculated according to Equation (1).
The presented design uses a Honeywell magneto resistive
sensor, HMC1043, for Hx, Hx and Hz measurement and an
Analog Devices dual-axis accelerometer, ADXL322, as a
tilt sensor.
Device Design Basis
Allow us to consider a few geometric aspects of the vector
measurements on the tilted platform. Assume the
coordinate system is chosen in such a way that the X-axis
is oriented forward, the Y-axis is to the right, and the Zaxis is downward (Figure 4). The stationary coordinate
frame will be signed as XYZ and the local tilted coordinate
system is X'Y'Z'.
There are several ways to describe rotation of the
coordinate frame of the compass relative to the fixed
roll-pitch-heading, rotation matrix, spin matrix and so on.
The aircraft convention of the rotation angles is used
below. Roll angle (θ) is defined as rotation around the
X-axis. Pitch angle (φ) is defined as rotation around the
Y-axis. All rotations are performed counter-clockwise, if
viewed from the positive axis direction toward the origin of
the coordinate frame. The X-axis and Y-axis rotation
sequence is important (try to rotate an object 90 degrees
around the X-axis and then around the Y-axis, or in the
reverse order, and the results will be different).
Therefore, the assumed rotation to be performed is around
the X-axis first, then around the Y-axis (roll, then pitch).
Each basic rotation can be described by the rotation
matrix that transforms the coordinates from the stationary
coordinate frame of XYZ to the rotated tilted coordinate
system of X'Y'Z'. The roll rotation matrix is:
C r =  0 cos θ
 0 − sin θ
0 
sin θ 
cos θ 
Equation 2
The pitch rotation matrix is:
 cosθ 0 − sin θ 
Cp =  0
0 
 sin φ 0 cos φ 
Equation 3
Rotation transformation of the coordinates occurs using
either of the following equations:
Document No. 001-32379 Rev. *C
Sensing – Magnetic Compass with Tilt Compensation
 x
 x' 
 
 
 
p  y
 z' 
 
 
 x'   cos φ
  
 y '  =  sin θ sin φ cosθ
 z '   cosθ sin φ − sin θ
  
Equation 4
− sin φ   x 
  
sin θ cos φ  ⋅  y  Equation 5
cosθ cos φ   z 
The magnetic sensor measures the x'y'z' components of
the Earth’s magnetic vector. For azimuth estimation, these
values should be converted to the stationary coordinate
system. That conversion is performed using an inverted
rotation matrix:
 x   cos φ sin θ sin φ cos θ sin φ   x' 
  
  
− sin θ  ⋅  y '  Equation 6
cos θ
 y =  0
 z   − sin φ sin θ cos φ cos θ cos φ   z ' 
  
  
Since the z coordinate is not used for azimuth estimation,
the tilt-compensated values for x and y can be evaluated
x = x' cos φ + y ' sin θ sin φ + z ' cosθ sin φ
y = y ' cos θ − z ' sin θ
Equation 7
Equation 8
x ' and y ' are the measured components of the magnetic
Consequently, to convert the measured values into tiltcompensated values, the roll and pitch angles should be
estimated. This task is solved by a dual-axis
The accelerometer output signals are proportional to the
gravitation vector projections on the X'Y' plane (see
Figure 5).
Figure 5. Gravitation Vector Projections
The accelerometer output values can be considered as
the sin of the angle between the X'-axis and the level Ax,
and between the Y'-axis and the level Ay. Sometimes
these angles are called the pitch angle P and the roll angle
R. However, these angles should not be confused with the
θ and φ angles that were previously defined.
Nevertheless, in most application notes devoted to tilt
compensation, including AN00022 Electronic Compass
Design using KMZ51 and KMZ52 by Philips (see
Figure 24, Definition of Pitch and Roll, on p.32); these
angles are directly substituted in the corresponding values
shown in Equation 7 and Equation 8.
Ax = − sin φ
Equation 9
Ay = sin θ
Equation 10
This assumption is valid only when the tilt is small. Allow
us to consider this issue in more detail. The normalized
accelerometer outputs Ax and Ay can be considered
transformed by the rotation matrix in Equation (5) of the
normalized gravitation vector:
 Ax   cos φ
  
 y 
 A   cosθ sin φ − sin θ
 z 
− sin φ   0 
  
sin θ cos φ  ⋅  0  Equation 11
cosθ cos φ   1 
Ax = − sin φ
Equation 12
Ay = sin θ cos φ
Equation 13
It is easy to observe from Equations 12 and 13 that, in the
case of a small pitch angle φ , when cos φ ≈ 1 a commonly
used simplification of the roll is, the pitch angle’s
estimation is acceptable. Therefore, if the wide range tilt
compensation is required, then Equations 12 and 13
should be used.
Using Equations 12 and 13 and standard trigonometry
identities, the values for the tilt compensation formula,
Equations 7 and 8, can be given as:
sin φ = − Ax
Equation 14
cos φ = 1 − sin 2 φ = 1 − Ax2
sin θ = −
cos φ
Document No. 001-32379 Rev. *C
Equation 16
1 − Ax2
cosθ = 1 − sin 2 θ =
Equation 15
1 − Ax2 − Ay2
1 − Ax2
Equation 17
Sensing – Magnetic Compass with Tilt Compensation
Since, for navigation purposes only, the ratio of the
measured values is important (see Equation 1), both
Equations 7 and 8 can be multiplied by the same value. It
is convenient to multiply these equations by cos φ to
Figure 6. Compass Hardware Architecture
12 bit
12 bit
12 bit
Finally, the equations for the tilt compensation are next:
x = x' 1 − Ax2 − y ' Ax Ay − z ' Ax 1 − Ax2 − Ay2 Equation 18
y = y' 1 −
− z ' Ay
Equation 19
x ', y ' and z ' are the measured values of the magnetic
vector, and Ax and Ay are the normalized measurements of
the accelerometer.
Heading = arctan
Equation 20
To calculate the geographic azimuth as a clockwise angle
between the north direction and X-axis, the signs of y and
x must be taken into account:
180 − arctan y x ,
 − arctan y x ,
Azimuth = 360 − arctan y x ,
x > 0, y < 0
x > 0, y > 0
x = 0, y < 0
x = 0, y > 0
Equation 21
Expressions in equations (18), (19) and (21) are used in
the present design to estimate tilt compensated heading.
PSoC Implementation
The main parts of the presented design are:
PSoC® CPU (CY8C27xxx device family).
Dual-axis accelerometer (Analog Devices ADXL 322).
Magnetic sensor set/reset circuit.
3-axis magneto
Sensor’s signal
Each channel of the magneto resistive sensor is a
Wheatstone bridge, which converts the magnetic field into
a differential output voltage. The typical sensor sensitivity
is 5 mV/gauss (at Vdd=5 V). The Earth’s magnetic field
can reach ±800 mgauss; therefore, the useful sensor
output voltage can be up to ±4 mV. The magnetic sensor
also has a considerable DC offset voltage of up to
±6.25 mV. The total output signal will be up to ±10.25 mV.
After an amplifier with a gain equal to 200, the amplitude is
about 4 volts. This value fits in the range of an ADC with a
reference of Vdd/2 ± Vdd/2.
The output of the accelerometer and the magnetic sensor
is ratio metric. The output signal peak to peak amplitude is
about 600 mV (300 mV/g). With a 12-bit ADC tilt
measurement, the error will be no more than 0.5 percent,
without additional amplification.
An important advantage of implementing the PSoC device
inside the compass is the option to use a three-channel
ADC. This allows simultaneous conversion of all
magnetoresistive sensor output signals (X, Y and Z) or
accelerometers signals. Traditional methods use one ADC
to sequentially convert all inputs. If the device is moved,
then the measurements will reflect vector components at
different moments, which can cause additional errors. The
present device measures all of the values simultaneously,
thus improving the accuracy of the results. The ADC
conversion time is set to about 60 ms, which allows about
7 azimuth measurements per second to be received. This
value can easily be changed, if another measurement
speed is required.
The set/reset (S/R) circuit is used to compensate both the
magneto resistive sensor offset and the amplifier-ADC
circuit’s offset.
Multichannel RS-232 Driver (MAX232).
The simplified hardware architecture is presented in
Figure 6.
Document No. 001-32379 Rev. *C
Sensing – Magnetic Compass with Tilt Compensation
The idea of such offset compensation is based on the
option to flip the sensor’s bridge output polarity using
sequential high-current pulses of the opposite polarity
across the S/R strap. Polarity changes in the signal are
only caused by the magnetic field. The offset of the bridge
and signal conditioning circuits remains unchanged.
Consequently, the offset can be canceled by subtraction of
the two measurements:
Reset: Code R = K − VMagnetic + VOffset
Set: CodeS = K VMagnetic + VOffset
VOffset =
CodeS − CodeR
All next signal processing is performed by PSoC.
Equation 23
Software Description
Code R + CodeS
VMagnetic =
Equation 22
Equation 24
Equation 25
CodeR is the ADC code after the reset pulse, CodeS is
the ADC code after the set pulse, VOffset is the summary
offset, and VMagnetic is the signal.
For high-precision measurements, S/R pulses can be
used for each sample. But for common tasks, occasionally
recalculating the offset and subtracting it from each
sample is sufficient. This design recalculates VOffset each
256 measurements or about twice per minute. S/R pulses
are formed by the charge/dump current of the capacitor
connected in serial with the S/R strap. Due to low strap
resistance (about 5 Ω) the peak current reaches up to 1A
which is enough to flip magnetic orientation of the sensor.
The pulse width is defined by the CR time constant. It is
relatively small at several microseconds. The low value of
the S/R pulse’s duty factor gives a small averaged power
consumption of the S/R circuit in spite of the considerable
peak current. Pulse energy is given by:
U 2C 52 ⋅ 0.5 ⋅ 10−6
≈ 6 micro-Joules
Equation 26
Taking into account the pulse’s duty factor we can
estimate the S/R circuit power consumption to be less
than one microwatt.
Additional details on S/R operations are described in the
sensor manufacturer’s application notes such as
Honeywell’s AN213 Set/Reset Function for Magnetic
The full device schematic is shown in Figure 14 in
Appendix A: Device Schematics.
Input signals from sensor are amplified by differential
amplifiers U2A-U2C. Resistors for these amplifiers should
be chosen with tolerance of 0.1% to avoid significant DC
offset at output. It is not obligatory to use precision
operational amplifier. It can be low-cost but low-noise with
offset voltage no more than 1-2 mV.
Magneto resistive sensor’s outputs are shunted by 1uF
capacitors C9, C14 and C21. These capacitors interact
with sensor output impedance of 1 kilohm and limit
sensors bandwidth to about 160 Hz. Such bandwidth
limitation is advisable because sensor can produce signals
up to 5 MHz that can cause disturbances. The side effect
of bandwidth limit is increasing of transient time after
Set/Reset pulses applying. This problem is solved by
software applying delay during Set/Reset operations.
The software’s main task is to perform calculations of the
heading according to Equations 18, 19, and 21. These
calculations are complicated by arctangent and square
root functions. If a PC performs the calculations, there is
no problem in using the floating-point arithmetic and
standard libraries. However, in most cases, the usage of a
floating point with microcontrollers is not acceptable. That
is why all of the calculations in this design are performed
with integer numbers. Arctangent and square root are
calculated using COordinate Rotation DIgital Computer
(CORDIC) algorithms that only require addition and shift
operations. There are many CORDIC descriptions on the
web, for instance “CORDIC FAQ.” The algorithms
described below are based on “Arctan(x) using CORDIC,”
sci.math.num-analysis newsgroup archives.
Allow us to consider arctangent calculations in more detail.
The function arctan
denotes the angle between X-axis
and vector (x;y). To estimate this angle, several rotations
of the vector by predefined angles are performed.
Rotations are made until the resulting vector sufficiently
approaches the X-axis. The sum of these rotation angles
yields the desired arctangent. The predefined angles are
 1 
chosen to be ± arctan
 .
 2n 
The vector rotation by angle α changes its coordinates
according to the rotation transformation:
x' = x cos α − y sin α
Equation 27
y ' = x sin α + y cos α
Equation 28
x' = cos α [x − tan α ]
Equation 29
y ' = cos α [x tan α + y ]
Equation 30
For angle estimation (if vector length is insignificant), the
term cos α can be ignored. If tan α i = ± i , then
Document No. 001-32379 Rev. *C
Sensing – Magnetic Compass with Tilt Compensation
xi +1 = xi −
y i +1 = y i −
yi ⋅ d i
xi ⋅ d i
Equation 31
Figure 7. Simplified Flowchart of ArcTan2 Function
Equation 32
i := 0;
Ang := 0
d i = ±1 . The angles α i are calculated at design time and
stored in a look-up table. The sum of each rotation angle
is stored in the angle accumulator:
Ang i +1 = Ang i + d i ⋅ α i
Equation 33
yi > 0
Each following rotation direction is determined in such a
way to approach the resulting vector toward the X-axis:
d i = −1 if yi > 0 , +1 otherwise
Equation 34
Iterations in Equations 31, 32, 33, and 34 are performed
until α i < 1 . This procedure is shown in a simplified
flowchart in Figure 7.
xi+1 := xi – yi/2i;
yi+1 := yi + xi/2i;
Ang := Ang+a[i];
To achieve precision better than 1°, the weight of the least
significant bit (LSB) of the angle accumulator Ang should
be less than 1°. In the present design, it is assumed that 1
LSB = 0.25° or 360° → Ang = 360 ⋅ 4 . The described
algorithm is implemented in the ArcTan2 () function.
Another extension of the CORDIC algorithm is used to
calculate the square root function in Equations 18 and 19.
The main idea of this algorithm is to determine whether or
not a square of each binary digit is present in the input
If s =
a and s contains binary 1 with weight 2i , then a
contains 22i . In that way, the iterative algorithm can be
xi+1 := xi – yi/2i;
yi+1 := yi + xi/2i;
Ang := Ang-a[i];
i := i +1
Return Ang
written as:
s 21 = 2i +1 ⋅ s + 2 2i ;
Equation 35
if a ≥ s 21 , then s + = 2 i ; a − = s 21
Equation 36
i 8;=
s 0 and they are performed until
Iterations start at
i = 0 (see Figure 8). It is easy to observe that this
procedure requires only addition and shift operations;
therefore, it is friendly to microcontroller implementation.
The described algorithm is implemented in the function
Document No. 001-32379 Rev. *C
Sensing – Magnetic Compass with Tilt Compensation
Figure 8. Flowchart of ISqrt Function
Table 1. Functions Description
i := 8;
s := 0;
a := input
s21=: 2i +1 ⋅ s + 22i
a >= s21
s =: s + 2i ;
a =: a − s21
Performs startup device configuration,
measures magnetic vector and tilt,
calculates azimuth.
FiltrA, FiltrB,
Low-pass digital filters for measured
magnetic vector components.
Calculates ArcTan(y/x) taking into account
signs of y and x.
Calculates square root.
Makes n x 15 ms delay using low-precision
sleep timer.
Forms S/R pulse’s sequence for magnetic
sensor, calculates offsets.
Performs hard iron offset and axis scale
factor calibration.
Calibrates accelerometer.
Performs true north calibration.
Saves calibration results into internal
EEPROM as power-on defaults.
i := i -1
i >= 0
Return s
The measured values of the magnetic vectors x ', y ' and
z ' , before substitution into equations (18) and (19), are
filtered by a low-pass second order digital IIR-filter as
described by this equation:
fn =
(cn + 2 ⋅ cn −1 + cn − 2 ) + f n −1 − 1 f n − 2 Equation 37
cn is the samples of input values and f n is the filter
This filter has a gain of 4 and cut-off frequency at
approximately 0.07 times the sample rate. The presented
design samples data at a rate of about 7 Hz; therefore, the
cut-off frequency is close to 0.5 Hz. The described
filtration is implemented in the procedures FiltrA(), FiltrB()
and FiltrC() for x ', y ' and z ' , correspondingly.
There are several additional functions in the firmware. The
complete list and brief description is shown in Table 1.
Compass Calibration
There are many known compass error factors that are
described in detail in a number of papers. For instance,
“Applications of Magnetic Sensors for Low Cost Compass
Systems.” The present design implements hard iron error
and true north declination angle compensation, in addition
to the tilt compensation previously described.
If the compass is rotated in the horizontal plane and no
disturbances are present, then the output values plot y
versus x should form an ideal circle centered at the
coordinate system origin. However, the real plot differs
from the ideal case. The circle becomes an ellipse with the
center shifted from the zero point (see Figure 9).
To compensate for the described error, the scale factors
should be applied and the offset subtracted.
xh = x ⋅ X sf − X off
Equation 38
y h = y ⋅ Ysf − Yoff
Equation 39
The scale factors X sf and Ysf as well as offsets X off and
Yoff are determined during the calibration procedure.
Document No. 001-32379 Rev. *C
Sensing – Magnetic Compass with Tilt Compensation
During calibration, the compass is rotated in the horizontal
plane and the minimum and maximum measured values
for both the X- and Y-axis are collected. Then the desired
values are calculated as follows:
− y min
X sf = max max
 max − xmin
− xmin
Ysf = max max
 max − y min
Figure 10. Real Data Plot with Applied Compensation
Equation 40
Equation 41
X off =
xmax + xmin
⋅ X sf
Equation 42
Yoff =
y max + y min
⋅ X sf
Equation 43
The calibration procedure is initiated by pressing the
switch SW1. Then, several slow rotations in the horizontal
plane are performed. To alert the device that the rotations
are complete, the switch SW1 should be pressed once
again. During this calibration, the compass should be
exactly leveled.
The result of the applied compensation is shown in
Figure 10. The attentive observer may notice that the data
jitter shown in Figure 10 is a little larger than in Figure 9.
That is because in Figure 10, the tilt compensation is
applied along with the hard iron compensation. The tilt
on the
measurements. If the platform rotation is not steady, then
the accelerometer will respond to jerks, thus introducing
additional errors to measurement.
Figure 9. Real Data Plot with Magnetic Disturbances
The second calibration procedure deals with the
accelerometer. It measures the minimum and maximum
output values for both axes when the device is directed
vertically. These values are used for calculating
normalized Ax , Ay values for equations (18) and (19).
Such calibration is necessary because of the variation in
sensor parameters. The calibration procedure is initiated
by pressing the switch SW2. Then, the device should be
slowly turned vertically and rotated in the vertical plane. In
other words, the device’s X-axis and Y-axis should be
alternately directed upward and downward. After that, the
device should be placed horizontally and the switch SW2
should be pressed again, alerting the device that the
procedure has ended.
The third calibration procedure compensates the
difference between the geographical north direction and
magnetic north. That difference is known as the
declination angle. To compensate this angle, position the
device so that the X-axis points in the geographical north
direction, then press switch SW3. After that, the
declination angle is subtracted from each measured
All calibration results are stored in the internal EEPROM
and loaded each time the device is powered-on.
Testing Results
The compass prototype was designed to verify the
described algorithms. The test board is shown in
Figure 11.
Document No. 001-32379 Rev. *C
Sensing – Magnetic Compass with Tilt Compensation
For instance, the internal PSoC instrumental amplifiers
can be used instead of an external opamp. Due to the
limited quantity of analog blocks, only two amplifiers are
available. Therefore, inputs should be multiplexed allowing
alternate measurements of X, Y, Z and Ax, Ay values (see
Figure 12). In this case, a dual ADC is used, instead of
triple. The full device schematic is shown in Figure 15 of
Appendix A: Device Schematics.
Figure 11. Compass Test Board
Figure 12. Simplified Hardware Architecture for TiltCompensated Compass
13 bit
13 bit
If tilt compensation is not required, then the device
schematic can be simplified (see Figure 13). Internal
PSoC instrumental amplifiers can be used instead of an
external opamp. ADC resolution is increased to 13 bits
due to the gain limit of the internal instrumental amplifiers.
Measurement results are displayed on the LCD.
The magnetic sensor is mounted on a separate plate to
facilitate mounting/unmounting operations without special
The results of the measurements are displayed on the
LCD. The azimuth is displayed in the first row and the Ax
and Ay hexadecimal values are displayed in the second
row. The measured values are also transmitted to the PC
via the RS-232 interface.
Tests were performed indoors not far from the computer
and near other high-disturbance sources. The results were
encouraging: the angle jitter was about ±0.25 degrees.
The absolute error was not measured because of the
absence of a reference compass. For comparison, similar
measurements were implemented using a single ADC and
a three-channel ADC. When using a single ADC, some
bursts were observed and full peak-to-peak jitter reached
about 3 degrees. This result proves the advantages of
employing the three-channel ADC.
Simplified Compass Versions
The previously described compass implementation is
appropriate for high-precision measurement systems. It is
possible to simplify that design, if the precision
requirements are not as strict.
Figure 13. Hardware Architecture for Dual-Axis Compass
13 bit
13 bit
The full device schematic is shown in Figure 16 of
Appendix A: Device Schematics. There are several
external components on this schematic, including the
optional RS-232 interface.
Another possible design simplification can be achieved be
replacing the LCD with several LEDs. These LEDs are
placed counterclockwise on the circle. A lit LED indicates
north. This version schematic is shown in Figure 17.
Document No. 001-32379 Rev. *C
Sensing – Magnetic Compass with Tilt Compensation
The application note presented 3-axis magneto resistive
sensor-based digital compass with tilt compensation.
Calibration methods
Simplified designs for low-precision measurement
The following topics were covered in the application note:
Working of a magnetic compass including the design
Role of PSoC, PSoC implementation and advantages
of PSoC
Software implementation including the use of
CORDIC algorithms that are used to calculate
arctangent and square root which require just addition
and shift operations
About the Author
Vadym Grygorenko.
Systems Engrg Sr MTS
Document No. 001-32379 Rev. *C
Sensing – Magnetic Compass with Tilt Compensation
Appendix A: Device Schematics
Figure 14. Tilt-Compensated Compass Schematic
Figure 15. Simplified Tilt-Compensated Compass Schematic
Document No. 001-32379 Rev. *C
Sensing – Magnetic Compass with Tilt Compensation
Figure 16. Dual-Axis Compass Schematic
Figure 17. Simplified Compass Schematic
Document No. 001-32379 Rev. *C
Sensing – Magnetic Compass with Tilt Compensation
Document History
Document Title: Sensing – Magnetic Compass with Tilt Compensation - AN2272
Document Number: 001-32379
Orig. of
Description of Change
New Application note
Associated Project files zipped with source document.
No changes in the document.
Added Document History details.
Updated in new template.
Updated Software Version as “PSoC Designer™ 5.1 (SP1.1)”.
Project updated to latest version namely “PSoC Designer™ 5.1 (SP1.1)”.
Updated in new template.
Completing Sunset Review.
Document No. 001-32379 Rev. *C
Sensing – Magnetic Compass with Tilt Compensation
Worldwide Sales and Design Support
Cypress maintains a worldwide network of offices, solution centers, manufacturer’s representatives, and distributors. To find
the office closest to you, visit us at Cypress Locations.
PSoC® Solutions
Clocks & Buffers
PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP
Lighting & Power Control
Touch Sensing
USB Controllers
Cypress Developer Community
Community | Forums | Blogs | Video | Training
Technical Support
PSoC is a registered trademark of Cypress Semiconductor Corp. "Programmable System-on-Chip," PSoC Designer, and PSoC Express are trademarks
of Cypress Semiconductor Corp. All other trademarks or registered trademarks referenced herein are the property of their respective owners.
Cypress Semiconductor
198 Champion Court
San Jose, CA 95134-1709
: 408-943-2600
: 408-943-4730
© Cypress Semiconductor Corporation, 2007-2014. The information contained herein is subject to change without notice. Cypress Semiconductor
Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any
license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or
safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as
critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The
inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies
Cypress against all charges.
This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide
patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a
personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative
works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress
integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source
Code except as specified above is prohibited without the express written permission of Cypress.
right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or
use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a
malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress’ product in a life-support systems
application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges.
Use may be limited by and subject to the applicable Cypress software license agreement.
Document No. 001-32379 Rev. *C