Hello,
In my project i am currently creating a sub-module to read the battery voltage and convert that into percentage based on the ADC value read. I have refereed the guide from Nordic to measure the battery voltage.
In the guide as well as the in the docs of SAADC peripheral of nRF52840, its mentioned that max source resistance that we can use is 800K for 40us data acquisition. But in my case i have to use high value of source resistance to reduce the leakage current. Source resistance around 10 M Ohm and R2 around 2.2 Ohm reduces the leakage current for me.
My question is can i use the source resistor value as mentioned above which are higher than 800K ? Would it damage anything ? Will my SAADC give proper readings / work properly ?
We have used high value of resistor to decrease the leakage current.
Here is my calculation using R1 and R2 value used by me ? Are this values to high for SAADC peripheral ?
Calculation based on the Reference Guide:
R1 = 10 M Ohm
R2 = 2.2 M Ohm
Maximum voltage: 4.2 V * (2.2 M/(2.2 M + 10 M)) = 0.757377049 V
Minimum voltage: 2.7 V * (2.2 M/(2.2 M + 10 M)) = 0.540983607 V
ADC value at 4.2 V – 12 bit setup: 0.757377049 V * (1/5) / 0.6 V * 4095 = 1033.819671885
ADC value at 2.7 V - 12 bit setup: 0.540983607 V * (1/5) / 0.6 V * 4095 = 739
So voltage measured across pins will be in range of .75V to .54V.
So if the above resistor values are deemed appropriated can you please check my low power code for SAADC Init function which will be called every 5 minutes on app timer timeout.
Here is code implementation for the SAADC peripheral, for the same configuration. I am using 12bit resolution with TACQ value of 40us. I am using oversampling with burst enabled and my sample buffer size is of 1.
/**
* @brief Function for initializing the ADC module in Single Shot mode
for Battery Voltage Monitoring.
* @param void
* @retval BSP Status
*/
uint32_t Battery_Voltage_Monitior_Init(void)
{
ret_code_t err_code;
nrf_drv_saadc_config_t saadc_config;
nrf_saadc_channel_config_t channel_config0;
/* Configure SAADC: Set resolution to 12-bit and oversample to 8x.
This will make the SAADC output a single averaged value when the
SAMPLE task is triggered 8 times. */
saadc_config.resolution = NRF_SAADC_RESOLUTION_12BIT;
saadc_config.oversample = SAADC_OVERSAMPLE;
saadc_config.interrupt_priority = APP_IRQ_PRIORITY_LOW;
saadc_config.low_power_mode = true;
/* Initialize SAADC */
err_code = nrf_drv_saadc_init(&saadc_config, battery_voltlage_callback_handler);
APP_ERROR_CHECK(err_code);
/* Struct to hold the configurations ADC channel. */
nrf_saadc_channel_config_t channel_config = NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(BATTERY_VOLTAGE_MONITOR_PIN);
channel_config.gain = SAADC_CH_CONFIG_GAIN_Gain1_5;
channel_config.acq_time = NRF_SAADC_ACQTIME_40US;
/* Initialize the ADC Channel with ADC channel configuration */
err_code = nrfx_saadc_channel_init(0, &channel_config);
APP_ERROR_CHECK(err_code);
/* Configure burst mode for channel 0. Burst is useful together
with oversampling. When triggering the SAMPLE task in burst mode,
the SAADC will sample "Oversample" number of times as fast as it
can and then output a single averaged value to the RAM buffer. */
if(SAADC_BURST_MODE)
{
NRF_SAADC->CH[0].CONFIG |= 0x01000000;
}
/* Allocate buffer to store sample data using EASYDMA */
err_code = nrfx_saadc_buffer_convert(m_buffer_pool[0], SAADC_SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
/* Allocate second buffer where the values will be stored if overwritten on first before reading*/
err_code = nrfx_saadc_buffer_convert(m_buffer_pool[1], SAADC_SAMPLES_IN_BUFFER);
APP_ERROR_CHECK(err_code);
// nrf_gpio_cfg_output(BATTERY_MONITOR_TRIG_PIN);
/* Disable the Battery monitor section */
// Trigger_Device_State(DEV_BATTERY_MONITOR,STATE_ON);
nrf_delay_us(100);
return err_code;
}
Waiting for some help as soon as possible.