Problem Writing values to Magnetometer FXOS8700CQ

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem Writing values to Magnetometer FXOS8700CQ

2,057 Views
lukelynch
Contributor III

Hello,

 

I have a couple of questions regarding writing to the:

  • M_OFF_Z_MSB(0x43), M_OFF_Z_LSB (0x44) registers
  • M_THS_Z_MSB (0x58), M_THS_Z_LSB (0x59) registers

 

With the offset register it says in the datasheet: "For example, to correct for an offset of 60 uT, a value representing 60 uT (= 60 uT / 0.1 uT/LSB= 600 LSB), which is 0x0258 in 15-bit two's complement representation, should be written to the offset registers following a left-shift for proper alignment (0x0258<<1 = 0x04b0)".  What happens if i want to correct for an offset of -60uT (which is -60uT/0.1uT/LSB=-600LSB), which is 0x7DA8 in 15-bit two's complement representation,  0x7DA8<<1 =0xFB50, it this what i would write to the offset register to correct for a negative offset?

 

With writing to the magnetometer threshold register. I want to set an offset of -1000 counts or does it have to be +1000 as its a absolute number. Can it be wrote to the threshold register as -1000 (FC18). Does it need to be wrote as 15 bit or 16 bit 2's complement?

 

I am having some trouble, I take a reading (with the north pole, negative side of a magnet) facing at the magnetometer along the +z-axis and for example my reading out is 0xFC18. I then write this reading as ,0xFC to the M_THS_Z_MSB and 0x18 to the M_THS_Z_LSB. But when i move my magnet closer and reading increases (0xFC18 is = -1000 so it goes pass -1000 to -2000, 0xF830). my interrupt does not become set (low to indicate my threshold value on the z-axis has been exceeded). I feel i am writing the threshold value wrong, could someone help me?

if it make a difference i am taking a reading with no magnet in place and setting it as my offset so with no magnet in place i am getting a reading of  zero.

 

I have no problem setting a positive threshold (same as above but with the south pole, positive side facing the magnetometer), take a reading, set its as my threshold and when i move the magnet closer my interrupt becomes set.

 

Any help would be great,

Luke.

Labels (1)
0 Kudos
11 Replies

1,385 Views
aswins
NXP Employee
NXP Employee

Hi Luke,

       I reviewed your questions. Here are my answers to the same. Please let me know if you have further questions.

To explain it better I have attached screenshots from Freescale's Kinetis Interface toolkit.  Kinetis Interface toolkit will allow you to read/write register values by using the Register Level interface and stream data. I strongly encourage you to use the same for your experimentation!

First, Offset questions

Yes you are right . You can write both positive and negative values in 15 bit two's complement (with <<1). Please find that the Z axis (green) in the graphs below that has exact +60 and -60 uT shifts.

Without Offset (0x43 =00, 0x44 =00)     60uT Z axis offset (Value =0x04B0)  With 60uT Z axis offset (Value =0xFB50)

WithoutOffset.pngWith60uT(0x04b0)Offset.pngWith-60uT(0xFB50)Offset.png

Secondly , Threshold registers

The thresholds are unsigned 15-bit values with 0.1uT/LSB resolution. This means as shown in datasheet (figure 18)

If you set a threshold value as 'X' it means both Threshold '+X'  and threshold '-X' are defined

               pastedImage_0.png

Now, it seems like in your example you have directly written the value 0xFC18 to THS register. But have you taken care of the right shift operation as bit field position 15 is m_ths_dbcntm? (>>1). You might have ended up with a different offset shift value. pls check with this.

Also one more consideration, what is the value of m_ths_oae bit in M_THS_CFG ? depending on this your logical decision (AND ing  or OR ing  of all events) may vary.

Thanks

Aswin Sivakumar

Sensor Apps Engineer

0 Kudos

1,385 Views
lukelynch
Contributor III

Ive another question also, After my offset calibration, m-z-out is 0. if i bring a magnet really close (on the -zaxis, havent tried the +z-axis) and remove it, my m-z-out data does not return to 0 like you would expect, why would this happen?

0 Kudos

1,385 Views
michaelestanley
NXP Employee
NXP Employee

Luke,

I'll let Aswin continue to follow up on the original thread, but I can answer your last questions about changing Z-offset.

Freescale uses a magnetic sensor technology called "TMR" (Tunnelling Magneto Resistive).  The native sensors for this technology are "in-plane".  These handle X and Y portions of the 3D vector naturally.  In order to get "Z", we utilize a flux-guide which redirects Z axis field such that it can be sensed with an in-plane sensor.  If the magnetic field exceeds specifications (which it will almost certainly do if you subject it to an external magnet in the immediate area), that flux-guide will retain some residual magnetism (your offset) when you take the original source away.   This is known as "perming".  If you reapply the opposite side of the same magnet, you'll probably see the offset shift a similar amount the other side of the baseline.

Regards,

Mike

0 Kudos

1,385 Views
lukelynch
Contributor III

Thank you for your reply Michael.

What strength magnetic field would have to be exposed to the magnetometer to cause "perming"?

