Incorrect reading ADC value on SAM4L8 refrence board

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi;

 

 I am trying to read ADC value on the SAM4L8 Xplained reference board. But I got a random ADC value.

 

 I think the problem is incorrect configuration to ADC but I could not figure out. I hope somebody can help me.

 

Below is the ADC configuration. I select ADVEFP is external voltage reference 1. The input voltage (0-3.3v)  is fed into the board via EXT1 on pin PA04 (Note: the measured voltage on pin PA04 is correct when input voltage is varied)

 

ioport_set_pin_peripheral_mode (PIN_PA04A_ADCIFE_AD0, MUX_PA04A_ADCIFE_AD0)
 
struct adc_config adc_cfg =
    {
     /* System clock division factor is 16 */
     .prescal = ADC_PRESCAL_DIV16,
     /* The APB clock is used */
     .clksel = ADC_CLKSEL_APBCLK,
     /* Max speed is 150K */
     .speed = ADC_SPEED_150K,
     /* ADC Reference voltage is ADVREFP */
     .refsel = ADC_REFSEL_2,
     /* Enables the Startup time */
     .start_up = CONFIG_ADC_STARTUP
    };
   
 

 

struct adc_seq_config adc_seq_cfg =
    {
        /* Select Vref for shift cycle */
        .zoomrange = ADC_ZOOMRANGE_0,
        /* Pad Ground */
        .muxneg = ADC_MUXNEG_0, 
        /* DAC internal */
        .muxpos = ADC_MUXPOS_0,
        /* Enables the internal voltage sources */
        .internal = ADC_INTERNAL_0,
        /* Disables the ADC gain error reduction */
        .gcomp = ADC_GCOMP_DIS,
        /* Disables the HWLA mode */
        .hwla = ADC_HWLA_DIS,
        /* 12-bits resolution */
        .res = ADC_RES_12_BIT, 
        /* Enables the single-ended mode */
        .bipolar = ADC_BIPOLAR_SINGLEENDED
    };
    struct adc_ch_config adc_ch_cfg =
    {
     .seq_cfg = &adc_seq_cfg,
     /* Internal Timer Max Counter */
     .internal_timer_max_count = 60,
     /* Window monitor mode is off */
     .window_mode = 0,
     .low_threshold = 0,
     .high_threshold = 0,
    };

 

 

 

NNinh