Application Note AN8000.12 Wireless Compass AN8000.12 Application Note Wireless Compass Rev 1 February 2006 www.semtech.com 1 Application Note AN8000.12 Table of Contents 1 INTRODUCTION ......................................................................................................................................3 2 GENERAL DESCRIPTION.......................................................................................................................3 2.1 BLOCK DESCRIPTION .............................................................................................................................3 2.2 FUNCTIONAL DESCRIPTION .....................................................................................................................4 2.3 COMPONENTS DESCRIPTION ...................................................................................................................4 2.3.1 Compass Sensor ........................................................................................................................4 2.3.2 XE8805/05A microcontroller .......................................................................................................4 2.3.3 XE1209 Transceiver (30 – 70 kHz) for short-range apps (1 to 3 meters)....................................4 2.3.4 XE1201A Transceiver (300 - 500 MHz) for long range apps (200 to 300 meters).......................4 3 SENSOR INTERFACE .............................................................................................................................5 3.1 MEASURE PRINCIPLE .............................................................................................................................5 3.1.1 HMC1052 characteristics............................................................................................................5 3.1.2 XE8805/05A ZoomingADCTM characteristics ..............................................................................7 TM 3.1.3 ZoomingADC configuration example.......................................................................................7 3.1.4 Hardware Interface .....................................................................................................................9 3.1.5 Measurement Flowchart .............................................................................................................9 4 RF TRANSCEIVER INTERFACE ...........................................................................................................12 4.1 PROTOCOL DESCRIPTION .....................................................................................................................12 4.2 HARDWARE INTERFACE ........................................................................................................................13 4.2.1 XE1209 - XE8805/05A interface...............................................................................................13 4.2.2 XE1201A - XE8805/05A interface ............................................................................................14 4.3 RF LINK FLOWCHART ...........................................................................................................................16 5 SYSTEM PERFORMANCES..................................................................................................................19 6 MOBILE SYSTEM SCHEMATICS..........................................................................................................20 7 BOARD DESCRIPTION .........................................................................................................................21 © Semtech 2006 www.semtech.com 2 Application Note AN8000.12 1 Introduction The aim of this application note is to explain the different steps to build a wireless compass based on XE8805/05A capabilities. This application note demonstrates XE8805/05A performances as both sensing machine and RF communication driver. To implement the compass function, we use a HMC1052 magnetic sensor. XE1209 (LW) or XE1201A (UHF) radio transceivers are used to handle RF communication. 2 General Description 2.1 Block Description Figure 1 shows a wireless compass sensing machine. This system is composed of two different parts: - The first part, including compass sensor, which is mobile The second part, which is connected to a base station (PC) The mobile system includes a HMC1052 compass sensor, a transceiver (XE1201A or XE1209) and a XE8805/05A microcontroller. The base system includes a transceiver (XE1201A or XE1209), a XE8805/05A microcontroller and a PC. COMPASS SENSOR Y X ANTENNA X Y 2 XE1201 or XE1209 ZoomingADC HMC1052 8 XE88LC05 MOBILE SYSTEM XE88LC05 ANTENNA 2 XE1201 or XE1209 UART Tx RS 232 UART Rx 8 PC station BASE SYSTEM Figure 1 : Global Description © Semtech 2006 www.semtech.com 3 Application Note AN8000.12 2.2 Functional Description The mobile system is in reception mode and waits for a command message from the base system. This command can be “measure” or “calibrate”. If it is “measure”, the mobile system performs an acquisition, calculates heading and finally sends the measure to the base station. If it is “calibrate”, it performs a calibration of the compass sensor in order to eliminate its offset. On the other hand, the base system is waiting for an UART message. This message can be “measure request” or “calibration request”. If it is “measure request”, the base system sends the command “measure” to the mobile system and waits for the measure. When it receives the measure, it is sent to the PC using UART connection. Then the position appears on the Com Port interface. 2.3 Components description 2.3.1 Compass Sensor HMC1052 is a high performance two-axis magnetoresistive sensor on a single chip. Advantages of this design include perfectly orthogonal two-axis sensing, ultra small size and low power. HMC1052 sensitivity is 1mV/Vsupply/Oersted (1Oersted=1Gauss=1µTesla). As Earth’s magnetic field is about 0.5 Gauss, the HMC1052 sensor is very efficient in compassing applications. Sensor principle is the following. There are two resistive Wheatstone bridges formed by a magnetoresistive metal film. When a power supply is connected to the bridge, the sensor converts any ambient or applied magnetic field in the sensitive direction to a voltage output. For more information about this product, consult http://www.magneticsensors.com web site. 2.3.2 XE8805/05A microcontroller The XE8805/05A is an ultra low-power microcontroller unit associated with a versatile analog-to-digital converter including programmable offset and gain pre-amplifier. This acquisition chain named ZoomingADCTM also includes an analog multiplexer (AMUX) allowing selection of four differential input channels. As the XE8805/05A has several sources of interrupts and events, it can directly read the XE1201A or XE1209 data output and synchronized clock. 2.3.3 XE1209 Transceiver (30 – 70 kHz) for short-range apps (1 to 3 meters) The XE1209 is a CMOS Ultra Low-Power single chip transceiver for short-range low frequency RF data communications system. It uses 2-level Continuous Phase FSK modulation. The receiver section includes the preamplifier, the down-converter, the channel filters, the demodulator and the bit synchronizer, which delivers synchronized data at the output. The transmitter section is composed of a Direct Digital Synthesizer, and the power amplifier generating a square-wave output current. The XE1209 has a peak detector to detect the presence of a signal at the carrier frequency. The local clock is based on a 32 kHz crystal oscillator and a PLL to generate the required output frequency. The XE1209 has a simple interface with an external microcontroller. 2.3.4 XE1201A Transceiver (300 - 500 MHz) for long range apps (200 to 300 meters) The XE1201A is a half-duplex FSK transceiver for operation in the 433 MHz ISM band (optimized) and in the 300-500 MHz band. The modulation used is the Continuous Phase, 2 level Frequency Shift Keying (CPFSK). The direct conversion (zero-IF) receiver architecture enables on-chip channel filtering. The XE1201A includes a bit synchronizer so that glitch free data with synchronized clock can directly be read by a low cost / low complexity microcontroller. The transmitted power level can also be controlled via the bus. For more information on XE8000 microcontroller series and XE1200 RF transceiver series, please consult the Semtech website http://www.semtech.com . © Semtech 2006 www.semtech.com 4 Application Note AN8000.12 3 Sensor Interface 3.1 Measure Principle 3.1.1 HMC1052 characteristics HMC1052 is a two-axis linear magnetic field sensor. Each sensor is a resistive Wheatstone bridge formed by a magnetoresistive metal film. This device contains two magnetic field sensors with sensitive directions perpendicular to each other. Sensor A and Sensor B coexist on a single silicon chip with nearly perfect orthogonality and matching characteristics. Figure below shows internal circuit diagram of the HMC1052 sensor, with its two Wheatstone bridges. Figure 2 : HMC1052 internal circuit As the sensor has two axis, measuring differential output voltage on each one gives Earth magnetic field X and Y components. Using mathematical expression Arctan (Y / X) allows to calculate the heading angle of the compass. Depending on the sign of X and Y components, heading position can be calculated as below: IF (|Y| > |X|) For (Y < 0) X Heading = − (arcTan Y − 90°) For (Y > 0) X Heading = 180° − (arcTan Y − 90°) IF (|X| > |Y|) For (X > 0, Y < 0) Y Heading = 360° + arcTan X For (X > 0, Y > 0) Y Heading = arcTan X For (X < 0) Y Heading = 180° + arcTan X IF (|X| = |Y|) For (X > 0, Y > 0) Heading = 45° For (X > 0, Y < 0) Heading = 315° For (X < 0, Y > 0) Heading = 135° For (X < 0, Y < 0) Heading = 225° © Semtech 2006 www.semtech.com 5 Application Note AN8000.12 Sensor sensitivity is approximately 1mV / V /Gauss, so the sensor transfer function is the following for Vbridge = 3 Volts. HMC1052 Output Voltage in mV 4 3 2 1 0 -1.5 -1 -0.5 -1 0 0.5 1 1.5 -2 -3 -4 Magnetic Field in Gauss Figure 3 : HMC1052 Transfer Function This transfer function does not include bridge offset that could be from –2.5 mV / V to 2.5 mV / V. Because the Earth’s magnetic Field maximal value is 0.5 Gauss, it is possible to zoom on this chart. Figure 4 below shows sensor output characteristic without offset, and both positive and negative maximum offset. HMC1052 Output Voltage in mV 10 With maximum positive offset 8 6 4 2 0 -0.6 -0.4 -0.2 -2 0 0.2 0.4 0.6 Without offset -4 -6 -8 -10 With maximum negative offset Magnetic Field in Gauss Figure 4 : Zoom on HMC1052 Transfer Function with bridge offset For more details on Honeywell HMC1052 magnetic sensor, consult: http://www.magneticsensors.com/datasheets/hmc1051-1052.pdf . © Semtech 2006 www.semtech.com 6 Application Note AN8000.12 3.1.2 XE8805/05A ZoomingADCTM characteristics XE8805/05A ZoomingADCTM is appropriate for that kind of measure thanks to its programmable gain amplifier with offset compensation (PGAs). It also allows the measure of the two axis with its efficient analog multiplexer. See below Figure 5 that shows XE8805/05A ZoomingADCTM block diagram. Figure 5 : ZoomingADCTM block diagram In our case, the two axis of the sensor are respectively connected to the first (AC_A0–AC_A1) and second (AC_A2–AC_A3) input channel of ZoomingADCTM and all PGAs are enabled. The AD converter is used to convert the differential input signal into a 16 bit 2’s complement output format. For more details on ZoomingADCTM performances, consult AN8000.05 on the Semtech website. 3.1.3 TM ZoomingADC configuration example Vsupply = ZoomingADCTM reference (Vref) = 3 V How does one calculate the necessary gain to cover ADC full scale? First, one has to measure the maximum (in absolute value) output voltage of the sensor he is using because each sensor has its own offset. Vref/2 Gain = | Vout (max) | . How does one calculate the necessary offset compensation for each axis? A software routine calculates this offset compensation. It is called calibration (). During this routine execution, one has to rotate the sensor in all direction to be sure that the acquisition chain measures X &Y components extreme value (Xmax, Xmin, Ymax, and Ymin). At the end of the calibration routine, the program calculates offset compensation the way below: Xmax Xmin Xoffset = 2 + 2 . Yoffset = Ymax Ymin 2 + 2 . © Semtech 2006 www.semtech.com 7 Application Note AN8000.12 These offsets are subtracted from each measure: X = Xmeasure – Xoffset. Y = Ymeasure – Yoffset. 40000 30000 20000 TM ZoomingADC output code (decimal) When all these parameters are defined, ZoomingADCTM output characteristic is the one on Figure 6 below: 10000 0 -0.6 -0.4 -0.2 -10000 0 0.2 0.4 0.6 -20000 -30000 -40000 Magnetic Field in Gauss Figure 6 : ZoomingADCTM block diagram © Semtech 2006 www.semtech.com 8 Application Note AN8000.12 AC_R1 PB3 Hardware Interface Interfacing HMC1052 and XE8805/05A is quite simple. Each differential output voltage of the sensor is connected to one ZoomingADCTM input channel. For lower power consumption, sensor voltage supply is connected to XE8805/05A pin PB [2] and PB [3] as ZoomingADCTM voltage reference is. To perform a 0.5 A set pulse on the sensor, a RC circuit with a push button are used. Figure 7 shows HMC1052-XE8805/05A hardware interface. PB2 3.1.4 AC_R0 OUT A- AC_A0 GND1 OUT A+ AC_A1 GND2 HMC1052 OUT B- AC_A2 S/R- OUT B+ AC_A3 S/R+ VDD GND XE88LC05 3V R C Figure 7 : HMC1052-XE8805/05A interface 3.1.5 Measurement Flowchart First, you need to initialize ZoomingADCTM configuration registers with the appropriate value. You can see below the configuration register map on Figure 8. TM Figure 8 : ZoomingADC register map X and Y components cannot be measured simultaneously. You need to use AMUX (4:0) to select the appropriate input channel. In our case, AMUX = 0 (select Vin1 = AC_A0 – AC_A1) to measure X component and AMUX = 1 (select Vin2 = AC_A2 – AC_A3) to measure Y component. The last step is the heading calculation. © Semtech 2006 www.semtech.com 9 Application Note AN8000.12 You can see in the table below (Figure 9) the aim of each function used in measurement application. Function name Function purpose Source file Init_ZoomingADC () initialize acquisition chain configuration registers AMUX configure on Channel1 (Vin1) and measure X AMUX configure on Channel2 (Vin2) and measure Y Measure X & Y 300 times to find each axis offset Calculate heading position of the compass Measure X & Y component and calculate heading measure.c Meas_X () Meas_Y () Calibration () Heading () meas_calc_heading () measure.c measure.c measure.c measure.c measure.c Figure 9 : Measure Functions. © Semtech 2006 www.semtech.com 10 Application Note AN8000.12 Figure 10 shows measurement flowchart that explains different steps of heading calculation. ZoomingADC init Measure_Request Measure_X Calibration_Request Measure_X ADC_Interrupt ADC_Interrupt Store X measure Store X measure Measure_Y ADC_Interrupt Store Y measure Measure_Y ADC_Interrupt Search X & Y extremum value Store Y measure Rotate sensor Calculate Heading Loop = 300 No Yes Calculate Xoffset & Yoffset Store Xoffset & Yoffset Figure 10 : Measurement Flowchart © Semtech 2006 www.semtech.com 11 Application Note AN8000.12 4 RF Transceiver Interface To achieve an RF link, use of Semtech’s RF transceivers is quite easy. Their programming via a 3-wire bus facilitates interface with microcontrollers. In our case, XE1209 (30–70 kHz band) and XE1201A (300–500 MHz band) are used to handle the RF link, depending on the frequency and on the range one wants to use for RF communication. 4.1 Protocol Description This description handles both XE1209 and XE1201A RF transceivers. Only the programming changes between these transceivers because XE1209 has only one programming register whereas XE1201A has three. Figure 11 below describes RF frame contents. Preamble (16 to 32 bits) Start word (8 bits) Receiver ID (8 bits) Transmitter ID (8 bits) RF Command (8 bits) Buffer Length (8 bits) DATA Stop word (8 bits) Buffer [0] to Buffer [Length] (8 bits * Buffer Length) Figure 11 : RF Frame contents Preamble is a sequence of “0” and “1” used to synchronize data and clock at transceiver output. Start word defines the beginning of RF transmission. Receiver ID and Transmitter ID define recipient and owner identity. In our case, they are not very useful because there are only two transceivers in the application. However, if you want to handle a multipoint application, you just have to define one identity for each mobile system, and this way you can avoid possible collision problems. RF Command defines the process recipient has to handle. For example, it can be measure or calibration for the mobile system. Buffer Length defines size of the transmitted buffer []. Stop word defines the end of RF transmission. © Semtech 2006 www.semtech.com 12 Application Note AN8000.12 For each transmission, the recipient does not handle the RF Command until frame parameters received have been tested. RF Command can have different values explained in the table below (Figure 12). RF Command name role identification Send to the base system after each power on or reset Send to the transmitter after each good reception of a message Send to the mobile system after each UART measure request Send to the mobile system after each UART calibration request Send to the base system in the same frame as heading ACK measure_head calibrate measure_send Figure 12 : RF Command Table A transmission is complete when the owner of the message has received an ACK Command from the recipient so that there is no data losses. 4.2 Hardware Interface 4.2.1 XE1209 - XE8805/05A interface Figure 13 below shows XE1209 pins characteristics. Figure 13 : XE1209 pinout and pin description XE8805/05A with is large source of interrupt and event permits the interface with a XE1209 RF transceiver in a very simple way. First, XE1209 needs 3-wire bus for its programming (pins SC, SD and DE). This can be done by using 3 output pin of Port C (PC [0…2]). To change mode from transmission to reception you just have to put VDD on pin RE of the XE1209. So, a simple connection with the output pin PC[3] is necessary. Data are transmitted and received on the same pin named DATA. So, you have to use the I / O pin PC[4]. In reception mode, data must be read on rising edge of DCLK. To achieve this, using pin PA[1] seems appropriate since it is one of XE8805/05A event sources. On each PA[1] event (rising edge) it is quite easy to read DATA on pin PC[4]. Of course, XE1209 needs a power supply. You just have to connect XE1209 VDDA and VDD pins to XE8805/05A VDD pin, and VSSPA VSSA and VSS to XE8805/05A VSS pin. © Semtech 2006 www.semtech.com 13 Application Note AN8000.12 Figure 14 below shows all these connections. Test SC PC1 VSS SD PC2 Qin DE PC0 VDDA DATA PC4 Qout DCLK PA1 VDD PC3 VSSA XE1209 IREF PAOUT Vref VSSPA SUPTest RE XE88LC05 INB INA For ease of reading, power supply is not shown on this Figure 14 : : XE1209 – XE8805/05A interface 4.2.2 XE1201A - XE8805/05A interface Figure 15 below shows XE1201A pins characteristics. © Semtech 2006 www.semtech.com 14 Application Note AN8000.12 Figure 15 : XE1201A pinout and description Contrary to XE1209, XE1201A has separated pins for received data (RXD) and transmitted data (TXD). It also has a chip enable pin (EN). Except these pins, all others are connected to the XE8805/05A microcontroller, the same way as XE1209. Only some changes appear on port C: SD is connected to PC[0] SC is connected to PC[1] DE is connected to PC[2] EN is connected to PC[5] RXTX is connected to PC[6] TXD is connected to PC[7] RXD is connected to PA[0] to wake up the microcontroller when there is data received (event generation). CLKD is connected to PA[1] for event generation on each rising edge of received clock. Figure 16 below shows XE1201A – XE8805/05A interface. EN RF VD D TL B TL A RF RF RF OU GN B D T RF A Q0 DE DVDD AVDD TPA TPB XTAL XE1201A AGND SC LO SD GN TK D A IO TK B TK C S W A S W B RX TX XTAL PC[5] DGND PC[2] RXD PA[0] CLKD PA[1] VRTXD EF PC[7] XE88LC05 PC[6] PC[0] PC[1] For ease of reading, power supply is not shown on this Figure 16 : XE1201A – XE8805/05A interface Note: RF transceivers need specific design rules. That’s why in this application, we used RF modules XM1209 and XM1201 that are existing products. These modules respect RF design rules in order to ensure RF transceiver expected behavior. © Semtech 2006 www.semtech.com 15 Application Note AN8000.12 4.3 RF link Flowchart According to protocol definition, RF link follows some rules. In our case, the mobile system is defined as SLAVE, and the base system is the MASTER. They have different behavior, so two flowcharts are necessary to describe RF link properties. The first step of RF link establishment is mobile system identification. At power on or reset, the mobile system sends a frame with RF command = identification. On the other hand, the base system is waiting for identification from the mobile system. If it detects the corrrect slave_ID with this identification Command, it sends ACK Command to the mobile system. Once this identification is done, the mobile system turns on reception mode and the base system waits for UART Request. For system behavior full comprehension, refers to C functions in files “XE1209Driver.c” and “XE1201Driver.c”: © Semtech 2006 www.semtech.com 16 Application Note AN8000.12 Figures 17 and 18 show respectively SLAVE and MASTER flowchart. XE120X_Init Send _Identification Frame Read_Frame Command = ACK No Yes Wait_Message Event PA[0] Read_Frame Send ACK Frame Command = measure_head Command = calibrate Measure Process Calibration Process Send measure frame Read_Frame Command = ACK No Yes Figure 17 : Slave Flowchart © Semtech 2006 www.semtech.com 17 Application Note AN8000.12 XE120X_Init Wait_Message Event PA[0] Read Frame Command = identification No Yes Send ACK Frame Wait UART Request Int_UART_Rx Decode UART Command Calibration_Request Measure_Request Send measure_head Command Send Calibrate Command Read Frame Command = ACK Read Frame No No Yes Command = ACK Yes Event PA[0] Read Frame Command = measure_send No Yes Send heading on UART Master Flowchart © Semtech 2006 www.semtech.com 18 Application Note AN8000.12 5 System performances With this system it is possible to obtain one-degree resolution on heading position. Repeatability is about 2 degrees between two calibration phases. X,Y, and Heading evolution 8000 ZoomingADC output code 6000 X component 4000 2000 0 -2000 0 20 40 60 80 Y component 100 -4000 -6000 Time in seconds Heading angle related to North 250 200 150 Heading 100 50 0 0 10 20 30 40 50 60 70 80 90 -50 Time in seconds Figure 18 : X & Y measurement evolution © Semtech 2006 www.semtech.com 19 Application Note AN8000.12 6 Mobile System Schematics XEMICS Figure 19 : Wireless Compass schematics © Semtech 2006 www.semtech.com 20 Application Note AN8000.12 7 Board Description XE88LC05 programmation connector XE88LC05 microcontroller System reset push button XE1201A connector Lithium Battery Sensor Set push button XE1209 connector Port B leds for debug HMC1052 magnetic sensor Power Supply switch Figure 20 : Wireless Compass Description © Semtech 2006 www.semtech.com 21 Application Note AN8000.12 Table of Figures FIGURE 1 : GLOBAL DESCRIPTION ...............................................................................................3 FIGURE 2 : HMC1052 INTERNAL CIRCUIT .....................................................................................5 FIGURE 3 : HMC1052 TRANSFER FUNCTION ...............................................................................6 FIGURE 4 : ZOOM ON HMC1052 TRANSFER FUNCTION WITH BRIDGE OFFSET .................................6 FIGURE 5 : ZOOMINGADCTM BLOCK DIAGRAM...............................................................................7 FIGURE 6 : ZOOMINGADCTM BLOCK DIAGRAM...............................................................................8 FIGURE 7 : HMC1052-XE8805/05A INTERFACE ..........................................................................9 FIGURE 8 : ZOOMINGADCTM REGISTER MAP .................................................................................9 FIGURE 9 : MEASURE FUNCTIONS. ............................................................................................10 FIGURE 10 : MEASUREMENT FLOWCHART ..................................................................................11 FIGURE 11 : RF FRAME CONTENTS............................................................................................12 FIGURE 12 : RF COMMAND TABLE.............................................................................................13 FIGURE 13 : XE1209 PINOUT AND PIN DESCRIPTION ...................................................................13 FIGURE 14 : : XE1209 – XE8805/05A INTERFACE .....................................................................14 FIGURE 15 : XE1201A PINOUT AND DESCRIPTION ......................................................................15 FIGURE 16 : XE1201A – XE8805/05A INTERFACE ....................................................................15 FIGURE 17 : SLAVE FLOWCHART ...............................................................................................17 FIGURE 18 : MASTER FLOWCHART ............................................................................................18 FIGURE 19 : X & Y MEASUREMENT EVOLUTION ...........................................................................19 FIGURE 20 : WIRELESS COMPASS SCHEMATICS .........................................................................20 FIGURE 21 : WIRELESS COMPASS DESCRIPTION ........................................................................21 © Semtech 2006 www.semtech.com 22 Application Note AN8000.12 © Semtech 2006 All rights reserved. Reproduction in whole or in part is prohibited without the prior written consent of the copyright owner. The information presented in this document does not form part of any quotation or contract, is believed to be accurate and reliable and may be changed without notice. No liability will be accepted by the publisher for any consequence of its use. Publication thereof does not convey nor imply any license under patent or other industrial or intellectual property rights. Semtech. assumes no responsibility or liability whatsoever for any failure or unexpected operation resulting from misuse, neglect improper installation, repair or improper handling or unusual physical or electrical stress including, but not limited to, exposure to parameters beyond the specified maximum ratings or operation outside the specified range. SEMTECH PRODUCTS ARE NOT DESIGNED, INTENDED, AUTHORIZED OR WARRANTED TO BE SUITABLE FOR USE IN LIFE-SUPPORT APPLICATIONS, DEVICES OR SYSTEMS OR OTHER CRITICAL APPLICATIONS. INCLUSION OF SEMTECH PRODUCTS IN SUCH APPLICATIONS IS UNDERSTOOD TO BE UNDERTAKEN SOLELY AT THE CUSTOMER’S OWN RISK. Should a customer purchase or use Semtech products for any such unauthorized application, the customer shall indemnify and hold Semtech and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs damages and attorney fees which could arise. Contact Information Semtech Corporation Wireless and Sensing Products Division 200 Flynn Road, Camarillo, CA 93012 Phone (805) 498-2111 Fax : (805) 498-3804 © Semtech 2006 www.semtech.com 23