Hi
i am trying to reduce the adc read times to a minimum we currently have it setup for 3us acq and 32 samples so expecting something close to 160us
Its getting around 250us.
Below is how I set it up and do the adc reads
You will see for each read I need to change gain and input pin
Q1 Am I doing the correct thing below (it works) or am i doing something unnecessary
and making the read cycles longer than necessary.
If my code is good any suggestions on how we can reduce the time
Q2 I am finding I have to put large delays in order of milliseconds to get good readings every time
if I dont some readings come back all FS IE 4095
FIRST TIME THROUGH
void saadc_adc_init(void) {
ret_code_t err_code;
nrf_drv_saadc_config_t adc_config;
adc_config.resolution = (nrf_saadc_resolution_t)NRF_SAADC_RESOLUTION_12BIT;
adc_config.oversample = (nrf_saadc_oversample_t)NRF_SAADC_OVERSAMPLE_DISABLED;
adc_config.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY;
adc_config.low_power_mode = NRFX_SAADC_CONFIG_LP_MODE;
err_code = nrf_drv_saadc_init(&adc_config, saadc_callback);
APP_ERROR_CHECK(err_code);
}
CALL following function
to setup for the provided pin and gain
void saadc_channel_init(saadc_adc_input_t adc_input, saadc_adc_input_gain_t adc_ip_gain) {
ret_code_t err_code;
nrf_saadc_channel_config_t channel_config;
channel_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;
channel_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
channel_config.gain = adc_ip_gain;
channel_config.reference = NRF_SAADC_REFERENCE_INTERNAL;
channel_config.acq_time = NRF_SAADC_ACQTIME_3US; // Note this was 3us on the prototype
channel_config.mode = NRF_SAADC_MODE_SINGLE_ENDED;
channel_config.burst = NRF_SAADC_BURST_DISABLED;
channel_config.pin_p = (nrf_saadc_input_t)(adc_input);
channel_config.pin_n = NRF_SAADC_INPUT_DISABLED;
// Channel number can be 0 -7 We may wish to use same channel for each ADC we read
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], ADC_SAMPLES_BUFFER_LEN);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], ADC_SAMPLES_BUFFER_LEN);
APP_ERROR_CHECK(err_code);
}
Call the following to start ADC
ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
APP_ERROR_CHECK(err_code);
THEN ON SUBSEQUENT adc reads I do this
nrf_drv_saadc_uninit();
Call my function above
saadc_adc_init(..)
Call my function above to init with new pin and gain
saadc_channel_init(...
Then enable it
ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);
APP_ERROR_CHECK(err_code);