Atmel Software Framework

imu3000.c File Reference

InvenSense IMU-3000 digital triaxial gyroscope.

This module implements a driver for the InvenSense IMU-3000 digital 3-axis MEMS gyroscope and digital motion processor (IMU). The IMU-3000 provides digital-output x-, y-, and z-axis angular rate sensor readings with a sensitivity of 16 LSBs per deg/sec and programmable full-scale ranges of +/-250, +/-500, +/-1000, and +/-2000 deg/sec. The device includes a dedicated I2C master accelerometer sensor bus facilitating direct data acquisition from an off-chip third party accelerometer without intervention from an external processor. A configurable 512 Byte FIFO allows system microcontrollers to burst read the sensor data and then sleep while the IMU collects more data.

Copyright (c) 2012 Atmel Corporation. All rights reserved.

#include "imu3000.h"

Data Structures

struct  imu3000_event_t
 

Macros

#define IMU3000_RESOLUTION   (16)
 Axis data sample resolution (bits) More...
 

Functions

static bool imu3000_default_init (sensor_hal_t *hal, sensor_hal_t *aux)
 InvenSense IMU-3000 gyroscope driver defaults. More...
 
static bool imu3000_device_id (sensor_hal_t *hal, sensor_data_t *data)
 Read gyroscope device ID. More...
 
static bool imu3000_event (sensor_t *sensor, sensor_event_t sensor_event, sensor_event_callback_t *callback, bool enable)
 Enable/disable IMU3000 sensor event. More...
 
static bool imu3000_get_rotation (sensor_hal_t *hal, sensor_data_t *data)
 Read gyroscope angular rate axis data. More...
 
static bool imu3000_get_temperature (sensor_hal_t *hal, sensor_data_t *data)
 Read gyroscope integrated temperature sensor data. More...
 
bool imu3000_init (sensor_t *sensor, int resvd)
 InvenSense IMU-3000 motion processor driver initialization. More...
 
static bool imu3000_ioctl (sensor_t *sensor, sensor_command_t cmd, void *arg)
 IMU3000 ioctl control entry point. More...
 
static void imu3000_isr (volatile void *arg)
 Invensense IMU3000 driver interrupt service routine. More...
 
static bool imu3000_read (sensor_t *sensor, sensor_read_t type, sensor_data_t *data)
 Read sensor data. More...
 
static bool imu3000_set_bandwidth (sensor_hal_t *hal, int16_t band)
 Set the IMU-3000 low-pass filter bandwidth. More...
 
static bool imu3000_set_range (sensor_hal_t *hal, int16_t range)
 Set the IMU-3000 full scale range. More...
 
static bool imu3000_set_sample_rate (sensor_hal_t *hal, int16_t rate)
 Set the IMU3000 sample rate. More...
 
static bool imu3000_set_state (sensor_hal_t *hal, sensor_state_t state)
 Set the IMU-3000 execution mode. More...
 

Variables

static const sensor_map_t band_table []
 InvenSense IMU-3000 low-pass Bandwidth Table (hertz, register value) More...
 
static sensor_event_callback_t event_cb = {.handler = default_event_handler}
 Sensor Event Callback Descriptor. More...
 
static const sensor_map_t range_table []
 InvenSense IMU-3000 Range Table (deg/sec, register value) More...
 
int16_t const scale_lsb_per_dps []
 Sensitivity Scale Factors. More...
 
static int sensor_dlpf_cfg = 3
 The digital low-pass filter table index defaults to 42 Hz. More...
 
static int sensor_fs_sel = 3
 The range table index defaults to 2000 deg/sec full-scale. More...
 

#define IMU3000_RESOLUTION   (16)

Axis data sample resolution (bits)

static bool imu3000_default_init ( sensor_hal_t hal,
sensor_hal_t aux 
)
static

InvenSense IMU-3000 gyroscope driver defaults.

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

Returns
bool true if the sensor is ready for use, else false.

References bus_desc_t::addr, AUX_ADDR_CLKOUTEN, sensor_hal::burst_addr, sensor_hal::bus, IMU3000_AUX_BURST_ADDR, IMU3000_AUX_SLV_ADDR, IMU3000_DLPF_FS, IMU3000_ID_VAL, IMU3000_PWR_MGM, IMU3000_SMPLRT_DIV, IMU3000_USER_CTRL, IMU3000_WHO_AM_I, IMU3000_X_OFFS_USRH, PWR_MGM_CLK_SEL_Z, PWR_MGM_H_RESET, sensor_map_t::reserved_val, sensor_bus_get, sensor_bus_put, sensor_bus_write, sensor_dlpf_cfg, sensor_fs_sel, bus_desc_t::status, status, STATUS_OK, USER_CTRL_AUX_IF_EN, and USER_CTRL_AUX_IF_RST.

Referenced by imu3000_set_state().

static bool imu3000_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, IMU3000_WHO_AM_I, and sensor_bus_get.

Referenced by imu3000_read().

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

Enable/disable IMU3000 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 callback, sensor_desc::hal, IMU3000_INT_CFG, INT_CFG_ANYRD_2CLEAR, INT_CFG_LATCH_INT_EN, INT_CFG_RAW_RDY_EN, sensor_bus_put, SENSOR_EVENT_NEW_DATA, sensor_reg_bitclear, and status.

Referenced by imu3000_init(), and imu3000_ioctl().

static bool imu3000_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 IMU-3000 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, count, IMU3000_GYRO_XOUT_H, input, sensor_hal::orientation, scale_lsb_per_dps, sensor_data_t::scaled, sensor_bus_read, sensor_fs_sel, sensor_axis_vec_t::sign, sensor_orient_t::x, sensor_orient_t::y, and sensor_orient_t::z.

