<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to configuration multi saadc channel with different sample interval</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/35455/how-to-configuration-multi-saadc-channel-with-different-sample-interval</link><description>Dear Sir： 
 
 i seen the proximity example，the battery level measure is init by a m_battery_timer_id ，in my project ， 
 
 
 i need user multi saadc channel ，and different channel has different sample interval ， but the api nrf_drv_saadc_init seems only</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 15 Jun 2018 13:30:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/35455/how-to-configuration-multi-saadc-channel-with-different-sample-interval" /><item><title>RE: How to configuration multi saadc channel with different sample interval</title><link>https://devzone.nordicsemi.com/thread/136385?ContentTypeID=1</link><pubDate>Fri, 15 Jun 2018 13:30:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef28e9d3-2ce3-4318-9b08-6f204fe86055</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It is not possible to set different sample interval for each channel in the SAADC peripheral, you will have to handle this manually in your application by init/uninit the channels before and after each sample. Something like this should work:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;bool sample_in_progress = false;
uint8_t current_sample_channel;
int16_t channel0_sample;
int16_t channel1_sample;

nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);

timer_handler_0()
{
  if(!sample_in_progress)
  {
    current_sample_channel = 0;
    channel_config.pselp = NRF_SAADC_INPUT_AIN0;
    nrf_drv_saadc_channel_init(0,channel_config);
    sample_in_progress = true;
    nrf_drv_saadc_sample();
  }
}

timer_handler_1()
{
  if(!sample_in_progress)
  {
    current_sample_channel = 1;
    channel_config.pselp = NRF_SAADC_INPUT_AIN1;
    nrf_drv_saadc_channel_init(0,channel_config);
    sample_in_progress = true;
    nrf_drv_saadc_sample();
  }
}

saacd_callback_handler()
{
  if(current_sample_channel == 0)
  {
    channel0_sample = result;
  }
  else 
  {
    channel1_sample = result;
  }
  nrf_drv_saadc_channel_uninit(0);
  sample_in_progress = false;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Note that this is not intended as a complete example, it only shows how to do the switching between channels. Also note that if the other channel is sampling, this code will simply skip the sample for the channel. If you need to sample each channel every time, you need to wait for the other channel to finish before switching channel. Make sure you get your priorities correct if you need to do waiting in interrupt context.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>