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

sampling multiple ADC channels with PPI, adc event triggered adc_event_handler as many times as channels (instead of just once after completion of entire buffer)

Hi Al

I'm implementing multiple channel ADC with PPI 

sampling multiple ADC channels with PPI, adc event triggered adc_event_handler as many times as channels (instead of just once after completion of entire buffer)

I've used the RTC

uint32_t timer_compare_event_addr = (uint32_t)&NRF_RTC1->EVENTS_COMPARE[1]; 
uint32_t adc_sample_event_addr = nrf_drv_adc_start_task_get();

/* setup ppi channel so that timer compare event is triggering sample task in SAADC */
err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_ppi_channel_assign(m_ppi_channel, timer_compare_event_addr, adc_sample_event_addr);
APP_ERROR_CHECK(err_code);

To my understanding the size of adc buffer to be filled before triggering the event is defined so : (by ADC_BUFFER_SIZE)

APP_ERROR_CHECK(nrf_drv_adc_buffer_convert(adc_buffer,ADC_BUFFER_SIZE));

After starting the RTC with one channel everything is working fine

but if I use 2 channels (and say ADC_BUFFER_SIZE=8 element buffer), I get the event twice, the first after the first 4 and the second after the next 4.

If I use 3 channels (and say 9 element buffer ) I get the adc_ppi event 3 times (3,6,9)

I don't understand why this happens and would appreciate any insights!

Thanks a lot

------------------------

this is how I define the channels :

static nrf_drv_adc_channel_t m_channel_0_config = NRF_DRV_ADC_DEFAULT_CHANNEL(ADC_CONFIG_PSEL_AnalogInput6);
static nrf_drv_adc_channel_t m_channel_1_config = NRF_DRV_ADC_DEFAULT_CHANNEL(ADC_CONFIG_PSEL_AnalogInput7);
static nrf_drv_adc_channel_t m_channel_2_config = NRF_DRV_ADC_DEFAULT_CHANNEL(ADC_CONFIG_PSEL_AnalogInput0);

m_channel_0_config.config.config.input = NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD;
m_channel_1_config.config.config.input = NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD;
m_channel_2_config.config.config.input = NRF_ADC_CONFIG_SCALING_INPUT_ONE_THIRD;


nrf_drv_adc_channel_enable(&m_channel_0_config);
nrf_drv_adc_channel_enable(&m_channel_1_config);
nrf_drv_adc_channel_enable(&m_channel_2_config);

Related