cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2DH: Minimum delay between commands during Self-test

Cesco Gar
Associate II
Posted on March 28, 2017 at 17:08

Hi,

is it possible to know the minimum delay required to wait between register writing during the self-test?

I write down my code, to make myself more clear

while(1)

{

BYTE xH = 0;

BYTE yH = 0;

BYTE zH = 0;

//HPF disabling

writeRegAccel(BYTE_REG2, WRT_CTRL_REG2_WO_MS);

//Minimum delay to swotch from a mode to another

delayMs(7);

//I set the frequency at 5k376 Hz

writeRegAccel(LOW_PWR_MODE_5K376HZ_W_XYZ, WRT_CTRL_REG1_WO_MS);

delayMs(7);

//I read the 3 H axis

//First reading with garbage data

xxx1:

if(((readRegAccel(STATUS_REG)) & 0x08) == 0x08)

{

readRegAccel(OUT_X_H);

readRegAccel(OUT_Y_H);

readRegAccel(OUT_Z_H);

}else{

goto xxx1;

}

//Second reading of the 'real' datas

xxx2:

if(((readRegAccel(STATUS_REG)) & 0x08) == 0x08)

{

xH = readRegAccel(OUT_X_H);

resultAbsX = abs(xH);

yH = readRegAccel(OUT_Y_H);

resultAbsY = abs(yH);

zH = readRegAccel(OUT_Z_H);

resultAbsZ = abs(zH);

}else{

goto xxx2;

}

//Self-test function

accel_Test();

//Display refresh

shwAccelTest(SHW_ACCEL_RFSH);

//Disabling the self-test mode

writeRegAccel(BYTE_REG4, WRT_CTRL_REG4_WO_MS);

//I clear the memory in case there are garbage readings

xxx3:

if(((readRegAccel(STATUS_REG)) & 0x08) == 0x08)

{

readRegAccel(OUT_X_H);

readRegAccel(OUT_Y_H);

readRegAccel(OUT_Z_H);

}else{

goto xxx3;

}

xxx4:

if(((readRegAccel(STATUS_REG)) & 0x08) == 0x08)

{

readRegAccel(OUT_X_H);

readRegAccel(OUT_Y_H);

readRegAccel(OUT_Z_H);

}else{

goto xxx4;

}

//HPF reactivation 

writeRegAccel(BYTE_REG2_HP, WRT_CTRL_REG2_WO_MS);

//I set the frequency to 50 Hz 

writeRegAccel(LOW_PWR_MODE_50HZ_W_XYZ, WRT_CTRL_REG1_WO_MS);

delayMs(20);

}

accel_Test FUNCTION

void accel_Test()

{

BYTE xH_Test = 0;

BYTE yH_Test = 0;

BYTE zH_Test = 0;

BYTE delta_X = 0;

BYTE delta_Y = 0;

BYTE delta_Z = 0;

//I activate the self-test

writeRegAccel(BYTE_REG4_SELF_TEST, WRT_CTRL_REG4_WO_MS);

//Minimum delay to activate the self-test

delayMs(7);

//First reading (garbage data)

xxx3:

if(((readRegAccel(STATUS_REG)) & 0x08) == 0x08)

{

readRegAccel(OUT_X_H);

readRegAccel(OUT_Y_H);

readRegAccel(OUT_Z_H);

}else{

goto xxx3;

}

//Second reading of the effective data

xxx4:

if(((readRegAccel(STATUS_REG)) & 0x08) == 0x08)

{

xH_Test = readRegAccel(OUT_X_H);

resultAbsTestX = abs(xH_Test);

yH_Test = readRegAccel(OUT_Y_H);

resultAbsTestY = abs(yH_Test);

zH_Test = readRegAccel(OUT_Z_H);

resultAbsTestZ = abs(zH_Test);

}else{

goto xxx4;

}

//I make a delta between the two reading

delta_X = resultAbsTestX - resultAbsX;

delta_Y = resultAbsTestY - resultAbsY;

delta_Z = resultAbsTestZ - resultAbsZ;

//Delta's absolute of the datas

delta_X = abs(delta_X);

delta_Y = abs(delta_Y);

delta_Z = abs(delta_Z);

//Results control

if(delta_X > KMIN_DELTA_TEST_ACC ||

delta_Y > KMIN_DELTA_TEST_ACC ||

delta_Z > KMIN_DELTA_TEST_ACC )

{

//Result OK

}else{

//Result error

}

}

If I don't put those delay of 7ms, the accelerometer will give me back wrong datas, like 0xff or datas from before the self-test was deactivated.

Thus, is there a minimum delay I need to set after I change my frequency or set other registers?

I translated my comments so that the reading will be simplier.

Thank you

#lis2dh12 #self-test #delay #register
3 REPLIES 3
Miroslav BATEK
ST Employee
Posted on March 29, 2017 at 10:23

Recommended delay after the self-test is enabled is 200ms.

You should also discard 2 or 8 samples according to selected mode (see note 7 below)

0690X00000606bSQAQ.png
Posted on March 30, 2017 at 09:24

And when I change the HPF mode and frequency? Do I need to put a minimum delay here too? Because I noticed that if I don't delay of a minimum of 7 ms  when I change those, I get strange readings.

M Poppitz
Associate II
Posted on January 11, 2018 at 00:03

ST rep sent a confidential doc specific to the selftest of the LIS2DH that calls for a minimum 11mS or ( 1/ODR + 1mS ).

The calculated time may be better depending on what ODR frequency you set but I found 

( 1/ODR + 2mS ) is safer

I should note the doc I got from Terry at FirstAlliance(ST support rep) shows a different flow chart than the public PDF

I asked Terry and you can contact him for the doc but i asked and was told not to post it in the public sector