Which electronic compass is better, HMC5883L or HMC5983?

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

Using geomagnetism as a reference, the azimuth angle data can be obtained by measuring the angle between the sensor and the geomagnetic lines, thereby achieving precise direction control. Here we discuss geomagnetic sensors (also known as digital compasses or electronic compasses) and how to use them.

Commonly used geomagnetic sensors mainly include FreeScale’s MAG series and Honeywell’s HMC series. The following discussion will be based on the common Honeywell HMC5883 geomagnetic sensor on the market. .

HMC5883 is a surface mount, highly integrated, weak magnetic sensor chip with IIC digital interface. It contains the most advanced high-resolution HMC118X series magnetoresistive sensor, and comes with Honeywell's patented integrated circuit (including amplifier, automatic degaussing driver and deviation calibration, etc.), with a 12-bit analog-to-digital converter to ensure compass accuracy. Control it between 1° and 2°. Honeywell's magnetic sensors are the most sensitive and reliable in the low field sensor industry. Its measurement range can be from milligauss to 8 gauss.

The operating voltage of HMC5883 is between 2.16V~3.6V, typically 3.3V. Although the working voltage is low voltage mode, the voltage of the data port can be specified through the VDDIO port, so there are two ways to interface with the microcontroller, one is the 5V mode for the microcontroller, and the other is the 3.3V mode for the microcontroller.

For the electrical parameters and characteristics of HMC5883, please refer to its management data sheet. Here we only discuss how to apply HMC5883 to obtain geomagnetic data. Since the control of the module is generally achieved by writing corresponding registers, let's first understand the register situation of HMC5883. There are 12 sets of registers inside the HMC5883, of which 6 are used to store X, Y, and Z axis data, and the remaining 6 are control registers.

Like all IIC bus devices, HMC5883 also has a fixed address of the device. According to its data sheet, the factory default slave address of HMC5883 is 0x3C (write direction), or 0x3D (read direction) ). At the same time, in order to minimize communication with the microcontroller, HMC5883 can automatically update its address pointer without host intervention. There are two principles for pointer update. First, if the accessed address is 12 (i.e., identification register C) or above, the pointer will be updated to address 00 (i.e., it will automatically return to the beginning). Second, if the accessed address reaches 8 (i.e., it will automatically return to the beginning). That is, the LSB register of Y), the pointer will roll back to address 03 (that is, the MSB register of X). The benefits of this are obvious, because addresses 03~0 8 store data measurement values ??that need to be read repeatedly, so the address pointer automatically circulates here when reading, which can reduce a large amount of code to reset the address and improve Access efficiency. Like other IIC devices, to move the address pointer to a specified register address, a write command must first be issued to the register address, followed by an address bit. For example, to make the address pointer point to register 10, the instruction issued is 0x3C (write direction) 0x0A (ie address 10). Configuration register A (address 00) is mainly used to set related parameters such as output sampling average, output rate and measurement configuration bits. For regular applications, its default value can be used (sampling average 8, output rate 15Hz, normal measurement configuration), no need to change it. If you really want to change it, you can refer to the management's data manual for details. Configuration register B (address 01) is mainly used to set the gain. For regular applications, its default value can be used without changing it. If you really want to change it, you can refer to the management's data manual for details.

The mode register (address 0 2) is used to select the working mode of HMC5883. It has three working modes at a time, namely continuous measurement mode (the last two digits are 00) and single measurement mode (the last two digits are 01). and idle mode (last two bits are 1 0 or 11). The default is single measurement mode, generally it needs to be changed to continuous measurement mode. When changing, you only need to change the last two digits of the 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. The device can only be operated after ready is set. The penultimate bit is the data output register latch bit. When this bit is set, any measurement data will not be updated until the measurement data is read. Generally, conventional applications can read with appropriate delay without having to read the status of this register, unless reading the status of this register is considered when the frequency of reading is very high. Identification register A (address 10) to identification register C (address 12) are not used here and will not be discussed. If necessary, please read the data sheet by yourself. At that time, HMC5883 also had some other practical functions, such as the ability to perform self-test. It was equipped with a self-test function module that used the excitation sensor offset band to generate a nominal magnetic field strength to be measured for self-test to prove its good performance. bad. In addition, there is a scaling factor calibration function, which can compensate for the interference caused by the surrounding magnetic field to obtain accurate geomagnetic measurements. Let's take an example to look at the specific application of HMC5883.

Example: Use the microcontroller to read the geomagnetic data from HMC5883, convert it into angle data with true south, and display it through LCD16 02. The microcontroller uses ATMega16, and the connection method with HMC5883 is 5V. The SDA and SCL terminals of HMC5883 are connected to the TWI terminals (PC1, PC0) of ATMega16 respectively. The connection method of LCD1602 is the same as before.