+ All Categories
Home > Business > ABSTRACT

ABSTRACT

Date post: 20-Aug-2015
Category:
Upload: garry54
View: 540 times
Download: 0 times
Share this document with a friend
Popular Tags:
34
Combined Magnetic Compass and Cellular Tower Radio Direction Finder By Justin Beam Yang Gu Ryan Shi ECE 445, SENIOR DESIGN PROJECT SPRING 2009 TA: Zuhaib Sheikh Date 5/5/09 Project No. 22
Transcript

Combined Magnetic Compass and Cellular Tower Radio Direction Finder

By

Justin BeamYang GuRyan Shi

ECE 445, SENIOR DESIGN PROJECT

SPRING 2009

TA: Zuhaib Sheikh

Date5/5/09

Project No.22

ABSTRACT

This project involves communicating with a cell phone tower’s beacon frequency. This device will detect the signal and display the strength of the signal on an LED display. The display consists of a ring of 16 LEDs. Furthermore, a simple switch flips between the display of our onboard compass and the display of the cell phone tower signal strength. The compass section displays north, at all times, on our display. All of the circuits are centered around a PIC microcontroller which primarily routes our data.

ii

TABLE OF CONTENTS

1. INTRODUCTION....................................................................................................................11.1 Purpose...............................................................................................................................11.2 Specifications......................................................................................................................11.3 Subprojects.........................................................................................................................1 1.3.1 Battery and Voltage Regulator..................................................................................1 1.3.2 PIC Microcontroller...................................................................................................1 1.3.3 Compass.....................................................................................................................1 1.3.4 Cell Phone Tower Detector.......................................................................................2 1.3.5 Display.......................................................................................................................2

2. DESIGN PROCEDURE...........................................................................................................32.1 Design Decisions................................................................................................................3 2.1.1 Power Design.............................................................................................................3 2.1.2 Cellular Tower Beacon Detector Design...................................................................3 2.1.3 Software Design.........................................................................................................5 2.1.4 Display Design...........................................................................................................5 2.1.5 Hardware Design.......................................................................................................5

3. DESIGN DETAILS..................................................................................................................63.1 Power Design......................................................................................................................63.2 Cellular Tower Beacon Detector Design............................................................................63.3 Compass Design.................................................................................................................93.4 Display Design..................................................................................................................103.5 Hardware Design..............................................................................................................10

4. DESIGN VERIFICATION.....................................................................................................124.1 Testing..............................................................................................................................12 4.1.1 Power Design...........................................................................................................12 4.1.2 Cellular Tower Beacon Design................................................................................12 4.1.3 Compass...................................................................................................................15 4.1.4 Signal Strength.........................................................................................................16

5. COST......................................................................................................................................175.1 Parts..................................................................................................................................175.2 Labor.................................................................................................................................185.3 Analysis............................................................................................................................18

6. CONCLUSIONS....................................................................................................................19

APPENDIX – TITLE.............................................................................................................20

REFERENCES.......................................................................................................................23

iii

iv

1. INTRODUCTION

A cell signal indicator is a very useful device for anyone in a remote location. In case of emergency, this device would be able to help to find the closest location with signal very quickly and efficiently. Our device is relatively sensitive to cell phone signals and displays the strength of the incoming beacon signal. Also, there is a switch to view the compass, showing north, or the signal strength. Our display consists of 16 LEDs set in a ring.

1.1 Purpose

Many of us have been in a location with very bad cell phone signal. Some of us may have pondered the idea of a device that would be able to indicate where the nearest tower is located; thus, we would know where we can get a signal. This occurrence is exactly why this device was created. One particular group that may find this device useful would be hikers. Also, skiers could use this in times of emergency (i.e. an avalanche smothers your friend).

1.2 Specifications

This project is divided into three main components. The first main component is the compass. The compass’ signal is read by the PIC microcontroller and then the angle is calculated to display the proper LED on the display. The second main component is the cell phone tower beacon detector. This provides the PIC with a variable voltage between 0 and 2.5 volts. This variable voltage corresponds to the strength of the incoming signal. Lastly, the third main component is the signal meter. Once the PIC receives the variable voltage from the beacon detector, it displays the strength of the signal on the ring of LEDs.

