Self test boot program for testing icarus sensors
Dependencies: BLE_API mbed nRF51822
Fork of BLE_UARTConsole by
Diff: ADXL362Sensor.cpp
- Revision:
- 14:cb369746225d
- Parent:
- 13:ef0ce8fa871f
--- a/ADXL362Sensor.cpp Sun Apr 05 09:54:04 2015 +0000 +++ b/ADXL362Sensor.cpp Wed Apr 15 20:01:16 2015 +0000 @@ -4,6 +4,9 @@ ADXL362Sensor::ADXL362Sensor(SPI& spi_,DigitalOut& cs_,void (*debug_)(const char* format, ...)) : BaseSensor(debug_), spi(spi_), cs(cs_) { cs = UP; + writeRegister(ADXL362_SOFT_RESET, 0x52); + wait_ms(1); + writeRegister(ADXL362_POWER_CTL,0x02); } @@ -13,7 +16,7 @@ uint32_t ADXL362Sensor::verifyIntegrity(uint32_t* errorResult) { - LOG("Start verfication of ADXL362 Sensor"); + LOG("Start verfication of ADXL362 Sensor\r\n"); uint32_t errors = 0; //Device id is 0xAD //Device mems id is 0x1D @@ -22,7 +25,7 @@ if (sensorId >> 8 !=0xAD1DF2){ errorResult[errors++] = ERROR_WRONG_DEVICE_ID; - LOG("Wrong sensorId: %X",sensorId); + LOG("Wrong sensorId: %X\r\n",sensorId); } //check status registry @@ -30,13 +33,13 @@ //indicate that SEU error was detetcted if (status & (1 << 7)){ - errorResult[errors++] = ERROR_SEU_ERROR_DETECT; - LOG("SEU error detected: %X",status); + errorResult[errors++] = ERROR_WRONG_DEVICE_STATE; + LOG("SEU error detected: %X\r\n",status); } //check that chip is in awaken state if (!(status & (1 << 6))){ errorResult[errors++] = ERROR_DEVICE_SLEEPING; - LOG("Chip not awaken: %X",status); + LOG("Chip not awaken: %X\r\n",status); } //perform self test @@ -56,29 +59,28 @@ int16_t test_x12,test_y12,test_z12; // 1. Read acceleration data for the x-, y-, and z-axes. refreshAcceleration12(&x12, &y12, &z12); - LOG("Acc1: %d %d %d\r\n",x12,y12,z12); // 2. Assert self test by setting the ST bit in the SELF_TEST register, Address 0x2E. writeRegister(ADXL362_SELF_TEST,0x01); // 3. Wait 1/ODR for the output to settle to its new value. - wait(1/ADXL362_ODR); + wait(4.0/ADXL362_ODR); // 4. Read acceleration data for the x-, y-, and z-axes. refreshAcceleration12(&test_x12, &test_y12, &test_z12); - LOG("Acc2: %d %d %d\r\n",test_x12,test_y12,test_z12); // 5. Compare to the values from Step 1, and convert the difference from LSB to mg by multiplying by the sensitivity. If the observed difference falls within the self test output change specification listed in Table 1, then the device passes self test and is deemed operational. - float reactionX = (x12-test_x12)* ADXL362_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD / ADXL362_SELF_TEST_SCALE_FACTOR; - float reactionY = (y12-test_y12)* ADXL362_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD / ADXL362_SELF_TEST_SCALE_FACTOR; - float reactionZ = (z12-test_z12)* ADXL362_MG2G_MULTIPLIER * SENSORS_GRAVITY_STANDARD / ADXL362_SELF_TEST_SCALE_FACTOR; + float reactionX = (test_x12-x12) * 0.250f; + float reactionY = (test_y12-y12) * 0.250f; + float reactionZ = (test_z12-z12) * 0.250f; + - if (reactionX<0.450F || reactionX>0.710F || - reactionY<-0.710F || reactionY>-0.450F || - reactionZ<0.350F || reactionZ>0.650F){ - errorResult[errors++] = ERROR_SELF_TEST_FAILED; + if (reactionX<230.0F || reactionX>870.0F || + reactionY<-870.0F || reactionY>-230.0F || + reactionZ<270.0F || reactionZ>800.0F){ + errorResult[errors++] = ERROR_ACCE_SELF_TEST_FAILED; LOG("Reaction: %+5.3f %+5.3f %+5.3f\r\n",reactionX,reactionY,reactionZ); } // 6. Deassert self test by clearing the ST bit in the SELF_TEST register, Address 0x2E. writeRegister(ADXL362_SELF_TEST,0x00); - + wait(4.0/ADXL362_ODR); return errors; }