From: Michel Pollet Date: Wed, 14 Sep 2011 08:07:07 +0000 (+0100) Subject: adc: Added VCC/4 reading X-Git-Tag: v1.0a9~7 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=55bbf1a9a25e034524d8581a2e1e104d03101e1f;p=sx%2Fsimavr.git adc: Added VCC/4 reading For mega16m1 Signed-off-by: Markus Lampert Signed-off-by: Michel Pollet --- diff --git a/simavr/sim/avr_adc.c b/simavr/sim/avr_adc.c index f2b2606..e771ff6 100644 --- a/simavr/sim/avr_adc.c +++ b/simavr/sim/avr_adc.c @@ -68,6 +68,12 @@ static uint8_t avr_adc_read_l(struct avr_t * avr, avr_io_addr_t addr, void * par case ADC_MUX_REF: reg = mux.src; // reference voltage break; + case ADC_MUX_VCC4: + if ( !avr->vcc) { + printf("ADC Warning : missing VCC analog voltage\n"); + } else + reg = avr->vcc / 4; + break; } uint32_t vref = 3300; switch (ref) { diff --git a/simavr/sim/avr_adc.h b/simavr/sim/avr_adc.h index 85f82cf..c453f87 100644 --- a/simavr/sim/avr_adc.h +++ b/simavr/sim/avr_adc.h @@ -60,6 +60,7 @@ enum { ADC_MUX_DIFF, // differencial channels (src-diff) ADC_MUX_TEMP, // internal temp sensor ADC_MUX_REF, // reference voltage (in src * 100) + ADC_MUX_VCC4, // VCC/4 }; typedef struct avr_adc_mux_t { unsigned long kind : 3, gain : 8, diff : 8, src : 13; @@ -135,4 +136,8 @@ void avr_adc_init(avr_t * avr, avr_adc_t * port); .kind = ADC_MUX_TEMP, \ } +#define AVR_ADC_VCC4() { \ + .kind = ADC_MUX_VCC4, \ + } + #endif /* __AVR_ADC_H___ */