Revision 862
Updated analog.c and analog.h documentation and regenerated the docs. No need to remake the library as its just comments.
analog.c | ||
---|---|---|
64 | 64 |
an_val[i].adc8 = 0; |
65 | 65 |
} |
66 | 66 |
|
67 |
//cli(); |
|
68 | 67 |
// ADMUX register |
69 | 68 |
// Bit 7,6 - Set voltage reference to AVcc (0b01) |
70 | 69 |
// Bit 5 - ADLAR set to simplify moving from register |
... | ... | |
74 | 73 |
ADMUX = 0; |
75 | 74 |
ADMUX |= ADMUX_OPT | _BV(MUX0); |
76 | 75 |
|
77 |
|
|
78 | 76 |
// ADC Status Register A |
79 | 77 |
// Bit 7 - ADEN is set (enables analog) |
80 | 78 |
// Bit 6 - Start conversion bit is set (must be done once for free-running mode) |
... | ... | |
97 | 95 |
analog_start_loop(); |
98 | 96 |
else |
99 | 97 |
analog_stop_loop(); |
100 |
//sei(); |
|
101 |
|
|
102 | 98 |
} |
103 | 99 |
|
100 |
/** |
|
101 |
* Returns the 8-bit analog conversion of which from |
|
102 |
* the lookup table. If the requested port is the BOM_PORT |
|
103 |
* you will get an automatic 0 since the BOM_PORT is not |
|
104 |
* read in the loop and not stored. If you need that port |
|
105 |
* you should use the functions in bom.c. There is an analog_get8 |
|
106 |
* function which for instant lookups but should be avoided unless |
|
107 |
* you know what you're doing. |
|
108 |
* |
|
109 |
* @param which the port that you want to read |
|
110 |
* |
|
111 |
* @bug may cause a seg fault if which is a larger value |
|
112 |
* than exists in an_val table. Not sure if we should fix |
|
113 |
* this or not since it would add overhead. |
|
114 |
* |
|
115 |
* @return 8-bit analog value for the which port requested |
|
116 |
* |
|
117 |
* @see analog10, analog_get8, analog_get10 |
|
118 |
**/ |
|
104 | 119 |
unsigned int analog8(int which) { |
105 | 120 |
if (which == BOM_PORT) { |
106 | 121 |
return 0; |
... | ... | |
115 | 130 |
* you will get an automatic 0 since the BOM_PORT is not |
116 | 131 |
* read in the loop and not stored. If you need that port |
117 | 132 |
* you should use the functions in bom.c. There is an analog_get10 |
118 |
* function which for instant lookups but should be avoided. |
|
133 |
* function which for instant lookups but should be avoided unless |
|
134 |
* you know what you are doing. |
|
119 | 135 |
* |
120 | 136 |
* @param which the port that you want to read |
121 | 137 |
* |
... | ... | |
135 | 151 |
} |
136 | 152 |
} |
137 | 153 |
|
138 |
|
|
139 | 154 |
/** |
140 | 155 |
* Starts the analog update loop. Will continue to run |
141 | 156 |
* until analog_stop_loop is called. |
... | ... | |
161 | 176 |
adc_loop_running = 0x0; |
162 | 177 |
} |
163 | 178 |
/** |
164 |
* Reads an eight bit number from an analog port.
|
|
179 |
* Reads an 8-bit number from an analog port.
|
|
165 | 180 |
* analog_init must be called before using this function. |
181 |
* The analog loop must also be stopped before using this |
|
182 |
* function or you will mess up the lookup table. You |
|
183 |
* must also reenabled the loop when you are done unless |
|
184 |
* you are doing more instant reads. See analog_stop_loop |
|
185 |
* and analog_start_loop for more information about the loop. |
|
166 | 186 |
* |
167 | 187 |
* @param which the analog port to read from. One of |
168 | 188 |
* the constants AN0 - AN7. |
169 | 189 |
* |
170 |
* @return the eight bit input to the specified port
|
|
190 |
* @return the 8-bit input to the specified port
|
|
171 | 191 |
* |
172 |
* @see analog_init, analog10 |
|
192 |
* @see analog_init, analog_get10, analog8, analog_stop_loop, |
|
193 |
* analog_start_loop |
|
173 | 194 |
**/ |
174 | 195 |
unsigned int analog_get8(int which) { |
175 | 196 |
// Let any previous conversion finish |
... | ... | |
192 | 213 |
} |
193 | 214 |
|
194 | 215 |
/** |
195 |
* Reads a ten bit number from the specified port.
|
|
216 |
* Reads an 10-bit number from an analog port.
|
|
196 | 217 |
* analog_init must be called before using this function. |
218 |
* The analog loop must also be stopped before using this |
|
219 |
* function or you will mess up the lookup table. You |
|
220 |
* must also reenabled the loop when you are done unless |
|
221 |
* you are doing more instant reads. See analog_stop_loop |
|
222 |
* and analog_start_loop for more information about the loop. |
|
197 | 223 |
* |
198 | 224 |
* |
199 | 225 |
* @param which the analog port to read from. Typically |
200 | 226 |
* a constant, one of AN0 - AN7. |
201 | 227 |
* |
202 |
* @return the ten bit number input to the specified port
|
|
228 |
* @return the 10-bit number input to the specified port
|
|
203 | 229 |
* |
204 |
* @see analog_init, analog8 |
|
230 |
* @see analog_init, analog_get8, analog10, analog_stop_loop, |
|
231 |
* analog_start_loop |
|
205 | 232 |
**/ |
206 | 233 |
unsigned int analog_get10(int which) { |
207 | 234 |
int adc_h; |
Also available in: Unified diff