diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-12-21 22:03:21 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-12-21 22:03:21 +0100 |
commit | 69433286b30a228c0422d95cf189d648e0485060 (patch) | |
tree | 7c520475bca8ac0c8546498258bad8887cb2e921 /src/app | |
parent | 65856cb69cd0212daeeab8eea10203c9899c5d27 (diff) |
adctest: switch to getPin_mV helper function
Diffstat (limited to 'src/app')
-rw-r--r-- | src/app/adctest/main.cc | 49 |
1 files changed, 2 insertions, 47 deletions
diff --git a/src/app/adctest/main.cc b/src/app/adctest/main.cc index 7a87ede..af3147f 100644 --- a/src/app/adctest/main.cc +++ b/src/app/adctest/main.cc @@ -17,54 +17,9 @@ void loop(void) kout << "Temperature " << temp << " m°C" << endl; for (uint8_t admux_sel = 0; admux_sel < 8; admux_sel++) { - // measure with avcc reference - ADMUX = _BV(REFS0) | admux_sel; - - // Enable ADC with /64 prescaler - ADCSRA = _BV(ADEN) | _BV(ADPS2); - - // Start conversion - ADCSRA |= _BV(ADSC); - - // wait until conversion is complete - while (ADCSRA & _BV(ADSC)) ; - - uint8_t adcr_l = ADCL; - uint8_t adcr_h = ADCH; - uint16_t adcr = adcr_l + (adcr_h << 8); - uint16_t vadc = (uint32_t)vcc * adcr / 1023L; - - kout << "ADC" << admux_sel << " " << vadc << " mV vs AVCC" << endl; + kout << "ADC" << admux_sel << " " << adc.getPin_mV(admux_sel, vcc) << " mV vs AVCC" << endl; + kout << "ADC" << admux_sel << " " << adc.getPin_mV(admux_sel) << " mV vs 1.1V bandgap" << endl; } - - // enable bandgap; wait for it to stabilise - ADMUX = _BV(REFS1) | _BV(REFS0); - ADCSRA = _BV(ADEN) | _BV(ADPS2); - arch.delay_ms(1); - - for (uint8_t admux_sel = 0; admux_sel < 8; admux_sel++) { - // measure with bandgap reference - ADMUX = _BV(REFS1) | _BV(REFS0) | admux_sel; - - // Enable ADC with /64 prescaler - ADCSRA = _BV(ADEN) | _BV(ADPS2); - - // Start conversion - ADCSRA |= _BV(ADSC); - - // wait until conversion is complete - while (ADCSRA & _BV(ADSC)) ; - - uint8_t adcr_l = ADCL; - uint8_t adcr_h = ADCH; - uint16_t adcr = adcr_l + (adcr_h << 8); - uint16_t vadc = 1100L * adcr / 1023L; - - kout << "ADC" << admux_sel << " " << vadc << " mV vs 1.1V bandgap" << endl; - } - - // disable ADC - ADCSRA &= ~_BV(ADEN); } int main(void) |