You are on page 1of 16

Sixteen-Point Digital Compass

Sixteen-Point Digital Compass


While the Dinsmore 1490 digital compass is a reasonable solution for providing absolute azimuth data for a robot, I felt that it did not make optimal used of the data bits it used on an I/O port. The Dinsmore 1490 only provides eight compass directions (N, NE, E, SE, S, SW, W, and NW), but requires four bits of I/O if the sensor is accessed directly. Four bits should be able represent sixteen different directions. Encoding logic could be used to translate the output of the Dinsmore 1490 into a three-bit representation. Doing this adds to the cost of the compass. Nowadays (2006), the Dinsmore 1490 lists for around US$14 - US$15. Adding the cost of shipping usually raises the cost to nearly twenty dollars. I wondered if an alternate solution could be had that would cost less, but provide better performance.

Compass Circuit
I wanted to optimize the use of four data bits of an I/O port. That implied that I wanted to have sixteen points of precision on my digital compass. If I wanted to read in the data serially, even higher precision could potentially be obtained. I toyed with one digital compass design that uses a PIC processor, two of LED-optotransistors pairs placed in quadrature, and a compass with an encoder disk with varied tone shading to represent orientation. The PIC processor would implement two successive approximation analog-to-digital converters to measure the position of the encoder disk. I decided that this was far too much work to get only sixteen unique compass positions. I settled on a simpler design that uses four IRLED-phototransistor pairs and a reflective encoder disk. The rotation of the encoder disk would position reflective or non-reflective fields in front of the IRLED-phototransistor pairs. Each IRLED is biased such that a reflective field will deliver enough infrared light to the corresponding phototransistor to turn it on. The presence of a non-reflective field will diminish the amount of infrared light from the IRLED such that the phototransistor will turn off. The collector of each transistor is connected to a 74HC14 Schmitt Trigger gate, which conditions the output to provide a clean logic level. Below is a parts list for the compass:
Designator U1 Description 74HC14 Hex Schmitt Trigger Quantity 1 4 4 4 4 1 1 1 1 1 1 2 Source any available source BG Micro (half of LED1023) BG Micro (half of LED1023) any available source any available source any available source any available source any available source any available source any available source any available source any available source

Q1, Q2, Q3, Q4 Honeywell SDP8426 IR Phototransistor D1, D2, D3 ,D4 Honeywell SEP8526 GaAs IR LED R1, R2, R3, R4 150 1/4 watt resistor R5, R6, R7, R8 1 K 1/4 watt resistor C1 C2 CONN1 N/A N/A N/A N/A 10 F, 25V electrolytic capacitor 0.1 F ceramic capacitor Six-pin in-line connector Augat (or similar) machine socket pin 1 3/4 inch seamstress pin Cap from travel-size shaving cream can 3/16-inch dia, 1/4 inch rare-earth magnet

A simple schematic of the circuit was drawn using gschem. From the schematic, a printed circuit board layout was created using the PCB program. The gschem and PCB programs are both part of the gEDA project. The compass schematic is found here. The file is in Adobe PDF. While PCB generates several output layers, only the back side and
http://home.roadrunner.com/~maccody/robotics/compass2/compass2.html (1 of 5)6/9/2008 9:13:14 AM

Sixteen-Point Digital Compass

front silk layers are used for the printed circuit board and the component layout silk screen. Note that the front silk layer file has been manipulated to form a mirror image file. This was done so that laser toner transfer method could be used to create the component layout pattern as well as the printed circuit positive mask. These files are also in Adobe PDF.

