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 07:34:36 2012 +0000
Revision:
0:5a636973285e
Child:
1:1ea611e007f3
Basic library test #1: Gyro functions for reading axis data and setting low pass filter are implemented.

Who changed what in which revision?

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