cancel
Showing results for 
Search instead for 
Did you mean: 

magnetomter

ankushkhare89
Associate II
Posted on August 08, 2016 at 14:39

Hello folks, 

I am trying to implement the LIS3MDL magnetometer. I have a small confusion about its configuration.

It have option of +-4 gauss upto +-16 gauss.

So for the full scale configuration, i should configure to +-4 gauss or +-16 gauss ?

 

#!stm32
6 REPLIES 6
Posted on August 08, 2016 at 17:37

Let's try to keep things related in topic by a single individual in one thread. [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Magnetometer&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx&currentviews=7]Other Thread

You'd pick the smallest full-scale range that you expect to see so as to have the finest granularity in the measurements.

If you don't know what the range is that you are likely to see, then you should experiment under expected use conditions to come to some determination. I would perhaps have it as something I could configure, and then have the ability to scale the measurements received into common units, in a floating point representation with more bits and range so the down stream code is agnostic to what the hardware is, and what it is doing.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ankushkhare89
Associate II
Posted on August 09, 2016 at 10:09

Since the temperature sensor works between -40 to +85 C, how can I show the temperature on the LCD. Is it just by converting 2's complement into hexadecimal and display on the LCD ?

Is there more documentation on temperature sensor inside LIS3MDL?

ankushkhare89
Associate II
Posted on August 09, 2016 at 16:41

Also, what should be the values on the register X axis, Y axis and Z axis if configured in continuous configuration and +-8 gauss ? Do I need to convert the values which are 2s complement to hexadecimal ?

Posted on August 09, 2016 at 17:31

Do I need to convert the values which are 2s complement to hexadecimal ?

You seem to have some serious confusion about basic numeric representation.

From the manual, if I had Z as an int16_t (signed 16-bit integer) then

float z = (float)Z / 3421.0f; // Scale Z gauss for +/-8 range. Units in Gauss

16384 -> 0x4000 -> 4.78924

-16384 -> 0xC000 -> -4.78924

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 09, 2016 at 17:41

Since the temperature sensor works between -40 to +85 C, how can I show the temperature on the LCD. Is it just by converting 2's complement into hexadecimal and display on the LCD ? Is there more documentation on temperature sensor inside LIS3MDL?

I don't understand this hexadecimal angle here. The numeric representation is in binary, and you want output in base 10 not base 16

Manual says it reports in 1/8 degree increments, ie 0.125 of a degree

Where TEMP is int16_t

float temp = (float)TEMP / 8.0f;

or 

float temp = (float)TEMP * 0.125f;

sprintf(buffer,''%7.3f'', temp);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ankushkhare89
Associate II
Posted on August 10, 2016 at 09:54

Sorry, I am new to programming. Thank you for replying.

I checked with 2s complement interpretation.

So I am reading the temperature register by 

int16_t temp_data = (temp_reg_M<< 8) + temp_reg_L;

if it is positive then MSB(15th bit) will be 0 and if the temperature is negative then the MSB will be 1. If the value is negative then I will take 2s complement (flip the bits and add 1) to get the hex value. Then I divide the temperature value with 8.0f. 

float final_temp =  (float)TEMP / 8.0f;

and then display on the UART. Did I get it right ?