This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Getting different ADC readings when using JLink debugging than when not

I have built a PCB that includes the nRF51822. I have AIN7 reading an input voltage that I measure on my DMM at 269mV.

When I measure the voltage through the nRF51822's ADC, I get 261 mV when the code is run through Eclipse debugging with the nRF51 DK's debug out hooked up to the SWD lines of the nRF51822 on my board.

When I run with just my board hooked up to a 3V power source, I get 213mV reading from the ADC.

Why would the readings vary by 48mV? (with the reading when debugging using the SEGGER SWD channels being 48mV more?).

The app I am running uses the SoftDevice S110 stack. Here is the ADC Code:

    NRF_ADC->CONFIG	= (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos) /* Not using an external reference for AREF */
											| (ADC_CONFIG_PSEL_AnalogInput7 << ADC_CONFIG_PSEL_Pos) /* Sets which AIN (0-7) to sample from */
											| (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos) /* use the internal 1.2V bandgap voltage as reference */
											| (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) /* use 1/3 prescaling */
											| (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos);	/* use 10 bit resolution when sampling */
/*!
 * \brief *->enable the ADC by setting the NRF_ADC->ENABLE register
 */
NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
/*!
 * \brief *->an ADC sample starts when NRF_ADC->TASKS_START is set to 1
 */
NRF_ADC->TASKS_START = 1;
/*!
 * \brief *->as noted in the nRF51_Series_Reference_manual v3.0.pdf: "During sampling the ADC will enter a busy state.  The ADC busy/ready state can be monitored
 * via the BUSY register."
 * \note The "White paper content - nrf51 ADC.pdf" states: ..."multiple samples are made and the ADC output value is the mean value from the sample pool...the sample pool is created
 * during 20µS period for 8 bit sample, 36µS for 9 bit sampling, and 68µS for 10 bit sampling.  I originally was going to take multiple samples and average - but heck, looks like the
 * smart folks at Nordic took care of this! :-)
 */
while (NRF_ADC->BUSY){
}
/*!
 * \brief *->the results are ready to be copied from the NRF_ADC->RESULT register.
 */
int16_t adc_result = NRF_ADC->RESULT;
/**
 * \brief *->while 31.1.6 of the nRF51_Series_Reference_manual v3.0.pdf poings out the ADC supports one-shot operation, the code seems to still have to tell the ADC to stop
 * using NRF_ADC->TASKS_STOP = 1;
 */
NRF_ADC->TASKS_STOP = 1;
/*!
Parents
  • I isolated the problem of incorrect ADC reading (i.e.: saturated 1.2V reading) to happen when ADC sampling request occurs within 10-100ms of supplying 3V power from a bench power supply (note: This does not occur when immediately supplying 3V power from a battery).

    What I don't understand: subsequent samplings maintain the saturated reading as if the ADC is "stuck" ...i.e.: the initial reading caused the ADC to not be set up to sample correctly. I would like to understand why this is happening however it would take more internal knowledge on the specifics of how the ADC works (which I do not have).

    A "hack/fix" is to delay taking an ADC sample to about 1/2 second after a reboot (in the case the power source is mains/power bench).

    Thank you very much!

  • So it is a very slow power ramp-up that causes the problem? The ADC core is shut down completely when the ADC is disabled. You could therefore try to disable the ADC, wait 2us, and enable the ADC again before sampling.

Reply Children
No Data
Related