Interface library for the Atmel Inertial One IMU. Contains drivers for the ITG 3200 3 axis gyro, BMA-150 3 axis accelerometer, and AK8975 3 axis compass

Committer:
Ductapemaster
Date:
Thu Feb 02 08:05:41 2012 +0000
Revision:
6:7a77438c94fb
Parent:
5:3756a7bc1f06
Child:
7:9e3b79b06e27
doxygen - description section

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Ductapemaster 5:3756a7bc1f06 1 /**
Ductapemaster 5:3756a7bc1f06 2 * @author Daniel Kouba
Ductapemaster 5:3756a7bc1f06 3 * @section Licence
Ductapemaster 5:3756a7bc1f06 4 *
Ductapemaster 5:3756a7bc1f06 5 * Atmel Inertial One IMU Library
Ductapemaster 5:3756a7bc1f06 6 * Copyright (c) 2012 Daniel Kouba
Ductapemaster 0:5a636973285e 7 *
Ductapemaster 0:5a636973285e 8 * Permission is hereby granted, free of charge, to any person obtaining a copy
Ductapemaster 0:5a636973285e 9 * of this software and associated documentation files (the "Software"), to deal
Ductapemaster 0:5a636973285e 10 * in the Software without restriction, including without limitation the rights
Ductapemaster 0:5a636973285e 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Ductapemaster 0:5a636973285e 12 * copies of the Software, and to permit persons to whom the Software is
Ductapemaster 0:5a636973285e 13 * furnished to do so, subject to the following conditions:
Ductapemaster 0:5a636973285e 14 *
Ductapemaster 0:5a636973285e 15 * The above copyright notice and this permission notice shall be included in
Ductapemaster 0:5a636973285e 16 * all copies or substantial portions of the Software.
Ductapemaster 0:5a636973285e 17 *
Ductapemaster 0:5a636973285e 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Ductapemaster 0:5a636973285e 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Ductapemaster 0:5a636973285e 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Ductapemaster 0:5a636973285e 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Ductapemaster 0:5a636973285e 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Ductapemaster 0:5a636973285e 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Ductapemaster 0:5a636973285e 24 * THE SOFTWARE.
Ductapemaster 0:5a636973285e 25 *
Ductapemaster 6:7a77438c94fb 26 * @section Description
Ductapemaster 6:7a77438c94fb 27 *
Ductapemaster 6:7a77438c94fb 28 * Atmel Inertial One IMU Library
Ductapemaster 6:7a77438c94fb 29 *
Ductapemaster 6:7a77438c94fb 30 * Includes control routines for:
Ductapemaster 6:7a77438c94fb 31 * - ITG-3200 3-axis, 16 bit gyroscope
Ductapemaster 6:7a77438c94fb 32 * - BMA-150 3-axis, 16 bit accelerometer
Ductapemaster 6:7a77438c94fb 33 * - AK8975 3-axis, 16 bit magnetometer
Ductapemaster 6:7a77438c94fb 34 *
Ductapemaster 6:7a77438c94fb 35 * Datasheets:
Ductapemaster 6:7a77438c94fb 36 *
Ductapemaster 6:7a77438c94fb 37 * http://www.atmel.com/dyn/resources/prod_documents/doc8354.pdf
Ductapemaster 6:7a77438c94fb 38 *
Ductapemaster 6:7a77438c94fb 39 * http://invensense.com/mems/gyro/documents/PS-ITG-3200A.pdf
Ductapemaster 6:7a77438c94fb 40 *
Ductapemaster 6:7a77438c94fb 41 * http://www.bosch-sensortec.com/content/language1/downloads/BMA150_DataSheet_Rev.1.5_30May2008.pdf
Ductapemaster 6:7a77438c94fb 42 *
Ductapemaster 6:7a77438c94fb 43 * http://pdf1.alldatasheet.com/datasheet-pdf/view/219477/AKM/AK8973/+Q18W89VYpLawLCDwv+/datasheet.pdf
Ductapemaster 6:7a77438c94fb 44 *
Ductapemaster 0:5a636973285e 45 */
Ductapemaster 0:5a636973285e 46
Ductapemaster 0:5a636973285e 47 #ifndef IMU_AIO_H //IMU Atmel Inertial One
Ductapemaster 0:5a636973285e 48 #define IMU_AIO_H
Ductapemaster 0:5a636973285e 49
Ductapemaster 0:5a636973285e 50 #include "mbed.h"
Ductapemaster 0:5a636973285e 51
Ductapemaster 0:5a636973285e 52 /* Defines */
Ductapemaster 0:5a636973285e 53
Ductapemaster 0:5a636973285e 54 //7 bit I2C Addresses, shifted left to allow for read/write bit as LSB
Ductapemaster 0:5a636973285e 55
Ductapemaster 0:5a636973285e 56 #define GYRO_ADR 0x68 << 1
Ductapemaster 0:5a636973285e 57 #define ACC_ADR 0x38 << 1
Ductapemaster 0:5a636973285e 58 #define COMP_ADR 0x0C << 1
Ductapemaster 0:5a636973285e 59
Ductapemaster 0:5a636973285e 60 // ITG3200 Gyro Registers
Ductapemaster 0:5a636973285e 61
Ductapemaster 0:5a636973285e 62 #define GYRO_WHO_AM_I_REG 0x00
Ductapemaster 0:5a636973285e 63 #define GYRO_SAMPLE_DIV_REG 0x15
Ductapemaster 0:5a636973285e 64 #define GYRO_DLPF_REG 0x16
Ductapemaster 0:5a636973285e 65 #define GYRO_INT_CFG_REG 0x17
Ductapemaster 0:5a636973285e 66 #define GYRO_INT_STATUS_REG 0x1A
Ductapemaster 0:5a636973285e 67 #define GYRO_TEMP_H_REG 0x1B
Ductapemaster 0:5a636973285e 68 #define GYRO_TEMP_L_REG 0x1C
Ductapemaster 0:5a636973285e 69 #define GYRO_XOUT_H_REG 0x1D
Ductapemaster 0:5a636973285e 70 #define GYRO_XOUT_L_REG 0x1E
Ductapemaster 0:5a636973285e 71 #define GYRO_YOUT_H_REG 0x1F
Ductapemaster 0:5a636973285e 72 #define GYRO_YOUT_L_REG 0x20
Ductapemaster 0:5a636973285e 73 #define GYRO_ZOUT_H_REG 0x21
Ductapemaster 0:5a636973285e 74 #define GYRO_ZOUT_L_REG 0x22
Ductapemaster 0:5a636973285e 75
Ductapemaster 0:5a636973285e 76 // Gyro LPF bandwidths
Ductapemaster 0:5a636973285e 77
Ductapemaster 0:5a636973285e 78 #define BW_256HZ 0x00 //8kHz sample rate
Ductapemaster 0:5a636973285e 79 #define BW_188HZ 0x01 //1kHz sample rate for 188Hz and below
Ductapemaster 0:5a636973285e 80 #define BW_98HZ 0x02
Ductapemaster 0:5a636973285e 81 #define BW_42HZ 0x03
Ductapemaster 0:5a636973285e 82 #define BW_20HZ 0x04
Ductapemaster 0:5a636973285e 83 #define BW_10HZ 0x05
Ductapemaster 0:5a636973285e 84 #define BW_5HZ 0x06
Ductapemaster 0:5a636973285e 85
Ductapemaster 0:5a636973285e 86 // Gyro Initial FS_SEL Register Config
Ductapemaster 0:5a636973285e 87
Ductapemaster 0:5a636973285e 88 #define FS_SEL_INIT 0x03 << 3
Ductapemaster 0:5a636973285e 89
Ductapemaster 0:5a636973285e 90 // BMA150 Accelerometer Registers
Ductapemaster 0:5a636973285e 91
Ductapemaster 0:5a636973285e 92
Ductapemaster 0:5a636973285e 93
Ductapemaster 0:5a636973285e 94 // AK8973 Compass Registers
Ductapemaster 2:262f9878bebf 95
Ductapemaster 0:5a636973285e 96
Ductapemaster 5:3756a7bc1f06 97 /** Atmel Inertial One IMU Control Class
Ductapemaster 2:262f9878bebf 98 *
Ductapemaster 2:262f9878bebf 99 */
Ductapemaster 0:5a636973285e 100 class IMU {
Ductapemaster 0:5a636973285e 101
Ductapemaster 0:5a636973285e 102 public:
Ductapemaster 0:5a636973285e 103
Ductapemaster 2:262f9878bebf 104 /** Creates IMU object and initializes all three chips
Ductapemaster 2:262f9878bebf 105 *
Ductapemaster 2:262f9878bebf 106 * Gyro: FS_SEL register is set to 0x03, as required by datasheet
Ductapemaster 2:262f9878bebf 107 * Accelerometer:
Ductapemaster 2:262f9878bebf 108 * Compass:
Ductapemaster 2:262f9878bebf 109 *
Ductapemaster 2:262f9878bebf 110 * @param sda - pin for I2C sda signal
Ductapemaster 2:262f9878bebf 111 * @param scl - pin for I2C scl signal
Ductapemaster 2:262f9878bebf 112 */
Ductapemaster 0:5a636973285e 113 IMU(PinName sda, PinName scl);
Ductapemaster 0:5a636973285e 114
Ductapemaster 0:5a636973285e 115 /* Gyro Methods */
Ductapemaster 0:5a636973285e 116
Ductapemaster 0:5a636973285e 117 /** Gets current X axis gyro measurement
Ductapemaster 0:5a636973285e 118 *
Ductapemaster 0:5a636973285e 119 * @return Raw X axis ADC measurement (signed 16 bits)
Ductapemaster 0:5a636973285e 120 */
Ductapemaster 0:5a636973285e 121 int gyroX(void);
Ductapemaster 0:5a636973285e 122
Ductapemaster 0:5a636973285e 123 /** Gets current Y axis gyro measurement
Ductapemaster 0:5a636973285e 124 *
Ductapemaster 0:5a636973285e 125 * @return Raw Y axis ADC measurement (signed 16 bits)
Ductapemaster 0:5a636973285e 126 */
Ductapemaster 0:5a636973285e 127 int gyroY(void);
Ductapemaster 0:5a636973285e 128
Ductapemaster 0:5a636973285e 129 /** Gets current Z axis gyro measurement
Ductapemaster 0:5a636973285e 130 *
Ductapemaster 0:5a636973285e 131 * @return Raw Z axis ADC measurement (signed 16 bits)
Ductapemaster 0:5a636973285e 132 */
Ductapemaster 0:5a636973285e 133 int gyroZ(void);
Ductapemaster 0:5a636973285e 134
Ductapemaster 0:5a636973285e 135 /** Gets current ADC data from all axes of gyro (uses burst read mode)
Ductapemaster 0:5a636973285e 136 *
Ductapemaster 0:5a636973285e 137 * @return Array of X, Y, and Z axis gyro measurements (signed 16 bits)
Ductapemaster 0:5a636973285e 138 */
Ductapemaster 0:5a636973285e 139 int[3] gyroXYZ(void);
Ductapemaster 0:5a636973285e 140
Ductapemaster 0:5a636973285e 141 /** Sets digital LPF bandwidth for all gyro channels
Ductapemaster 0:5a636973285e 142 *
Ductapemaster 0:5a636973285e 143 * @param Filter Bandwidth (use defined bandwidths)
Ductapemaster 0:5a636973285e 144 */
Ductapemaster 0:5a636973285e 145 void gyroSetLPF(char _BW);
Ductapemaster 0:5a636973285e 146
Ductapemaster 0:5a636973285e 147 /* Accelerometer Methods */
Ductapemaster 0:5a636973285e 148
Ductapemaster 0:5a636973285e 149
Ductapemaster 0:5a636973285e 150
Ductapemaster 0:5a636973285e 151 /* Compass Methods */
Ductapemaster 0:5a636973285e 152
Ductapemaster 0:5a636973285e 153
Ductapemaster 0:5a636973285e 154
Ductapemaster 2:262f9878bebf 155 protected:
Ductapemaster 0:5a636973285e 156
Ductapemaster 0:5a636973285e 157 I2C _i2c; //I2C object constructor
Ductapemaster 0:5a636973285e 158
Ductapemaster 0:5a636973285e 159 };
Ductapemaster 0:5a636973285e 160
Ductapemaster 0:5a636973285e 161 #endif