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

Strange value of ADC nrf51822

I'm coding a feature to measure the battery voltage via the internal VDD with an ADC.

The result I get from a 2,75 voltage source is 170.

When using the calculation ((((ADC_VALUE) * 1200 ) / 1023) * 3) my output would be 598mV.

The calculation is coming from: ((((ADC_VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLTS) / 10BITS) * ADC_PRE_SCALING_COMPENSATION)

The ADC measures the same voltage when using 8 or 9 bit selection.

We use the nRF5 SDK 12.2.0. See below my code:

INIT:

ret_code_t ret_code;

	nrf_drv_adc_config_t adc_config = NRF_DRV_ADC_DEFAULT_CONFIG;        //Get default ADC configuration

	static nrf_drv_adc_channel_t adc_channel_config;

	adc_channel_config.config.config.resolution = NRF_ADC_CONFIG_RES_10BIT;
	adc_channel_config.config.config.input      = NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD;
	adc_channel_config.config.config.reference  = NRF_ADC_CONFIG_REF_VBG;
	adc_channel_config.config.config.ain        = NRF_ADC_CONFIG_INPUT_DISABLED;

	ret_code = nrf_drv_adc_init(&adc_config, ADC_event_handler);              //Initialize the ADC
	APP_ERROR_CHECK(ret_code);

	nrf_drv_adc_channel_enable(&adc_channel_config);                          //Configure and enable an ADC channel

SAMPLE:

	ret_code_t ret_code;
	uint32_t p_is_running = 0;

	ret_code = nrf_drv_adc_buffer_convert(adc_buffer, 6);       // Allocate buffer for ADC
	APP_ERROR_CHECK(ret_code);

	//Request the external high frequency crystal for best ADC accuracy. For lowest current consumption, don't request the crystal.
	sd_clock_hfclk_request();

	while(! p_is_running) {          //wait for the hfclk to be available
	    sd_clock_hfclk_is_running((&p_is_running));
	}

	for (uint32_t i = 0; i < 6; i++)
	{
	    while((NRF_ADC->BUSY & ADC_BUSY_BUSY_Msk) == ADC_BUSY_BUSY_Busy) {}   //Wait until the ADC is finished sampling

	    nrf_drv_adc_sample();        // Trigger ADC conversion
	}

Bluetooth does not run at the moment I do a sample.

Maybe good to add, we are writing code in C++.

Parents Reply Children
No Data
Related