diff options
Diffstat (limited to 'software/hhd70dongle')
-rw-r--r-- | software/hhd70dongle/hhd70dongle.c | 3 | ||||
-rw-r--r-- | software/hhd70dongle/util.c | 17 | ||||
-rw-r--r-- | software/hhd70dongle/util.h | 2 |
3 files changed, 17 insertions, 5 deletions
diff --git a/software/hhd70dongle/hhd70dongle.c b/software/hhd70dongle/hhd70dongle.c index bc62dea..9bf3e8b 100644 --- a/software/hhd70dongle/hhd70dongle.c +++ b/software/hhd70dongle/hhd70dongle.c @@ -106,6 +106,8 @@ int main(void) write_buffer[3]='p'; write_buffer[4]='s'; write_buffer[5]=':'; + adc_on(); + _delay_ms(250); usb_rawhid_send((uint8_t*)"temp c1101:",255); debug_sprint_int16hex(write_buffer+6, c1101_measureTemp()); usb_rawhid_send(write_buffer+6,255); @@ -113,6 +115,7 @@ int main(void) usb_rawhid_send((uint8_t*)"temp atmega:",255); debug_sprint_int16hex(write_buffer+10, adc_read(ADCMUX_ADC12)); usb_rawhid_send(write_buffer+10,255); + adc_off(); _delay_ms(250); led_on(); usb_rawhid_send((uint8_t*)"TX Data: String",255); diff --git a/software/hhd70dongle/util.c b/software/hhd70dongle/util.c index 2c358fa..56fe575 100644 --- a/software/hhd70dongle/util.c +++ b/software/hhd70dongle/util.c @@ -70,19 +70,26 @@ void reset(void) #endif } +//not switchin off adc produces slightly besser results +void adc_on(void) +{ + ADCSRA = (1<<ADEN) | 0b00000111; // enable ADC, Prescaler 1:128 +} + +void adc_off(void) +{ + ADCSRA &= ~(1<<ADEN); // disable ADC -> save power +} + + uint8_t adc_read(uint8_t mux) { 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 - - ADCSRA &= ~(1<<ADEN); // disable ADC -> save power - return ADCH; } diff --git a/software/hhd70dongle/util.h b/software/hhd70dongle/util.h index 20068fd..4554af9 100644 --- a/software/hhd70dongle/util.h +++ b/software/hhd70dongle/util.h @@ -37,6 +37,8 @@ #define ADCMUX_ADC12 0b00100100 void reset(void); +void adc_on(void); +void adc_off(void); uint8_t adc_read(uint8_t mux); void debug_sprint_int16hex(uint8_t *buffer, int16_t num); |