blackbox/driver/adc.c

changeset 7
f4e250d5402b
parent 0
9b7de464f0ea
equal deleted inserted replaced
6:2405aff29a51 7:f4e250d5402b
10 static uint8_t adcReference=(1<<REFS0); // = VCC 5V 10 static uint8_t adcReference=(1<<REFS0); // = VCC 5V
11 11
12 // get a sample from ADC chip. 12 // get a sample from ADC chip.
13 // chanell must be in range 0-7. 13 // chanell must be in range 0-7.
14 uint16_t getADC(int channel) { 14 uint16_t getADC(int channel) {
15 if (channel == 0) 15 // if (channel == 0)
16 adcReference = ((1<<REFS1) | (1<<REFS0)); // switch to 2.56V (~2x 16 adcReference = ((1<<REFS1) | (1<<REFS0)); // switch to 2.56V (~2x
17 //adcReference = (1<<REFS1); // switch to 1.1v (~4.5x) - not on ATMEGA16 17 //adcReference = (1<<REFS1); // switch to 1.1v (~4.5x) - not on ATMEGA16
18 else 18 // else
19 adcReference = (1<<REFS0); // switch to 5v (1x) 19 // adcReference = (1<<REFS0); // switch to 5v (1x)
20 ADMUX = adcReference + channel; 20 ADMUX = adcReference + channel;
21 // start one sample 21 // start one sample
22 ADCSRA |= (1<<ADSC); 22 ADCSRA |= (1<<ADSC);
23 // wait for the result 23 // wait for the result
24 loop_until_bit_is_clear(ADCSRA, ADSC); 24 loop_until_bit_is_clear(ADCSRA, ADSC);

mercurial