1.3 Subprojects

1.3.1 Battery and Voltage Regulator

A 9V battery was used with a 7505 voltage regulator which regulates our input to +5 volts. Furthermore, some decoupling capacitors were used to decrease the noise output of this regulator. Noise suppression was required with the signal processing circuitry. This was not as big of a problem with the LEDs or the microcontroller.

1.3.2 PIC Microcontroller

The PIC is model PIC16F877A. The main features that brought our attention to this device is its 10-bit, up to 8-channel, Analog-to-Digital Converter and its 5 I/O ports. There was more than enough capabilities in this microcontroller for all of our needs. We even had enough room to add more antennas to our design and we could have easily included the flashlight portion.

1.3.3 Compass

The HM55B is a fairly simplistic chip composing of only a single data-in and a single data-out. This component communicates serially with the PIC16F877A. The x and y coordinates are determined and an angle is calculated before displaying this information on the display.

1

1.3.4 Cell Phone Tower Detector

The Cell Phone Tower Beacon detector is a purely analog system designed to detect the direction of largest magnitude of signal belonging to common cell phone protocols, one at a time. These protocols include:

AMPS (824 – 896 MHz) GSM (890 – 960 MHz) PCS (1850 – 1990 MHz) DCS (1710 – 1880 MHz) UMTS (1920 – 2170 MHz)

After checking the local surroundings, the minimum requirement is that the detector will be able to operate on the GSM band, as towers on other bands are not present or otherwise not yet operational.

1.3.5 Display

The display board shows the signal strength and the compass’ output. The strength is determined by choosing the zero-degree LED to be strength zero. As strength increases, the LEDs light up on the display in a clockwise fashion. The highest possible strength is fifteen. The compass always outputs the direction of north so whichever LED lights up points to north. The circuitry between the PIC and the display consisted of a 4:16 decoder and three inverter IC chips.

2

2. DESIGN PROCEDURE

2.1 Design Decisions

2.1.1 Power Design

Our circuits did not require an overwhelming amount of power so a simple 9 volt battery supplied more than enough power for this device. However, we did have to include some decoupling capacitors in order to suppress the noise induced by the voltage regulator. This was especially important for the signal processing circuitry.

2.1.2 Cellular Tower Beacon Detector Design

The cellular tower beacon detector design was heavily influenced by constraints of equipment available and the design hurdles particular to high-frequency system design. The initial system was intended to use three flat-panel antennae displaced at 120 degrees from each other in order to triangulate the direction vector of a signal from their magnitudes and the known normal vectors, as shown in Figure 1. This turned out to be impossible, as antennas cannot output a negative magnitude and therefore cannot identify whether the signal is coming from in front or behind them. Theoretically, it is possible to determine directions from the relative phase shifts, given the wavelength of the signal and the distances between each antenna panel, but that requires high-speed processing power far beyond what is available to our system.

Fig. 1 – Antenna Iteration 1

The second iteration of the design still used the angularly-displaced three-antenna setup, but isolated each antenna from the other by an interposed aluminum-foil reflector, as shown in Figure 2. Knowing the absolute magnitude of the signal falling upon each arc of the antenna, it is possible to find when the signal source, the tower, is within the range of a particular arc. This was quickly refined to where one arc was shrunk to just 20 degrees angular, with both other arcs expanded equally, in order to provide a signal of ‘left’, ‘right’, or ‘ahead’. In this setup, the 20-degree-wide ‘ahead’ signal has the same resolution as the planned display board. This detection principle was termed ‘guided manual search’.

3

Fig. 2 – Antenna Iteration 2

In both iterations of the direction detection design thus far, it was intended for the PIC microcontroller to poll each antenna, using the onboard ADC, by means of control lines sent to a radio-frequency analog multiplexer. It was found that the necessity of making the requisite connections and setups, vis-à-vis the multiplexer and the amplifier necessary to raise the incoming RF signal from the antenna to a level easily handled by the multiplexer, using methods known to the design team was very difficult and no stable setup could be found due to the abundance of shifting parasitic capacitance and coupling.

A third iteration of the design was used in order to remove as many components at the radio frequency as possible. This design was the final design used and used a single antenna with an incomplete 20-degree cup antenna and required a manual search by rotating the device through a full arc until the strongest signal was found. The setup is shown in Figure 3. It eliminated all high-frequency components in the signal train except for the mixer.

