Hi,
I'm using nRF52832 with S140 v7.2.0 base on nRF5_SDK_17.1.0. I use PCA10100 development kit and set VDDH/5 as input and use internal reference (0.6 V) to do the battery measure. I found the battery voltage measured is a bit high(3.3v) than the actural voltage(3.0v) . The ADC configuration as bellow:
void saadc_init(void) { ret_code_t err_code; nrf_saadc_channel_config_t channel_config_NTC = { .resistor_p = NRF_SAADC_RESISTOR_DISABLED, .resistor_n = NRF_SAADC_RESISTOR_DISABLED, .gain = NRF_SAADC_GAIN1_6, .reference = NRF_SAADC_REFERENCE_VDD4, .acq_time = NRF_SAADC_ACQTIME_10US, .mode = NRF_SAADC_MODE_SINGLE_ENDED, .burst = NRF_SAADC_BURST_DISABLED, .pin_p = NRF_SAADC_INPUT_AIN5, .pin_n = NRF_SAADC_INPUT_DISABLED }; nrfx_saadc_config_t saadc_NTC_config = { .resolution = NRF_SAADC_RESOLUTION_12BIT ///< Resolution configuration. }; err_code = nrf_drv_saadc_init(&saadc_NTC_config, saadc_NTC_callback); APP_ERROR_CHECK(err_code); err_code = nrf_drv_saadc_channel_init(1, &channel_config_NTC); APP_ERROR_CHECK(err_code); err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], SAMPLES_IN_BUFFER); APP_ERROR_CHECK(err_code); }
I use the ADC result to caculate valtage such as: valtage=(ADC_VALUE*6*1200mv)/1024*5, 6 means NRF_SAADC_GAIN1_6, 1200mv means NRF_SAADC_REFERENCE_VDD4, 1024 means NRF_SAADC_RESOLUTION_10BIT and 5 means VDDH/5 as input.
Is there any problem with my code?
Besides, I want to use 4 ADC in total. But when I use the same way to configure another ADC as follow, it returns 0x11 error.
nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0); err_code = nrf_drv_saadc_init(NULL, saadc_callback); APP_ERROR_CHECK(err_code); err_code = nrf_drv_saadc_channel_init(0, &channel_config); APP_ERROR_CHECK(err_code); err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], SAMPLES_IN_BUFFER); APP_ERROR_CHECK(err_code); err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], SAMPLES_IN_BUFFER); APP_ERROR_CHECK(err_code);
Could you help me have a look? Thanks a lot.