Referenced by imu3000_ioctl(), and imu3000_read().

static bool imu3000_get_temperature ( sensor_hal_t hal,
sensor_data_t data 
)
static

Read gyroscope integrated temperature sensor data.

This function reads IMU-3000 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, count, IMU3000_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 imu3000_read().

bool imu3000_init ( sensor_t sensor,
int  resvd 
)

InvenSense IMU-3000 motion processor driver initialization.

This is the main initialization function for the IMU-3000 device.

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

References ARRAYSIZE, sensor_desc::aux, sensor_device_t::func, sensor_desc::hal, imu3000_event(), imu3000_ioctl(), imu3000_read(), sensor_funcs_t::read, SENSOR_CAPS_3_AXIS, SENSOR_CAPS_AUX_ACCEL, SENSOR_CAPS_AUX_TEMP, SENSOR_UNITS_deg_per_sec, SENSOR_VENDOR_INVENSENSE, and status.

static bool imu3000_ioctl ( sensor_t sensor,
sensor_command_t  cmd,
void *  arg 
)
static

IMU3000 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, imu3000_event(), imu3000_get_rotation(), imu3000_set_bandwidth(), imu3000_set_range(), imu3000_set_sample_rate(), imu3000_set_state(), sensor_data_t::scaled, SENSOR_DISABLE_EVENT, SENSOR_ENABLE_EVENT, SENSOR_ERR_UNSUPPORTED, SENSOR_READ_VECTOR, SENSOR_SET_BANDWIDTH, SENSOR_SET_RANGE, SENSOR_SET_SAMPLE_RATE, SENSOR_SET_STATE, vector3_t::x, vector3_t::y, and vector3_t::z.

Referenced by imu3000_init().

static void imu3000_isr ( volatile void *  arg)
static
static bool imu3000_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, imu3000_device_id(), imu3000_get_rotation(), imu3000_get_temperature(), SENSOR_ERR_FUNCTION, SENSOR_READ_ID, SENSOR_READ_ROTATION, and SENSOR_READ_TEMPERATURE.

Referenced by imu3000_init().

static bool imu3000_set_bandwidth ( sensor_hal_t hal,
int16_t  band 
)
static

Set the IMU-3000 low-pass filter bandwidth.

This routine sets the IMU-3000 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 DLPF_CFG_FIELD, IMU3000_DLPF_FS, sensor_bus_get, sensor_bus_put, and sensor_dlpf_cfg.

Referenced by imu3000_ioctl().

static bool imu3000_set_range ( sensor_hal_t hal,
int16_t  range 
)
static

Set the IMU-3000 full scale range.

This routine sets the IMU-3000 full scale range using an index to a table of valid ranges: +/-250, +/-500, +/-1000, and +/-2000 deg/sec.

Parameters
halAddress of an initialized sensor device descriptor.
rangeThe index o a driver-specific range table entry.
Returns
bool true if the call succeeds, else false is returned.

References FS_SEL_FIELD, IMU3000_DLPF_FS, sensor_bus_get, sensor_bus_put, and sensor_fs_sel.

Referenced by imu3000_ioctl().

static bool imu3000_set_sample_rate ( sensor_hal_t hal,
int16_t  rate 
)
static

Set the IMU3000 sample rate.

This routine sets the externally visible IMU3000 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, IMU3000_SMPLRT_DIV, and sensor_bus_put.

Referenced by imu3000_ioctl().

static bool imu3000_set_state ( sensor_hal_t hal,
sensor_state_t  state 
)
static

Set the IMU-3000 execution mode.

This routine sets a specified IMU-3000 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.
Todo:

Update sensor device descriptor operational settings.

References delay_ms, imu3000_default_init(), IMU3000_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 imu3000_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:135
#define DLPF_CFG_256HZ
Definition: itg3200.h:132
#define DLPF_CFG_188HZ
Definition: itg3200.h:133
#define DLPF_CFG_5HZ
Definition: itg3200.h:138
#define DLPF_CFG_20HZ
Definition: itg3200.h:136
#define DLPF_CFG_98HZ
Definition: itg3200.h:134
#define DLPF_CFG_10HZ
Definition: itg3200.h:137

InvenSense IMU-3000 low-pass Bandwidth Table (hertz, register value)

sensor_event_callback_t event_cb = {.handler = default_event_handler}
static

Sensor Event Callback Descriptor.

const sensor_map_t range_table[]
static
Initial value:
= {
{{ 250}, FS_SEL_250 }, {{ 500}, FS_SEL_500 },
{{1000}, FS_SEL_1000}, {{2000}, FS_SEL_2000}
}
#define FS_SEL_1000
Definition: imu3000.h:184
#define FS_SEL_2000
Definition: itg3200.h:140
#define FS_SEL_500
Definition: imu3000.h:183
#define FS_SEL_250
Definition: imu3000.h:182

InvenSense IMU-3000 Range Table (deg/sec, register value)

int16_t const scale_lsb_per_dps[]
Initial value:
= {
(131 / 1),
(655 / 10),
(328 / 10),
(164 / 10)
}

Sensitivity Scale Factors.

Referenced by imu3000_get_rotation(), and imu3000_isr().

int sensor_dlpf_cfg = 3
static

The digital low-pass filter table index defaults to 42 Hz.

Referenced by imu3000_default_init(), and imu3000_set_bandwidth().

int sensor_fs_sel = 3
static

The range table index defaults to 2000 deg/sec full-scale.

Referenced by imu3000_default_init(), imu3000_get_rotation(), imu3000_isr(), and imu3000_set_range().