Fig. 3 – Antenna Iteration 3

4

Past the antennas, the signal strength detector is a tunable superheterodyne receiver, in order to reduce the frequency of the signal of interest down to a much lower bandwidth and thus easier to handle. The simplest and most robust design for such a device is to mix the center of the intermediate frequency down to DC and use an AC-coupled low-pass filter. This still, however, produced a signal bandwidth of over 50 MHz for the whole GSM band and design at these frequencies was still somewhat difficult.

After some research, it was discovered that the GSM protocol specifies a FCCCH (Frequency Correction Control Channel), allocated to the tower only, which serves as Doppler correction and also was constantly on and pulsing. Therefore, it served to advertise the tower’s presence and provide a specific “beacon” to hunt for on the tower. Some testing with the spectroscope showed that the tower of the local GSM cell was centered at 890.9 MHz. Every GSM channel has a bandwidth of 200 kHz; thus, the last modification of the system design, to detect the specific beacon channel, drastically reduced the bandwidth requirement down to an easily-handled 200 kHz.

2.1.3 Software Design

We decided to use the 16F877A PIC Microcontroller as the central unit handling computations and logic. Our two considerations for programming languages were Assembly and C. We knew the compass driver would involve fairly complex logic due to serial communications and coordinate mapping. Thus, we used the C programming language to simplify the complexity. The 16F877A interfaces with both the compass module and the beacon detector.

2.1.4 Display Design

The display needed to be in a ring and it consisted of 16 LEDs. The easiest way to do this was to have all of the LEDs routed to the same ground while each LED had its own input. The voltage input came from the PIC, through a decoder, through an inverter, and finally through a resistor to the LED.

2.1.5 Hardware Design

Originally the plan was to have everything on a single circuit board. However, there were constraints with the PCB board software we used, called Eagle. Eagle’s lite-edition only allows for boards to be 2”x3”. The final decision was to just create jumper circuit boards and combine everything on generic prototype boards.

5

3. DESIGN DETAILS

3.1 Power Design

An industrial strength energizer 9 volt battery was used with a 9 volt battery connector. The voltage regulator was a standard +5 volt regulator, model 7505. Three decoupling capacitors were used with the signal circuitry. The capacitors we used were a 0.1uF and a 10uF electrolytic. These were combined in parallel so that the capacitances added together.

3.2 Cellular Tower Beacon Detector Design

Due to the difficulty of testing and building stable systems operating in the low gigahertz radio-frequency range with the available equipment, the chosen design for the detector system was chosen to minimize the number of RF components and connections. Overall, it is a superheterodyne receiver tuned by adjusting the local oscillator frequency, as shown in Figure 4.

Fig. 4 – Cellular Tower Beacon Detector Block Diagram............................................................................................................................................................All components in the system are powered off of +5V and ground. There is no negative supply or virtual ground. The power supply rail is heavily filtered with capacitors to ground, since the switching power supply produced some half a volt peak to peak of switching noise. While that quantity of noise is not a detriment to the digital systems, it is actually more powerful than the initial antenna signal and must be filtered out for the analog system to function.

The antenna chosen is a Janus Remote Communications PC29, a flat-panel antenna rated for all 5 cell phone bands in the initial specification. It comes default with a coaxial cable, which in turn was replaced for the project with two separate wires for connector compatibility. The antenna is shown in Figure 5.

Fig. 5 – PC29 Antenna

The majority of components used in the signal processing were manufactured by Analog Devices, due to their good documentation on applications of their components and the long conversations on constructing the system with their application engineers. The mixer used is an Analog Devices AD8343, connected in the documented down-converting mixer application as shown in Figure 6.

6

Fig. 6 – AD8343 Downconverting Configuration

Due to the conscious design choice to match all impedances in to the 50 Ohm standard, impedance-matching networks Z1 and Z2 in Figure 6 were not necessary. Additionally, due to the relatively low bandwidth of the signal in question and the matched impedances, none of the inductors and transformers turned out to be necessary. This greatly simplified system design. The AD8343 was mounted on a pin-out PCB, due to its surface-mount packaging and the uncertainty of connections at the time.

