cancel
Showing results for 
Search instead for 
Did you mean: 

LIS3MDL Magnetometer data reading Error

HGohe
Associate II

Hi All,

I am working on the LIS3MDL register on my board. But When I try to measure the Magnetic field Produced by motors, I am getting very high deviation.

My settings for the LIS3MDL are as below.

0x22 -- 0x00 (also tried with 0x22 -- 0x03)

0x21 -- 0x00

0x23 -- 0x0C

0x24 -- 0x00

0x30 -- 0x00

0x32 -- 0x00

0x33 -- 0x00

And I am setting 300 ODR (HP Mode).

(delay of 100 ms after reading 1 sample from each axis).

(Below para is for reference , you can also neglect).

So The deviation Which I am talking here is, when I collect samples/time, and convert frequency I get somewhere around 30-35hz but when I measured with other sensor(bosch sensortech) I am getting exact match of magnetic readings. (verified with field applied and also converting as above (same conversion) ) the exact match would be 50hz.

Sensor is connected over SPI (4 wires) mode.

Here I wanted to know, If I am doing correct settings in the register and also Is there any other settings/process.

So , Please if any one can point me out in right direction, that would be very helpful.

Thanks in advance.

(also enclosing the x,y,z raw samples file)

8 REPLIES 8
Miroslav BATEK
ST Employee

What is your settings in register CTRL_REG1 (20h)?

How do you read the data? Are you using DRDY interrupt?

HGohe
Associate II

Hi Miroslav,

My settings in CTRL_REG1 is = 0x5E,

Reading data on 300 hz speed.( In main application it will be user defined, but the readings pasted here is on 300 hz.

Right now I am not using DRDY interrupt., And I read data directly from x,y,z registers as raw data over spi.

Please let me know for any other inputs required for solution.

Thanks,

Hinesh

Miroslav BATEK
ST Employee

OK, the configuration is correct.

But you have to measure the real ODR of the sensor using the DRDY signal to get correct frequency value. The ODR can have quite significant error from the typical value which is in datasheet.

HGohe
Associate II

Ok,

So what do suggest is good way to check as I need to collect the raw data.

And Here I am collecting is raw samples from the registers.

For collecting some 1000 samples , By the DRDY signal approach will take longer time.

Miroslav BATEK
ST Employee

My recommendation is to read the samples after DRDY interrupt and a the same time measure the data rate by a timer in your MCU (save time at first and last sample). It will take the same amount of time as polling status register for new data, which you are do now.

HGohe
Associate II

Hi @Miroslav BATEK​ 

ok,

Let me try that way,

But Also Today I did one interesting thing.

I collected the raw samples from sensors, And I converted to FFT.

In fft , Though I have selected sampling freq. 300hz in reg. but when I gave sampling freq 250 (in fft calculation), I got match.

So, Another question,

is there any possibility that the ODR which is mentioned in data sheet, may have error, (as you said in last post) of 50hz?

Thanks,

Hinesh

Miroslav BATEK
ST Employee

50Hz seems to me too much, but I double check you configuration and I think I see the problem.

If you configure the CTRL_REG1 is = 0x5E (High-performance mode for X,Y axis) you have to configure also Z axis into the same mode, it means CTRL_REG4 = 0x80 (not 0x0C).

If the modes for X,Y and Z are different the ODR will be different, which you would see if you measure it using DRDY.

HGohe
Associate II

Hi @Miroslav BATEK​ ,

Thank you for insde, Let me try with the configuration for ctrl_reg4 as you have suggested.

I am implementing DRDY setting, (As in project, middle layer and application is already implemented, So going through them on driver level to implement same ).

Meanwhile, If you think any experiment that can be done to measure readings, That will be helpful.

Also I was going through the data sheet, And for CTRL_REG4 if I set 0x80 , then It would be

 1000 0000 , Which As per data sheet may not be correct,

Are you trying to say CTRL_REG4= 0x08 ( Z high performance mode)?

UPDATE:-

I have tried with the register settings in CTRL_REG4=0x08 and 0x80,

But results from both are also almost similer to what I was getting for 0x0C, ( there is difference)

But Thank you for pointing it out, I have changed it for correctness.

Thanks,

Hinesh