Encoder Disk
As mentioned earlier, an encoder disk is used to sense the orientation of the compass. The encoder disk rotates above the IRLED-phototransistor pairs. The compass magnet is attached to the encoder disk such that the rotational offset of the encoder disk indicates absolute azimuth of the compass mechanism. For optical encoding applications, a Grey Code pattern is typically used. A Grey code pattern guarantees one, and only one, bit state change for all code bits with each encoder state change. For the compass encoder, a four-bit Grey code pattern will be used. The table, shown below, lists the four-bit Grey code in the left-hand column and the corresponding compass point in the right-hand column. When a Grey Code pattern is usually placed onto an encoder disk, each bit of the code is represented as a concentric rings of light and dark patches radiating from the central axis. For simplicity, the bit order of the bands are maintained; either from most-significant out to least-significant, or vice-versa. The illustration to the upper-right of the table is that of a true Gray Code encoder disk. Dark patches represent reflecting regions, while white patches represent non-reflecting regions. The most-significant bit of the code is presented in the innermost ring. The least-significant bit of the code is presented in the outermost ring. The compass cardinal points are placed to indicate their gray code representations as shown in the table. Studying the component placement mask of the compass circuit shows that the two IRLED-phototransistor pairs are set on opposite sides of the axis of rotation (D4/Q4 and D3/Q3 on one side, D1/Q1 and D2/Q2 on the other). The size of the components precludes placing all of the sensors on the same side, as the true Gray Code encoder disk indicates. Consequently, a clever shifting of the encoding bands is required in order to obtain the correct code values. The secondmost significant and third-most significant bits are swapped. The third-most significant and least significant bit patterns are then shifted eight states (180-degree shift). The center column of the table below shows the shifted Gray Code sequence that provides the correct code values, given the component placements. The shifted Gray Code encoder disk is illustrated to the lower right of the table. The bit order (from inner ring to outer ring) is: most-significant bit (D4/Q4), third-most significant bit (D2/Q2), second-most significant bit (D3/Q3), and leastsignificant bit (D1/Q1). The compass cardinal points are placed to indicate the direction sensed if that side of the encoder were aligned with the forward-part of the compass circuit board. A PDF of the encoder mask can be found here. The mask is correctly oriented for placement onto printed circuit board material if the laser printer toner transfer method is being used.
4-Bit Gray Code Shifted Code Compass Point 0000 0001 0011 0010 0110 0111 0101 0100 0000 0001 0101 0100 0110 0111 0011 0010 E ENE NE NNE N NNW NW WNW

http://home.roadrunner.com/~maccody/robotics/compass2/compass2.html (2 of 5)6/9/2008 9:13:14 AM

Sixteen-Point Digital Compass

1100 1101 1111 1110 1010 1011 1001 1000

1010 1011 1111 1110 1100 1101 1001 1000

W WSW SW SSW S SSE SE ESE The pattern for a true Gray Code encoder disk.

The pattern for the shifted Gray Code encoder disk.

Compass Assembly and Testing


The compass circuit board is easily fabricated using the laser printer toner transfer method and the circuit and component layout masks described above. The assembly of the compass circuit is straightforward, as there are few components to place on the circuit board. The three photos to the right show the compass board after the components have been soldered to it. The first and second photos are the circuit and component sidesof the board, respectively. The large printed ring on the component side of the board represents the location where the rim of the shaving cream cap sits when it is attached to the board. The third photo is a side view of the board. This photo was taken to show the positioning of the IRLED-phototransistor pairs on the board. These devices are positioned such that the infrared light fromt the IRLED is reflected off of the encoder disk to the corresponding phototransitor. The socket pin, sitting between the IRLEDphototransistor pairs, serves as a bearing for the compass needle. It is filled with solder to form a low-friction concave bowl for the needle point to rest in. The original design of this simplified digital compass used a compass taken from a small, fluid-filled capsule. A seamstress needle was inserted through the center of the compass to provide a pivot point. The photo on the right shows this original configuration. Initial testing quickly demonstrated that the small magnet on the compass was not up to the task. It turns out that the IRLED and phototransistors used in the design have steel leads. Consequently, the close proximity of these components deflected the compass magnet from true north.

http://home.roadrunner.com/~maccody/robotics/compass2/compass2.html (3 of 5)6/9/2008 9:13:14 AM

Sixteen-Point Digital Compass

