Some views on geomagnetic sensors

Geomagnetic sensor (HMC5883) sometimes needs precise direction control in some motion systems. Although there are many ways to measure the direction, the most convenient and common one is to measure the earth's magnetic field.

Taking geomagnetism as a reference, the azimuth data can be obtained by measuring the angle between the sensor and the geomagnetic line, so as to realize accurate direction control. What we are going to discuss here is the geomagnetic sensor (also called digital compass or electronic compass) and its usage.

Commonly used geomagnetic sensors mainly include Freescale's MAG series and Honeywell's HMC series. Here is to discuss the common Honeywell HMC5883 geomagnetic sensor on the market.

HMC5883 is a surface-mounted weak magnetic sensor chip with high integration and IIC digital interface. It includes the most advanced high-resolution HMC 1 18X series magnetoresistive sensors, and Honeywell patented integrated circuits (including amplifiers, automatic degaussing drivers and deviation calibration, etc.). ). It has a 12 bit analog-to-digital converter, which can control the compass accuracy between 1 ~ 2. Honeywell's magnetic sensor is the most sensitive and reliable sensor in the low magnetic field sensor industry. Its measuring range can be from milligauss to 8 gauss.

The working voltage of HMC5883 is between 2. 16V~3.6V, with a typical value of 3.3V. Although the working voltage is low, the voltage of the data port can be specified through VDDIO port, so there are two ways to interface with the single chip microcomputer, one is 5V mode, and the other is 3.3V mode.

For the electrical parameters and characteristics of HMC5883, please refer to its data manual. Here, we only discuss how to use HMC5883 to obtain geomagnetic data. Because the control of the module is generally realized by writing the corresponding register, let's first understand the register of HMC5883. HMC5883 has 12 sets of registers, of which 6 sets are used to store X, Y and Z triaxial data, and the other 6 sets are control registers.

Like all IIC bus devices, HMC5883 has a fixed device address. According to its data sheet, the default slave address of HMC5883 is 0x3C (writing direction) or 0x3D (reading direction). At the same time, in order to minimize communication with single chip microcomputer, HMC5883 can automatically update its address pointer without host intervention. There are two principles for pointer update. First, if the accessed address is 12 or above (that is, identification register c), the pointer will be updated to address 00 (that is, it will automatically return to the beginning). Second, if the accessed address reaches 8 (LSB register of Y), the pointer will roll back to address 03 (MSB register of X). The advantage of this is obvious, because the address 03~0 8 stores the measurement data to be read repeatedly, so the address pointer automatically circulates here when reading, which can reduce a lot of codes for resetting the address and improve the access efficiency. Like other IIC devices, in order to move the address pointer to the specified register address, a write instruction is first issued to the register address, and then the address bit. For example, let the address pointer point to the register 10, and the instruction issued is 0 x3C (writing direction) 0 x0A (i.e. address 10). Configuration register A (address 00) is mainly used to set the average value of output samples, output rate, measurement configuration bits and other related parameters. For normal application, its default value (average sampling value is 8, output rate is 15Hz, normal measurement configuration) can be adopted without change. If changes are really needed, please refer to the management data sheet in detail. The configuration register B (address 0 1) is mainly used to set the gain, and its default value can also be used for normal application without change. If changes are really needed, please refer to the management data sheet in detail. The mode register (Address 0 2) is used to select the working mode of HMC5883. It has three working modes, namely continuous measurement mode (the last two digits are 00), single measurement mode (the last two digits are 0 1) and idle mode (the last two digits are 1 0 or1). The default is single measurement mode, which generally needs to be changed to continuous measurement mode. You only need to change the last two digits of this register to 00. The status register (address 0-9) is mainly used to provide the current status of the device. Only the last two bits are valid, and the last bit is the ready bit. Only when the ready bit is set can the device operate. The penultimate bit is the data output register latch bit. When this bit is set, no measurement data will be updated before reading the measurement data. Generally speaking, conventional applications can read the status of the register with appropriate delay, and it is not necessary to read the status of the register unless the reading frequency is very high. There is no need to identify register A (address 10) to identify register C (address 12) here, so we will not discuss them. Please read the data sheet yourself if necessary. At that time, HMC5883 had some other practical functions, such as self-checking. It is equipped with a self-checking function module, which uses the bias band of the excitation sensor to generate a nominal magnetic field intensity for self-checking to prove its quality. In addition, there is a calibration function of scale factor, which can compensate the interference caused by the surrounding magnetic field to obtain accurate geomagnetic measurements. Let's take an example to see the specific application of HMC5883.

Example: Single chip microcomputer reads geomagnetic data from HMC5883, converts it into angle data due south, and displays it by LCD 16 02. The microcontroller adopts ATMega 16, and the connection with HMC5883 adopts 5V mode. The SDA and SCL terminals of HMC5883 are respectively connected to TWI terminals (PC 1 and PC0) of ATMega 16, and the connection method of LCD 1602 is the same as the previous one.