<?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>Why is saadc reading taking more than expected time and why do i have to put delay between readings</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/58051/why-is-saadc-reading-taking-more-than-expected-time-and-why-do-i-have-to-put-delay-between-readings</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 27 Feb 2020 08:33:51 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/58051/why-is-saadc-reading-taking-more-than-expected-time-and-why-do-i-have-to-put-delay-between-readings" /><item><title>RE: Why is saadc reading taking more than expected time and why do i have to put delay between readings</title><link>https://devzone.nordicsemi.com/thread/236716?ContentTypeID=1</link><pubDate>Thu, 27 Feb 2020 08:33:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:758ff6fe-f9a4-4818-b962-60ddc3079400</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;You use PPI in the same way as you&amp;#39;ve connected the TIMER&amp;#39;s COMPARE event to the SAADC&amp;#39;s SAMPLE task. It&amp;#39;s the same procedure to connect any event to any task.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Call&amp;nbsp;&lt;a title="nrf_saadc_event_address_get" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__nrf__saadc__hal.html?cp=7_1_6_9_0_30_2_32#ga283b4029280ebb5f11dd7410a2363d97"&gt;nrf_saadc_event_address_get&lt;/a&gt;(&lt;em&gt;NRF_SAADC_EVENT_END&lt;/em&gt;) to get the address of the END event.&lt;br /&gt;Call&amp;nbsp;&lt;a title="nrfx_timer_task_address_get" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__nrfx__timer.html?cp=7_1_6_9_0_37_1_24#gaebf0e0f2450dba5c6a8643aaf2b780ba"&gt;nrfx_timer_task_address_get&lt;/a&gt;(Your_Timer_Instance, &lt;em&gt;NRF_TIMER_TASK_STOP&lt;/em&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;) to get the address of the STOP task.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;The PPI example will show you how to set up a PPI channel with an arbitrary event and task addresses.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why is saadc reading taking more than expected time and why do i have to put delay between readings</title><link>https://devzone.nordicsemi.com/thread/236635?ContentTypeID=1</link><pubDate>Wed, 26 Feb 2020 16:45:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7b3d296-4c14-433f-84dc-a658662b3c3e</guid><dc:creator>robin</dc:creator><description>&lt;p&gt;Thanks I think I almost have it now, one last question&lt;/p&gt;
&lt;p&gt;&amp;quot;&lt;span&gt;You can connect the SAADC&amp;#39;s END event to the TIMER&amp;#39;s STOP task to do that. Then you don&amp;#39;t have to execute any code to do it.&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;How do I do this ?&lt;br /&gt;maybe you could show me how this would be done in the nordic saadc exmaple that comes with SDK 16.0.0&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;RObin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why is saadc reading taking more than expected time and why do i have to put delay between readings</title><link>https://devzone.nordicsemi.com/thread/236463?ContentTypeID=1</link><pubDate>Wed, 26 Feb 2020 09:35:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1880cac8-9b3c-427c-a763-0c5c9f1b0cc0</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;All you need to enable a channel is to write to the&amp;nbsp;&lt;span&gt;NRF_SAADC-&amp;gt;CH[x].PSELP register, to disable a channel you clear it.&lt;br /&gt;&lt;br /&gt;You don&amp;#39;t need to call&amp;nbsp;nrf_drv_ppi_channel_disable(m_ppi_channel);, you just need to stop the TIMER. You can connect the SAADC&amp;#39;s END event to the TIMER&amp;#39;s STOP task to do that. Then you don&amp;#39;t have to execute any code to do it.&lt;br /&gt;&lt;br /&gt;To start the timer again you call&amp;nbsp;&lt;/span&gt;nrfx_timer_resume(), or NRF_TIMERn-&amp;gt;TASKS_START = 1; replace &amp;#39;n&amp;#39; with your timer instance number.&lt;br /&gt;&lt;br /&gt;&amp;quot;&lt;span&gt;Is this call&amp;nbsp;&amp;nbsp;nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, ADC_SAMPLES_BUFFER_LEN);&lt;/span&gt;&lt;br /&gt;&lt;span&gt;in the event handler starting the next read cycle while I am still processing the first &amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;No, it writes the address and size of the next buffer to the RESULT.PTR and .MAXCOUNT registers and triggers the START task. It does not start any sampling, only the SAMPLE task can trigger a sample event. You can safely process your previous buffer until the next time you call&amp;nbsp;nrf_drv_saadc_buffer_convert.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why is saadc reading taking more than expected time and why do i have to put delay between readings</title><link>https://devzone.nordicsemi.com/thread/236352?ContentTypeID=1</link><pubDate>Tue, 25 Feb 2020 17:00:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6d9f0420-69cc-436b-999d-fdcd376f894e</guid><dc:creator>robin</dc:creator><description>&lt;p&gt;Thanks Haarkonsh&lt;br /&gt;Currently in my existing code I am calling&amp;nbsp;&lt;br /&gt;nrf_drv_ppi_channel_disable(m_ppi_channel);&lt;br /&gt;In the ADC read complete event handler as it looked like another ADC read was being started.&lt;br /&gt;And this is why I am calling&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span&gt;nrf_drv_ppi_channel_enable(m_ppi_channel);&amp;nbsp;&amp;nbsp; &amp;nbsp;to start the next ADC read.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;So looking at my code i provided have I setup the SAADCC/PPI/TIMER feature correctly so it runs once for the number of channels enabled and samples ?&lt;br /&gt;If it is ok and I shouldnt have to call&amp;nbsp;nrf_drv_ppi_channel_disable(m_ppi_channel);&amp;nbsp; in the saadc read event complete handler , then&amp;nbsp;how do I restart it again for the next read after I disable and enable channels for the next read using&amp;nbsp;NRF_SAADC-&amp;gt;CH[&amp;lt;next channel&amp;gt;].PSELP = &amp;lt;pin number&amp;gt;;&lt;br /&gt;&lt;br /&gt;Is this call&amp;nbsp;&amp;nbsp;nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, ADC_SAMPLES_BUFFER_LEN);&lt;br /&gt;in the event handler starting the next read cycle while I am still processing the first&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Robin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why is saadc reading taking more than expected time and why do i have to put delay between readings</title><link>https://devzone.nordicsemi.com/thread/236302?ContentTypeID=1</link><pubDate>Tue, 25 Feb 2020 14:56:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:695c11d7-ac5c-471c-9a80-3557509bc4e0</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;&amp;quot;Then this to start the next read&lt;br /&gt;nrf_drv_ppi_channel_enable(m_ppi_channel);&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is that correct ?&amp;quot;&lt;/p&gt;
&lt;p&gt;No, this line enables the given channe, just replace &amp;lt;next channel&amp;gt; and &amp;lt;pin number&amp;gt; whith the values you want :&lt;br /&gt;&lt;span&gt;NRF_SAADC-&amp;gt;CH[&amp;lt;next channel&amp;gt;].PSELP = &amp;lt;pin number&amp;gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&amp;quot;&lt;span&gt;Why do I have to call&amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;nrf_drv_saadc_buffer_convert(m_buffer_pool[0], ADC_SAMPLES_BUFFER_LEN);&lt;/span&gt;&lt;br /&gt;&lt;span&gt;I have a call in the event handler&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, ADC_SAMPLES_BUFFER_LEN);&lt;/span&gt;&lt;br /&gt;&lt;span&gt;Do I need to still do this, or do I only need this one in the event handler as I have 2 buffers, which I may not need thinking about this as we dont read the adc continuously and therefore need time to process a read while another is going on.&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This will probably work, but I have not tried to change the channel settings after I&amp;#39;ve called the START task, therefore I thought it best to do it after.&lt;br /&gt;&lt;br /&gt;&amp;quot;When I enable 2 of the ADC inputs I see it will then scan these sequentially, will the results be put in one buffer or is this why I would need 2 buffers. If its just one then I would need to double its size and I believe the results would be interleaved.&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;One buffer, you need to double the size, and they will be stored sequentially(interleaved), f.ex&lt;br /&gt;&lt;br /&gt; [Chan1][Chan2][Chan1][Chan2]...&lt;br /&gt;[32-bit word 0 ][32-bit word 1&amp;nbsp; ]...&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why is saadc reading taking more than expected time and why do i have to put delay between readings</title><link>https://devzone.nordicsemi.com/thread/236063?ContentTypeID=1</link><pubDate>Mon, 24 Feb 2020 16:52:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:721a1abc-77ad-4e76-8d0a-ab64f2bff671</guid><dc:creator>robin</dc:creator><description>&lt;p&gt;Thanks Haakonsh I was looking at this approach and wondered if it would work,&lt;br /&gt;So using your code for each adc read&amp;nbsp; i would simply do this&amp;nbsp;&lt;br /&gt;NRF_SAADC-&amp;gt;CH[&amp;lt;previous channel&amp;gt;].PSELP = 0;&lt;br /&gt;NRF_SAADC-&amp;gt;CH[&amp;lt;next channel&amp;gt;].PSELP = &amp;lt;pin number&amp;gt;;&lt;br /&gt;err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], ADC_SAMPLES_BUFFER_LEN);&lt;br /&gt;Then this to start the next read&lt;br /&gt;nrf_drv_ppi_channel_enable(m_ppi_channel);&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is that correct ?&lt;/p&gt;
&lt;p&gt;Why do I have to call&amp;nbsp;&lt;span&gt;&amp;nbsp;nrf_drv_saadc_buffer_convert(m_buffer_pool[0], ADC_SAMPLES_BUFFER_LEN);&lt;/span&gt;&lt;br /&gt;I have a call in the event handler&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;br /&gt;nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, ADC_SAMPLES_BUFFER_LEN);&lt;br /&gt;Do I need to still do this, or do I only need this one in the event handler as I have 2 buffers, which I may not need thinking about this as we dont read the adc continuously and therefore need time to process a read while another is going on.&lt;/p&gt;
&lt;p&gt;When I enable 2 of the ADC inputs I see it will then scan these sequentially, will the results be put in one buffer or is this why I would need 2 buffers. If its just one then I would need to double its size and I believe the results would be interleaved.&lt;/p&gt;
&lt;p&gt;UPDATE: I tried this code but I get an BUSy ERROR when I call&lt;br /&gt;&lt;span&gt;nrf_drv_saadc_buffer_convert(m_buffer_pool[0], ADC_SAMPLES_BUFFER_LEN);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;to start the next adc read on different pin&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Robin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why is saadc reading taking more than expected time and why do i have to put delay between readings</title><link>https://devzone.nordicsemi.com/thread/235889?ContentTypeID=1</link><pubDate>Mon, 24 Feb 2020 09:29:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34e25490-3467-44ab-ab88-31f06e9035ca</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;There&amp;#39;s is something that you can do that will lower the overhead by quite a bit. When you initialize the SAADC you should also initialize all three channels with their proper settings, then call:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//Disable all three channels
NRF_SAADC-&amp;gt;CH[0].PSELP = 0;
NRF_SAADC-&amp;gt;CH[1].PSELP = 0;
NRF_SAADC-&amp;gt;CH[2].PSELP = 0;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;For each time you want to sample a channel:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Disable last channel used
NRF_SAADC-&amp;gt;CH[&amp;lt;previous channel&amp;gt;].PSELP = 0;

