ST integrated sensor solution realizes electronic compass function

Publisher:知者如渊Latest update time:2010-12-18 Source: 意法半导体 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The electronic compass is an important navigation tool that can provide the heading and attitude of moving objects in real time. With the advancement of semiconductor technology and the development of mobile phone operating systems, smartphones that integrate more and more sensors have become more powerful, and many mobile phones have implemented the function of electronic compasses. Applications based on electronic compasses (such as Skymap for Android) have also become popular on various software platforms.

To realize the electronic compass function, a three-axis magnetic sensor for detecting magnetic fields and a three-axis acceleration sensor are required. With the maturity of micro-mechanical technology, STMicroelectronics has launched the LSM303DLH, a two-in-one sensor module that integrates a three-axis magnetometer and a three-axis accelerometer in one package, making it easy for users to design a low-cost, high-performance electronic compass in a short time. This article takes LSM303DLH as an example to discuss the working principle, technical parameters and implementation method of the electronic compass.

1. Background knowledge of geomagnetic field and heading angle

As shown in Figure 1, the Earth's magnetic field points from the magnetic south pole to the magnetic north pole like a bar magnet. At the magnetic pole, the magnetic field is perpendicular to the local horizontal plane, and at the equator, the magnetic field is parallel to the local horizontal plane, so the magnetic field in the northern hemisphere is tilted toward the ground. The unit used to measure the intensity of magnetic induction is Tesla or Gauss (1 Tesla = 10000 Gauss). Depending on the geographical location, the strength of the geomagnetic field is usually 0.4-0.6 Gauss. It should be noted that the magnetic north pole and the geographical north pole do not coincide, and there is usually an angle of about 11 degrees between them.

Geomagnetic field distribution map

Figure 1. Distribution of the Earth's magnetic field

The geomagnetic field is a vector. For a fixed location, this vector can be decomposed into two components parallel to the local horizontal plane and one component perpendicular to the local horizontal plane. If the electronic compass is kept parallel to the local horizontal plane, the three axes of the magnetometer in the compass correspond to these three components, as shown in Figure 2.

Schematic diagram of geomagnetic field vector decomposition

Figure 2 Schematic diagram of geomagnetic field vector decomposition

In fact, for the two components in the horizontal direction, their vector sum always points to the magnetic north. The heading angle (Azimuth) in the compass is the angle between the current direction and the magnetic north. Since the compass remains horizontal, only the detection data of the two horizontal axes (usually the X-axis and the Y-axis) of the magnetometer can be used to calculate the heading angle using Formula 1. When the compass rotates horizontally, the heading angle changes between 0º-360º.

formula

2. ST integrated magnetometer and accelerometer sensor module LSM303DLH

2.1 Working Principle of Magnetometer

In the LSM303DLH, the magnetometer uses anisotropic magnetoresistance (Anisotropic Magneto-Resistance) material to detect the magnitude of magnetic induction intensity in space. This alloy material with a crystal structure is very sensitive to the external magnetic field, and changes in the strength of the magnetic field will cause changes in the resistance value of the AMR itself.

During the manufacturing process, a strong magnetic field is applied to the AMR to magnetize it in a certain direction, establishing a main magnetic domain. The axis perpendicular to the main magnetic domain is called the sensitive axis of the AMR, as shown in Figure 3. In order to make the measurement result change in a linear manner, the metal wires on the AMR material are arranged at a 45° angle, and the current flows through these wires, as shown in Figure 4. The main magnetic domain established on the AMR material by the initial strong magnetic field has a 45° angle with the direction of the current.

AMR material diagram

45

When there is an external magnetic field Ha, the direction of the main magnetic domain on the AMR will change and will no longer be the initial direction, so the angle θ between the magnetic field direction and the current will also change, as shown in Figure 5. For AMR materials, the change in angle θ will cause the change in the resistance of the AMR itself, and the relationship is linear, as shown in Figure 6.

The angle between the magnetic field direction and the current

The change of angle θ will cause the change of AMR's own resistance

ST uses a Wheatstone bridge to detect the change in AMR resistance, as shown in Figure 7. R1/R2/R3/R4 are AMR resistors with the same initial state, but R1/R2 and R3/R4 have opposite magnetization characteristics. When an external magnetic field is detected, the resistance of R1/R2 increases by ∆R while that of R3/R4 decreases by ∆R. In this way, when there is no external magnetic field, the output of the bridge is zero; when there is an external magnetic field, the output of the bridge is a small voltage ∆V.

Wheatstone Bridge

Figure 7 Wheatstone bridge

When R1=R2=R3=R4=R, when the resistance changes to ∆R under the action of the external magnetic field, the bridge output ∆V is proportional to ∆R. This is the working principle of the magnetometer.

2.2 Set/Reset Circuit

Due to the influence of the external environment, the direction of the main magnetic domain on the AMR in the LSM303DLH will not remain unchanged permanently. The LSM303DLH has a built-in set/reset circuit that periodically generates current pulses through the internal metal coil to restore the initial main magnetic domain, as shown in Figure 8. It should be noted that the effect of the set pulse and the reset pulse is the same, but the direction is different.

