Microchip® Advanced Software Framework

itg3200.c File Reference

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().

static bool itg3200_default_init ( sensor_hal_t hal)
inlinestatic

InvenSense ITG-3200 gyroscope driver defaults.

This is a convenience routine for setting the default device configuration during initialization or after reset.

Parameters
halAddress of an initialized sensor hardware descriptor.
Returns
bool true if the sensor is ready for use, else false.

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 bool itg3200_device_id ( sensor_hal_t hal,
sensor_data_t data 
)
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.

Parameters
sensorAddress of an initialized sensor device descriptor.
dataAddress of sensor_data_t structure to return values.
Returns
bool true if the call succeeds, else false is returned.

References sensor_data_t::device, ITG3200_WHOAMI, and sensor_bus_get.

Referenced by itg3200_read().

static bool itg3200_event ( sensor_t sensor,
sensor_event_t  sensor_event,
sensor_event_callback_t callback,
bool  enable 
)
static

Enable/disable ITG3200 sensor event.

Parameters
sensorAddress of an initialized sensor device descriptor
callbackApplication-defined event callback handler descriptor
enableEnable flag: true = enable event, false = disable event
Returns
bool true if the call succeeds, else false is returned

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 bool itg3200_get_rotation ( sensor_hal_t hal,
sensor_data_t data 
)
static

Read gyroscope angular rate axis data.

This function reads angular rate data for all 3 axes of an ITG-3200 gyroscope.

Parameters
sensorAddress of an initialized sensor device descriptor.
dataThe address of a vector storing sensor axis data.
Returns
bool true if the call succeeds, else false is returned.

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 bool itg3200_get_temperature ( sensor_hal_t hal,
sensor_data_t data 
)
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).

Parameters
sensorAddress of an initialized sensor device descriptor.
dataThe address where temperature samples are returned.
Returns
bool true if the call succeeds, else false is 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().

bool itg3200_init ( sensor_t sensor,
int  resvd 
)

InvenSense ITG-3200 gyroscope driver initialization.

This is the main initialization function for the ITG-3200 device.

Parameters
sensorAddress of a sensor device descriptor.
resvdReserved value.
Returns
bool true if the sensor is ready for use, else false.

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 bool itg3200_ioctl ( sensor_t sensor,
sensor_command_t  cmd,
void *  arg 
)
static

ITG3200 ioctl control entry point.

This function provides a general-purpose interface for performing various control operations on the sensor device.

Parameters
sensorAddress of an initialized sensor device descriptor.
cmdCommand to execute
argArgument for command (varies)
Returns
bool true if the call succeeds, else false is returned.

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 void itg3200_isr ( volatile void *  arg)
static
static bool itg3200_read ( sensor_t sensor,
sensor_read_t  type,
sensor_data_t data 
)
static

Read sensor data.

This routine calls the appropriate internal data function to obtain the specified type of data from the sensor device.

Parameters
sensorAddress of an initialized sensor device descriptor.
typeType of sensor data to read.
dataThe address where data values are returned.
Returns
bool true if the call succeeds, else false is 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 bool itg3200_set_bandwidth ( sensor_hal_t hal,
int16_t  band 
)
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:

* F_sample = F_internal / (divider + 1)
*

Valid filter bandwidths and the associated internal sample rate are as follows:

* Low Pass Filter Bandwidth Internal Sample Rate
* ____________________________________________________
* 256Hz 8kHz
* 188Hz 1kHz
* 98Hz 1kHz
* 42Hz 1kHz
* 20Hz 1kHz
* 10Hz 1kHz
* 5Hz 1kHz
*
Parameters
halAddress of an initialized sensor device descriptor.
bandThe index of a driver-specific bandwidth table entry.
Returns
bool true if the call succeeds, else false is returned.

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 bool itg3200_set_sample_rate ( sensor_hal_t hal,
int16_t  rate 
)
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:

* F_sample = F_internal / (divider + 1)
*

The internal sampling rate is 1KHz for all filter bandwidths except 256Hz, which uses an 8KHz internal rate.

Parameters
halAddress of an initialized sensor device descriptor.
rateThe externally visible sampling rate to be set
Returns
bool true if the call succeeds, else false is returned.

References sensor_hal::bandwidth, ITG3200_SMPLRT_DIV, and sensor_bus_put.

Referenced by itg3200_ioctl(), and itg3200_set_bandwidth().

static bool itg3200_set_state ( sensor_hal_t hal,
sensor_state_t  state 
)
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.

Parameters
sensorAddress of an initialized sensor device descriptor.
stateA specified sensor operational state.
Returns
bool true if the call succeeds, else false is returned.

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().

const sensor_map_t band_table[]
static
Initial value:
= {
{{ 5}, DLPF_CFG_5HZ }, {{ 10}, DLPF_CFG_10HZ },
{{ 20}, DLPF_CFG_20HZ }, {{ 42}, DLPF_CFG_42HZ },
{{ 98}, DLPF_CFG_98HZ }, {{188}, DLPF_CFG_188HZ},
{{256}, DLPF_CFG_256HZ}
}
#define DLPF_CFG_42HZ
Definition: itg3200.h:128
#define DLPF_CFG_256HZ
Definition: itg3200.h:125
#define DLPF_CFG_188HZ
Definition: itg3200.h:126
#define DLPF_CFG_5HZ
Definition: itg3200.h:131
#define DLPF_CFG_20HZ
Definition: itg3200.h:129
#define DLPF_CFG_98HZ
Definition: itg3200.h:127
#define DLPF_CFG_10HZ
Definition: itg3200.h:130

InvenSense ITG-3200 low-pass Bandwidth Table (hertz, register value)

Referenced by itg3200_init().

sensor_event_callback_t event_cb = {.handler = default_event_handler}
static

Sensor Event Callback Descriptor.