1001766 R01- Revised 13Jan04 Application Note: Multipoint Calibration Primer Introduction PNI Corporation’s Magneto-Inductive (MI) sensors are based on patented technology that delivers breakthrough, cost-effective magnetic field sensing performance. These sensors change inductance with different applied magnetic fields. This variable inductance property is used in a patented temperature and noise stabilized oscillator/counter circuit to detect field variations. The PNI 11096 ASIC is the recommended implementation of this patented circuit, and can be used with the MI sensors to construct a magnetometer with up to 3-axes. PNI Corporation’s MI sensors employ a single solenoid winding for each axis and consume roughly an order of magnitude less power than conventional fluxgate or magneto-resistive technologies. The sensor coil serves as the inductive element in a very simple, low-power LR relaxation oscillator, with its effective inductance being influenced by the magnetic field component parallel to the coil axis. The frequency of the oscillation changes with the magnetic field. The 11096 ASIC outputs a digital signal that can be fed directly into a microprocessor. This eliminates the need for any signal conditioning or analog/digital interface between the sensor and a microprocessor. The simplicity of the sensor circuit combined with the lack of signal conditioning makes the magneto-inductive sensor easier and less expensive to use in your product design than fluxgate or magneto-resistive sensors. Magneto-inductive sensors and the 11096 ASIC are available from PNI Corporation through licensing agreements. Please contact PNI Corporation to discuss the possibility of a license agreement before designing these sensors into your products. This primer will cover the basics if how to determine heading, calibrate out hard iron distortions, and perform sensor gain matching for a compass built with PNI Corporation’s sensors and ASIC. More detailed information regarding the use of the ASIC and sensors can be found in their respective data sheets. • PNI 11096 ASIC – “PNI-11096 3-Axis Magneto-Inductive Sensor Driver and Controller with SPI Serial Interface” (Document Number 1000005) • SEN-S65 – “SEN-S65 Magneto-Inductive Sensor” (Document Number 1000619) • SEN-L – “SEN-L Magneto-Inductive Sensor” (Document Number 1000620) PNI Corporation 5464 Skylane Blvd., Ste. A, Santa Rosa CA 95403-1084 USA 1 For more information, please call PNI Corporation direct at (707) 566-2260, email: [email protected], or visit PNI’s website at http://www.pnicorp.com Multipoint Calibration Primer Compass Coordinates +X Y X -Y +Y -X Figure 1 Note: The X is the vertical axis while Y is the horizontal axis. Due to this arrangement the heading is the angle from the +X. The formula to compute the heading is as follows: angle = atan (Y / X ) Quadrant Determination Since the arctangent result is only in the range of 0 to 90, care is needed to take note of the sign of X and Y to determine the correct quadrant and to add the proper padding to determine heading. The following table lists the values and the corresponding formula to determine quadrant placement. PNI Corporation 5464 Skylane Blvd., Ste. A, Santa Rosa CA 95403-1084 USA 2 For more information, please call PNI Corporation direct at (707) 566-2260, email: [email protected], or visit PNI’s website at http://www.pnicorp.com Multipoint Calibration Primer X Value <0 <0 Y Value <0 <0 Formula Heading = angle Heading = 180 – angle Heading = 180 + angle Heading = 360 – angle Quadrant +X, +Y -X, +Y -X, -Y +X, -Y (0 – 90) (91 – 180) (181 – 270) (271 – 359) Sensor Orientation In order for the heading computation to be valid, the following points must be made: 1. The sensors are assumed to be at right angles with respect to each other and lie perpendicular with respect to the Earth’s gravity. 2. By convention, the positive end of the X-axis points to the North and the positive end of the Y-axis points East. See Figure 2. 3. The compass should be installed into the host system in its intended operating configuration in as level a position as possible. Do not calibrate the compass, and then place it into the host system. Front Y X Figure 2 Compass Calibration Using Multi-Point Method As the name implies, multiple (X, Y) points must be acquired to properly calibrate the compass. When using the PNI 11096 ASIC, acquire a (X, Y) point as shown in the “PNI 11096 ASIC Operation Flow Chart” at the end of this document. More detail is available in the “PNI-11096 3Axis Magneto-Inductive Sensor Driver and Controller with SPI Serial Interface” data sheet. The sensing circuit is composed of the MI sensors and external bias resistors along with digital gates and a comparator internal to the PNI-11096. Only one sensor can be measured at a time. The user sends a command byte to the PNI-11096 through the SPI port specifying the sensor axis to be measured. The PNI-11096 will return the result of a complete forward - reverse measurement of the sensor in a16-bit 2’s Complement format. (Range: -32768 to 32767) The code on the next page shows how the acquisition phase of the calibration is done. PNI Corporation 5464 Skylane Blvd., Ste. A, Santa Rosa CA 95403-1084 USA 3 For more information, please call PNI Corporation direct at (707) 566-2260, email: [email protected], or visit PNI’s website at http://www.pnicorp.com Multipoint Calibration Primer Acquisition Code int int Xmax, Xmin, Ymax, Ymin; Xraw, Yraw; // where you store max and min X and Ys // values you get from the ASIC // The numbers here will be 16-bit signed values. // Positive = 0x0000 to 0x7FFF // Negative = 0x8000 to 0xFFFF Xmax = Ymax = -32768; Xmin = Ymin = 32767; // start with lowest possible value // start with highest possible value for ( ; ; ) { GetRawXY(); // acquire a (X,Y) point // now sort it If( Xraw > Xmax ) Xmax = Xraw If( Xraw < Xmin ) Xmin = Xraw If( Yraw > Ymax ) Ymax = Yraw If( Yraw < Ymin ) Ymin = Yraw } The above code results in an infinite loop; it can be modified so the loop stops when there are enough points acquired. Figure 3 below shows a possible graph of all the points acquired. 500 400 300 200 100 0 -600 -400 -200 -100 0 200 400 600 800 -200 -300 -400 Figure 3 PNI Corporation 5464 Skylane Blvd., Ste. A, Santa Rosa CA 95403-1084 USA 4 For more information, please call PNI Corporation direct at (707) 566-2260, email: [email protected], or visit PNI’s website at http://www.pnicorp.com Multipoint Calibration Primer The graph in Figure 3 is elliptical with the major axis along the Y. The elliptical figure is due to the Y values having a greater gain than the X values. The center of the ellipse is also off the origin. The next section of code shows how to compute the calibration values based on the maximum and minimum X and Y values acquired. These values will later be used to correct the raw X and Y values acquired when computing the heading. Calibration Values int int Xrange, Yrange; Xoffset, Yoffset; Xoffset = ( Xmax + Xmin ) >> 1; Yoffset = ( Ymax + Ymin ) >> 1; Xrange = ( Xmax – Xmin ); Yrange = ( Ymax – Ymin ); // calculate offsets // calculate the range Computing the Heading To get the correct heading a graph of the points (X, Y) should show a circle with the center in the origin. The following code shows how the raw (X, Y) point is corrected using the calibration values to get a perfect circle at the origin: Compute Heading float int int pi = atan( 1 ) * 4; Xvalue, Yvalue; angle, heading; // compute PI GetRawXY(); // get coordinates Xvalue = Xraw – Xoffset; Yvalue = Yraw – Yoffset; // subtract out the offsets if( Xrange > Yrange ) Yvalue = ( Yvalue * Xrange ) / Yrange; // perform gain matching Xvalue = ( Xvalue * Yrange ) / Xrange; // perform gain matching else angle = atan( Yvalue / Xvalue ) * 180 / pi; // compute the angle if( Xvalue >=0 && Yvalue >= 0 ) heading = angle; // quadrant +X, +Y (0 to 90) else if( Xvalue < 0 && Yvalue >= 0 ) heading = 180 – angle; // quadrant –X, +y (91 to 180) else if( Xvalue < 0 && Yvalue < 0 ) heading = 180 + angle; // quadrant –X, -Y (181 to 270) else if( Xvalue >= 0 && Yvalue < 0 ) heading = 360 – angle; PNI Corporation // quadrant +X, -Y (271 to 359) 5464 Skylane Blvd., Ste. A, Santa Rosa CA 95403-1084 USA 5 For more information, please call PNI Corporation direct at (707) 566-2260, email: [email protected], or visit PNI’s website at http://www.pnicorp.com Multipoint Calibration Primer Figure 4 shows the plot of the corrected X, Y points using the calibration values. The offsets move the center of the circle back to the origin and the ranges are used to match the gain so the graph will become a circle from the original ellipse. 600 400 200 0 -600 -400 -200 0 200 400 600 -200 -400 -600 Figure 4 Notes Declination Declination is the difference between magnetic north and true north. There is a difference between the two directions because the earth’s magnetic North Pole is not in the same location as the true North Pole. A compass measures earth’s magnetic field, so it always points to magnetic North. An additional complexity is that the difference between magnetic North and true North varies from place to place. Fortunately, there are many ways to obtain declination. Most hiking topographic maps will list declination. Declination can also be found at web pages such as the National Geophysical Data Center’s site www.ngdc.noaa.gov/cgi-bin/seg/gmag/fldsnth1.pl . Declination is defined as "East" if magnetic North falls to the east of true North; and "West" if magnetic North falls to the West of true North. A positive declination is “East", and a negative declination is "West". For instance, the NGDC website listed above shows that for Mountain View, CA (37N, 122W) the declination is "15d 25.7m". First, it is positive, so it is Eastward declination. The "d" stands for degrees; the "m" stands for minutes. 60 minutes = 1 degree, so the declination is 15.4º east. Once declination is known, the compass heading can be corrected so that heading can be determined relative to true North. Add the declination value to the compass measurement to get the true heading. For example, if the declination is 15°E, add 15° to the compass measurement. If the declination is 10°W, add -10° to the compass measurement. PNI Corporation 5464 Skylane Blvd., Ste. A, Santa Rosa CA 95403-1084 USA 6 For more information, please call PNI Corporation direct at (707) 566-2260, email: [email protected], or visit PNI’s website at http://www.pnicorp.com Multipoint Calibration Primer Other Disturbances When an EL or other backlight is used in a compass system, it is often observed that turning the backlight on causes a heading change in one or more directions. This is due to the fact that the backlight system often draws enough current during operation to cause the voltage level of a battery based power supply to drop enough to affect the zero offset of the ASIC. In addition, if there is other backlight support circuitry, such as inductors or other current loops, the magnetic fields generated by those components can directly affect the sensor readings to create similar heading changes as well. An algorithmic solution to this problem can be implemented during the user calibration procedure that the user of the compass would normally execute. In addition to obtaining the magnetic offset for each of the X and Y axes (Xoffset and Yoffset), the backlight is turned on for 1/2 second (and then turned off) and an additional reading of the sensors is taken before the user is instructed to start the calibration rotations. The X and Y values taken while the backlight is momentarily on are stored as Xbacklight_offset and Ybacklight_offset. Then, whenever during normal operation, the backlight is turned on, simply take the raw sensor readings, Xraw and Yraw, subtract out Xoffset and Yoffset, and then subtract out Xbacklight_offset and Ybacklight_offset. So it is: X = Xraw - Xoffset - Xbacklight_offset Y = Yraw - Yoffset - Ybacklight_offset. Whenever the backlight is not on, then do not subtract out Xbacklight_offset and Ybacklight_offset for the values to be used in the ArcTan calculations. PNI Corporation 5464 Skylane Blvd., Ste. A, Santa Rosa CA 95403-1084 USA 7 For more information, please call PNI Corporation direct at (707) 566-2260, email: [email protected], or visit PNI’s website at http://www.pnicorp.com Multipoint Calibration Primer PNI 11096 ASIC Operation Flow Chart Notes: 1 This is optional. Applicable only if the PNI 11096 ASIC power is controlled by the microcontroller to reduce power consumption when not in used. START APPLY POW ER TO ASIC 1 2 *SS is an active low input. 3 XXX is the period select settings. It determines the resolution of the 16-bit count. *SS 2 <- COMMAND BYTE 3 0XXX0001b (X Coil) 4 RESET is an active high input. It is level triggered so the reason for sending a pulse. RESET 4 <- 5 Communications is done by synchronous serial. 6 DRDY is an active high output. This can be polled or connected to an external interrupt of the microtroller. SEND COMMAND BYTE 5 7 DRDY 6 -> YES GET 16-BIT VALUE 7 Y COIL VALUE? If the microcontroller SPI only does 8bits at a time then you can get the 16-bit value by initiating two 8-bit receptions, one after the other. NO COMMAND BYTE 3 0XXX0010b (Y Coil) NO YES *SS 2 <- REMOVE POW ER FROM ASIC 1 END PNI Corporation 5464 Skylane Blvd., Ste. A, Santa Rosa CA 95403-1084 USA 8 For more information, please call PNI Corporation direct at (707) 566-2260, email: [email protected], or visit PNI’s website at http://www.pnicorp.com