SAR-ADC is giving weird measurements.

Hi,

I am working with an nRF52832 in the nRF52-DK. I am trying to use the ADC with timers through PPI. I have a timer with five CC events, and one of them through ADC measurements. I think this is working fine. However, when I take a look at the content of the buffer, results are weird. I tried connecting the AI1 pin to VDD a GND, and I always get the same measure. What can be happening? I attach here the functions in which I configure the ADC and handle events.

Thanks in advanced.

#include "app_uart.h"
#include "boards.h"
#include "nrf_drv_saadc.h"

#include "my_constants.h"
#include "my_functions.h"

static nrf_saadc_value_t     adc_buffer[ADC_SAMPLES]  = {0};
static uint16_t              adc_voltage[ADC_SAMPLES] = {0};

void adc_init(void) {

  uint32_t * p_err_code = get_err_code();
  
  nrf_drv_saadc_config_t saadc_config = NRF_DRV_SAADC_DEFAULT_CONFIG;
  saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT;
  saadc_config.oversample = NRF_SAADC_OVERSAMPLE_DISABLED;

  nrf_saadc_channel_config_t channel_config = 
  NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(PIN_ASIC_OUTA);

  channel_config.acq_time  = NRF_SAADC_ACQTIME_20US;
  channel_config.gain      = NRF_SAADC_GAIN1_6;
  channel_config.reference = NRF_SAADC_REFERENCE_INTERNAL;
  
  *p_err_code = nrf_drv_saadc_init(&saadc_config, adc_handler);
  if (*p_err_code == NRF_ERROR_INVALID_STATE) {
    nrf_drv_saadc_uninit();
    *p_err_code = nrf_drv_saadc_init(&saadc_config, adc_handler);
  }
  *p_err_code = nrf_drv_saadc_channel_init(0, &channel_config);
  *p_err_code = nrf_drv_saadc_buffer_convert(adc_buffer, ADC_SAMPLES);

} 

void adc_handler(nrf_drv_saadc_evt_t const * p_event) {
  uint32_t * p_err_code = get_err_code();

  if (p_event->type == NRF_DRV_SAADC_EVT_DONE) {   
    int i = 0;
    for (i=0; i<ADC_SAMPLES; i++) {
      adc_voltage[i] = adc_buffer[i]*600*6/4096;
    }

    *p_err_code = nrf_drv_saadc_buffer_convert(adc_buffer, ADC_SAMPLES);
  }

  
}

Parents Reply Children
Related