Revision 1391
Revised analog.
analog.c | ||
---|---|---|
49 | 49 |
* @{ |
50 | 50 |
**/ |
51 | 51 |
|
52 |
int adc_loop_status = ADC_LOOP_STOPPED; |
|
53 |
int adc_sig_stop_loop = 0; |
|
54 |
int adc_current_port = 0; |
|
55 |
adc_t an_val[11]; |
|
52 |
volatile int adc_loop_status = ADC_LOOP_STOPPED;
|
|
53 |
volatile int adc_sig_stop_loop = 0;
|
|
54 |
volatile int adc_current_port = 0;
|
|
55 |
volatile adc_t an_val[11];
|
|
56 | 56 |
|
57 | 57 |
/** |
58 | 58 |
* Initializes the ADC. |
... | ... | |
173 | 173 |
* @see analog_stop_loop, analog_loop_status |
174 | 174 |
**/ |
175 | 175 |
void analog_start_loop(void) { |
176 |
//Start the conversion, enable ADC interrupt |
|
177 |
ADCSRA |= _BV(ADSC) | _BV(ADIE); |
|
178 |
adc_loop_status = ADC_LOOP_RUNNING; |
|
176 |
if(adc_loop_status != ADC_LOOP_RUNNING){ |
|
177 |
//Start the conversion, enable ADC interrupt |
|
178 |
ADCSRA |= _BV(ADIE); |
|
179 |
ADCSRA |= _BV(ADSC); |
|
180 |
adc_loop_status = ADC_LOOP_RUNNING; |
|
181 |
} |
|
179 | 182 |
} |
180 | 183 |
|
181 | 184 |
/** |
... | ... | |
322 | 325 |
ISR(ADC_vect) { |
323 | 326 |
int adc_h = 0; |
324 | 327 |
int adc_l = 0; |
328 |
|
|
329 |
if(adc_loop_status != ADC_LOOP_RUNNING) return; |
|
325 | 330 |
|
326 | 331 |
//Store the value only if this read isn't for the BOM |
327 | 332 |
if (ADMUX != BOM_PORT) { |
... | ... | |
355 | 360 |
|
356 | 361 |
//Stop loop if signal is set |
357 | 362 |
if(adc_sig_stop_loop) { |
358 |
//Disable the interrupt |
|
359 |
ADCSRA &= _BV(ADIE); |
|
360 | 363 |
adc_sig_stop_loop = 0; |
361 | 364 |
adc_loop_status = ADC_LOOP_STOPPED; |
362 | 365 |
return; |
363 | 366 |
} |
364 | 367 |
|
368 |
/* |
|
369 |
count++; |
|
370 |
usb_puts("adc_int\t"); |
|
371 |
usb_puti(count); |
|
372 |
usb_puts("\n\r"); |
|
373 |
|
|
374 |
delay_ms(100); |
|
375 |
*/ |
|
376 |
|
|
377 |
|
|
365 | 378 |
//Start next conversion |
366 | 379 |
ADCSRA |= _BV(ADSC); |
367 | 380 |
} |
Also available in: Unified diff