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

How to identify adc value from its adc channel?

I use nRF52840 and SDK16 with S140 softdevice. I need 3 ADC ports. The initial code as follows.

static void adc_configure(void)
{
ret_code_t err_code = nrf_drv_saadc_init(NULL, saadc_event_handler);
APP_ERROR_CHECK(err_code);

nrf_saadc_channel_config_t config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1);

err_code = nrf_drv_saadc_channel_init(0, &config);
APP_ERROR_CHECK(err_code);

config.pin_p = NRF_SAADC_INPUT_AIN0;
err_code = nrf_drv_saadc_channel_init(1, &config);
APP_ERROR_CHECK(err_code);

config.pin_p = NRF_SAADC_INPUT_AIN4;
err_code = nrf_drv_saadc_channel_init(2, &config);
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_saadc_buffer_convert(&adc_buf[0], 1);
APP_ERROR_CHECK(err_code);

err_code = nrf_drv_saadc_buffer_convert(&adc_buf[1], 1);
APP_ERROR_CHECK(err_code);
}

I call the function of nrf_drv_saadc_sample() once 2 seconds.  And the event handler will be called 3 times. The function of saadc_event_handler will display the channel information.

But it shows as follows: How to identify adc value from which channel? Why the channel isn't display 0/1/2?

<info> app: channel=156

<info> app: channel=158

<info> app: channel=156

void saadc_event_handler(nrf_drv_saadc_evt_t const * p_event)
{
NRF_LOG_INFO("channel=%d", p_event->data.limit.channel);

....
}

Parents Reply
  • That is not possible with the ADC. You must then sample all 3 every 50µs. 

    That is at least almost true. You can uninit and init the AIN1 only when you want to sample it, but I don't think that is any more power efficient than just sampling AIN1, and discard it later, than doing changes to it all the time. Also, you would have to be very careful, what buffer item belongs to what channel when you add and remove AIN1. 

Children
No Data
Related