Revision 1875
Cleaned up analog.c file. Removed the interrupt handler code and removed the "start analog loop" code from init function.
analog.c | ||
---|---|---|
106 | 106 |
set_adc_mux(0x00); |
107 | 107 |
adc_current_port = AN1; |
108 | 108 |
|
109 |
//Start the conversion loop if requested |
|
110 |
if (start_conversion) |
|
111 |
analog_start_loop(); |
|
112 | 109 |
|
113 | 110 |
//Conversion loop disabled by default |
114 | 111 |
} |
... | ... | |
325 | 322 |
} |
326 | 323 |
|
327 | 324 |
/**@}**/ //end defgroup |
328 |
|
|
329 |
|
|
330 |
ISR(ADC_vect) { |
|
331 |
int adc_h = 0; |
|
332 |
int adc_l = 0; |
|
333 |
|
|
334 |
if(adc_loop_status != ADC_LOOP_RUNNING) return; |
|
335 |
|
|
336 |
//Store the value only if this read isn't for the BOM |
|
337 |
if (ADMUX != BOM_PORT) { |
|
338 |
adc_l = ADCL; |
|
339 |
adc_h = ADCH; |
|
340 |
|
|
341 |
an_val[adc_current_port - 1].adc10 = (adc_h << 2) | (adc_l >> 6); |
|
342 |
an_val[adc_current_port - 1].adc8 = adc_h; |
|
343 |
} |
|
344 |
|
|
345 |
//Skip AN7 because it is not a real port |
|
346 |
if (adc_current_port == AN6) { |
|
347 |
ADMUX = ADMUX_OPT | EXT_MUX; |
|
348 |
set_adc_mux(AN8 - 8); |
|
349 |
adc_current_port = AN8; |
|
350 |
//Wrap around |
|
351 |
} else if (adc_current_port == AN11) { |
|
352 |
adc_current_port = AN1; |
|
353 |
ADMUX = ADMUX_OPT | adc_current_port; |
|
354 |
//Normal increment |
|
355 |
} else { |
|
356 |
adc_current_port++; |
|
357 |
|
|
358 |
if(adc_current_port < EXT_MUX) { |
|
359 |
ADMUX = ADMUX_OPT | adc_current_port; |
|
360 |
} else { |
|
361 |
ADMUX = ADMUX_OPT | EXT_MUX; |
|
362 |
set_adc_mux(adc_current_port - 8); |
|
363 |
} |
|
364 |
} |
|
365 |
|
|
366 |
//Stop loop if signal is set |
|
367 |
if(adc_sig_stop_loop) { |
|
368 |
adc_sig_stop_loop = 0; |
|
369 |
adc_loop_status = ADC_LOOP_STOPPED; |
|
370 |
return; |
|
371 |
} |
|
372 |
|
|
373 |
//Start next conversion |
|
374 |
ADCSRA |= _BV(ADSC); |
|
375 |
} |
|
376 |
|
Also available in: Unified diff