void readacc(void) { unsigned char data[6]; lib_i2c_readdata(BMA180_ADDRESS, 0x02, (unsigned char *) &data, 6); // convert readings to fixedpointnum (in g's) //usefull info is on the 14 bits [2-15] bits /4 => [0-13] bits /4 => 12 bit resolution ACC_ORIENTATION(global.acc_g_vector, (((data[1] << 8) | data[0]) >> 2) * 64L, (((data[3] << 8) | data[2]) >> 2) * 64L, (((data[5] << 8) | data[4]) >> 2) * 64L); }
void read_gyro() { unsigned char data[6]; lib_i2c_readdata(MPU6050_ADDRESS,0x43,(unsigned char *)&data,6); // convert to fixedpointnum, in degrees per second // the gyro puts out an int where each count equals 0.0609756097561 degrees/second // we want fixedpointnums, so we multiply by 3996 (0.0609756097561 * (1<<FIXEDPOINTSHIFT)) GYRO_ORIENTATION(global.gyrorate,((data[0]<<8) | data[1])*3996L , // range: +/- 8192; +/- 2000 deg/sec ((data[2]<<8) | data[3])*3996L , ((data[4]<<8) | data[5])*3996L ); }
void read_gyro() { unsigned char data[6]; lib_i2c_readdata(ITG3200_ADDRESS,0X1D,(unsigned char *)&data,6); // convert to fixedpointnum, in degrees per second // the gyro puts out an int where each count equals 0.0695652173913 degrees/second // we want fixedpointnums, so we multiply by 4559 (0.0695652173913 * (1<<FIXEDPOINTSHIFT)) GYRO_ORIENTATION(global.gyrorate,((data[0]<<8) | data[1])*4559L , // range: +/- 8192; +/- 2000 deg/sec ((data[2]<<8) | data[3])*4559L , ((data[4]<<8) | data[5])*4559L ); }
void readacc(void) { unsigned char data[6]; lib_i2c_readdata( MC3210_ADDRESS, 0x0D, (unsigned char *)&data, 6); // convert readings to fixedpointnum (in g's) // Sensor output is 14 bit signed, sign extended to 16 bit, full scale +/- 8g // So we have 13 bit fractional part, need to shift that to FIXEDPOINTSHIFT and // take 8g into account (further shift by 3 bits). // This only works if FIXEDPOINTSHIFT >= 10 ACC_ORIENTATION(global.acc_g_vector, ((fixedpointnum)((int16_t)((data[1] << 8) | data[0]))) << (FIXEDPOINTSHIFT - 13 + 3), ((fixedpointnum)((int16_t)((data[3] << 8) | data[2]))) << (FIXEDPOINTSHIFT - 13 + 3), ((fixedpointnum)((int16_t)((data[5] << 8) | data[4]))) << (FIXEDPOINTSHIFT - 13 + 3)); }
void readgyro(void) { unsigned char data[6]; lib_i2c_readdata(MPU3050_ADDRESS, 0x1D, (unsigned char *) &data, 6); // convert to fixedpointnum, in degrees per second // the gyro puts out a 16 bit signed int where each count equals 0.0609756097561 degrees/second // So we have 15 bit fractional part, need to shift that to FIXEDPOINTSHIFT and // take 2000deg/s into account. // This only works if FIXEDPOINTSHIFT >= 15 GYRO_ORIENTATION(global.gyrorate, ((int16_t) ((data[0] << 8) | data[1])) * (2000L << (FIXEDPOINTSHIFT - 15)), ((int16_t) ((data[2] << 8) | data[3])) * (2000L << (FIXEDPOINTSHIFT - 15)), ((int16_t) ((data[4] << 8) | data[5])) * (2000L << (FIXEDPOINTSHIFT - 15))); }