Revision 314
Updated BOM and rangefinder to use new analog. Entering alpha testing phase.
analog.c | ||
---|---|---|
164 | 164 |
/** |
165 | 165 |
* Reads a ten bit number from the specified port. |
166 | 166 |
* analog_init must be called before using this function. |
167 |
* |
|
167 | 168 |
* |
168 | 169 |
* @param which the analog port to read from. Typically |
169 | 170 |
* a constant, one of AN0 - AN7. |
... | ... | |
174 | 175 |
**/ |
175 | 176 |
unsigned int analog10(int which) |
176 | 177 |
{ |
178 |
int adc_h; |
|
179 |
int adc_l; |
|
180 |
|
|
177 | 181 |
// Let any previous conversion finish |
178 | 182 |
while (ADCSRA & _BV(ADSC)); |
179 | 183 |
|
... | ... | |
190 | 194 |
// Wait for the conversion to finish |
191 | 195 |
while (ADCSRA & _BV(ADSC)); |
192 | 196 |
|
193 |
return ((ADCH << 2) | (ADCL >> 6)); |
|
197 |
adc_l = ADCL; |
|
198 |
adc_h = ADCH; |
|
199 |
|
|
200 |
return ((adc_h << 2) | (adc_l >> 6)); |
|
194 | 201 |
} |
195 | 202 |
|
196 | 203 |
/** |
... | ... | |
208 | 215 |
return analog_get8(WHEEL_PORT); |
209 | 216 |
} |
210 | 217 |
|
211 |
/**@}**/ //end defgroup |
|
212 | 218 |
|
219 |
/** |
|
220 |
* Sets the value of the external analog mux. Values are read |
|
221 |
* on AN7 physical port. (AN8 - AN15 are "virtual" ports). |
|
222 |
* |
|
223 |
* @param which which analog mux port (0-7) which corresponds |
|
224 |
* to AN8-AN15. |
|
225 |
* |
|
226 |
* @bug FIX THIS IN THE NEXT BOARD REVISION: |
|
227 |
* ADDR2 ADDR1 ADDR0 |
|
228 |
* G2.G4.G3 set mux to port 0-7 via vinary selection |
|
229 |
* math would be much cleaner if it was G4.G3.G2 |
|
230 |
* |
|
231 |
* @see analog_init |
|
232 |
**/ |
|
213 | 233 |
void set_adc_mux(int which) |
214 |
{ |
|
215 |
// FIX THIS IN NEXT REVISION |
|
216 |
// ADDR2 ADDR1 ADDR0 |
|
217 |
// G2.G4.G3 set mux to port 0-7 via binary selection |
|
218 |
// math would be much cleaner if it was G4.G3.G2 |
|
219 |
|
|
234 |
{ |
|
220 | 235 |
// mask so only proper bits are possible. |
221 | 236 |
PORTG = (PORTG & 0xE3) | ((which & 0x03) << 3) | (which & 0x04); |
222 | 237 |
} |
238 |
|
|
239 |
/**@}**/ //end defgroup |
|
240 |
|
|
223 | 241 |
|
224 | 242 |
ISR(ADC_vect) { |
225 | 243 |
static volatile int adc_prev_loop_running = 0; |
Also available in: Unified diff