I've got the ADC working on the ATmega4809 using VDD as reference.
/* Disable digital input buffer */ PORTE.PIN0CTRL |= PORT_ISC_INPUT_DISABLE_gc; ADC0.CTRLC = ADC_PRESC_DIV16_gc | ADC_SAMPCAP_bm | ADC_REFSEL_VDDREF_gc; ADC0.CTRLB = ADC_SAMPNUM_ACC4_gc; /* Select ADC channel */ ADC0.MUXPOS = ADC_MUXPOS_AIN8_gc; ADC0.CTRLA |= ADC_ENABLE_bm; /* ADC Enable: enabled */
and to trigger the ADC
/* Start ADC conversion */ ADC0.COMMAND = ADC_STCONV_bm; /* Wait until ADC conversion done */ while ( !(ADC0.INTFLAGS & ADC_RESRDY_bm) ) { ; } /* Clear the interrupt flag by writing 1: */ ADC0.INTFLAGS = ADC_RESRDY_bm; return ADC0.RES >> 2;
but my question is; The reference voltage is 4.3 instead of the 5V I have powering the device.
Is this expected behavior? if so does anyone have an explanation as to why?