Would you have this effect on the x or y axis as it is using a different technique?

Regards,

Luke.

0 Kudos

1,385 Views
aswins
NXP Employee
NXP Employee

Thanks Mike.

Hi Luke,

                   Regarding your question on the pre triggering (that is interrupt flagged before set threshold is reached), did you check if the calibrated readings returned to zero correctly  if the magnet is removed.? Like Mike had explained before, if you have crossed the specifications - absolute maximum readings as discussed in the datasheet, the device might have "permed" -a constant offset would occur. This constant offset might cause triggering as the offset calibration now doesnt make the device to return to 0. Can you check your field strength conformance to the specifications in the maximum ratings table? I would recommend to try with a small threshold value first.

Also I assume while writing to the THS_register you are taking care of the "unsigned" nature of this register

If you have further questions, pls inbox me your number we can have a call to resolve your questions quickly.

Thanks

Aswin

0 Kudos

1,385 Views
lukelynch
Contributor III

I tried inboxing you but i need to be friends with you first, could you please follow?

Thanks,

Luke.

0 Kudos

1,385 Views
lukelynch
Contributor III

Hello Aswin,

I created a new thread about this problem specifically as i didn't want this thread going to far off topic, if you care to look at it.

I have checked, if i do my offset, take a reading it is a 0, if i move my magnet into place and then remove it, the reading returns to 0.

As i mentioned in my other thread i think my ths register is ignoring my offset?

Regards,

Luke.

0 Kudos

1,385 Views
michaelestanley
NXP Employee
NXP Employee

Luke,

10K microTeslas is the "Maximum exposed magnetic field without perming".  It applies specifically to the Z axis, as that is the only axis that includes a flux guide.  There is no internal mechanism to reverse flux guide perming.

There is a second physical mechanism that can apply to all axes, as it affects the free layer of the MJT.  The maximum field here is the maximum range of the sensor (1200 microTesla for the 8700).  There is a software reset command (specified in the datasheet) which is recommended before every read cycle that can reset the MJT.

Regards,

Mike

0 Kudos

1,385 Views
lukelynch
Contributor III

With my magnet in place I should roughly see a max reading of 400uT, so i should be ok. I had the effects of perming during testing when i brought a stronger magnet very close to the magnetometer to see would it have any effects.

The way i have this set up is an interrupt is generated when the z-axis exceeds the threshold, the interrupt will change state with the realtime status of the event detection logic. In my software i have a external interrupt handler taking care of the interrupt (when it is low, the threshold has been exceeded, when its high the threshold has not been exceeded). For me to do a reset after every read will make my code more complicated which i am trying to avoid.

0 Kudos

1,385 Views
lukelynch
Contributor III

After doing a small bit of testing and i feel im getting towards the correct solution.

I do my offset calibration,put my magnet in place, take a reading and apply it to ths register. it should be at this point that an interrupt is generated, but my interrupt is generated exactly my ths value-half of my offset value? 

This how i do my offset (no magnet in place, takes an average reading and applies it to the offset register after been left shifted). My offset is 0x25e(before left shifting).

pastedImage_0.png

I then move my magnet into place, take an average reading and apply this reading to the ths register.

pastedImage_1.png

But my interrupt is generated when the reading is greater than 0x07c3 even though my thershold is set to 0x08f2. The difference between 0x08f2 and 0x07c3 is 0x012f, half of my offset value before it has been left shifted one place.

pastedImage_2.png

Any idea why this is happening?

0 Kudos

1,385 Views
lukelynch
Contributor III

aswinsivakumar

Thanks for the reply Aswin.

Ok i feel that my offset is ok. What i do is take 10 readings. First M_OUT_X_MSB(0x33) to update the rest of the register and then read M_OUT_Z_MSB(0x37) and M_OUT_Z_LSB(0x38), i then add all the values together and divide by 10 to give an average reading. I then left shift this value 1 plave to turn it into a 2's complement number, i apply this value to the z offset register (0x44 & 0x43). To make sure it worked i keep printing the value of the M_OUT_Z_MSB(0x37) and M_OUT_Z_LSB(0x38) on the uart and it is roughly 0.

With the Threshold:

0x52 is set to 1 (or'ed), so if any of the registers exceed my threshold value it will generate a interrupt.

m_ths_dbcntm is defaluted to 0, and i never write to this register so i presume it stays at this.

What i am doing is doing my offset and applying it to the offset register as above. i then move a magnet into position, i take an average reading and apply this value to the threshold register, so when this magnet comes closer it will generate an output and when it moves away the interrupt it gone. I feel i am writing to the register wrong or reading a value incorrectly.

This is my idea: i do the offset calibration on the z-axis, I take a reading of the z-axis with a magnet in position(Returns a value corrected by the offset) and write this value to the ths_z register. But the ths-z register is not corrected by the offset? so when i write 0x0923 to the thershold register(which is not corrected by the offset), it will generate an interupt minus the offset value? Or is the thershold registers reading the value of the corrected magnetomter z out register?

Regards,

Luke. 

0 Kudos