This is my quadcopter prototype software, still in development!
Embed:
(wiki syntax)
Show/hide line numbers
ITG3200.h
00001 /** 00002 * @author Aaron Berk 00003 * 00004 * @section LICENSE 00005 * 00006 * Copyright (c) 2010 ARM Limited 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a copy 00009 * of this software and associated documentation files (the "Software"), to deal 00010 * in the Software without restriction, including without limitation the rights 00011 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00012 * copies of the Software, and to permit persons to whom the Software is 00013 * furnished to do so, subject to the following conditions: 00014 * 00015 * The above copyright notice and this permission notice shall be included in 00016 * all copies or substantial portions of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00021 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00022 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00023 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00024 * THE SOFTWARE. 00025 * 00026 * @section DESCRIPTION 00027 * 00028 * ITG-3200 triple axis, digital interface, gyroscope. 00029 * 00030 * Datasheet: 00031 * 00032 * http://invensense.com/mems/gyro/documents/PS-ITG-3200-00-01.4.pdf 00033 */ 00034 00035 /** 00036 * Includes 00037 */ 00038 00039 00040 #ifndef ITG3200_H 00041 #define ITG3200_H 00042 /** 00043 * Includes 00044 */ 00045 #include "mbed.h" 00046 00047 /** 00048 * Defines 00049 */ 00050 #define ITG3200_I2C_ADDRESS 0x68 //7-bit address. 00051 00052 //----------- 00053 // Registers 00054 //----------- 00055 #define WHO_AM_I_REG 0x00 00056 #define SMPLRT_DIV_REG 0x15 00057 #define DLPF_FS_REG 0x16 00058 #define INT_CFG_REG 0x17 00059 #define INT_STATUS 0x1A 00060 #define TEMP_OUT_H_REG 0x1B 00061 #define TEMP_OUT_L_REG 0x1C 00062 #define GYRO_XOUT_H_REG 0x1D 00063 #define GYRO_XOUT_L_REG 0x1E 00064 #define GYRO_YOUT_H_REG 0x1F 00065 #define GYRO_YOUT_L_REG 0x20 00066 #define GYRO_ZOUT_H_REG 0x21 00067 #define GYRO_ZOUT_L_REG 0x22 00068 #define PWR_MGM_REG 0x3E 00069 00070 //---------------------------- 00071 // Low Pass Filter Bandwidths 00072 //---------------------------- 00073 #define LPFBW_256HZ 0x00 00074 #define LPFBW_188HZ 0x01 00075 #define LPFBW_98HZ 0x02 00076 #define LPFBW_42HZ 0x03 00077 #define LPFBW_20HZ 0x04 00078 #define LPFBW_10HZ 0x05 00079 #define LPFBW_5HZ 0x06 00080 /** 00081 * ITG-3200 triple axis digital gyroscope. 00082 */ 00083 class ITG3200 { 00084 public: 00085 /** 00086 * Constructor. 00087 * 00088 * Sets FS_SEL to 0x03 for proper opertaion. 00089 * 00090 * @param sda - mbed pin to use for the SDA I2C line. 00091 * @param scl - mbed pin to use for the SCL I2C line. 00092 */ 00093 ITG3200(PinName sda, PinName scl); 00094 /** 00095 * Get the identity of the device. 00096 * 00097 * @return The contents of the Who Am I register which contains the I2C 00098 * address of the device. 00099 */ 00100 char getWhoAmI(void); 00101 /** 00102 * Set the address of the device. 00103 * 00104 * @param address The I2C slave address to write to the Who Am I register 00105 * on the device. 00106 */ 00107 void setWhoAmI(char address); 00108 /** 00109 * Get the sample rate divider. 00110 * 00111 * @return The sample rate divider as a number from 0-255. 00112 */ 00113 char getSampleRateDivider(void); 00114 /** 00115 * Set the sample rate divider. 00116 * 00117 * Fsample = Finternal / (divider + 1), where Finternal = 1kHz or 8kHz, 00118 * as decidied by the DLPF_FS register. 00119 * 00120 * @param The sample rate divider as a number from 0-255. 00121 */ 00122 void setSampleRateDivider(char divider); 00123 /** 00124 * Get the internal sample rate. 00125 * 00126 * @return The internal sample rate in kHz - either 1 or 8. 00127 */ 00128 int getInternalSampleRate(void); 00129 00130 void setLpBandwidth(char bandwidth); 00131 /** 00132 * Get the interrupt configuration. 00133 * 00134 * See datasheet for register contents details. 00135 * 00136 * 7 6 5 4 00137 * +------+------+--------------+------------------+ 00138 * | ACTL | OPEN | LATCH_INT_EN | INT_ANYRD_2CLEAR | 00139 * +------+------+--------------+------------------+ 00140 * 00141 * 3 2 1 0 00142 * +---+------------+------------+---+ 00143 * | 0 | ITG_RDY_EN | RAW_RDY_EN | 0 | 00144 * +---+------------+------------+---+ 00145 * 00146 * ACTL Logic level for INT output pin; 1 = active low, 0 = active high. 00147 * OPEN Drive type for INT output pin; 1 = open drain, 0 = push-pull. 00148 * LATCH_INT_EN Latch mode; 1 = latch until interrupt is cleared, 00149 * 0 = 50us pulse. 00150 * INT_ANYRD_2CLEAR Latch clear method; 1 = any register read, 00151 * 0 = status register read only. 00152 * ITG_RDY_EN Enable interrupt when device is ready, 00153 * (PLL ready after changing clock source). 00154 * RAW_RDY_EN Enable interrupt when data is available. 00155 * 0 Bits 1 and 3 of the INT_CFG register should be zero. 00156 * 00157 * @return the contents of the INT_CFG register. 00158 */ 00159 char getInterruptConfiguration(void); 00160 /** 00161 * Set the interrupt configuration. 00162 * 00163 * See datasheet for configuration byte details. 00164 * 00165 * 7 6 5 4 00166 * +------+------+--------------+------------------+ 00167 * | ACTL | OPEN | LATCH_INT_EN | INT_ANYRD_2CLEAR | 00168 * +------+------+--------------+------------------+ 00169 * 00170 * 3 2 1 0 00171 * +---+------------+------------+---+ 00172 * | 0 | ITG_RDY_EN | RAW_RDY_EN | 0 | 00173 * +---+------------+------------+---+ 00174 * 00175 * ACTL Logic level for INT output pin; 1 = active low, 0 = active high. 00176 * OPEN Drive type for INT output pin; 1 = open drain, 0 = push-pull. 00177 * LATCH_INT_EN Latch mode; 1 = latch until interrupt is cleared, 00178 * 0 = 50us pulse. 00179 * INT_ANYRD_2CLEAR Latch clear method; 1 = any register read, 00180 * 0 = status register read only. 00181 * ITG_RDY_EN Enable interrupt when device is ready, 00182 * (PLL ready after changing clock source). 00183 * RAW_RDY_EN Enable interrupt when data is available. 00184 * 0 Bits 1 and 3 of the INT_CFG register should be zero. 00185 * 00186 * @param config Configuration byte to write to INT_CFG register. 00187 */ 00188 void setInterruptConfiguration(char config); 00189 /** 00190 * Check the ITG_RDY bit of the INT_STATUS register. 00191 * 00192 * @return True if the ITG_RDY bit is set, corresponding to PLL ready, 00193 * false if the ITG_RDY bit is not set, corresponding to PLL not 00194 * ready. 00195 */ 00196 bool isPllReady(void); 00197 00198 bool isRawDataReady(void); 00199 /** 00200 * Get the temperature of the device. 00201 * 00202 * @return The temperature in degrees celsius. 00203 */ 00204 float getTemperature(void); 00205 /** 00206 * Get the output for the x-axis gyroscope. 00207 * 00208 * Typical sensitivity is 14.375 LSB/(degrees/sec). 00209 * 00210 * @return The output on the x-axis in raw ADC counts. 00211 */ 00212 int getGyroX(void); 00213 /** 00214 * Get the output for the y-axis gyroscope. 00215 * 00216 * Typical sensitivity is 14.375 LSB/(degrees/sec). 00217 * 00218 * @return The output on the y-axis in raw ADC counts. 00219 */ 00220 int getGyroY(void); 00221 00222 int getGyroZ(void); 00223 /** 00224 * Get the power management configuration. 00225 * 00226 * See the datasheet for register contents details. 00227 * 00228 * 7 6 5 4 00229 * +---------+-------+---------+---------+ 00230 * | H_RESET | SLEEP | STBY_XG | STBY_YG | 00231 * +---------+-------+---------+---------+ 00232 * 00233 * 3 2 1 0 00234 * +---------+----------+----------+----------+ 00235 * | STBY_ZG | CLK_SEL2 | CLK_SEL1 | CLK_SEL0 | 00236 * +---------+----------+----------+----------+ 00237 * 00238 * H_RESET Reset device and internal registers to the power-up-default settings. 00239 * SLEEP Enable low power sleep mode. 00240 * STBY_XG Put gyro X in standby mode (1=standby, 0=normal). 00241 * STBY_YG Put gyro Y in standby mode (1=standby, 0=normal). 00242 * STBY_ZG Put gyro Z in standby mode (1=standby, 0=normal). 00243 * CLK_SEL Select device clock source: 00244 * 00245 * CLK_SEL | Clock Source 00246 * --------+-------------- 00247 * 0 Internal oscillator 00248 * 1 PLL with X Gyro reference 00249 * 2 PLL with Y Gyro reference 00250 * 3 PLL with Z Gyro reference 00251 * 4 PLL with external 32.768kHz reference 00252 * 5 PLL with external 19.2MHz reference 00253 * 6 Reserved 00254 * 7 Reserved 00255 * 00256 * @return The contents of the PWR_MGM register. 00257 */ 00258 char getPowerManagement(void); 00259 /** 00260 * Set power management configuration. 00261 * 00262 * See the datasheet for configuration byte details 00263 * 00264 * 7 6 5 4 00265 * +---------+-------+---------+---------+ 00266 * | H_RESET | SLEEP | STBY_XG | STBY_YG | 00267 * +---------+-------+---------+---------+ 00268 * 00269 * 3 2 1 0 00270 * +---------+----------+----------+----------+ 00271 * | STBY_ZG | CLK_SEL2 | CLK_SEL1 | CLK_SEL0 | 00272 * +---------+----------+----------+----------+ 00273 * 00274 * H_RESET Reset device and internal registers to the power-up-default settings. 00275 * SLEEP Enable low power sleep mode. 00276 * STBY_XG Put gyro X in standby mode (1=standby, 0=normal). 00277 * STBY_YG Put gyro Y in standby mode (1=standby, 0=normal). 00278 * STBY_ZG Put gyro Z in standby mode (1=standby, 0=normal). 00279 * CLK_SEL Select device clock source: 00280 * 00281 * CLK_SEL | Clock Source 00282 * --------+-------------- 00283 * 0 Internal oscillator 00284 * 1 PLL with X Gyro reference 00285 * 2 PLL with Y Gyro reference 00286 * 3 PLL with Z Gyro reference 00287 * 4 PLL with external 32.768kHz reference 00288 * 5 PLL with external 19.2MHz reference 00289 * 6 Reserved 00290 * 7 Reserved 00291 * 00292 * @param config The configuration byte to write to the PWR_MGM register. 00293 */ 00294 void setPowerManagement(char config); 00295 private: 00296 I2C i2c_; 00297 }; 00298 #endif /* ITG3200_H */
Generated on Wed Jul 13 2022 23:20:56 by 1.7.2