LSM303DLH Set/Reset Circuit

Figure 8 LSM303DLH set/reset circuit

The set/reset circuit brings many advantages to the LSM303DLH:

1) Even if there is interference from a strong external magnetic field, the LSM303DLH can resume normal operation after the interference disappears without the need for the user to calibrate again.

2) Even when working for a long time, the initial magnetization direction can be maintained to achieve accurate measurement, and the measurement accuracy will not be affected by changes in chip temperature or increased internal noise.

3) Eliminate bridge deviation caused by temperature drift.

2.3 Performance parameters of LSM303DLH

LSM303DLH integrates a three-axis magnetometer and a three-axis accelerometer with a digital interface. The measurement range of the magnetometer is from 1.3 Gauss to 8.1 Gauss, divided into 7 levels, and users can choose freely. And it can maintain consistent measurement results and the same sensitivity in a magnetic field environment within 20 Gauss. Its resolution can reach 8 mGauss and a 12-bit ADC is used internally to ensure accurate measurement of magnetic field strength. Compared with magnetometers using the Hall effect principle, LSM303DLH has low power consumption, high accuracy, good linearity, and does not require temperature compensation.

LSM303DLH has an automatic detection function. When the control register A is set, the self-test circuit inside the chip will generate an excitation signal of approximately the magnitude of the geomagnetic field and output it. Users can use the output data to determine whether the chip is working properly.

As a highly integrated sensor module, LSM303DLH integrates a high-performance accelerometer in addition to the magnetometer. The accelerometer also uses a 12-bit ADC, which can achieve a measurement accuracy of 1mg. The accelerometer can run in low-power mode and has a sleep/wake-up function, which can greatly reduce power consumption. At the same time, the accelerometer also integrates 6-axis direction detection and two programmable interrupt interfaces.

3. Introduction of ST electronic compass solution

A traditional electronic compass system requires at least a three-axis magnetometer to measure magnetic field data and a three-axis accelerometer to measure compass inclination. The gravity distribution and magnetic field data in three-dimensional space are transmitted to the processor through the signal processing and data acquisition part. The processor calculates the azimuth from the magnetic field data and performs tilt compensation through the gravity data. The azimuth output after processing is not affected by the spatial attitude of the electronic compass, as shown in Figure 9.

Schematic diagram of electronic compass structure

Figure 9 Schematic diagram of electronic compass structure

LSM303DLH integrates the above accelerometer, magnetometer, A/D converter and signal processing circuit, and still communicates with the processor through the I2C bus. In this way, only one chip can realize 6-axis data detection and output, which reduces the design difficulty of customers, reduces the occupied area of ​​PCB board, and reduces the device cost.

The typical application of LSM303DLH is shown in Figure 10. It requires few peripheral devices and the connection is also simple. The magnetometer and accelerometer each have an I2C bus to communicate with the processor. If the customer's I/O interface level is 1.8V, Vdd_dig_M, Vdd_IO_A and Vdd_I2C_Bus can all be powered by 1.8V, and Vdd can be powered by 2.5V or above; if the customer's interface level is 2.6V, except for Vdd_dig_M requiring 1.8V, all others can use 2.6V. As mentioned above, LSM303DLH requires a set/reset circuit to maintain the main magnetic domain of AMR. C1 and C2 are external matching capacitors for the set/reset circuit. Since there are certain requirements for the set pulse and reset pulse, it is recommended that users do not modify the size of C1 and C2 at will.

For portable devices, the power consumption of the device is very important and directly affects its standby time. LSM303DLH can control the power supply mode of the magnetometer and accelerometer separately to put them into sleep or low power mode. And users can adjust the data update frequency of the magnetometer and accelerometer to adjust the power consumption level. When the magnetometer data update frequency is 7.5Hz and the accelerometer data update frequency is 50Hz, the typical current consumption is 0.83mA. In standby mode, the current consumption is less than 3uA.

LSM303DLH typical application circuit diagram

Figure 10 LSM303DLH typical application circuit diagram

[page]

4. Ferrous magnetic field interference and calibration

Electronic compasses calculate the direction of the magnetic north pole mainly by sensing the presence of the earth's magnetic field. However, since the earth's magnetic field is generally only weak at 0.5 gauss, an ordinary mobile phone speaker will still have a magnetic field of about 4 gauss when it is 2 cm away, and a mobile phone motor will have a magnetic field of about 6 gauss when it is 2 cm away, this feature makes the measurement of the earth's magnetic field on the surface of electronic equipment easily interfered by the electronic equipment itself.

Magnetic field interference refers to the deviation of the earth's magnetic field at the location where the magnetic sensor is placed due to the presence of magnetic materials or materials that can affect the local magnetic field strength. As shown in Figure 11, in the XYZ coordinate system of the magnetic sensor, the green circle represents the projection trajectory of the earth's magnetic field vector in the XY plane during the circular rotation around the z-axis. In the absence of any external magnetic field interference, this trajectory will be a standard circle centered at O(0,0). When there is external magnetic field interference, the measured magnetic field intensity vector α will be the vector sum of the earth's magnetic field β and the interfering magnetic field γ at that point. It is expressed as:

