HMC5883l compass output
AGCB
Posts: 327
I've been fighting w/ a HMC5883L Parallax #29133 compass module for a month. I've made
it read out the 6 registers (I think) but when I convert the 16 bit 2s compliment value to decimal,
I get way too high numbers. Like X= +65282 Y= -65535 Z= -39167. It's probably that I am
doing the conversion wrong. Although I am using a PIC 18F MC and assembly code and do not
understand the sample codes in Spin or BS2, I could write the code if I could understand the
basics of doing the math and conversions.
From what I have learned on the web, this is the way I am treating the register values
that I get from the compass.
It is a 16 bit 2s compliment value so I test the Msb bit 7 for sign (1 if negative 0 if +) and save it.
Then I compliment both registers and add 1 to the Lsb, if there is a carry, I also add 1 to
the Msb. Now having a 2 byte binary number, I convert it to decimal and add the sign.
If this is wrong, please tell me.
Page 15 of the Honeywell documentation is not easy for me to understand. It says the
range is 0xF800(decimal 63,488) to 0x07FF (decimal 2,047). These numbers are way higher
than what I expect them to be. Also I believe that the -65535 decimal that I'm getting for Y is the
error code -4096. Even this -4096 I do not understand. Is it decimal (I assume) or hex?
WHAT am I doing wrong?? Without some help, I'm about ready to give this up. Thanks
Aaron, new to this forum but been programing PICs for 4 or 5 years of winter months.
it read out the 6 registers (I think) but when I convert the 16 bit 2s compliment value to decimal,
I get way too high numbers. Like X= +65282 Y= -65535 Z= -39167. It's probably that I am
doing the conversion wrong. Although I am using a PIC 18F MC and assembly code and do not
understand the sample codes in Spin or BS2, I could write the code if I could understand the
basics of doing the math and conversions.
From what I have learned on the web, this is the way I am treating the register values
that I get from the compass.
It is a 16 bit 2s compliment value so I test the Msb bit 7 for sign (1 if negative 0 if +) and save it.
Then I compliment both registers and add 1 to the Lsb, if there is a carry, I also add 1 to
the Msb. Now having a 2 byte binary number, I convert it to decimal and add the sign.
If this is wrong, please tell me.
Page 15 of the Honeywell documentation is not easy for me to understand. It says the
range is 0xF800(decimal 63,488) to 0x07FF (decimal 2,047). These numbers are way higher
than what I expect them to be. Also I believe that the -65535 decimal that I'm getting for Y is the
error code -4096. Even this -4096 I do not understand. Is it decimal (I assume) or hex?
WHAT am I doing wrong?? Without some help, I'm about ready to give this up. Thanks
Aaron, new to this forum but been programing PICs for 4 or 5 years of winter months.
Comments
The C code is on-line here: https://code.google.com/p/propsideworkspace/source/browse/#hg%2FLearn%2FSimple%20Libraries%2FSensor%2Flibcompass3d
The entire Learn Library can be downloaded from here: http://learn.parallax.com/node/658
I was thinking the raw values and what your program generates as their decimal equivalents. This will let others see if you're converting from the raw value correctly.
I don't understand this part of your post:
Is the x component magnetic field always zero? If so then there's something wrong with the way you're either reading the data from the sensor or there's a problem with your connections between the microcontroller and the sensor.
I've used a HMC5883L sensor but I didn't write the low level code to read from the sensor so I'll need to let someone else help you if they can.
Yes. the X registers are always 0 and the Y registers are always 65535