The Local Oscillator was provided by a Crystek CVCO55CL-0800-0980 voltage-controlled oscillator. It is simply connected, with only 5V supply, ground, Vt (for tuning), and RF out. The device itself is shown in Figure 7; its tuning curve is shown in Figure 8. There is also a second VCO, operating from 1650 MHz to 2150 MHz, ordered and placed onto the PCB. It was intended that a high-frequency multiplexer be used to switch between these two as the LO output in order to give the system multi-band detection capabilities. This functionality was never implemented, but all parts are in place; all it needs are the requisite connections.

7

Fig. 7 – CVCO55CL Oscillator

Fig. 8 – CVCO55CL 800-980 MHz Tuning Curve

In actual testing, the VCO was tuned by means of a voltage divider, with a trimmable 10 kOhm potentiometer comprising the lower resistor and a static 10 kOhm resistor for the upper. It was found that this setup is very sensitive to minor disturbances. For example, so much as touching the screw driver to the potentiometer port will drop the output frequency (and presumably, the output voltage) by as much as 250 kHz. Once the screw-driver is removed, the output frequency returns by approximately the same amount. Manual tuning was critical to the system’s success as a prototype.

Since a mixer produces not only the DC-region images of the signal in question but also multiple harmonics at higher frequencies, as dictated by its local oscillator input, it is critical for the operation of the system to filter these out with a low-pass filter. The most important aspect of the signal for the system is its magnitude, so a Butterworth filter was used, on account of its maximally flat passband gain.

8

A second-order Butterworth using a Sallen-Key topology was constructed. Because there was no negative power supply, the incoming signal was first AC-coupled with a capacitor and then biased to 2.5 V DC before the filter, then AC-coupled again after the filter at the output. The filter was initially constructed with Analog Devices ADA4857 High-Speed Operational Amplifiers; the part was chosen originally for its ability to perform with the pre-FCCCH-detecting 50+ MHz full GSM bandwidth. Testing failed for yet-undiagnosed reasons, and the system was switched to the 200 kHz FCCCH detection method. Trusted LM741 op-amps were used in place of the ADA4857s; their operational bandwidth of 1.5 MHz was very satisfactory for the new requirements. One of two filter stages is shown in Figure 9, as sourced from Texas Instruments’ Filter Design in Thirty Seconds.

Fig. 9 – Single-Supply 2-Pole Low-Pass Sallen-Key Butterworth Filter

Cin and Cout were 0.1 μF each. C1 is 100 pF. C2 is 200 pF. R1 and R2 were 5 kOhm.

A third LM741 stage was added as an inverting amplifier, with a gain of 5 and a input resistor of 10 kOhm, in order to increase the <400 mV magnitude of the filter output in passband to <2V for better ADC resolution and to correctly pass through the envelope detector.

The half-wave envelope detector was of typical construction: a forward-biased single diode with a resistor and a capacitor to ground after the diode. The diode was a 1N914 switching diode. The capacitor was 0.1 μF, the resistor was 1 kOhm. The resulting natural frequency was about 1.6 kHz. It was much less than the 200 kHz bandwidth of the channel and thus acceptable.

3.3 Compass DesignThe Hitachi HM55B Compass Module uses a dual-axis Hall effect sensor. The two perpendicular axes senses magnetic field intensities. We transfer data between the PIC and the Compass Module through synchronous serial communication by shifting bits in and out. X and Y measurements are reported in microteslas in 11-bit signed values. We used a 4-wire interface for the compass device:

9

Fig. 10 – Compass HM55B Pinout

To obtain a measurement from the Compass, we had to follow a certain procedure based on the module itself:

Fig. 11 – Compass HM55B Commands

By shifting in commands, we can make the compass reset, start measuring, and transmit the completed measurements. We used the regular digital I/O ports off the PIC to perform the bit shifting. Each command is initiated by setting the Enable high then low. The bit signals for the commands are then shifted into the compass through the Din signal. We make this shifting system synchronous by controlling the compass’ CLK signal manually with the compass driver code on the PIC. When we shift in the “report measurement status,” the compass will shift out the status through Dout. When the bits shifted out read 1100, it indicates the measurement is complete. At this time, two sets of 11 bit signed values are shifted out through Dout.

