root / trunk / code / projects / colonet / utilities / robot_slave / analog.h @ 13
History | View | Annotate | Download (2.26 KB)
1 | 13 | emarinel | /*
|
---|---|---|---|
2 | * analog.h - Contains definitions and function prototypes for using the
|
||
3 | * ADC to detect analog signals on pins AN0 - AN7
|
||
4 | * AN6 and AN7 are used for the wheel and battery
|
||
5 | |||
6 | * The pins labeled E6 and E7 are external interrupt pins and are not related
|
||
7 | * to analog
|
||
8 | |||
9 | * author: CMU Robotics Club, Colony Project
|
||
10 | * code taken from the fwr analog file (author: Tom Lauwers)
|
||
11 | */
|
||
12 | |||
13 | #ifndef _ANALOG_H
|
||
14 | #define _ANALOG_H
|
||
15 | |||
16 | #define AN0 0x00 |
||
17 | #define AN1 0x01 |
||
18 | #define AN2 0x02 |
||
19 | #define AN3 0x03 |
||
20 | #define AN4 0x04 |
||
21 | #define AN5 0x05 |
||
22 | #define AN6 0x06 |
||
23 | #define AN7 0x07 |
||
24 | #define AN8 0x08 |
||
25 | #define AN9 0x09 |
||
26 | #define AN10 0x0a |
||
27 | #define AN11 0x0b |
||
28 | #define AN12 0x0c |
||
29 | #define AN13 0x0d |
||
30 | #define AN14 0x0e |
||
31 | #define AN15 0x0f |
||
32 | |||
33 | #define ANALOG0 AN0
|
||
34 | #define ANALOG1 AN1
|
||
35 | #define ANALOG2 AN8
|
||
36 | #define ANALOG3 AN9
|
||
37 | #define ANALOG4 AN2
|
||
38 | #define ANALOG5 AN3
|
||
39 | #define ANALOG6 AN4
|
||
40 | #define ANALOG7 AN5
|
||
41 | #define ANALOG8 AN6
|
||
42 | |||
43 | #define EXT_MUX AN7
|
||
44 | #define WHEEL_PORT AN10
|
||
45 | #define BATT_PORT AN11
|
||
46 | |||
47 | //Macros for Battery
|
||
48 | //Constants determined experimentally 2/9/2007 - James Kong
|
||
49 | //See Battery8_data.xls for experiment data
|
||
50 | #define NORMALV 6 |
||
51 | #define CHARGINGV 7.00 |
||
52 | #define LOWV 5.25 |
||
53 | |||
54 | #define BATT_NRMLV (int)(25.7*NORMALV) |
||
55 | #define BATT_CHRGV (int)(25.7*CHARGINGV) |
||
56 | #define BATT_LOWV (int)(25.7*LOWV) |
||
57 | |||
58 | |||
59 | /*
|
||
60 | Call this function before reading from the analog ports
|
||
61 | turns on the ADC
|
||
62 | */
|
||
63 | void analog_init(void); |
||
64 | |||
65 | /*
|
||
66 | returns an 8-bit number from the desired analog port
|
||
67 | argument should be one of the constants AN0 - AN7
|
||
68 | behavior is undefined otherwise
|
||
69 | analog_init() must be called before a call to this function
|
||
70 | */
|
||
71 | unsigned int analog8(int which); |
||
72 | |||
73 | /*
|
||
74 | returns a 10-bit number from the desired analog port
|
||
75 | argument should be one of the constants AN0 - AN7
|
||
76 | behavior is undefined otherwise
|
||
77 | analog_init() must be called before a call to this function
|
||
78 | */
|
||
79 | unsigned int analog10(int which); |
||
80 | |||
81 | /*
|
||
82 | returns the current value (0-255) of the wheel
|
||
83 | analog_init() must be called before a call to this function
|
||
84 | */
|
||
85 | int wheel(void); |
||
86 | |||
87 | /*
|
||
88 | returns the current voltage of the battery (deciVolts)
|
||
89 | analog_init() must be called before a call to this function
|
||
90 | */
|
||
91 | int battery(void); |
||
92 | |||
93 | /*
|
||
94 | returns the current analog8 reading of the battery voltage
|
||
95 | 128 ~= 5 volts, higher value -> higher voltage
|
||
96 | analog_init() must be called before a call to this function
|
||
97 | */
|
||
98 | int battery8(void); |
||
99 | |||
100 | #endif |