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;
/*!