root / trunk / code / lib / include / libdragonfly / analog.h @ 1461
History | View | Annotate | Download (4.28 KB)
1 | 7 | bcoltin | /**
|
---|---|---|---|
2 | 241 | bcoltin | * Copyright (c) 2007 Colony Project
|
3 | 7 | bcoltin | *
|
4 | 241 | bcoltin | * 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 | 7 | bcoltin | * @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 | 1409 | bneuman | * originally taken from fwr analog file (author: Tom Lauwers)
|
40 | * loop code written by Kevin Woo and James Kong
|
||
41 | 437 | kwoo | */
|
42 | 7 | bcoltin | |
43 | #ifndef _ANALOG_H
|
||
44 | #define _ANALOG_H
|
||
45 | |||
46 | 338 | bcoltin | #include <inttypes.h> |
47 | |||
48 | 7 | bcoltin | /**
|
49 | * @addtogroup analog
|
||
50 | * @{
|
||
51 | **/
|
||
52 | |||
53 | /** @brief Analog port 0 **/
|
||
54 | #define AN0 0x00 |
||
55 | /** @brief Analog port 1 **/
|
||
56 | #define AN1 0x01 |
||
57 | /** @brief Analog port 2 **/
|
||
58 | #define AN2 0x02 |
||
59 | /** @brief Analog port 3 **/
|
||
60 | #define AN3 0x03 |
||
61 | /** @brief Analog port 4 **/
|
||
62 | #define AN4 0x04 |
||
63 | /** @brief Analog port 5 **/
|
||
64 | #define AN5 0x05 |
||
65 | /** @brief Analog port 6 **/
|
||
66 | #define AN6 0x06 |
||
67 | /** @brief Analog port 7 **/
|
||
68 | #define AN7 0x07 |
||
69 | /** @brief Analog port 8 **/
|
||
70 | #define AN8 0x08 |
||
71 | /** @brief Analog port 9 **/
|
||
72 | #define AN9 0x09 |
||
73 | /** @brief Analog port 10 **/
|
||
74 | 338 | bcoltin | #define AN10 0x0A |
75 | 7 | bcoltin | /** @brief Analog port 11 **/
|
76 | 338 | bcoltin | #define AN11 0x0B |
77 | 7 | bcoltin | /** @brief Analog port 12 **/
|
78 | 338 | bcoltin | #define AN12 0x0C |
79 | 7 | bcoltin | /** @brief Analog port 13 **/
|
80 | 338 | bcoltin | #define AN13 0x0D |
81 | 7 | bcoltin | /** @brief Analog port 14 **/
|
82 | 338 | bcoltin | #define AN14 0x0E |
83 | 7 | bcoltin | /** @brief Analog port 15 **/
|
84 | 338 | bcoltin | #define AN15 0x0F |
85 | 7 | bcoltin | |
86 | 338 | bcoltin | /** @brief BOM_PORT analog port for BOM **/
|
87 | #define BOM_PORT AN0
|
||
88 | 7 | bcoltin | /** @brief EXT_MUX analog port **/
|
89 | #define EXT_MUX AN7
|
||
90 | /** @brief Analog port for the wheel **/
|
||
91 | #define WHEEL_PORT AN10
|
||
92 | /** @brief Analog port for the battery voltage detector **/
|
||
93 | #define BATT_PORT AN11
|
||
94 | |||
95 | 1409 | bneuman | /** @brief Analog loop status. ADC conversion running. **/
|
96 | #define ADC_LOOP_RUNNING 1 |
||
97 | /** @brief Analog loop status. No ADC conversion running.**/
|
||
98 | #define ADC_LOOP_STOPPED 0 |
||
99 | |||
100 | /** @brief Analog init parameter. Start the analog loop. **/
|
||
101 | 338 | bcoltin | #define ADC_START 1 |
102 | 1409 | bneuman | /** @brief Analog init parameter. Don't start the analog loop. **/
|
103 | #define ADC_STOP 0 |
||
104 | 338 | bcoltin | |
105 | #define ADMUX_OPT 0x60 |
||
106 | |||
107 | 871 | justin | /** @brief Struct to hold the value of a particular analog port **/
|
108 | 338 | bcoltin | typedef struct { |
109 | 437 | kwoo | uint8_t adc8; |
110 | uint16_t adc10; |
||
111 | 338 | bcoltin | } adc_t; |
112 | |||
113 | |||
114 | /** @brief Initialize analog ports. Will start running a loop
|
||
115 | 437 | kwoo | if start_conversion is ADC_START.**/
|
116 | 1461 | bneuman | int analog_init(int start_conversion); |
117 | 338 | bcoltin | /** @brief starts the analog loop. Doesn't do anything if the loop is already running. **/
|
118 | 1461 | bneuman | int analog_start_loop(void); |
119 | 338 | bcoltin | /** @brief Stops the analog loop. Doesn't do anything if the loop is already stopped. **/
|
120 | 1461 | bneuman | int analog_stop_loop(void); |
121 | 1409 | bneuman | /** @brief Returns the status of the analog loop. **/
|
122 | int analog_loop_status(void); |
||
123 | 871 | justin | /** @brief Returns an 8-bit analog value from the look up table. Use this instead of analog_get8. **/
|
124 | 7 | bcoltin | unsigned int analog8(int which); |
125 | 871 | justin | /** @brief Returns an 10-bit analog value from the look up table. Use this instead of analog_get10. **/
|
126 | 7 | bcoltin | unsigned int analog10(int which); |
127 | /** @brief Read the position of the wheel. **/
|
||
128 | int wheel(void); |
||
129 | 871 | justin | /** @brief Read an 8-bit number from an analog port. Loop must be stopped for this to work. **/
|
130 | 338 | bcoltin | unsigned int analog_get8(int which); |
131 | 871 | justin | /** @brief Read a 10-bit number from an analog port. Loop must be stopped for this to work. **/
|
132 | 338 | bcoltin | unsigned int analog_get10(int which); |
133 | 7 | bcoltin | |
134 | 338 | bcoltin | |
135 | 7 | bcoltin | /**@}**/ //end group |
136 | |||
137 | #endif
|