2012-09-12 10:51 PM
I am trying to calculate the heading of the 3 axis compass and stuck with this issue that I can't solve. when I read the compass output register viz.
0x03 (x_msb), 0x04 (x_lsb), 0x05 (z_msb), 0x06 (z_lsb), 0x07 (y_msb) and 0x08 (y_lsb). the x,y and z MSB values are not updated at all where as y and z LSB are updated as expected. I configured the CRA_REG_M (00h) to 0x10 for 30Hz ODR, MR_REG_M (02h) to 0x00 for continuous mode and CRB_REG_M (01h) to every possible value of (GN2,GN1,GN0) for all sensor rangebut had same result. I can't understand what the problem is, The I2C software seems to be fine as it works perfectly for accelerometer and gyro!!!!.did anyone come across this issue????sample output:Mxh=-16 Mxl=0 Myh=-1 Myl=35 Mzh=-1 Mzl=20Mxh=-16 Mxl=0 Myh=-1 Myl=35 Mzh=-1 Mzl=20Mxh=-16 Mxl=0 Myh=-1 Myl=35 Mzh=-1 Mzl=20Mxh=-16 Mxl=0 Myh=-1 Myl=35 Mzh=-1 Mzl=20Mxh=-16 Mxl=0 Myh=-1 Myl=35 Mzh=-1 Mzl=20Mxh=-16 Mxl=0 Myh=-1 Myl=35 Mzh=-1 Mzl=20Mxh=-16 Mxl=0 Myh=-1 Myl=35 Mzh=-1 Mzl=23Mxh=-16 Mxl=0 Myh=-1 Myl=35 Mzh=-1 Mzl=23please note the Mxh, Myh and Mzh won't buzz however I rotate or move the compass. #lsm303dlm2012-09-13 02:27 AM
I have finally solved the problem. but it took me some agonizing hours to figure out the problem. The problem is that the default sensitivity of the compass or the magnetometer is easily overran by surrounding magnetic fields, (may be from power supply or other devices). This causes the output registers to overflow and contain -4096 as output. THIS WAS NOT MENTIONED IN THE LSM303DLM datasheet!!!.
However the solution is simple, just select the least sensitivity. I selected the value 0xE0 for 0x02 register and it worked :)2012-09-16 08:40 PM
Ah you found the same thing I did:
[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32F%20MEMS%20%20iNEMO/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32F MEMS iNEMO/LSM303DLHC max mag range is wrong&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580003E26E7DD54228C428E8F9FB5EE9C5185¤tviews=47]LSM303DLHC max mag range is wrongI share your aggravation with this!There's actually 4 things wrong here I was seeing in this part:One, yes, the ''out-of-range'' value is not specified.Two, the ''out-of-range'' value weirdly did this thing where it flipped sign near the out-of-range value, but only with the Z-axis.Three, the point at which it goes out-of-range is not only unspecified, but makes little sense- it was not at the max/min of the number space, but a far lower value- I've never even seen this before in any part I can think of.Four- this is big, I suspect you have the same problem but haven't realized it yet- the total range is not only much less than specified in the datasheet, but it's uselessly low for Earth-based applications as it will saturate even within the Earth's magnetic field, when the part's axis starts to line up with the Earth's magnetic vector.The measurement's units all made sense, sqrt(x^2+y^2+z^2)~=0.480gauss, ambient for my area. But with the scale set to 1.3gauss, the max values I could read were:Xrange=+/-0.736 gaussYrange=+/-0.439gaussZrange=+/-2.080 gauss(!)The Y will break when aligned with Earth's magnetic field. This is a WICKED problem, because your code will work just fine and give good output until you hit a small range of orientations where it aligns enough that it suddenly jumps to -4096!I recommend you set this up to read live on your screen and bring a magnet near it, slowly, to see what YOUR part can read as a max and min axis value before you get the ''out-of-range'' error. From what I could tell, the magnetic field amplitude was indeed correct, but the limits of the axes are all wrong. If you've got the same problem I saw on my part- that an axis can't read even the Earth's magnetic field- then you can't use that scale.In fact, PLEASE do this test for me! I'd suspected I merely got a bad part, but the product itself may have a major design flaw. Your problem sounds the same as mine.2012-10-11 07:37 AM
Yeah, I have the same problem with magnetic measurement as you!
The interesting thing: the effect is device dependent. I work with a couple of the LSM303DLM and some of them have this saturation problem, jumping to -4096. I'm not happy with and try now to change the measurement range to +/- 1.9 gauss at those sensors with problems. I hope there will be a hint for fixing it or improvement of the sensor for the future. ;)