The design of the digital compass is modified such that a more powerful magnets are used. The magnets are also positioned further away from any devices that have steel leads. Any small rare-earth magnets can be used that can be easily attached to the compass needle. Two Quartet brand "white board" magnets, with their handles cut off, have been employed in this case. The three photos on the right show the digital compass in various stages of testing. The first photo shows the compass magnet and encoder disk attached to the needle, which is resting in its bearing. The top end of the needle is held by a plastic straw, whose lower half is shown in the top center of the photo. The position of the compass hold to true north as the compass board is rotated. The second and third photos show electrical tests of the digital compass. The outputs of the compass circuit were connected to four LEDs and current limiting resistors on a solderless breadboard. The second photo shows the compass board facing in an eastward direction. The front part of the board is actually outside the camera's field of view. According to the Gray code table above, a value of 0000 is assigned to the east (E) compass point. This causes all four LEDs to conduct, turning them on. The third photo shows the compass board facing in a southward direction. The front part of the board is facing away from the camera. The south (S) compass point has a Gray code value of 1100. In the photo, the most-significant bit is on the right and the least-significant bit is on the left. Consequently, the two left LEDs conduct, turning them on, and the two right LEDs do not conduct, turning them off. The two photos to the right show the finished compass. A cap from a travel-size shaving cream can was used to house the compass needle and encoder assembly. The side were cut out to allow inspection of the compass needle assembly. A small hole was drilled in the center of the cap to allow the compass needle to pass though. The yellow ball on the needle was removed temporarily to allow the needle to be inserted through the hole. The ball was then glued back on with epoxy. As shown in the top photo, the magnets were positioned to align with the compass dial. The tip of the compass needle rests in the socket pin that was soldered to the printed circuit board. In the bottom photo, it can be seen how close the magnets are to the top of the cap. This distance was carefully adjusted so the the compass would turn freely, but not allow the compass point to fall out of the socket. Once everthing was correctly positioned, the cap was secured to the printed circuit board with epoxy. When the compass was mounted to my robot, it was decided to replace the six-pin header strip with a six-socket header strip. This allowed the interconnection cable to attach to the board from the bottom (circuit side) of the compass. Admittedly, some tweaking of the current limiting resistors (R1, R2,
http://home.roadrunner.com/~maccody/robotics/compass2/compass2.html (4 of 5)6/9/2008 9:13:14 AM

Sixteen-Point Digital Compass

R3, and R4) must be performed to obtain the desired switching performance. I used resistors with 20% tolerance, so I ended up picking and choosing resistors until the transistors switched properly as the encoder disk rotated. A more repeatable circuit design would probably require resistors with better tolerance ratings (10% or 5%). At any rate, the compass sensor does work once the resistances are properly selected.

2006, 2007 Mac A. Cody Last updated Friday, March 9, 2007

http://home.roadrunner.com/~maccody/robotics/compass2/compass2.html (5 of 5)6/9/2008 9:13:14 AM

http://home.roadrunner.com/~maccody/robotics/compass2/photos/board_bottom.jpg

http://home.roadrunner.com/~maccody/robotics/compass2/photos/board_bottom.jpg6/9/2008 9:13:47 AM

http://home.roadrunner.com/~maccody/robotics/compass2/photos/board_top.jpg

http://home.roadrunner.com/~maccody/robotics/compass2/photos/board_top.jpg6/9/2008 9:14:00 AM

http://home.roadrunner.com/~maccody/robotics/compass2/photos/board_side.jpg

http://home.roadrunner.com/~maccody/robotics/compass2/photos/board_side.jpg6/9/2008 9:14:04 AM

http://home.roadrunner.com/~maccody/robotics/compass2/photos/weak_compass.jpg

http://home.roadrunner.com/~maccody/robotics/compass2/photos/weak_compass.jpg6/9/2008 9:14:07 AM

http://home.roadrunner.com/~maccody/robotics/compass2/photos/quartet_magnets.jpg

http://home.roadrunner.com/~maccody/robotics/compass2/photos/quartet_magnets.jpg6/9/2008 9:14:13 AM

http://home.roadrunner.com/~maccody/robotics/compass2/photos/compass_test1.jpg

http://home.roadrunner.com/~maccody/robotics/compass2/photos/compass_test1.jpg6/9/2008 9:14:18 AM

http://home.roadrunner.com/~maccody/robotics/compass2/photos/compass_test2_east.jpg

http://home.roadrunner.com/~maccody/robotics/compass2/photos/compass_test2_east.jpg6/9/2008 9:14:23 AM

http://home.roadrunner.com/~maccody/robotics/compass2/photos/compass_test2_south.jpg

http://home.roadrunner.com/~maccody/robotics/compass2/photos/compass_test2_south.jpg6/9/2008 9:14:27 AM

http://home.roadrunner.com/~maccody/robotics/compass2/photos/compass_done1.jpg

http://home.roadrunner.com/~maccody/robotics/compass2/photos/compass_done1.jpg6/9/2008 9:14:32 AM

http://home.roadrunner.com/~maccody/robotics/compass2/photos/compass_done2.jpg

http://home.roadrunner.com/~maccody/robotics/compass2/photos/compass_done2.jpg6/9/2008 9:14:35 AM

You might also like