Given the X and Y values, we converted this into an angle of deflection from north. A full strength signal along one axis gives a value of 1 or -1 depending on the direction. Using the trigonometric tangent function, we can calculate the angle. The signs of the X and Y values give us the correct quadrant. We then use the calculated angle to light up the correct LED on the display board.

The calculated angle is compared against 16 conditional statements, each giving an angle tolerance of 22.5 degrees. If the calculated angle falls within range of an LED’s angle coverage, the corresponding LED would be turned on.

3.4 Display Design

The decoder model number is MM74HC154N. Unfortunately, this chip has active-low outputs. This means that all of the outputs are set high except for one. This required that we used inverters. The three inverter chips we used were model SN74ALS04. These chips were chosen specifically because they did not have open collector outputs. This was done to simplify the circuit as much as possible.

3.5 Hardware Design

The prototype boards we used were very similar in style to an actual breadboard. Yet, we were able to solder to them. Also, these boards are very common in any electronics store so these were also used for

10

ease of availability. The actual circuit boards we created were milled at the parts shop provided to us. In the final design, we had a total of six boards. Three boards were milled and three were prototype boards. All of the surface mount chips were on the milled boards. These included the mixer, VCOs, amplifiers, multiplexers, and gain blocks. The decoder, inverters, through-hole components, PIC, and IC amplifiers were soldered onto the prototype boards. In order to connect between the milled boards and the prototype boards, jumper wires were used. This was especially easy to do because we designed the milled boards for this functionality.

11

4. DESIGN VERIFICATION

4.1 Testing

4.1.1 Power DesignThe input was connected to an oscilloscope. It was very easy to see that there was about 400mV of noise on the power input from the voltage regulator. After the decoupling capacitors were used, the noise was sufficiently reduced.

4.1.2 Cellular Tower Beacon Detector

The full battery of testing for the final, single-antenna, FCCCH-sensing design is as follows. First, the FCCCH beacon was located on the spectroscope by connecting it to the antenna, thus verifying antenna functionality and the existence of the FCCCH. The VCO for the local oscillator was next turned on and adjusted until it neared, but not overlapped, the beacon frequency, thus demonstrating the LO’s functionality. (Figure 10) The mixer’s RF input and LO input were replaced with function generator inputs and first tested at low frequencies (50 kHz LO) to verify mixer functionality. (Figure 11)

Figure 12 – FCCCH Beacon (right) and VCO as LO (left)

12

Figure 13 – Low-Frequency Test Result (Mixer Output)

Subsequently, the system was tested with function generators in the 900 MHz range, in order to verify functionality at high frequencies. There is significant ripple and distortion at these frequencies from the instruments; the results shown in Figure 12 are not representative of the whole space.

13

Figure 14 – High-Frequency Test Result (Mixer Output)

Finally, the system was wholly assembled and the LO frequency tuned up to that of the beacon (Figure 13), in order to mix it down to DC level (Figure 14). As can be seen, in the process of switching the spectroscope over, sufficient interference with the system was generated that the beacon actually shifted out of the intended passband.

Figure 15 – VCO Adjusted to Overlap FCCCH

14

Figure 16 – FCCCH Detected at DC Level

The -3 dB frequency of the filter system was set to be 200 kHz. Given the 400 kHz bandwidth of the display shown in Figure 14, the FCCCH signal is actually transitioning to the stopband. The effect of the four-pole Butterworth filter can be seen by the -20 dB per decade attenuation visible on the right half of the detected signal. Had there been no filter, the signal magnitude would have been essentially flat out to ~450 kHz. Figures 13 and 14 are at different resolutions along the frequency axis; any resemblance in scale is coincidental.

4.1.3 Compass

First Stage

Our initial verification of a functioning compass driver code was to test the compass with three LEDs. Two LEDs indicated the calculated angle: one between 0 to 180 degrees and the other between 180 to 360 degrees. We verified that the angle was either in the first/second quadrant or the third/fourth quadrant by seeing only one LED lit at a time. The third LED was set to light up when the calculated angle was between 0 and 5 degrees. We verified that the 0 degree calibration on the compass was correct when the third LED lit as the compass faced north.

