6

I have a LIS3MDL outputting what seem to be reasonable magnetic field strength values (see second image). However, I am confused why the temperature reading seems to be dependent on the orientation of the magnetometer when I performed the "figure 8" motions. As far as I understand, the temperature value I am reading is used as an input to a compensation algorithm in the magnetometer, so it should be independent of the field itself.

Concerning acquisition of the value, I am reading out the 16-bit, 2's complement value and then dividing by 2^8 and offsetting to 25 degC. I believe this is justified by the application note AN4602 (http://www.st.com/resource/en/application_note/dm00136626.pdf):

Serial.print((((int16_t)((buf[8] << 8) | buf[7])) / 256.0) + 25.0); // temp

Temperature Readings

Magnetometer values "Figure 8"

abc
  • 619
  • 6
  • 21
  • 1
    Is the board equipped with decoupling capacitors? Is the voltage filtered and stable? What about computing cross-correlation between two signals to make sure the temperature is correlated with angle? – Marko Buršič Mar 17 '17 at 00:10
  • 1
    I seriously doubt the temperature is going up and down 7 degrees celcius every second... so it's either reading it wrong or more likely you are somehow. Are you sure you are actually reading the temperature? – Trevor_G Mar 17 '17 at 01:16
  • Just to clarify, this fluctuation in temperature occurs due to changing orientation of the IC. It will remain relatively constant if left alone. – abc Mar 17 '17 at 01:30
  • @MarkoBuršič There are two 4.7uF and one .1uF caps in parallel. I am using the Pololu board https://www.pololu.com/product/2737. I can check the correlation to angle. – abc Mar 17 '17 at 01:32
  • Yes but if its really a magnetism value so would that. It doesn't draw enough current to heat up that much either. – Trevor_G Mar 17 '17 at 01:33
  • @Trevor I see what you are saying. As far as I can tell, I am reading the correct registers based on the datasheet, and using the scaling/offset it comes out to the expected temperature range, but I wouldn't know how to verify this for sure. – abc Mar 17 '17 at 01:35
  • Double check your address constants in your code would be my first place to go. 8 degrees is a lot.. you ought to be able to feel that much. – Trevor_G Mar 17 '17 at 01:37
  • 1
    You could also leave it sitting and warm it up with a heat gun or hair drier and see if it changes as much you expect. If it doesn't then you are not reading the temperature. Though bare in mind the magnetic values will change a bit too. – Trevor_G Mar 17 '17 at 01:44
  • 1
    @abc - I suggest going back to basics, cut down your code to the minimum, analyse *raw* data bytes from the sensor (X, Y, Z and temperature) not the *computed* values, and look for patterns. As *Trevor* mentioned, I wonder if your code is actually using the correct bytes from the sensor, to compute the "temperature" value. Looking at calculated values can hide problems visible in the underlying raw data. Also, please perform the "gently heat the stationary sensor" test suggested by *Trevor* and see what happens to the *raw* data from the sensor. Do *only* the expected raw bytes change? – SamGibson Mar 17 '17 at 04:19
  • 1
    If that is the MATLAB plot, then use XCORR (signal processing toolbox) : temperature VS. X-axis, temperature VS. Y-axis, temperature VS. Z-axis. It will show and confirm//reject your hypothesis. I gave you an upvote for preparation. – Marko Buršič Mar 17 '17 at 09:31
  • 1
    Another useful plot would be a temperature vs. H-magnitude vector: \$R=\sqrt{x^2+y^2+z^2}\$. It would show the correlation between reference voltage of internal ADC. If both curves follows, then a plausible explanation would be the supply voltage fluctuation. – Marko Buršič Mar 17 '17 at 09:49

2 Answers2

3

I recaptured data and plotted the temperature individually against each magnetometer axis. From the plots below, its apparent that the temperature data was actually the x-axis data.

enter image description here

enter image description here

enter image description here

I believe this is due to the SPI address auto-increment not working as expected. It seems to 'wrap around' only within the mag x/y/z registers, and does not go to the adjacent temperature registers. My original code was:

#define OUT_X_L 0x28
#define OUT_X_H 0x29
#define OUT_Y_L 0x2A
#define OUT_Y_H 0x2B
#define OUT_Z_L 0x2C
#define OUT_Z_H 0x2D
#define TEMP_OUT_L 0x2E
#define TEMP_OUT_H 0x2F
#define SPI_READ_BURST_START OUT_X_L

uint8_t buf[8]; // xyz, temp

...

  spiReadBurstLIS3MDL(SPI_READ_BURST_START, buf, sizeof(buf));
  Serial.print(micros());
  Serial.print("\t");
  Serial.print((int16_t)((buf[1] << 8) | buf[0])); // x
  Serial.print("\t");
  Serial.print((int16_t)((buf[3] << 8) | buf[2])); // y
  Serial.print("\t");
  Serial.print((int16_t)((buf[5] << 8) | buf[4])); // z
  Serial.print("\t");
  Serial.print((((int16_t)((buf[7] << 8) | buf[6])) / 256.0) + 25.0); // temp
  Serial.print("\n");

But after changing to the following, the temperature output is as expected:

...

uint8_t buf[6]; // xyz
int16_t temp;

...

  spiReadBurstLIS3MDL(SPI_READ_BURST_START, buf, sizeof(buf));
  temp = 0xFF & spiReadLIS3MDL(TEMP_OUT_L);
  temp |= spiReadLIS3MDL(TEMP_OUT_H) << 8;
  Serial.print(micros());
  Serial.print("\t");
  Serial.print((int16_t)((buf[1] << 8) | buf[0])); // x
  Serial.print("\t");
  Serial.print((int16_t)((buf[3] << 8) | buf[2])); // y
  Serial.print("\t");
  Serial.print((int16_t)((buf[5] << 8) | buf[4])); // z
  Serial.print("\t");
  Serial.print((temp / 256.0) + 25.0); // temp
  Serial.print("\n");

enter image description here

Thanks for all the input. It was a silly issue with serial comms after all, nothing to do with the sensor.

abc
  • 619
  • 6
  • 21
1

You and your face are a heat source. Approximately 1/4 watt/cm^2. Your hands are cooler, but you use your hands to hold the PCB.

Simply by being near, by closely examining the PCB, you are injecting heat and causing temperature gradients.

PCB foil, the default 1ounce/foot^2 CU foil, has thermal resistance of 70 degree Centigrade per watt.

Is that a problem?

analogsystemsrf
  • 33,703
  • 2
  • 18
  • 46
  • 1
    Again, I want to reiterate that the only thing appearing to cause this is a change in orientation. My grip on the board and distance from heat sources is constant. – abc Mar 17 '17 at 03:40