# ADC minimum value is half of max

I'm trying to read an analog value using the ADC of a ATSAM4E microcontroller. The problem i have is that it always reads 2047 or 2046 when the pin is connected to GND and 4096 when connected to VCC. I don't have it configured in differential mode.

Here is the code for it:

void adc_init(void){
struct afec_config afec_cfg;
afec_enable(AFEC0);
afec_get_config_defaults(&afec_cfg);
afec_init(AFEC0, &afec_cfg);
afec_set_trigger(AFEC0, AFEC_TRIG_SW);
afec_channel_enable(AFEC0, AFEC_CHANNEL_0);
}

//every 100ms
printf("CHANNEL 0: %d\r\n\n", afec_channel_get_value(AFEC0, AFEC_CHANNEL_0));
afec_start_software_conversion(AFEC0);


I don't know what the problem is. The ADC clock is 6MHz, so waiting 100ms between conversions should be sufficient to ensure it is finished.

It is a bit suspicious that the value is always so close to half. Least i got was 1790 but these "smaller" values occur after disconnecting the pin from VCC.

Anyone have any idea what it might be?

• Looks like a differential ADC. – Gregory Kornblum Apr 17 '17 at 17:04