diff options
Diffstat (limited to 'software/hhd70dongle')
-rw-r--r-- | software/hhd70dongle/util.c | 24 | ||||
-rw-r--r-- | software/hhd70dongle/util.h | 7 |
2 files changed, 16 insertions, 15 deletions
diff --git a/software/hhd70dongle/util.c b/software/hhd70dongle/util.c index b0e6e89..2c358fa 100644 --- a/software/hhd70dongle/util.c +++ b/software/hhd70dongle/util.c @@ -70,18 +70,20 @@ void reset(void) #endif } -int16_t adc_read(uint8_t mux) +uint8_t adc_read(uint8_t mux) { - uint8_t low; - char aref = 0b01000000; - ADCSRA = (1<<ADEN) | ADC_PRESCALER; // enable ADC - ADCSRB = (1<<ADHSM) | (mux & 0x20); // high speed mode - ADMUX = aref | (mux & 0x1F); // configure mux input - ADCSRA = (1<<ADEN) | ADC_PRESCALER | (1<<ADSC); // start the conversion + ADCSRB = (mux & 0x20); // select input + ADMUX = 0b11100000 | (mux & 0x1F); // select input cont'd + // select internal 2.56V reference, + // result is left justified + ADCSRA = (1<<ADEN) | 0b00000111; // enable ADC, Prescaler 1:128 + + ADCSRA |= (1<<ADSC); // start the conversion while (ADCSRA & (1<<ADSC)) ; // wait for result - low = ADCL; // must read LSB first - ADCSRA &= ~(1<<ADEN); // disable ADC - return (ADCH << 8) | low; // must read MSB only once! + + ADCSRA &= ~(1<<ADEN); // disable ADC -> save power + + return ADCH; } void debug_sprint_int16hex(uint8_t *buffer, int16_t num) @@ -93,4 +95,4 @@ void debug_sprint_int16hex(uint8_t *buffer, int16_t num) buffer[c] = n + ((n < 10) ? '0' : 'A' - 10); } buffer[4]=0; -}
\ No newline at end of file +} diff --git a/software/hhd70dongle/util.h b/software/hhd70dongle/util.h index 1c4cb21..20068fd 100644 --- a/software/hhd70dongle/util.h +++ b/software/hhd70dongle/util.h @@ -32,13 +32,12 @@ #ifndef MURSAT_util_h_INCLUDED #define MURSAT_util_h_INCLUDED -#define ADC_PRESCALER 0 -#define ADCMUX_INTERNALTEMP 0b100111 -#define ADCMUX_ADC12 0b100100 +#define ADCMUX_INTERNALTEMP 0b00100111 +#define ADCMUX_ADC12 0b00100100 void reset(void); -int16_t adc_read(uint8_t mux); +uint8_t adc_read(uint8_t mux); void debug_sprint_int16hex(uint8_t *buffer, int16_t num); #endif |