InvenSense ITG-3200 digital triaxial gyroscope.
This module implements a driver for the InvenSense ITG-3200 digital 3-axis MEMS gyroscope. The ITG-3200 provides digital-output x-, y-, and z-axis angular rate sensor readings with a sensitivity of 16 LSBs per deg/sec and a full-scale range of +/-2000 deg/sec.
The ITG-3200 consists of the following key blocks and functions:
- Three-axis MEMS rate gyroscope sensors with individual 16-bit ADCs and signal conditioning - I2C serial communications interface - Clocking - Sensor Data Registers - Interrupts - Digital-Output Temperature Sensor - Bias and LDO - Charge Pump - Three-Axis MEMS Gyroscope with 16-bit ADCs and Signal Conditioning
The ITG-3200 consists of three independent vibratory MEMS gyroscopes, which detect rotational rate about the X (roll), Y (pitch), and Z (yaw) axes. When the gyros are rotated about any of the sense axes, the Coriolis Effect causes a deflection that is detected by a capacitive pickoff. The resulting signal is amplified, demodulated, and filtered to produce a voltage that is proportional to the angular rate. This voltage is digitized using individual on-chip 16-bit Analog-to-Digital Converters (ADCs) to sample each axis.
The full-scale range of the gyro sensors is preset to +/-2000 degrees per second (deg/sec). The ADC output rate is programmable up to a maximum of 8,000 samples per second down to 3.9 samples per second, and user-selectable low-pass filters enable a wide range of cut-off frequencies.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include "itg3200.h"
Data Structures | |
struct | itg3200_event_t |
Interrupt Service Routine Data Descriptor. More... | |
Macros | |
#define | ITG3200_FS_RANGE (2000) /* fixed full-scale range (deg/sec) */ |
#define | ITG3200_RESOLUTION (16) /* axis data sample resolution (bits) */ |
#define | SCALE_LSB_PER_DPS (14375 / 1000) |
The ITG-3200 specification originally stated that the sensitivity scale factor was 16.4 LSB/deg/sec. More... | |
Functions | |
static bool | itg3200_default_init (sensor_hal_t *hal) |
InvenSense ITG-3200 gyroscope driver defaults. More... | |
static bool | itg3200_device_id (sensor_hal_t *hal, sensor_data_t *data) |
Read gyroscope device ID. More... | |
static bool | itg3200_event (sensor_t *sensor, sensor_event_t sensor_event, sensor_event_callback_t *callback, bool enable) |
Enable/disable ITG3200 sensor event. More... | |
static bool | itg3200_get_rotation (sensor_hal_t *hal, sensor_data_t *data) |
Read gyroscope angular rate axis data. More... | |
static bool | itg3200_get_temperature (sensor_hal_t *hal, sensor_data_t *data) |
Read gyroscope integrated temperature sensor data. More... | |
bool | itg3200_init (sensor_t *sensor, int resvd) |
InvenSense ITG-3200 gyroscope driver initialization. More... | |
static bool | itg3200_ioctl (sensor_t *sensor, sensor_command_t cmd, void *arg) |
ITG3200 ioctl control entry point. More... | |
static void | itg3200_isr (volatile void *arg) |
Invensense ITG3200 driver interrupt service routine. More... | |
static bool | itg3200_read (sensor_t *sensor, sensor_read_t type, sensor_data_t *data) |
Read sensor data. More... | |
static bool | itg3200_set_bandwidth (sensor_hal_t *hal, int16_t band) |
Set the ITG-3200 low-pass filter bandwidth. More... | |
static bool | itg3200_set_sample_rate (sensor_hal_t *hal, int16_t rate) |
Set the ITG-3200 sample rate. More... | |
static bool | itg3200_set_state (sensor_hal_t *hal, sensor_state_t state) |
Set the ITG-3200 execution mode. More... | |
Variables | |
static const sensor_map_t | band_table [] |
InvenSense ITG-3200 low-pass Bandwidth Table (hertz, register value) More... | |
static sensor_event_callback_t | event_cb = {.handler = default_event_handler} |
Sensor Event Callback Descriptor. More... | |
#define ITG3200_FS_RANGE (2000) /* fixed full-scale range (deg/sec) */ |
Referenced by itg3200_init().
#define ITG3200_RESOLUTION (16) /* axis data sample resolution (bits) */ |
Referenced by itg3200_init().
#define SCALE_LSB_PER_DPS (14375 / 1000) |
The ITG-3200 specification originally stated that the sensitivity scale factor was 16.4 LSB/deg/sec.
As of revision 1.4 of the specification, that has been modified to 14.375 LSB/deg/sec. The vendor may supply a way to interrogate ITG-3200 parts to determine which scale factor to use.
Referenced by itg3200_get_rotation(), and itg3200_isr().
|
inlinestatic |
InvenSense ITG-3200 gyroscope driver defaults.
This is a convenience routine for setting the default device configuration during initialization or after reset.
hal | Address of an initialized sensor hardware descriptor. |
References sensor_hal::bus, DLPF_CFG_42HZ, FS_SEL_2000, ITG3200_DLPF_FS, ITG3200_ID_VAL, ITG3200_PWR_MGM, ITG3200_SMPLRT_DIV, ITG3200_WHOAMI, PWR_MGM_CLK_SEL_Z, PWR_MGM_H_RESET, sensor_bus_get, sensor_bus_put, status, bus_desc_t::status, and STATUS_OK.
Referenced by itg3200_init(), and itg3200_set_state().
|
static |
Read gyroscope device ID.
This function reads the gyroscope hardware identification registers and returns these values to the addresses specified in the function parameters.
sensor | Address of an initialized sensor device descriptor. |
data | Address of sensor_data_t structure to return values. |
References sensor_data_t::device, ITG3200_WHOAMI, and sensor_bus_get.
Referenced by itg3200_read().
|
static |
Enable/disable ITG3200 sensor event.
sensor | Address of an initialized sensor device descriptor |
callback | Application-defined event callback handler descriptor |
enable | Enable flag: true = enable event, false = disable event |
References sensor_desc::hal, INT_CFG_ANYRD_2CLEAR, INT_CFG_LATCH_INT_EN, INT_CFG_RAW_RDY_EN, ITG3200_INT_CFG, sensor_bus_put, SENSOR_EVENT_NEW_DATA, sensor_reg_bitclear, and status.
Referenced by itg3200_init(), and itg3200_ioctl().
|
static |
Read gyroscope angular rate axis data.
This function reads angular rate data for all 3 axes of an ITG-3200 gyroscope.
sensor | Address of an initialized sensor device descriptor. |
data | The address of a vector storing sensor axis data. |
References sensor_data_t::axis, sensor_axis_vec_t::axis, ITG3200_GYRO_XOUT_H, sensor_hal::orientation, SCALE_LSB_PER_DPS, sensor_data_t::scaled, sensor_bus_read, sensor_axis_vec_t::sign, sensor_orient_t::x, sensor_orient_t::y, and sensor_orient_t::z.
Referenced by itg3200_ioctl(), and itg3200_read().
|
static |
Read gyroscope integrated temperature sensor data.
This function reads ITG-3200 integrated temperature sensor data. The temperature is always returned in scaled engineering units (degrees Celsius).
sensor | Address of an initialized sensor device descriptor. |
data | The address where temperature samples are returned. |
References be16_to_cpu, ITG3200_TEMP_OUT_H, sensor_data_t::scaled, sensor_bus_read, TEMP_COUNTS_PER_DEG_C, TEMP_OFFSET, TEMP_REF_DEG, and sensor_data_t::temperature.
Referenced by itg3200_read().
InvenSense ITG-3200 gyroscope driver initialization.
This is the main initialization function for the ITG-3200 device.
sensor | Address of a sensor device descriptor. |
resvd | Reserved value. |
References ARRAYSIZE, band_table, sensor_hal::bandwidth, sensor_hal::burst_addr, sensor_desc::drv, sensor_device_t::func, sensor_desc::hal, itg3200_default_init(), itg3200_event(), ITG3200_FS_RANGE, ITG3200_INT_STATUS, itg3200_ioctl(), itg3200_isr(), itg3200_read(), ITG3200_RESOLUTION, sensor_hal::mcu_sigint, sensor_hal::range, sensor_funcs_t::read, sensor_hal::resolution, sensor_hal::sample_rate, SENSOR_CAPS_3_AXIS, SENSOR_CAPS_AUX_TEMP, sensor_irq_connect(), SENSOR_UNITS_deg_per_sec, SENSOR_VENDOR_INVENSENSE, and status.
|
static |
ITG3200 ioctl control entry point.
This function provides a general-purpose interface for performing various control operations on the sensor device.
sensor | Address of an initialized sensor device descriptor. |
cmd | Command to execute |
arg | Argument for command (varies) |
References sensor_data_t::axis, sensor_desc::err, sensor_desc::hal, itg3200_event(), itg3200_get_rotation(), itg3200_set_bandwidth(), itg3200_set_sample_rate(), itg3200_set_state(), sensor_data_t::scaled, SENSOR_DISABLE_EVENT, SENSOR_ENABLE_EVENT, SENSOR_ERR_UNSUPPORTED, SENSOR_READ_VECTOR, SENSOR_SET_BANDWIDTH, SENSOR_SET_SAMPLE_RATE, SENSOR_SET_STATE, vector3_t::x, vector3_t::y, and vector3_t::z.
Referenced by itg3200_init().
|
static |
Invensense ITG3200 driver interrupt service routine.
This is the interrupt service routine for enabled ITG3200 interrupt events. Only the new data ("raw data ready") interrupt is supported.
arg | The address of the driver sensor_hal_t descriptor. |
References sensor_event_callback_t::arg, sensor_data_t::axis, sensor_axis_vec_t::axis, sensor_hal::burst_addr, sensor_hal::bus, sensor_event_data_t::data, sensor_event_data_t::event, sensor_event_callback_t::handler, bus_desc_t::no_wait, sensor_hal::orientation, SCALE_LSB_PER_DPS, sensor_data_t::scaled, sensor_bus_read, SENSOR_EVENT_NEW_DATA, sensor_timestamp(), sensor_axis_vec_t::sign, bus_desc_t::status, STATUS_OK, sensor_data_t::timestamp, sensor_orient_t::x, itg3200_event_t::x_hi, itg3200_event_t::x_lo, sensor_orient_t::y, itg3200_event_t::y_hi, itg3200_event_t::y_lo, sensor_orient_t::z, itg3200_event_t::z_hi, and itg3200_event_t::z_lo.
Referenced by itg3200_init().
|
static |
Read sensor data.
This routine calls the appropriate internal data function to obtain the specified type of data from the sensor device.
sensor | Address of an initialized sensor device descriptor. |
type | Type of sensor data to read. |
data | The address where data values are returned. |
References sensor_desc::err, sensor_desc::hal, itg3200_device_id(), itg3200_get_rotation(), itg3200_get_temperature(), SENSOR_ERR_FUNCTION, SENSOR_READ_ID, SENSOR_READ_ROTATION, and SENSOR_READ_TEMPERATURE.
Referenced by itg3200_init().
|
static |
Set the ITG-3200 low-pass filter bandwidth.
This routine sets the ITG-3200 low-pass filter bandwidth and the internal sample rate used by the device. This internal sample rate is then further scaled by the sample rate divider (SMPLRT_DIV) value to produce the gyro sample rate according to the formula:
Valid filter bandwidths and the associated internal sample rate are as follows:
hal | Address of an initialized sensor device descriptor. |
band | The index of a driver-specific bandwidth table entry. |
References sensor_hal::bandwidth, sensor_map_t::bandwidth_Hz, FS_SEL_2000, ITG3200_DLPF_FS, itg3200_set_sample_rate(), sensor_hal::sample_rate, and sensor_bus_put.
Referenced by itg3200_ioctl().
|
static |
Set the ITG-3200 sample rate.
This routine sets the externally visible ITG-3200 sample rate for the device. This sets a divider that scaled down the internal 1Khz or 8 KHz sample rate to the specified frequency, according to the formula:
The internal sampling rate is 1KHz for all filter bandwidths except 256Hz, which uses an 8KHz internal rate.
hal | Address of an initialized sensor device descriptor. |
rate | The externally visible sampling rate to be set |
References sensor_hal::bandwidth, ITG3200_SMPLRT_DIV, and sensor_bus_put.
Referenced by itg3200_ioctl(), and itg3200_set_bandwidth().
|
static |
Set the ITG-3200 execution mode.
This routine sets a specified ITG-3200 execution state to one of the following:
SENSOR_STATE_SLEEP or SENSOR_STATE_LOWEST_POWER Setting the sleep mode puts the device into very low power sleep mode. In this mode, only the serial interface and internal registers remain active.
SENSOR_STATE_NORMAL or SENSOR_STATE_HIGHEST_POWER Sets the device to a normal operational state.
SENSOR_STATE_RESET Sets the device and internal registers to the power-up default settings.
sensor | Address of an initialized sensor device descriptor. |
state | A specified sensor operational state. |
References delay_ms, itg3200_default_init(), ITG3200_PWR_MGM, PWR_MGM_SLEEP, sensor_reg_bitclear, sensor_reg_bitset, SENSOR_STATE_HIGHEST_POWER, SENSOR_STATE_LOWEST_POWER, SENSOR_STATE_NORMAL, SENSOR_STATE_RESET, and SENSOR_STATE_SLEEP.
Referenced by itg3200_ioctl().
|
static |
InvenSense ITG-3200 low-pass Bandwidth Table (hertz, register value)
Referenced by itg3200_init().
|
static |
Sensor Event Callback Descriptor.