Second Stage

The next step was to simulate the compass’ correct orientation. We tested this with four LEDs as the binary representation of the 16 LEDs. Based on the compass angle, the LEDs would light up from binary 0 to binary 15. We verified that the LEDs would count from 0 to 15 as we turned the compass 360 degrees starting from north.

Third Stage

The last stage of testing verifies the compass driver code is fully functional. The PIC has to correctly interface with the display board. We were able to have all 16 LEDs light up at some point as we rotated the compass through 360 degrees. We encountered a problem of the LEDs

15

lighting up in the opposite direction. We corrected this orientation in the code. Our final code was fully functional such that the LED lit would always point to north.

4.1.3 Signal Strength

The test setup for the signal strength meter utilized the display board and some simple circuitry. The circuitry we used comprised of a 10k Ohm resistor and 10k Ohm potentiometer. The high reference voltage for the PIC was tied to 2.5 volts while the low reference voltage was tied to ground. The 2.5 volts was achieved by connecting between two of the same value resistors tied to +5 volts. Then the signal input was taken from the potentiometer. An increase in resistance caused a greater voltage drop and therefore the input voltage decreased. A decrease in resistance caused a low voltage drop and therefore a higher voltage output. This mimicked the variable voltage we would receive from the antenna.

16

5. COST

5.1 Parts

Component Type(if applicable)

Quantity Cost-Per-Unit

Cost

PCB Quad Band GSM Antenna

(PC29)850-2.1GHz

Janus Remote Communications

Part No. MC-0212

1 $11.18 $11.18

2 Position Dip Switch

Futurlec 1 $0.65 $0.65

Compass Module Hitachi HM55B 1 $27.00 $27.005mm LEDS 16 $0.80 $12.80

PIC Microcontroller

16F877A 1 $6.25 $6.25

4:16 Decoder Fairchild Semiconductor MM74HC154

1 $0.64 $0.64

VCO Multiplexer1x4:1

Analog Devices ADG904BRUZ

2 $3.87 $7.74

Voltage Controlled Oscillator

800-980 MHz

CrystekCVCO55CL-0800-0980

1 $28.75 $28.75

Voltage Controlled Oscillator

1650-2150 MHz

Crystek CVCO55BE-1650-2150

1 $29.50 $28.75

VCO InputMultiplexer

2x4:1

Analog DevicesADG609BRUZ

1 $5.24 5.24

Mixer Analog Devices AD8343ARUZ-ND

1 $8.82 $8.82

20 dB GainBlock, RF-range

Analog Devices AD8354ACAPZ

2 $3.87 $7.74

Op-Amp Fairchild SemiconductorLM741

3 $0.50 $1.50

9V Battery 1 $2.95 $2.95Voltage Regulator 7805 1 $1.59 $1.59

Misc. Resistors, Capacitors,

Diodes

1 $8.00 $8.00

TOTAL $159.6Table 1 – Parts Cost Breakdown

17

5.2 Labor

Salary Hours/Week Weeks/Semester Multiplication Factor Cost(per

engineer)$35/hour 10 13 2.5 $11,375

Table 2 – Labor Cost Breakdown

There are three engineers total; thus, the total cost of labor is $11,375 X 3 = $34,125.

5.3 Analysis

Total Costs: $159.6 + $34,125 = $34,284.60

18

6. CONCLUSIONS

Project 22's system is a success, though only after significant modification of the initial specifications and design. The magnetic compass unit is fully functional and has been demonstrated, as its own unit separate from any other instruments or assistance, to find the direction of north. The direction of north has been verified both by using a permanent magnet with known poles to test the response and, more importantly, by consulting local maps to correlate the compass indication with magnetic north indication.

The cellular direction finder has been reduced in user-friendliness specification from automatic direction computation to manual rotating search. Its compatible protocols have been reduced from an ambitious 5 to only GSM. Seeing that GSM is the singular most popular protocol in the local area, however, this loss is not critical. At the same time, it has been improved to be able to specifically seek out towers, rather than any signal in the protocol band. In this new specification, however, it has proven to be dependable and well-behaved; it successfully indicated the direction to the local cellular tower with the direction verified independently after detection.

