PDA

View Full Version : Digital Compass Project



BJSmith
- 7th April 2006, 03:17
I recently bought a Honeywell HMR3100 digital compass. It has a serial output which I want to send data to a Serial LCD Module. The data from the compass requires some very simple math in order to get a usable output. I plan to use a 16F84A chip and PICBASIC PRO to control the compass output and perform this simple math function.

For the compass, I'm using what is called "normal" mode. This requires pin 6 (on the compass chip) to be high and pin 3 (on the compass chip) to toggle (1 ms) in order to get an output from pin 5 (on the compass). I have written code and checked the outputs with LEDS and feel this part of my code is working.

High 0 'Set pin RB0 high: PIN 6 on compass
High 1 'Set pin RB1 high: PIN 3 on compass
Pause 1000 'Delay for 1 second to let compass settle
Low 1 'Sets pin RB1 low, triggers PIN 3 on compass

Here is my problem, for now I am just trying to get a correct output from the compass with out the simple math conversion. I wired the output of the compass into RB2 of the 16F84A, B0 is my variable:

SerIn2 2,4,[B0] '2400 baud: HEX input to RB2

I then hooked the serial line from the Serial LCD Module into RB3:

SerOut 3,4,[#B0] '2400 baud: HEX output to RB3


Unfortunately, all I get is an output of 255 over and over displayed on the LCD. The data is suppose to come out similar to the example below (depending on the direction of the compass):

80 02 85 (hex)

fyi- the 80 with be thrown out, the MSB (2) will be multiplied by 256 and added to the decimal conversion of the LSB (85h=133). The total is 645 which is divided by 2. This would equal 322.5 degrees.

The whole program (without the math conversion):

'Compass PICBasic PRO program
B0 VAR WORD
Main: Pause 500
High 0 'Set pin RB0 high: PIN 6 on compass
High 1 'Set pin RB1 high: PIN 3 on compass
Pause 1000 'Delay for 1 second to let compass settle
Low 1 'Sets pin RB1 low, triggers PIN 3 on compass
SerIn2 2,4,[B0] '2400 baud: HEX input to RB2
SerOut 3,4,[#B0] '2400 baud: HEX output to RB3
Pause 1 'Delay for 1 ms as per HMR3100 Manual
GoTo main



Please Help, I'm new to the PIC programming...

I'm a hardware engineer stuck in a software kind of world......

Ingvar
- 7th April 2006, 09:17
Your baudrate for serin2 will not be 2400, baudvalue should be 396. You could also just change Serin2 to Serin.

arniepj
- 7th April 2006, 20:32
You might try using the timeout function with the serin command.There's a good possibility that when the compass is triggered for data,the pic program has moved on before the data arrives.Also you could set the trigger low for continous data until troubleshooting is complete.If you only want to read data once,use the pulsout command for the trigger.