// Enable the next channel
NRF_SAADC-&amp;gt;CH[&amp;lt;next channel&amp;gt;].PSELP = &amp;lt;pin number&amp;gt;;

// Prepare the data buffer
err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], ADC_SAMPLES_BUFFER_LEN);
APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The channel settings will be stored even though they are disabled, you do not need to un-initialize the SAADC driver.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why is saadc reading taking more than expected time and why do i have to put delay between readings</title><link>https://devzone.nordicsemi.com/thread/235784?ContentTypeID=1</link><pubDate>Fri, 21 Feb 2020 17:10:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45fd3d1f-dab8-4899-866d-fbe75c2d2252</guid><dc:creator>robin</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I will explain it again hopefully it will be clearer. (The code is at the bottom with some I missed)&lt;br /&gt;We have 3 ADC inputs that require different gain settings, we use PPI/TIMER/SAADC to read the ADC as required. We DONT want to ever scan all 3 sequentially, it will vary between scanning individually and some times scan a combination of any 2.&amp;nbsp;&lt;br /&gt;We need to keep scan time and current to minimum possible.&lt;br /&gt;I know theoretically the scan time for one ADC is going to be 5us x 32 = 160us , the only over head is the code to set it up and then collect the result. That is why I wanted to check that I am not doing any unnecessary work, and from what you have said it seems I could pre-configure 3 channels at start up and then just enable the ones I need on each scan call.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please the code/functions at the bottom here are the calls I make to those functions, how can this be improved and changed so I can use less code ?&lt;/p&gt;
&lt;p&gt;1) POWER UP: I call&lt;br /&gt;&amp;nbsp; &amp;nbsp; saadc_sampling_event_init();&lt;br /&gt;&amp;nbsp; &amp;nbsp; saadc_adc_init();&lt;br /&gt;&lt;br /&gt;2) VERY FIRST ADC READ: I call&lt;br /&gt;&amp;nbsp; &amp;nbsp; saadc_channel_init( &amp;lt;the adc input I want IE AIN0....AINx&amp;gt;, &amp;lt;gain required&amp;gt; );&lt;br /&gt;&amp;nbsp; &amp;nbsp; saadc_sampling_event_enable();&lt;/p&gt;
&lt;p&gt;3) SUBSEQUENT ADC READS: I call&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;saadc_setup_next_adc_read(&lt;span&gt;&amp;lt;the adc input I want IE AIN0....AINx&amp;gt;&lt;/span&gt;);&amp;nbsp; &amp;nbsp;# Gain is determined in function&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;----------------------------&lt;/p&gt;
&lt;p&gt;1) POWER UP&lt;/p&gt;
&lt;p&gt;This is where our timer is setup&lt;/p&gt;
&lt;p&gt;void saadc_sampling_event_init(void) {&lt;br /&gt; ret_code_t err_code;&lt;/p&gt;
&lt;p&gt;err_code = nrf_drv_ppi_init();&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;&lt;br /&gt; timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;&lt;br /&gt; err_code = nrf_drv_timer_init(&amp;amp;m_timer, &amp;amp;timer_cfg, timer_handler);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;/* setup m_timer for compare event every 5us 200Khz */&lt;br /&gt; uint32_t ticks = nrf_drv_timer_us_to_ticks(&amp;amp;m_timer, 5); // Note same as prototype&lt;br /&gt;&lt;br /&gt; nrf_drv_timer_extended_compare(&amp;amp;m_timer,&lt;br /&gt; NRF_TIMER_CC_CHANNEL0,&lt;br /&gt; ticks,&lt;br /&gt; NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,&lt;br /&gt; false);&lt;br /&gt; nrf_drv_timer_enable(&amp;amp;m_timer);&lt;/p&gt;
&lt;p&gt;uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&amp;amp;m_timer,&lt;br /&gt; NRF_TIMER_CC_CHANNEL0);&lt;br /&gt; uint32_t saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();&lt;/p&gt;
&lt;p&gt;/* setup ppi channel so that timer compare event is triggering sample task in SAADC */&lt;br /&gt; err_code = nrf_drv_ppi_channel_alloc(&amp;amp;m_ppi_channel);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,&lt;br /&gt; timer_compare_event_addr,&lt;br /&gt; saadc_sample_task_addr);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;void saadc_adc_init(void) {&lt;/p&gt;
&lt;p&gt;ret_code_t err_code;&lt;br /&gt; nrf_drv_saadc_config_t adc_config;&lt;/p&gt;
&lt;p&gt;adc_config.resolution = (nrf_saadc_resolution_t)NRF_SAADC_RESOLUTION_12BIT;&lt;br /&gt; adc_config.oversample = (nrf_saadc_oversample_t)NRF_SAADC_OVERSAMPLE_DISABLED;&lt;br /&gt; adc_config.interrupt_priority = NRFX_SAADC_CONFIG_IRQ_PRIORITY;&lt;br /&gt; adc_config.low_power_mode = NRFX_SAADC_CONFIG_LP_MODE;&lt;/p&gt;
&lt;p&gt;err_code = nrf_drv_saadc_init(&amp;amp;adc_config, saadc_callback);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;---------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;span&gt;2) VERY FIRST ADC READ&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In here we setup the channel to use, I assume we could do this for all 3 inputs using different channels on power up, but will this enable them ?&amp;nbsp; We want to enable the one or two we want at the time and then read&lt;/p&gt;
&lt;p&gt;void saadc_channel_init(saadc_adc_input_t adc_input, saadc_adc_input_gain_t adc_ip_gain) {&lt;/p&gt;
&lt;p&gt;ret_code_t err_code;&lt;br /&gt; nrf_saadc_channel_config_t channel_config;&lt;/p&gt;
&lt;p&gt;channel_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;&lt;br /&gt; channel_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;&lt;br /&gt; channel_config.gain = adc_ip_gain;&lt;br /&gt; channel_config.reference = NRF_SAADC_REFERENCE_INTERNAL;&lt;br /&gt; channel_config.acq_time = NRF_SAADC_ACQTIME_3US; // Note this was 3us on the prototype&lt;br /&gt; channel_config.mode = NRF_SAADC_MODE_SINGLE_ENDED;&lt;br /&gt; channel_config.burst = NRF_SAADC_BURST_DISABLED;&lt;/p&gt;
&lt;p&gt;channel_config.pin_p = (nrf_saadc_input_t)(adc_input);&lt;br /&gt; channel_config.pin_n = NRF_SAADC_INPUT_DISABLED;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; // Channel number can be 0 -7 We may wish to use same channel for each ADC we read &lt;br /&gt; err_code = nrf_drv_saadc_channel_init(0, &amp;amp;channel_config);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], ADC_SAMPLES_BUFFER_LEN);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], ADC_SAMPLES_BUFFER_LEN);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;void saadc_sampling_event_enable(void)&lt;br /&gt;{&lt;/p&gt;
&lt;p&gt;ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;-----------------------------------&lt;/p&gt;
&lt;p&gt;&lt;span&gt;3) SUBSEQUENT ADC READS&lt;br /&gt;&lt;/span&gt;This is called for subsequent reads which in turn calls functions above. Could this be simplified I just want to change the ADC input and then read again.&lt;/p&gt;
&lt;p&gt;void saadc_setup_next_adc_read(saadc_adc_input_t adc_input) {&lt;/p&gt;
&lt;p&gt;saadc_adc_uninit();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;saadc_ctrl_channel_uninit(last_adc_read_state);&lt;/p&gt;
&lt;p&gt;saadc_adc_init();&lt;/p&gt;
&lt;p&gt;if (adc_input == SAADC_ADC_INPUT_VREF)&lt;br /&gt; saadc_channel_init(adc_input, SAADC_ADC_INPUT_GAIN_1_2);&lt;br /&gt; else if (adc_input == SAADC_ADC_INPUT_OPAMP_OUT)&lt;br /&gt; saadc_channel_init(adc_input, SAADC_ADC_INPUT_GAIN_1_4);&lt;br /&gt; else if (adc_input == SAADC_ADC_INPUT_BATTERY)&lt;br /&gt; saadc_channel_init(adc_input,SAADC_ADC_INPUT_GAIN_1_6);&lt;br /&gt; else&lt;br /&gt; NRF_LOG_ERROR(&amp;quot;saadc_setup_next_adc_read() Invalid ADC input\n&amp;quot;);&lt;/p&gt;
&lt;p&gt;ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);&lt;br /&gt; APP_ERROR_CHECK(err_code);&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why is saadc reading taking more than expected time and why do i have to put delay between readings</title><link>https://devzone.nordicsemi.com/thread/235663?ContentTypeID=1</link><pubDate>Fri, 21 Feb 2020 09:42:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ab54bce-4dd0-4d99-bb4c-fe2d127ad924</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;&lt;span&gt;&amp;quot;As per my code above&amp;nbsp;I call&amp;nbsp; &amp;nbsp;nrf_drv_ppi_channel_enable(m_ppi_channel);&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Yes, but what event triggers this channel? Are you using a TIMER?&lt;br /&gt;&lt;br /&gt;&amp;quot;I didnt think of that or was aware I could, I am relatively new to this. &amp;quot;&lt;br /&gt;From the SAADC specification:&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;When multiple channels are enabled, they are sampled successively in a sequence starting with the lowest channel number. The time it takes to sample all enabled channels is given as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Total time &amp;lt; Sum(CH[x].t&lt;sub&gt;ACQ&lt;/sub&gt;+t&lt;sub&gt;CONV&lt;/sub&gt;), x is the number of enabled channels&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A DONE event is generated for every single completed conversion, and an END event is generated when multiple samples, as specified in&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/saadc.html?cp=4_0_0_5_22#register.RESULT.MAXCNT"&gt;RESULT.MAXCNT&lt;/a&gt;, have been written to memory.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;br /&gt;&lt;br /&gt;You can enable three channels with different gain settings, increase the buffer to 96, trigger the sample task 32 times to fill the buffer.&amp;nbsp;&lt;br /&gt;See&amp;nbsp;&lt;a title="Scan mode" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/saadc.html?cp=4_2_0_36_4_3#saadc_operationmodes_scan"&gt;Scan mode&lt;/a&gt;.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&amp;quot;We need this to be as fast as possible.&amp;nbsp;&amp;quot;&lt;br /&gt;This will take 32samples x 3channels x (3µs+2µs) = 480µs if the sample task is triggered as fast as possible, f.ex every 5µs, or 80 ticks of a 16MHz TIMER.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;quot;We dont scan all 3 sequentially&amp;nbsp;in the same order, sometimes its 2 sometimes all 3 and in different order. &amp;quot;&lt;br /&gt;You can&amp;#39;t change the order the channels are sampled in when using scan mode, but you can enable/disable a channel during between samples.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Can you specify exactly what it is you&amp;#39;re trying to achieve with the SAADC?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why is saadc reading taking more than expected time and why do i have to put delay between readings</title><link>https://devzone.nordicsemi.com/thread/235559?ContentTypeID=1</link><pubDate>Thu, 20 Feb 2020 16:58:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63644fb7-f716-4f41-94d1-2feb7af0d5a7</guid><dc:creator>robin</dc:creator><description>&lt;p&gt;&lt;span&gt;Do you only take one sample before you change the SAADC settings?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Its set up to take 32 samples controlled by the PPI, so we kick it off and when its done we have 32 samples in the buffer. We would then change the input and gain and run again on the new input.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Do you disable the ppi channel after you&amp;#39;ve taken one sample?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;No , see the event handler at the bottom of this reply, you now have all the code involved,&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NOTE I commented out all my logging when I was measuring the time&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;What do you use to trigger m_ppi_channel?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; As per my code above&amp;nbsp;I call&amp;nbsp; &amp;nbsp;nrf_drv_ppi_channel_enable(m_ppi_channel);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Why do you not want to use more than one channel?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I didnt think of that or was aware I could, I am relatively new to this.&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; So are you suggesting I can pre-configure 3 channels for the 3 inputs I have and then just switch the channel for each read cycle. If so can you point me to an example ?&lt;br /&gt;I assume I would be able to keep the remaining code the same using the one timer and ppi channel ?&lt;br /&gt;&lt;br /&gt;In our application we have 3 gpios connected to 3 different analog sources, apart from the input pin being different the gain is different for all 3.&amp;nbsp; We need this to be as fast as possible. We dont scan all 3 sequentially&amp;nbsp;in the same order, sometimes its 2 sometimes all 3 and in different order.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks Robin&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Why is saadc reading taking more than expected time and why do i have to put delay between readings</title><link>https://devzone.nordicsemi.com/thread/235397?ContentTypeID=1</link><pubDate>Thu, 20 Feb 2020 10:23:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1d6506b-c4ed-4300-b351-fa63009dd5e7</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Do you only take one sample before you change the SAADC settings?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you disable the ppi channel after you&amp;#39;ve taken one sample?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;What do you use to trigger m_ppi_channel?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Why do you not want to use more than one channel?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>