Future expansions of the radio direction finding system may include upgrading the seeker to three-antenna guided manual search to increase user-friendliness and implementing the present but unconnected chips required for multi-band capability.

19

APPENDIX A – Main Design Schematic

20

APPENDIX B – Code Snippets of 16F877A PIC Microcontroller

Compass snippets from compasstest6.c

void main(){ setup_adc_ports(ALL_ANALOG); // setup_adc(ADC_CLOCK_INTERNAL); set_adc_channel( 0 ); delay_us(500); for(;;) {if(input(PIN_D3)==1) // switch between 2 modes: Compass or Antenna{ calibrateCompass(); // necessary to reset compass angle = getCompassAngle(); // reads compass measurement

// Code for lighting LEDs corresponding to angle measurement if ((angle>=348.8 && angle<360) || (angle>=0 && angle<11.25)) { OUTPUT_LOW(LED_DECOD_S0); // LED 12, 0 Degrees OUTPUT_LOW(LED_DECOD_S1); OUTPUT_HIGH(LED_DECOD_S2); OUTPUT_HIGH(LED_DECOD_S3); } if (angle>=11.25 && angle<33.75) { OUTPUT_HIGH(LED_DECOD_S0); // LED 11 OUTPUT_HIGH(LED_DECOD_S1); OUTPUT_LOW(LED_DECOD_S2); OUTPUT_HIGH(LED_DECOD_S3); }

if (angle>=33.75 && angle<56.25) { OUTPUT_LOW(LED_DECOD_S0); // LED 10 OUTPUT_HIGH(LED_DECOD_S1); OUTPUT_LOW(LED_DECOD_S2); OUTPUT_HIGH(LED_DECOD_S3); }

if (angle>=56.25 && angle<78.75) { OUTPUT_HIGH(LED_DECOD_S0); // LED 9 OUTPUT_LOW(LED_DECOD_S1); OUTPUT_LOW(LED_DECOD_S2); OUTPUT_HIGH(LED_DECOD_S3); }

if (angle>=78.75 && angle<101.3) { OUTPUT_LOW(LED_DECOD_S0); // LED 8, 90 Degrees OUTPUT_LOW(LED_DECOD_S1); OUTPUT_LOW(LED_DECOD_S2); OUTPUT_HIGH(LED_DECOD_S3); }

Beacon Detector snippets from compasstest6.c

}else{ ADC_antenna = read_adc();

ADC_reading = ADC_antenna;

// Code for lighting LEDs corresponding to Antenna Strength if (ADC_reading>=48 && ADC_reading<56) {

OUTPUT_LOW(LED_DECOD_S0); // LED 2 OUTPUT_HIGH(LED_DECOD_S1); OUTPUT_LOW(LED_DECOD_S2); OUTPUT_LOW(LED_DECOD_S3); }

if (ADC_reading>=56 && ADC_reading<64) { OUTPUT_HIGH(LED_DECOD_S0); // LED 3 OUTPUT_HIGH(LED_DECOD_S1); OUTPUT_LOW(LED_DECOD_S2); OUTPUT_LOW(LED_DECOD_S3); }

if (ADC_reading>=64 && ADC_reading<72) { OUTPUT_LOW(LED_DECOD_S0); // LED 4, 1/2 Strength OUTPUT_LOW(LED_DECOD_S1); OUTPUT_HIGH(LED_DECOD_S2); OUTPUT_LOW(LED_DECOD_S3); }

if (ADC_reading>=72 && ADC_reading<80) { OUTPUT_HIGH(LED_DECOD_S0); // LED 5 OUTPUT_LOW(LED_DECOD_S1); OUTPUT_HIGH(LED_DECOD_S2); OUTPUT_LOW(LED_DECOD_S3); }

if (ADC_reading>=80 && ADC_reading<88) { OUTPUT_LOW(LED_DECOD_S0); // LED 6 OUTPUT_HIGH(LED_DECOD_S1); OUTPUT_HIGH(LED_DECOD_S2); OUTPUT_LOW(LED_DECOD_S3); }

if (ADC_reading>=88 && ADC_reading<96) { OUTPUT_HIGH(LED_DECOD_S0); // LED 7 OUTPUT_HIGH(LED_DECOD_S1); OUTPUT_HIGH(LED_DECOD_S2); OUTPUT_LOW(LED_DECOD_S3);

Compass Driver snippet from Hm55b.c

//// Helper function to get data from the HM55B module.//int16 shiftInFromHm55b(int8 numBits){ int8 i; int16 out = 0;

for(i=0; i<numBits; ++i) { output_high(HM55B_CLK); shift_left(&out, 2, input(HM55B_IN)); output_low(HM55B_CLK); } return out;}

//// Helper function to send data to the HM55B module.//void shiftOutToHm55b(int8 var, int8 numBits){ int1 curBit; int8 i;

//

21

// We are shifting out the LSB first. // for(i=0; i<numBits; ++i) { output_high(HM55B_CLK); curBit = shift_right(&var, 1, 0); if(curBit) { output_high(HM55B_IN_OUT); } else { output_low(HM55B_IN_OUT); } output_low(HM55B_CLK); }

output_low(HM55B_IN_OUT);}

//// This Hitachi HM55B compass module test program displays x (N/S) and y (W/E)// axis measurements along with the direction the compass module is pointing,// measured in degrees clockwise from north.//void getCompassXY(int16 &x, int16 &y){ int16 hm55bStatus;

// Send a reset command to HM55B output_high(HM55B_ENABLE); output_low(HM55B_ENABLE); shiftOutToHm55b(CMD_RESET, 4);

// Send a start measurement command to HM55B output_high(HM55B_ENABLE); output_low(HM55B_ENABLE); shiftOutToHm55b(CMD_MEASURE, 4);

while(hm55bStatus != CMD_READY) { output_high(HM55B_ENABLE); output_low(HM55B_ENABLE); shiftOutToHm55b(CMD_REPORT, 4); hm55bStatus = shiftInFromHm55b(4); }

x = shiftInFromHm55b(11); y = shiftInFromHm55b(11); output_high(HM55B_ENABLE);

if(bit_test(x, 10)) { x |= NEG_MASK; }

if(bit_test(y, 10)) { y |= NEG_MASK; }

}

float getCompassAngle()

{ int16 x, y; float fx, fy, hypoth, angle;

getCompassXY(x, y);

// // Now convert this the x and y magnitudes that the HM55B module gives us // into something more useful like the angle of deflection from north. //

fx = (signed int16)x; fy = (signed int16)y;

hypoth = sqrt(fx*fx+fy*fy); fx /= hypoth; fy /= hypoth; angle = (atan2(fx, fy))*180/3.14; angle -= readEepromFloat(0); while(angle < 0) { angle += 360; } while(angle > 360) { angle -= 360; } return angle;}

void calibrateCompass(){ float offsetAngle;

// // We could get better results if we calculated more angles and then // interpolated between them, but I want to keep the calibration simple // for now. //

writeEepromFloat(0, 0); // Need to do this before getCompassAngle() offsetAngle = getCompassAngle(); writeEepromFloat(0, offsetAngle);}

Snippet from Utility.c

void writeEepromFloat(int8 addr, float data){ write_eeprom(addr+0, *(&data+0)); write_eeprom(addr+1, *(&data+1)); write_eeprom(addr+2, *(&data+2)); write_eeprom(addr+3, *(&data+3));}

float readEepromFloat(int8 addr){ float data;

*(&data+0) = read_eeprom(addr+0); *(&data+1) = read_eeprom(addr+1); *(&data+2) = read_eeprom(addr+2); *(&data+3) = read_eeprom(addr+3); return data;}

22

REFERENCES

[1] Carter, Bruce, Texas Instruments, “Filter Design in Thirty Seconds,” December 2001,

http://focus.ti.com/lit/an/sloa093/sloa093.pdf.

[2] PIC16F87XA Datasheet, Microchip,

http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf.

[3] HM55B Compass Module Datasheet, Hitachi,

http://www.parallax.com/dl/docs/prod/compshop/HM55BModDocs.pdf.

[4] Ribble, Maurice, “HM55B Compass Module”, January 2005,

http://www.glacialwanderer.com/robots/sensors/hm55b/.

[5] AD8343 Datasheet, Analog Devices,

www.analog.com/static/imported-files/data_sheets/AD8343.pdf.

23


Recommended