root / branches / simulator / lib / include / libdragonfly / analog.h @ 943
History | View | Annotate | Download (7.91 KB)
1 |
/**
|
---|---|
2 |
* Copyright (c) 2007 Colony Project
|
3 |
*
|
4 |
* Permission is hereby granted, free of charge, to any person
|
5 |
* obtaining a copy of this software and associated documentation
|
6 |
* files (the "Software"), to deal in the Software without
|
7 |
* restriction, including without limitation the rights to use,
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
* copies of the Software, and to permit persons to whom the
|
10 |
* Software is furnished to do so, subject to the following
|
11 |
* conditions:
|
12 |
*
|
13 |
* The above copyright notice and this permission notice shall be
|
14 |
* included in all copies or substantial portions of the Software.
|
15 |
*
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23 |
* OTHER DEALINGS IN THE SOFTWARE.
|
24 |
**/
|
25 |
|
26 |
/**
|
27 |
*
|
28 |
* @file analog.h
|
29 |
* @brief Contains functions and definitions for using the ADC
|
30 |
*
|
31 |
* Contains definitions and function prototypes for using the
|
32 |
* ADC to detect analog signals on pins AN0 - AN7.
|
33 |
* AN6 and AN7 are used for the wheel and battery.
|
34 |
|
35 |
* The pins labeled E6 and E7 are external interrupt pins and are not related
|
36 |
* to analog.
|
37 |
|
38 |
* @author Colony Project, CMU Robotics Club, based on firefly
|
39 |
* code by Tom Lauwers
|
40 |
*/
|
41 |
|
42 |
#ifndef _ANALOG_H
|
43 |
#define _ANALOG_H
|
44 |
|
45 |
#include <inttypes.h> |
46 |
|
47 |
/**
|
48 |
* @defgroup analog Analog
|
49 |
* Functions for manipulation the ADC on the dragonfly board.
|
50 |
* All definitions may be found in analog.h.
|
51 |
*
|
52 |
* @{
|
53 |
**/
|
54 |
|
55 |
/** @brief Analog port 0 **/
|
56 |
#define AN0 0x00 |
57 |
/** @brief Analog port 1 **/
|
58 |
#define AN1 0x01 |
59 |
/** @brief Analog port 2 **/
|
60 |
#define AN2 0x02 |
61 |
/** @brief Analog port 3 **/
|
62 |
#define AN3 0x03 |
63 |
/** @brief Analog port 4 **/
|
64 |
#define AN4 0x04 |
65 |
/** @brief Analog port 5 **/
|
66 |
#define AN5 0x05 |
67 |
/** @brief Analog port 6 **/
|
68 |
#define AN6 0x06 |
69 |
/** @brief Analog port 7 **/
|
70 |
#define AN7 0x07 |
71 |
/** @brief Analog port 8 **/
|
72 |
#define AN8 0x08 |
73 |
/** @brief Analog port 9 **/
|
74 |
#define AN9 0x09 |
75 |
/** @brief Analog port 10 **/
|
76 |
#define AN10 0x0A |
77 |
/** @brief Analog port 11 **/
|
78 |
#define AN11 0x0B |
79 |
/** @brief Analog port 12 **/
|
80 |
#define AN12 0x0C |
81 |
/** @brief Analog port 13 **/
|
82 |
#define AN13 0x0D |
83 |
/** @brief Analog port 14 **/
|
84 |
#define AN14 0x0E |
85 |
/** @brief Analog port 15 **/
|
86 |
#define AN15 0x0F |
87 |
|
88 |
/** @brief BOM_PORT analog port for BOM **/
|
89 |
#define BOM_PORT AN0
|
90 |
/** @brief EXT_MUX analog port **/
|
91 |
#define EXT_MUX AN7
|
92 |
/** @brief Analog port for the wheel **/
|
93 |
#define WHEEL_PORT AN10
|
94 |
/** @brief Analog port for the battery voltage detector **/
|
95 |
#define BATT_PORT AN11
|
96 |
|
97 |
#define ADC_START 1 |
98 |
#define ADC_STOP 0 |
99 |
|
100 |
/**
|
101 |
* @brief Initialize analog ports. Will start running a loop
|
102 |
* if start_conversion is ADC_START.
|
103 |
*
|
104 |
* Initializes the ADC.
|
105 |
* Call analog_init before reading from the analog ports.
|
106 |
*
|
107 |
* @see analog8, analog10, analog_get8, analog_get10
|
108 |
**/
|
109 |
void analog_init(int start_conversion); |
110 |
|
111 |
/**
|
112 |
* @brief starts the analog loop. Doesn't do anything if the loop is already running.
|
113 |
*
|
114 |
* Starts the analog update loop. Will continue to run
|
115 |
* until analog_stop_loop is called.
|
116 |
*
|
117 |
* @see analog_stop_loop
|
118 |
**/
|
119 |
void analog_start_loop(void); |
120 |
|
121 |
/**
|
122 |
* @brief Stops the analog loop. Doesn't do anything if the loop is already stopped.
|
123 |
*
|
124 |
* Stops the analog update loop. If there is a current
|
125 |
* read, it will finish up and be stored before the loop
|
126 |
* is interrupted. No further updates will be made until
|
127 |
* the loop is started again.
|
128 |
*
|
129 |
* @see analog_start_loop
|
130 |
**/
|
131 |
void analog_stop_loop(void); |
132 |
|
133 |
/**
|
134 |
* @brief Returns an 8-bit analog value from the look up table. Use this instead of analog_get8.
|
135 |
*
|
136 |
* Returns the 8-bit analog conversion of which from
|
137 |
* the lookup table. If the requested port is the BOM_PORT
|
138 |
* you will get an automatic 0 since the BOM_PORT is not
|
139 |
* read in the loop and not stored. If you need that port
|
140 |
* you should use the functions in bom.c. There is an analog_get8
|
141 |
* function which for instant lookups but should be avoided unless
|
142 |
* you know what you're doing.
|
143 |
*
|
144 |
* @param which the port that you want to read
|
145 |
*
|
146 |
* @bug may cause a seg fault if which is a larger value
|
147 |
* than exists in an_val table. Not sure if we should fix
|
148 |
* this or not since it would add overhead.
|
149 |
*
|
150 |
* @return 8-bit analog value for the which port requested
|
151 |
*
|
152 |
* @see analog10, analog_get8, analog_get10
|
153 |
**/
|
154 |
unsigned int analog8(int which); |
155 |
|
156 |
/**
|
157 |
* Returns the 8-bit analog conversion of which from
|
158 |
* the lookup table. If the requested port is the BOM_PORT
|
159 |
* you will get an automatic 0 since the BOM_PORT is not
|
160 |
* read in the loop and not stored. If you need that port
|
161 |
* you should use the functions in bom.c. There is an analog_get8
|
162 |
* function which for instant lookups but should be avoided unless
|
163 |
* you know what you're doing.
|
164 |
*
|
165 |
* @param which the port that you want to read
|
166 |
*
|
167 |
* @bug may cause a seg fault if which is a larger value
|
168 |
* than exists in an_val table. Not sure if we should fix
|
169 |
* this or not since it would add overhead.
|
170 |
*
|
171 |
* @return 8-bit analog value for the which port requested
|
172 |
*
|
173 |
* @see analog10, analog_get8, analog_get10
|
174 |
**/
|
175 |
unsigned int analog8(int which); |
176 |
|
177 |
/**
|
178 |
* @brief Returns an 10-bit analog value from the look up table. Use this instead of analog_get10.
|
179 |
*
|
180 |
* Returns the 10-bit analog conversion of which from
|
181 |
* the lookup table. If the requested port is the BOM_PORT
|
182 |
* you will get an automatic 0 since the BOM_PORT is not
|
183 |
* read in the loop and not stored. If you need that port
|
184 |
* you should use the functions in bom.c. There is an analog_get10
|
185 |
* function which for instant lookups but should be avoided unless
|
186 |
* you know what you are doing.
|
187 |
*
|
188 |
* @param which the port that you want to read
|
189 |
*
|
190 |
* @bug may cause a seg fault if which is a larger value
|
191 |
* than exists in an_val table. Not sure if we should fix
|
192 |
* this or not since it would add overhead.
|
193 |
*
|
194 |
* @return 10-bit analog value for the which port requested
|
195 |
*
|
196 |
* @see analog8, analog_get8, analog_get10
|
197 |
**/
|
198 |
unsigned int analog10(int which); |
199 |
|
200 |
/**
|
201 |
* @brief Read the position of the wheel.
|
202 |
*
|
203 |
* Returns the current position of the wheel, as an integer
|
204 |
* in the range 0 - 255.
|
205 |
* analog_init must be called before using this function.
|
206 |
*
|
207 |
* @return the orientation of the wheel, as an integer in
|
208 |
* the range 0 - 255.
|
209 |
*
|
210 |
* @see analog_init
|
211 |
**/
|
212 |
int wheel(void); |
213 |
|
214 |
/**
|
215 |
* @brief Read an 8-bit number from an analog port. Loop must be stopped for this to work.
|
216 |
*
|
217 |
* Reads an 8-bit number from an analog port.
|
218 |
* analog_init must be called before using this function.
|
219 |
* The analog loop must also be stopped before using this
|
220 |
* function or you will mess up the lookup table. You
|
221 |
* must also reenabled the loop when you are done unless
|
222 |
* you are doing more instant reads. See analog_stop_loop
|
223 |
* and analog_start_loop for more information about the loop.
|
224 |
*
|
225 |
* @param which the analog port to read from. One of
|
226 |
* the constants AN0 - AN7.
|
227 |
*
|
228 |
* @return the 8-bit input to the specified port
|
229 |
*
|
230 |
* @see analog_init, analog_get10, analog8, analog_stop_loop,
|
231 |
* analog_start_loop
|
232 |
**/
|
233 |
unsigned int analog_get8(int which); |
234 |
|
235 |
/**
|
236 |
* @brief Read a 10-bit number from an analog port. Loop must be stopped for this to work.
|
237 |
*
|
238 |
* Reads an 10-bit number from an analog port.
|
239 |
* analog_init must be called before using this function.
|
240 |
* The analog loop must also be stopped before using this
|
241 |
* function or you will mess up the lookup table. You
|
242 |
* must also reenabled the loop when you are done unless
|
243 |
* you are doing more instant reads. See analog_stop_loop
|
244 |
* and analog_start_loop for more information about the loop.
|
245 |
*
|
246 |
*
|
247 |
* @param which the analog port to read from. Typically
|
248 |
* a constant, one of AN0 - AN7.
|
249 |
*
|
250 |
* @return the 10-bit number input to the specified port
|
251 |
*
|
252 |
* @see analog_init, analog_get8, analog10, analog_stop_loop,
|
253 |
* analog_start_loop
|
254 |
**/
|
255 |
unsigned int analog_get10(int which); |
256 |
|
257 |
/**@}**/ //end group |
258 |
|
259 |
#endif
|
260 |
|