<?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>nRF52 SAADC Double Buffering</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/14116/nrf52-saadc-double-buffering</link><description>Hi, 
 I am trying to use the SAADC to periodically sample an input from AIN0 and send the resultant data over a BLE link to a phone. Going through the forums I saw that the ble_app_proximity is a good example of this so I went ahead to try and understand</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 02 Aug 2016 01:05:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/14116/nrf52-saadc-double-buffering" /><item><title>RE: nRF52 SAADC Double Buffering</title><link>https://devzone.nordicsemi.com/thread/53952?ContentTypeID=1</link><pubDate>Tue, 02 Aug 2016 01:05:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7929298c-23b6-4828-9900-cde7c90ae953</guid><dc:creator>Sterling Hughes</dc:creator><description>&lt;p&gt;I&amp;#39;ve noticed in most of the examples that nrf_drv_saadc_buffer_convert() is called in the event handler, &lt;em&gt;prior&lt;/em&gt; to the resulting buffer being processed.&lt;/p&gt;
&lt;p&gt;Does this mean that buffers we pass to nrf_drv_saadc_buffer_convert() are guaranteed not to be filled until the event handler has finished processing?   Or, should the results of the buffer in the event handler be processed, prior to calling nrf_drv_saadc_buffer_convert() and re-enabling it for data streaming.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52 SAADC Double Buffering</title><link>https://devzone.nordicsemi.com/thread/53951?ContentTypeID=1</link><pubDate>Fri, 27 May 2016 17:59:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:262da7f0-79fd-49b8-b2f3-e811b01136ed</guid><dc:creator>anasimtiaz</dc:creator><description>&lt;p&gt;Very nicely explained. Thanks James!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52 SAADC Double Buffering</title><link>https://devzone.nordicsemi.com/thread/53950?ContentTypeID=1</link><pubDate>Fri, 27 May 2016 17:07:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:701d702f-f615-4a59-bbb8-b9707cd6b84b</guid><dc:creator>James Yu</dc:creator><description>&lt;p&gt;Yes it will be in that order. Think of it as a FIFO queue: your first two &lt;code&gt;nrf_drv_saadc_buffer_convert&lt;/code&gt; calls sets up the queue as &lt;code&gt;adc_buf[0], adc_buf[1]&lt;/code&gt;. When the first &lt;code&gt;saadc_event_handler&lt;/code&gt; occurs &lt;code&gt;adc_buf[0]&lt;/code&gt; is removed from the queue, and when &lt;code&gt;nrf_drv_saadc_buffer_convert&lt;/code&gt; is called again in the event handler &lt;code&gt;adc_buf[0]&lt;/code&gt; is added back to the queue making it &lt;code&gt;adc_buf[1], adc_buf[0]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The saadc example is better for understanding how a double buffered scheme could be useful.
Instead of &lt;code&gt;adc_buf[2]&lt;/code&gt;, lets say you have &lt;code&gt;adc_buf[2][1000]&lt;/code&gt;, so now instead of having 2 buffers with 1 value each you have 2 buffers with 1000 values each. If you need to perform some operations on these 1000 samples it may be hard to maintain a high sampling rate at the same time. But with a double buffered scheme you can perform operations on 1 buffer while at the same time doing conversation on the other.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52 SAADC Double Buffering</title><link>https://devzone.nordicsemi.com/thread/53949?ContentTypeID=1</link><pubDate>Fri, 27 May 2016 08:44:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f663cef-117f-4446-99cd-dfdd9a253625</guid><dc:creator>anasimtiaz</dc:creator><description>&lt;p&gt;Many thanks for the explanation James. So from (3) of your answer, I understand that regardless of sing;e/double buffering scheme &lt;code&gt;nrf_drv_saadc_buffer_convert&lt;/code&gt; needs to be called to set up a buffer for conversion before sampling.&lt;/p&gt;
&lt;p&gt;However, I have a couple of follow up questions about (2):&lt;/p&gt;
&lt;p&gt;Initially, as you said, I have &lt;code&gt;adc_buf[0]&lt;/code&gt; and &lt;code&gt;adc_buf[1]&lt;/code&gt;, and the call to &lt;code&gt;nrf_drv_saadc_buffer_convert()&lt;/code&gt; sets up &lt;code&gt;adc_buf[0]&lt;/code&gt; for conversion. The next two buffers will then be &lt;code&gt;adc_buf[1]&lt;/code&gt; and &lt;code&gt;adc_buf[0]&lt;/code&gt; ... do you mean in that order i.e. array element 1 and 0? If so, why?&lt;/p&gt;
&lt;p&gt;Secondly, in a double buffered scheme with &lt;code&gt;adc_buf[0]&lt;/code&gt; and &lt;code&gt;adc_buf[1]&lt;/code&gt;, what is the purpose of the second buffer? If &lt;code&gt;adc_buf&lt;/code&gt; is an array with 16-bit elements, each sample will be 10-bits so what purpose does it serve to have an extra buffer element?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52 SAADC Double Buffering</title><link>https://devzone.nordicsemi.com/thread/53948?ContentTypeID=1</link><pubDate>Thu, 26 May 2016 17:04:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73bd51b7-bff9-49c2-95b4-b14b4274b592</guid><dc:creator>James Yu</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Yes, you will get a &lt;code&gt;NRF_DRV_SAADC_EVT_DONE&lt;/code&gt; when &lt;code&gt;adc_buf[0]&lt;/code&gt; result is ready and another when &lt;code&gt;adc_buf[1]&lt;/code&gt; is ready.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It sets up the completed buffer for the next conversion in non-blocking mode. So initially you have &lt;code&gt;adc_buf[0]&lt;/code&gt; and &lt;code&gt;adc_buf[1]&lt;/code&gt; set up as the 2 buffers. Then when you get the first &lt;code&gt;NRF_DRV_SAADC_EVT_DONE&lt;/code&gt; event the completed buffer is &lt;code&gt;adc_buf[0]&lt;/code&gt;. The &lt;code&gt;nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer,1)&lt;/code&gt; call sets up &lt;code&gt;adc_buf[0]&lt;/code&gt; for conversion again, so the next 2 buffers will be &lt;code&gt;adc_buf[1]&lt;/code&gt; and &lt;code&gt;adc_buf[0]&lt;/code&gt;. If you don&amp;#39;t call &lt;code&gt;nrf_drv_saadc_buffer_convert&lt;/code&gt; at this point then your next buffer is just &lt;code&gt;adc_buf[1]&lt;/code&gt; and is no longer double buffered.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You will still get the &lt;code&gt;NRF_DRV_SAADC_EVT_DONE&lt;/code&gt; event when adc_buf[0] is complete. If you want to continue sampling you will have to call &lt;code&gt;nrf_drv_saadc_buffer_convert&lt;/code&gt; to set up adc_buf[0] again for conversion, otherwise you won&amp;#39;t have any buffers ready for conversion.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>