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
  • Hi

    I dont think I have seen this issue before. Some thoughts:

    • Is the result different if you use another analog input pin, e.g. #5 ?, just thinking that there is possibly another adjacent pin that has some activity that causes disturbance.
    • Do you have LPCOMP enabled. That is known to cause some issues.
    • What are you measuring on the analog input pin? Does the external circuit have high impedance?
  • Update: I checked the AC side worked as expected. E.g.: on a AIN I expected to see 1.46V going in. This was true in all set ups.

    I then disabled LPCOMP. I also changed the macro for the clock - I do not have an external crystal on my board. Neither of these changes made a difference in getting 1.2V when NOT going through Eclipse debugger.

    So - since I observe this behavior only when the SWD lines are being used for debuging (i.e.: nrf51 DK is providing debug out), i assume there is something different when Eclipse/debug reads/writes to the SWD lines? Does this make sense? Any thoughts on why?

Reply
  • Update: I checked the AC side worked as expected. E.g.: on a AIN I expected to see 1.46V going in. This was true in all set ups.

    I then disabled LPCOMP. I also changed the macro for the clock - I do not have an external crystal on my board. Neither of these changes made a difference in getting 1.2V when NOT going through Eclipse debugger.

    So - since I observe this behavior only when the SWD lines are being used for debuging (i.e.: nrf51 DK is providing debug out), i assume there is something different when Eclipse/debug reads/writes to the SWD lines? Does this make sense? Any thoughts on why?

Children
No Data
Related