root / branches / analog / trunk / code / projects / libdragonfly / analog.h @ 324
History | View | Annotate | Download (3.99 KB)
1 | 8 | bcoltin | /**
|
---|---|---|---|
2 | 241 | bcoltin | * Copyright (c) 2007 Colony Project
|
3 | 8 | 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 | 8 | 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 | 324 | kwoo | * ADC to detect analog signals on pins AN0 - AN15.
|
33 | * See analog.c for implementation details.
|
||
34 | *
|
||
35 | 8 | bcoltin | * @author Colony Project, CMU Robotics Club, based on firefly
|
36 | * code by Tom Lauwers
|
||
37 | 324 | kwoo | **/
|
38 | 8 | bcoltin | |
39 | #ifndef _ANALOG_H
|
||
40 | #define _ANALOG_H
|
||
41 | |||
42 | 275 | kwoo | #include <inttypes.h> |
43 | |||
44 | 8 | bcoltin | /**
|
45 | * @addtogroup analog
|
||
46 | * @{
|
||
47 | **/
|
||
48 | |||
49 | /** @brief Analog port 0 **/
|
||
50 | #define AN0 0x00 |
||
51 | /** @brief Analog port 1 **/
|
||
52 | #define AN1 0x01 |
||
53 | /** @brief Analog port 2 **/
|
||
54 | #define AN2 0x02 |
||
55 | /** @brief Analog port 3 **/
|
||
56 | #define AN3 0x03 |
||
57 | /** @brief Analog port 4 **/
|
||
58 | #define AN4 0x04 |
||
59 | /** @brief Analog port 5 **/
|
||
60 | #define AN5 0x05 |
||
61 | /** @brief Analog port 6 **/
|
||
62 | #define AN6 0x06 |
||
63 | /** @brief Analog port 7 **/
|
||
64 | #define AN7 0x07 |
||
65 | /** @brief Analog port 8 **/
|
||
66 | #define AN8 0x08 |
||
67 | /** @brief Analog port 9 **/
|
||
68 | #define AN9 0x09 |
||
69 | /** @brief Analog port 10 **/
|
||
70 | 312 | kwoo | #define AN10 0x0A |
71 | 8 | bcoltin | /** @brief Analog port 11 **/
|
72 | 312 | kwoo | #define AN11 0x0B |
73 | 8 | bcoltin | /** @brief Analog port 12 **/
|
74 | 312 | kwoo | #define AN12 0x0C |
75 | 8 | bcoltin | /** @brief Analog port 13 **/
|
76 | 312 | kwoo | #define AN13 0x0D |
77 | 8 | bcoltin | /** @brief Analog port 14 **/
|
78 | 312 | kwoo | #define AN14 0x0E |
79 | 8 | bcoltin | /** @brief Analog port 15 **/
|
80 | 312 | kwoo | #define AN15 0x0F |
81 | 8 | bcoltin | |
82 | 300 | kwoo | /** @brief BOM_PORT analog port for BOM **/
|
83 | #define BOM_PORT AN0
|
||
84 | 8 | bcoltin | /** @brief EXT_MUX analog port **/
|
85 | #define EXT_MUX AN7
|
||
86 | /** @brief Analog port for the wheel **/
|
||
87 | #define WHEEL_PORT AN10
|
||
88 | /** @brief Analog port for the battery voltage detector **/
|
||
89 | #define BATT_PORT AN11
|
||
90 | |||
91 | 324 | kwoo | /** @brief Used in analog_init to start the analog loop from the get-go **/
|
92 | 300 | kwoo | #define ADC_START 1 |
93 | 324 | kwoo | /** @brief Used in analog_init to not start the analog loop from the get-go **/
|
94 | 300 | kwoo | #define ADC_STOP 0 |
95 | 324 | kwoo | /** @brief Maximum number of analog ports to check. This number is equivalent to
|
96 | * AN1 -> AN11 as AN0 and AN7 are skipped. **/
|
||
97 | #define ANMAX 11 |
||
98 | /** @brief For use with ADMUX register. Means that We will use AVCC (REFS0) and
|
||
99 | * enable ADLAR. **/
|
||
100 | 312 | kwoo | #define ADMUX_OPT 0x60 |
101 | 300 | kwoo | |
102 | 275 | kwoo | |
103 | 314 | kwoo | /** @brief Initialize analog ports. Will start running a loop
|
104 | if start_conversion is ADC_START.**/
|
||
105 | 300 | kwoo | void analog_init(int start_conversion); |
106 | 314 | kwoo | /** @brief starts the analog loop. Doesn't do anything if the loop is already running. **/
|
107 | 300 | kwoo | void analog_start_loop(void); |
108 | 314 | kwoo | /** @brief Stops the analog loop. Doesn't do anything if the loop is already stopped. **/
|
109 | 300 | kwoo | void analog_stop_loop(void); |
110 | 324 | kwoo | /** @brief Returns an 8-bit analog value from the look up table. Use this instead of analog8. **/
|
111 | 8 | bcoltin | unsigned int analog8(int which); |
112 | 324 | kwoo | /** @brief Returns an 10-bit analog value from the look up table. Use this instead of analog10. **/
|
113 | 8 | bcoltin | unsigned int analog10(int which); |
114 | /** @brief Read the position of the wheel. **/
|
||
115 | int wheel(void); |
||
116 | 324 | kwoo | /** @brief Read an 8-bit number from an analog port. Loop must be stopped for this to work. **/
|
117 | 275 | kwoo | unsigned int analog_get8(int which); |
118 | 324 | kwoo | /** @brief Read a 10-bit number from an analog port. Loop must be stopped for this to work. **/
|
119 | 275 | kwoo | unsigned int analog_get10(int which); |
120 | 8 | bcoltin | |
121 | 275 | kwoo | |
122 | 8 | bcoltin | /**@}**/ //end group |
123 | |||
124 | #endif
|