Magnetic sensor XY coordinates and magnetic field line projection trajectory

Figure 11 XY coordinates of magnetic sensor and projection trajectory of magnetic lines of force

Generally speaking, the interference magnetic field γ can be regarded as a constant vector at this point. There are many factors that can cause magnetic field interference, such as motors and speakers placed on the circuit board, and materials containing metals such as iron, nickel and cobalt, such as shielding covers, screws, resistors, LCD back panels and shells, etc. Similarly, according to Ampere's law, a wire with current passing through it will also generate a magnetic field, as shown in Figure 12.

Effect of electric current on magnetic field

Figure 12 Effect of current on magnetic field

In order to calibrate the magnetic field interference from the circuit board, the main task is to find out γ through calculation.

4.1 Plane calibration method

For the calibration of the XY axis, the device equipped with the magnetic sensor rotates in the XY plane, as shown in Figure 11, which is equivalent to rotating the earth's magnetic field vector around the normal line passing through point O(γx,γy) perpendicular to the XY plane. The red circle is the trajectory of the magnetic field vector projected in the XY plane during the rotation. The position of the center of the circle can be found as ((Xmax + Xmin)/2, (Ymax + Ymin)/2). Similarly, rotating the device in the XZ plane can obtain the trajectory circle of the earth's magnetic field in the XZ plane, which can be used to calculate the magnetic field interference vector γ(γx, γy, γz) in three-dimensional space.

4.2 Stereo 8-Character Calibration Method

Generally speaking, when a device with sensors rotates in all directions in the air, the spatial geometric structure composed of the measured values ​​is actually a sphere, and all sampling points fall on the surface of the sphere, as shown in Figure 13. This is similar to the circle obtained by projection in a two-dimensional plane.

After the Earth's magnetic field rotates in space, a sphere is obtained in the sensor space coordinates

Figure 13 The Earth's magnetic field rotates in space to form a sphere in the sensor's space coordinates

In this case, the center O(γx, γy, γz), that is, the magnitude and direction of the fixed magnetic field interference vector, can be calculated through sufficient sample points. The formula is as follows:

formula

The figure-8 calibration method requires the user to use the device to be calibrated to make an 8-shaped shake in the air. In principle, the normal direction of the device should point to all 8 quadrants of the space as much as possible, as shown in Figure 14.

The figure-8 calibration method requires the user to use the device to be calibrated to make an 8-shaped movement in the air.

4.2 Ten-sided calibration method

Similarly, the purpose of calibration can be achieved through the following 10-face calibration method.

10-face calibration method

As shown in FIG. 16 , after the 10-face calibration method, part of the trajectory of the sphere surface described above can also be sampled, thereby deducing the position of the sphere center, that is, the size and direction of the fixed magnetic field interference vector.

Spatial trajectory after 10-face calibration

Figure 16 Spatial trajectory after 10-surface calibration

5. Tilt compensation and yaw angle calculation

After calibration, the electronic compass can be used normally on the horizontal plane. However, most of the time, the mobile phone is not kept horizontal, and there is usually an angle between it and the horizontal plane. This angle will affect the accuracy of the heading angle, and the acceleration sensor needs to be used for tilt compensation.

The navigation system has long defined the posture of an object in the air, as shown in Figure 17. This definition is also used in Android. Pitch (Φ) is defined as the angle between the x-axis and the horizontal plane, with the positive direction shown in the figure; Roll (θ) is defined as the angle between the y-axis and the horizontal plane, with the positive direction shown in the figure. The heading angle error caused by the pitch angle is shown in Figure 18. It can be seen that a 10-degree tilt angle in the x-axis direction can cause a maximum heading angle error of 7-8 degrees.

Pitch Angle and Roll Angle Definition

Figure 17 Pitch angle and Roll angle definition

Heading angle error caused by pitch angle

Figure 18 Heading angle error caused by pitch angle

The tilt posture of the mobile phone in the air is shown in Figure 19. The components of gravity acceleration on the three axes are detected by the 3-axis acceleration sensor, and Pitch and Roll can be calculated by Formula 2.

The tilt of the phone in the air

Figure 19 The tilted posture of the mobile phone in the air

formula

6. Implementation of compass on Android platform

Many popular Android phones are equipped with a compass function. To achieve this function, you only need to equip it with the two-in-one sensor module LSM303DLH provided by ST. ST provides a complete solution. The software implementation in Android can be represented by the following block diagram:

Software implementation block diagram in Android

These include:

  • BSP Reference
  • Linux Kernel Driver (LSM303DLH_ACC + LSM303DLH_MAG)
  • HAL Library(Sensors_lsm303dlh + Liblsm303DLH) for sensors.default.so

After calculation by the library, upper-layer applications can easily use the yaw angle information defined by Android and provided by the Library to write their own applications.

Reference address:ST integrated sensor solution realizes electronic compass function

Previous article:Mobile Robot Motion Detection System Based on Dual-Axis Micromechanical Gyroscope
Next article:Design of low temperature co-fired multilayer ceramic bandpass filter

Latest Analog Electronics Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号