Contiki-Inga 3.x
acc-sensor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, TU Braunschweig.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 /**
31  * \file
32  * Accelerometer sensor definition
33  * \author
34  * Ulf Kulau <kulau@ibr.cs.tu-bs.de>
35  * Enrico Jörns <joerns@ibr.cs.tu-bs.de>
36  */
37 
38 /**
39  * \addtogroup inga_sensors
40  * @{
41  */
42 
43 /**
44  * \defgroup inga_acc_driver Accelerometer Sensor
45  *
46  * This sensor interface allows to control the accelerometer of the INGA sensor platform.
47  *
48  * @note This interface provides only a subset of the full sensor features.
49  * If you require extended configuration, consider using the underlying sensor driver.
50  *
51  *
52  * \section act_acc Activate Sensor
53  *
54  * Default initialization settings:
55  * - <b>bypass mode</b>, i.e. a read command will always return the latest sampled data
56  * - 100Hz sample rate
57  *
58  *
59  * \section cfg_sensor Configure sensor
60  * <code> acc_sensor.configure(type, value) </code>
61  *
62  * The sensor interface allows to configure:
63  * - Sensitivity (\ref ACC_CONF_SENSITIVITY)
64  * - Data rate (\ref ACC_CONF_DATA_RATE)
65  *
66  * Details of the different configurations are given in
67  * the documentation of respective config.
68  *
69  *
70  * \section query_measure Query measurements
71  * <code>acc_sensor.value(channel)</code>
72  *
73  * The sensor provides 6 data channels.
74  * - 3 provide mg values
75  * - 3 provide unprocessed raw values
76  * A detailed list can be found at \ref acc_sensor_channels "Channels"
77  *
78  * @note Measurement values are updated only if one channel
79  * is read twice. I.e. reading x,y, and z channel
80  * will provide values from a single measurement.
81  * If then one of these channels is read again, a new
82  * measurement is initated.
83  *
84  *
85  * \section usage Example Usage
86  *
87 \code
88 #include <sensors.h>
89 [...]
90 struct sensors_sensor accsensor = find_sensor("ACC");
91 ACTIVATE_SENSOR(accsensor);
92 accsensor.configure(GYRO_CONF_SENSITIVITY, ACC_25HZ);
93 [...]
94 int x = accsensor.value(ACC_X);
95 int y = accsensor.value(ACC_Y);
96 int z = accsensor.value(ACC_Z);
97 \endcode
98  *
99  * @{ */
100 
101 #ifndef __ADXL345_SENSOR_H__
102 #define __ADXL345_SENSOR_H__
103 
104 #include "lib/sensors.h"
105 
106 extern const struct sensors_sensor acc_sensor;
107 
108 #define ACC_SENSOR "Acc"
109 
110 /**
111  * \name Data Output Channels
112  * \anchor acc_sensor_channels
113  *
114  * @{ */
115 /** x axis data (mg output) */
116 #define ACC_X 0
117 /** y axis data (mg output) */
118 #define ACC_Y 1
119 /** z axis data (mg output) */
120 #define ACC_Z 2
121 /** x axis data (raw output) */
122 #define ACC_X_RAW 3
123 /** y axis data (raw output) */
124 #define ACC_Y_RAW 4
125 /** z axis data (raw output) */
126 #define ACC_Z_RAW 5
127 /** @} */
128 
129 /**
130  * \name Configuration types
131  * @{ */
132 /**
133  * Sensitivity configuration
134  * The sensor can operate at different ranges at different sensitivity levels (+/-2g,+/-4g,+/-8g,+/-16g)
135  * Possible values can be found in \ref sens_val "SENSITIVITY Values"
136  */
137 #define ACC_CONF_SENSITIVITY 10
138 /**
139  * FIFO mode configuration
140  *
141  * - \ref ACC_MODE_BYPASS - Bypass mode
142  * - \ref ACC_MODE_FIFO - FIFO mode
143  * - \ref ACC_MODE_STREAM - Stream mode
144  */
145 #define ACC_CONF_FIFOMODE 20
146 /**
147  * Controls power / sleep mode
148  *
149  * - \ref ACC_NOSLEEP - No sleep
150  * - \ref ACC_AUTOSLEEP - Autosleep
151  */
152 #define ACC_CONF_POWERMODE 30
153 /**
154  * Output data rate.
155  *
156  * Values should be one of those described in
157  * \ref acc_sensor_odr_values "Output Data Rate Values".
158  *
159  * \note If another value is given, the value is rounded to the next upper valid value.
160  *
161  * \note In bypass mode (default) you should always select twice the rate of your
162  * desired readout frequency
163  *
164  */
165 #define ACC_CONF_DATA_RATE 40
166 /** @} */
167 
168 /**
169  * \name Status types
170  * @{ */
171 /**
172  * Fill level of the sensor buffer (If working in FIFO or Streaming mode).
173  * Max value: 33 (full)
174  *
175  * This can be used to determine whether a buffer overflow occured between
176  * two readouts or to adapt readout rate.
177  */
178 #define ACC_STATUS_BUFFER_LEVEL 50
179 /** @} */
180 
181 
182 /**
183  * \name SENSITIVITY Values
184  * \anchor sens_val
185  * \see ACC_SENSOR_SENSITIVITY
186  * @{ */
187 #define ACC_2G 2
188 #define ACC_4G 4
189 #define ACC_8G 8
190 #define ACC_16G 16
191 /** @} */
192 
193 /**
194  * \name Output Data Rate Values
195  * \anchor acc_sensor_odr_values
196  * \{
197  */
198 /// ODR: 0.1 Hz, bandwith: 0.05Hz, I_DD: 23 µA
199 #define ACC_0HZ10 1
200 /// ODR: 0.2 Hz, bandwith: 0.1Hz, I_DD: 23 µA
201 #define ACC_0HZ20 2
202 /// ODR: 0.39 Hz, bandwith: 0.2Hz, I_DD: 23 µA
203 #define ACC_0HZ39 4
204 /// ODR: 0.78 Hz, bandwith: 0.39Hz, I_DD: 23 µA
205 #define ACC_0HZ78 8
206 /// ODR: 1.56 Hz, bandwith: x.xxHz, I_DD: xx µA
207 #define ACC_1HZ56 16
208 /// ODR: 3.13 Hz, bandwith: x.xxHz, I_DD: xx µA
209 #define ACC_3HZ13 31
210 /// ODR: 6.25 Hz, bandwith: x.xxHz, I_DD: xx µA
211 #define ACC_6HZ25 63
212 /// ODR: 12.5 Hz, bandwith: x.xxHz, I_DD: xx µA
213 #define ACC_12HZ5 125
214 /// ODR: 25 Hz, bandwith: x.xxHz, I_DD: xx µA
215 #define ACC_25HZ 250
216 /// ODR: 50 Hz, bandwith: x.xxHz, I_DD: xx µA
217 #define ACC_50HZ 500
218 /// ODR: 100 Hz, bandwith: x.xxHz, I_DD: xx µA (default)
219 #define ACC_100HZ 1000
220 /// ODR: 200 Hz, bandwith: x.xxHz, I_DD: xx µA
221 #define ACC_200HZ 2000
222 /// ODR: 400 Hz, bandwith: x.xxHz, I_DD: xx µA
223 #define ACC_400HZ 4000
224 /// ODR: 800 Hz, bandwith: x.xxHz, I_DD: xx µA
225 #define ACC_800HZ 8000
226 /// ODR: 1600 Hz, bandwith: x.xxHz, I_DD: xx µA
227 #define ACC_1600HZ 16000
228 /// ODR: 3200 Hz, bandwith: x.xxHz, I_DD: xx µA
229 #define ACC_3200HZ 32000
230 /** \} */
231 
232 /**
233  * \name FIFO mode values
234  * \see ACC_SENSOR_FIFOMODE
235  * @{ */
236 /** Bypass mode (default).
237  * No buffering, data is always the latest.
238  */
239 #define ACC_MODE_BYPASS 0x0
240 /** FIFO mode.
241  * A 32 entry fifo is used to buffer unread data.
242  * If buffer is full, no data is read anymore.
243  */
244 #define ACC_MODE_FIFO 0x1
245 /** Stream mode.
246  * A 32 entry fifo is used to buffer unread data.
247  * If buffer is full old data will be dropped and replaced by new one.
248  */
249 #define ACC_MODE_STREAM 0x2
250 /** @} */
251 
252 
253 /**
254  * \name Power mode values
255  * \see ACC_SENSOR_POWERMODE
256  * @{ */
257 /** No sleep */
258 #define ACC_NOSLEEP 0
259 /** Auto sleep */
260 #define ACC_AUTOSLEEP 1
261 /** @} */
262 
263 #endif /* __ACC-SENSOR_H__ */
264 
265 /** @} */
266 /** @} */
267