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