Data loger, logs 3D acc/mag every 100ms on external flash drive, requires FRDM-KL46Z, copyrighted except libraries used
Dependencies: mbed Rejestrator
Revision 1:5ad44a4edff9, committed 2015-05-09
- Comitter:
- Waldek
- Date:
- Sat May 09 15:06:38 2015 +0000
- Parent:
- 0:fa31f8461c63
- Commit message:
- Correction in the magnetic measurement
Changed in this revision
--- a/Acquisition.cpp Sat Apr 18 17:01:57 2015 +0000 +++ b/Acquisition.cpp Sat May 09 15:06:38 2015 +0000 @@ -27,10 +27,13 @@ { struct row_type *data_buffer = data_memory.alloc(); - mag.getValues(&data_buffer->mag_x, &data_buffer->mag_y, &data_buffer->mag_z); - data_buffer->mag_x = (int)((int16_t)data_buffer->mag_x); - data_buffer->mag_y = (int)((int16_t)data_buffer->mag_y); - data_buffer->mag_z = (int)((int16_t)data_buffer->mag_z); +// mag.getValues(&data_buffer->mag_x, &data_buffer->mag_y, &data_buffer->mag_z); + data_buffer->mag_x = (int)mag.readVal(MAG_OUT_X_MSB); +// (int)((int16_t)data_buffer->mag_x); + data_buffer->mag_y = (int)mag.readVal(MAG_OUT_Y_MSB); +// (int)((int16_t)data_buffer->mag_y); + data_buffer->mag_z = (int)mag.readVal(MAG_OUT_Z_MSB); +// (int)((int16_t)data_buffer->mag_z); data_buffer->giro_x = 0; data_buffer->giro_y = 0; @@ -73,7 +76,22 @@ rtos::RtosTimer timer(RunningTimer, osTimerPeriodic, NULL); rtos::RtosTimer Acquisition(RunningAcquisition, osTimerPeriodic, NULL); - +/* + // debug + { + extern Serial pc; + pc.printf("\nMag regs: "); + for (int i=0; i<20; ++i) + { + pc.printf("%02X ", mag.readReg(i)); + } + pc.printf(".\n"); + for (int i=0; i<1000; ++i) + { + pc.printf("%d %d %d \n", mag.readVal(MAG_OUT_X_MSB), mag.readVal(MAG_OUT_Y_MSB), mag.readVal(MAG_OUT_Z_MSB)); + } + } +*/ timer.start(1); Acquisition.start(100); @@ -95,3 +113,4 @@ } led_green = 1.; } +
--- a/FileWritter.cpp Sat Apr 18 17:01:57 2015 +0000 +++ b/FileWritter.cpp Sat May 09 15:06:38 2015 +0000 @@ -77,7 +77,7 @@ { fprintf(ft, "%8d\t%12d\t%5d\t%6d\t%6d\t%6d\t%6d\t%6d\t%6d\t%6d\t%6d\t%6d\t%6.4f\t%6.4f\t%6.3f\t%5d\t%1d\t\n", (int)filenumber, (int)data_buffer->time, (int)record_counter, - (int)data_buffer->mag_x, (int)data_buffer->mag_x, (int)data_buffer->mag_x, + (int)data_buffer->mag_x, (int)data_buffer->mag_y, (int)data_buffer->mag_z, (int)data_buffer->acc_x, (int)data_buffer->acc_y, (int)data_buffer->acc_z, (int)data_buffer->giro_x, (int)data_buffer->giro_y, (int)data_buffer->giro_z, (float)data_buffer->light, (float)data_buffer->Ain0,
--- a/MAG3110/MAG3110.cpp Sat Apr 18 17:01:57 2015 +0000 +++ b/MAG3110/MAG3110.cpp Sat May 09 15:06:38 2015 +0000 @@ -1,6 +1,24 @@ #include "MAG3110.h" #include "mbed.h" +/* + Mag regs: FF FC 5B 02 8A 0C EA C4 02 00 00 00 00 00 00 00 19 00 5F FF . +64601 650 3306 + +FF +x FB B9 +y 01 21 +z 0D 44 +id C4 +System mode 02 +off x 00 00 +off y 00 00 +off z 00 00 +temp 00 +ctrl reg1 19 +ctrl reg2 00 +BF FF . +*/ /****************************************************************************** * Constructors @@ -11,18 +29,24 @@ begin(); } -void MAG3110::begin() +void MAG3110::begin(void) { char cmd[2]; cmd[0] = MAG_CTRL_REG2; - cmd[1] = MAG_3110_AUTO_MRST_EN + MAG_3110_MAG_RST; + cmd[1] = MAG_3110_MAG_RST; _i2c.write(_i2c_address, cmd, 2); cmd[0] = MAG_CTRL_REG1; - cmd[1] = MAG_3110_SAMPLE80 + MAG_3110_OVERSAMPLE4 + MAG_3110_ACTIVE; + cmd[1] = MAG_3110_SAMPLE80 + MAG_3110_OVERSAMPLE3 + MAG_3110_ACTIVE; _i2c.write(_i2c_address, cmd, 2); + cmd[0] = MAG_WHO_AM_I; + _i2c.write(_i2c_address, cmd, 1); + cmd[0] = 0x00; + _i2c.read(_i2c_address, cmd, 1); +// if (cmd[0] == MAG_3110_WHO_AM_I_VALUE) + // No adjustment initially _avgX = 0; _avgY = 0; @@ -44,7 +68,7 @@ // read a register per, pass first reg value, reading 2 bytes increments register // Reads MSB first then LSB -int MAG3110::readVal(char regAddr) +int16_t MAG3110::readVal(char regAddr) { char cmd[2]; @@ -58,11 +82,22 @@ } +int MAG3110::readAll(char *buffer) +{ + char cmd[2]; + + cmd[0] = 0; + _i2c.write(_i2c_address, cmd, 1); + + _i2c.read(_i2c_address, buffer, 20); + return (int)buffer[0]; //status +} + float MAG3110::getHeading() { int xVal = readVal(MAG_OUT_X_MSB); int yVal = readVal(MAG_OUT_Y_MSB); - return (atan2((double)(yVal - _avgY),(double)(xVal - _avgX)))*180/PI; + return (atan2((double)(yVal - _avgY),(double)(xVal - _avgX)))*180./PI; } void MAG3110::getValues(int *xVal, int *yVal, int *zVal)
--- a/MAG3110/MAG3110.h Sat Apr 18 17:01:57 2015 +0000 +++ b/MAG3110/MAG3110.h Sat May 09 15:06:38 2015 +0000 @@ -91,7 +91,7 @@ * Setup the Magnetometer * */ - void begin(); + void begin(void); /** * Read a register, return its value as int * @param regAddr The address to read @@ -103,7 +103,13 @@ * @param regAddr The address to read * @return Value from 2 consecutive registers */ - int readVal(char regAddr); + int16_t readVal(char regAddr); + /** + * Read all registers + * @param buffer Buffer to store all registers + * @return Value from register 0 + */ + int readAll(char *buffer); /** * Calculate the heading * @return heading in degrees
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Rejestrator.lib Sat May 09 15:06:38 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/JW/code/Rejestrator/#fa31f8461c63