minor changes and typos

This commit is contained in:
Gunar Schorcht 2017-12-30 17:35:56 +01:00
parent 2ae145dcc0
commit 561c700531
5 changed files with 519 additions and 428 deletions

View file

@ -153,7 +153,7 @@ The high pass filter can independently apply to
- the raw output data,
- the data used for click detection, and
- the data used for interrupt generation like wake-up, free fall or 6D/4D orientation detection.
- the data used for inertial interrupt generation like wake-up, free fall or 6D/4D orientation detection.
The mode and the cutoff frequency of the high pass filter can be configured using function ```lis3dh_config_hpf```. Following HPF modes are available:
@ -241,26 +241,26 @@ void user_task_periodic (void *pvParameters)
The LIS3DH supports two dedicated interrupt signals **```INT1```** and **```INT2```** and three different types of interrupts:
- data ready and FIFO status interrupts,
- activity detection interrupts like wake-up, free fall, and 6D/4D orientation detection, and
- data interrupts (data ready and FIFO status),
- inertial event interrupts (axis movement, wake-up, free fall, and 6D/4D orientation detection), and
- click detection interrupts.
While activity detection and click detection interrupts can be configured for both interrupt signals, data ready and FIFO status interrupts can be configured only for interrupt signal ```INT1```.
While inertial event interrupts and click detection interrupts can be configured for both interrupt signals, data ready and FIFO status interrupts can be configured only for interrupt signal ```INT1```.
#### Data ready and FIFO status interrupts
#### Data interrupts (data ready and FIFO status)
Following sources can generate an interrupt on signal ```INT1```:
Interrupt source | Driver symbol
:-----------------|:-------------
Output data become ready to read | lis3dh_data_ready
FIFO content exceeds the watermark level | lis3dh_fifo_watermark
FIFO is completely filled | lis3dh_fifo_overrun
Output data become ready to read | lis3dh_int_data_ready
FIFO content exceeds the watermark level | lis3dh_int_fifo_watermark
FIFO is completely filled | lis3dh_int_fifo_overrun
Each of these interrupt sources can be enabled or disabled separately with function ```lis3dh_enable_int_data```. By default all interrupt sources are disabled.
Each of these interrupt sources can be enabled or disabled separately with function ```lis3dh_enable_int```. By default all interrupt sources are disabled.
```
lis3dh_enable_int_data (sensor, lis3dh_data_ready, true);
lis3dh_enable_int (sensor, lis3dh_int_data_ready, lis3dh_int1_signal, true);
```
Whenever an interrupt is generated at interrupt signal ```INT1```, the function ```lis3dh_get_int_data_source``` can be used to determine the source of the interrupt. This function returns a data structure of type ```lis3dh_int_data_source_t``` that contain a boolean member for each source that can be tested for true.
@ -270,114 +270,118 @@ void int1_handler ()
{
lis3dh_int_data_source_t data_src;
// get interrupt source of INT1
// get the interrupt source of INT1
lis3dh_get_int_data_source (sensor, &data_src);
// if data ready interrupt, get the results and do something with them
// in case of data ready interrupt, get the results and do something with them
if (data_src.data_ready)
// ... read data
// in case of FIFO interrupts read the whole FIFO
else if (data_src.fifo_watermark || data_src.fifo_overrun)
// read FIFO data
// ... read FIFO data
...
}
```
#### Activity detection interrupts
#### Inertial event interrupts
Activity detection allows to generate interrupts whenever a configured condition occur. If activated, the acceleration of each axis is compared with a defined threshold to check whether it is below or above the threshold. The results of all activated comparisons are then combined OR or AND to generate the interrupt signal.
Inertial interrupt generators allow to generate interrupts when certain inertial event occures (event interrupts), that is, the acceleration of defined axes is higher or lower than a defined threshold. If activated, the acceleration of each axis is compared with a defined threshold to check whether it is below or above the threshold. The results of all activated comparisons are then combined OR or AND to generate the interrupt signal.
The configuration of the threshold valid for all axes, the activated comparisons and the selected AND/OR combination allows to recognize special situations:
- **Wake-up detection** refers the special condition that the acceleration measured along any axis is above the defined threshold (```lis3dh_wake_up```).
- **Free fall detection** refers the special condition that the acceleration measured along all the axes goes to zero (```lis3dh_free_fall```).
- **6D/4D Orientation Detection** refers to the special condition that the measured acceleration along certain axes is above and along the other axes is below the threshold which indicates a particular orientation (```lis3dh_6d_movement```, ```lis3dh_6d_position```, ```lis3dh_4d_movement```, ```lis3dh_4d_position```).
- **6D/4D orientation detection** refers to the special condition that the measured acceleration along certain axes is above and along the other axes is below the threshold which indicates a particular orientation (```lis3dh_6d_movement```, ```lis3dh_6d_position```, ```lis3dh_4d_movement```, ```lis3dh_4d_position```).
Activity detection interrupts can be configured with the function ```lis3dh_get_int_activity_config```. This function requires as parameters the configuration of type ```lis3dh_int_activity_config_t``` and the interrupt signal to be used for activity detection interrupts.
Inertial event interrupts can be configured with the function ```lis3dh_get_int_event_config```. This function requires as parameters the configuration of type ```lis3dh_int_event_config_t``` and the interrupt generator to be used for inertial event interrupts.
Inertial event interrupts have to be enabled or disabled using function ```lis3dh_enable_int```. The interrupt signal on which the interrupts are generated is given as parameter.
For example, wake-up detection interrupt on signal ```INT1``` could be configured as following:
```
lis3dh_int_activity_config_t act_config;
lis3dh_int_event_config_t event_config;
act_config.activity = lis3dh_wake_up;
act_config.threshold = 10;
act_config.x_low_enabled = false;
act_config.x_high_enabled = true;
act_config.y_low_enabled = false;
act_config.y_high_enabled = true;
act_config.z_low_enabled = false;
act_config.z_high_enabled = true;
event_config.mode = lis3dh_wake_up;
event_config.threshold = 10;
event_config.x_low_enabled = false;
event_config.x_high_enabled = true;
event_config.y_low_enabled = false;
event_config.y_high_enabled = true;
event_config.z_low_enabled = false;
event_config.z_high_enabled = true;
act_config.duration = 0;
act_config.latch = true;
event_config.duration = 0;
event_config.latch = true;
lis3dh_set_int_activity_config (sensor, lis3dh_int1_signal, &act_config);
```
lis3dh_set_int_event_config (sensor, &event_config, lis3dh_int_event1_gen);
lis3dh_enable_int (sensor, lis3dh_int_event1, lis3dh_int1_signal, true);
```
The parameter of type ```lis3dh_int_activity_config_t``` also configures
The parameter of type ```lis3dh_int_event_config_t``` also configures
- whether the interrupt signal should latched until the interrupt source is read, and
- which time in 1/ODR an interrupt condition has to be given before the interrupt is generated.
- whether the interrupt should be latched until the interrupt source is read, and
- which time given in 1/ODR an interrupt condition has to be given before the interrupt is generated.
As with data ready and FIFO status interrupts, function ```lis3dh_get_int_activity_source``` can be used to determine the source of an activity interrupt whenever it is generated. This function returns a data structure of type ```lis3dh_int_activity_source_t``` which contains a boolean member for each source that can be tested for true.
As with data ready and FIFO status interrupts, function ```lis3dh_get_int_event_source``` can be used to determine the source of an inertial event interrupt whenever it is generated. This function returns a data structure of type ```lis3dh_int_event_source_t``` which contains a boolean member for each source that can be tested for true.
```
void int1_handler ()
{
lis3dh_int_data_source_t data_src;
lis3dh_int_activity_source_t activity_src;
lis3dh_int_data_source_t data_src;
lis3dh_int_event_source_t event_src;
// get interrupt source of INT1
lis3dh_get_int_data_source (sensor, &data_src);
lis3dh_get_int_activity_source (sensor, &activity_src, lis3dh_int1_signal);
// get the interrupt source of INT1
lis3dh_get_int_data_source (sensor, &data_src);
lis3dh_get_int_event_source (sensor, &event_src, lis3dh_int_event1_gen);
// if data ready interrupt, get the results and do something with them
// in case of data ready interrupt, get the results and do something with them
if (data_src.data_ready)
// ... read data
// in case of FIFO interrupts read the whole FIFO
else if (data_src.fifo_watermark || data_src.fifo_overrun)
// read FIFO data
// ... read FIFO data
// in case of activity interrupt
else if (activity_src.active)
// in case of inertial event interrupt
else if (event_src.active)
// ... read data
...
}
```
**Please note** Activating all threshold comparisons and the OR combination (```lis3dh_wake_up```) is the most flexible way to deal with activity interrupts. Functions such as free fall detection and so on can then be realized by suitably combining the various interrupt sources by the user task. Following example realizes the free fall detection in user task.
**Please note** Activating all threshold comparisons and the OR combination (```lis3dh_wake_up```) is the most flexible way to deal with inertial event interrupts. Functions such as free fall detection and so on can then be realized by suitably combining the various interrupt sources by the user task. Following example realizes the free fall detection in user task.
```
lis3dh_int_activity_config_t act_config;
lis3dh_int_event_config_t event_config;
act_config.activity = lis3dh_wake_up;
act_config.threshold = 10;
act_config.x_low_enabled = true;
act_config.x_high_enabled = true;
act_config.y_low_enabled = true;
act_config.y_high_enabled = true;
act_config.z_low_enabled = true;
act_config.z_high_enabled = true;
event_config.mode = lis3dh_wake_up;
event_config.threshold = 10;
event_config.x_low_enabled = true;
event_config.x_high_enabled = true;
event_config.y_low_enabled = true;
event_config.y_high_enabled = true;
event_config.z_low_enabled = true;
event_config.z_high_enabled = true;
act_config.duration = 0;
act_config.latch = true;
event_config.duration = 0;
event_config.latch = true;
lis3dh_set_int_activity_config (sensor, lis3dh_int1_signal, &act_config);
lis3dh_set_int_event_config (sensor, &event_config, lis3dh_int_event1_gen);
lis3dh_enable_int (sensor, lis3dh_int_event1, lis3dh_int1_signal, true);
```
```
void int1_handler ()
{
lis3dh_int_activity_source_t activity_src;
lis3dh_int_event_source_t event_src;
// get interrupt source of INT1
lis3dh_get_int_activity_source (sensor, &activity_src, lis3dh_int1_signal);
// get the interrupt source of INT1
lis3dh_get_int_event_source (sensor, &event_src, lis3dh_int1_signal);
// detect free fall (all accelerations are below the threshold)
if (activity_src.x_low && activity_src.y_low && activity_src.z_low)
if (event_src.x_low && event_src.y_low && event_src.z_low)
...
...
}
@ -390,6 +394,8 @@ A sequence of acceleration values over time measured along certain axes can be u
Click detection interrupts are configured with function ```lis3dh_set_int_click_config```. This function requires as parameters the configuration of type ```lis3dh_int_click_config_t``` and the interrupt signal to be used for click detection interrupts.
Inertial event interrupts have to be enabled or disabled using function ```lis3dh_enable_int```. The interrupt signal on which the interrupts are generated is given as parameter.
In following example, the single click detection for z-axis is enabled with a time limit of 1/ODR, a time latency of 1/ODR and a time window of 3/ODR.
```
@ -407,7 +413,8 @@ click_config.time_limit = 1;
click_config.time_latency = 1;
click_config.time_window = 3;
lis3dh_set_int_click_config (sensor, lis3dh_int1_signal, &click_config);
lis3dh_set_int_click_config (sensor, &click_config);
lis3dh_enable_int (sensor, lis3dh_int_click, lis3dh_int1_signal, true);
```
As with other interrupts, the function ```lis3dh_get_int_click_source``` can be used to determine the source of the interrupt signal whenever it is generated. This function returns a data structure of type ```lis3dh_int_click_source_t``` that contains a boolean member for each source that can be tested for true.
@ -417,7 +424,7 @@ void int1_handler ()
{
lis3dh_int_click_source_t click_src;
// get interrupt source of INT1
// get the interrupt source of INT1
lis3dh_get_int_click_source (sensor, &click_src);
// detect single click along z-axis
@ -690,15 +697,13 @@ lis3dh_set_mode (sensor, lis3dh_odr_10, lis3dh_high_res, true, true, true);
## Full Example
```
/* -- use following constants to define the example mode ----------- */
// #define SPI_USED // if defined SPI is used, otherwise I2C
#define DATA_INT // data ready and FIFO status interrupts
// #define CLICK_INT // click detection interrupt
// #define ACTIVITY_INT // wake-up, free fall or 6D/4D orientation detection
// #define SPI_USED // SPI interface is used, otherwise I2C
// #define FIFO_MODE // multiple sample read mode
// #define INT_DATA // data interrupts used (data ready and FIFO status)
// #define INT_EVENT // inertial event interrupts used (wake-up, free fall or 6D/4D orientation)
// #define INT_CLICK // click detection interrupts used
#if defined(DATA_INT) || defined(ACTIVITY_INT) || defined(CLICK_INT)
#if defined(INT_DATA) || defined(INT_EVENT) || defined(INT_CLICK)
#define INT_USED
#endif
@ -744,7 +749,7 @@ lis3dh_set_mode (sensor, lis3dh_odr_10, lis3dh_high_res, true, true, true);
#define INT1_PIN 5
#define INT2_PIN 4
/* -- user tasks ---------------------------------------------- */
/* -- user tasks --------------------------------------------------- */
static lis3dh_sensor_t* sensor;
@ -802,29 +807,46 @@ static QueueHandle_t gpio_evt_queue = NULL;
void user_task_interrupt (void *pvParameters)
{
uint32_t gpio_num;
uint8_t gpio_num;
while (1)
{
if (xQueueReceive(gpio_evt_queue, &gpio_num, portMAX_DELAY))
{
lis3dh_int_activity_source_t activity_src;
lis3dh_int_data_source_t data_src;
lis3dh_int_click_source_t click_src;
lis3dh_int_data_source_t data_src = {};
lis3dh_int_event_source_t event_src = {};
lis3dh_int_click_source_t click_src = {};
// get the source of the interrupt and reset INT signals
lis3dh_get_int_activity_source (sensor, &activity_src, lis3dh_int1_signal);
lis3dh_get_int_data_source (sensor, &data_src);
lis3dh_get_int_click_source (sensor, &click_src);
// get the source of the interrupt and reset *INTx* signals
#ifdef INT_DATA
lis3dh_get_int_data_source (sensor, &data_src);
#elif INT_EVENT
lis3dh_get_int_event_source (sensor, &event_src, lis3dh_int_event1_gen);
#elif INT_CLICK
lis3dh_get_int_click_source (sensor, &click_src);
#endif
// in case of DRDY interrupt or activity interrupt read one data sample
if (data_src.data_ready || activity_src.active)
// in case of DRDY interrupt or inertial event interrupt read one data sample
if (data_src.data_ready)
read_data ();
// in case of FIFO interrupts read the whole FIFO
else if (data_src.fifo_watermark || data_src.fifo_overrun)
read_data ();
// in case of event interrupt
else if (event_src.active)
{
printf("%.3f LIS3DH ", (double)sdk_system_get_time()*1e-3);
if (event_src.x_low) printf("x is lower than threshold\n");
if (event_src.y_low) printf("y is lower than threshold\n");
if (event_src.z_low) printf("z is lower than threshold\n");
if (event_src.x_high) printf("x is higher than threshold\n");
if (event_src.y_high) printf("y is higher than threshold\n");
if (event_src.z_high) printf("z is higher than threshold\n");
}
// in case of click detection interrupt
else if (click_src.active)
printf("%.3f LIS3DH %s\n", (double)sdk_system_get_time()*1e-3,
click_src.s_click ? "single click" : "double click");
@ -862,7 +884,7 @@ void user_task_periodic(void *pvParameters)
#endif // INT_USED
/* -- main program ---------------------------------------------- */
/* -- main program ------------------------------------------------- */
void user_init(void)
{
@ -922,41 +944,42 @@ void user_init(void)
// set polarity of INT signals if necessary
// lis3dh_config_int_signals (sensor, lis3dh_high_active);
#ifdef DATA_INT
#ifdef INT_DATA
// enable data interrupts on INT1 (data ready or FIFO status interrupts)
// data ready and FIFO status interrupts must not be enabled at the same time
#ifdef FIFO_MODE
lis3dh_enable_int_data (sensor, lis3dh_fifo_overrun, true);
lis3dh_enable_int_data (sensor, lis3dh_fifo_watermark, true);
lis3dh_enable_int (sensor, lis3dh_int_fifo_overrun , lis3dh_int1_signal, true);
lis3dh_enable_int (sensor, lis3dh_int_fifo_watermark, lis3dh_int1_signal, true);
#else
lis3dh_enable_int_data (sensor, lis3dh_data_ready, true);
lis3dh_enable_int (sensor, lis3dh_int_data_ready, lis3dh_int1_signal, true);
#endif // FIFO_MODE
#endif // DATA_INT
#endif // INT_DATA
#ifdef ACTIVITY_INT
#ifdef INT_EVENT
// enable data interrupts on INT1
lis3dh_int_activity_config_t act_config;
lis3dh_int_event_config_t event_config;
act_config.activity = lis3dh_wake_up;
// act_config.activity = lis3dh_free_fall;
// act_config.activity = lis3dh_6d_movement;
// act_config.activity = lis3dh_6d_position;
// act_config.activity = lis3dh_4d_movement;
// act_config.activity = lis3dh_4d_position;
act_config.threshold = 10;
act_config.x_low_enabled = false;
act_config.x_high_enabled = true;
act_config.y_low_enabled = false;
act_config.y_high_enabled = true;
act_config.z_low_enabled = false;
act_config.z_high_enabled = true;
act_config.duration = 0;
act_config.latch = true;
event_config.mode = lis3dh_wake_up;
// event_config.mode = lis3dh_free_fall;
// event_config.mode = lis3dh_6d_movement;
// event_config.mode = lis3dh_6d_position;
// event_config.mode = lis3dh_4d_movement;
// event_config.mode = lis3dh_4d_position;
event_config.threshold = 10;
event_config.x_low_enabled = false;
event_config.x_high_enabled = true;
event_config.y_low_enabled = false;
event_config.y_high_enabled = true;
event_config.z_low_enabled = false;
event_config.z_high_enabled = true;
event_config.duration = 0;
event_config.latch = true;
lis3dh_set_int_activity_config (sensor, lis3dh_int1_signal, &act_config);
#endif // ACTIVITY_INT
lis3dh_set_int_event_config (sensor, &event_config, lis3dh_int_event1_gen);
lis3dh_enable_int (sensor, lis3dh_int_event1, lis3dh_int1_signal, true);
#endif // INT_EVENT
#ifdef CLICK_INT
#ifdef INT_CLICK
// enable click interrupt on INT1
lis3dh_int_click_config_t click_config;
@ -972,8 +995,9 @@ void user_init(void)
click_config.time_latency = 1;
click_config.time_window = 3;
lis3dh_set_int_click_config (sensor, lis3dh_int1_signal, &click_config);
#endif // CLICK_INT
lis3dh_set_int_click_config (sensor, &click_config);
lis3dh_enable_int (sensor, lis3dh_int_click, lis3dh_int1_signal, true);
#endif // INT_CLICK
#ifdef FIFO_MODE
// clear FIFO and activate FIFO mode if needed