<?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>questions regarding saadc example</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/61531/questions-regarding-saadc-example</link><description>Hi 
 
 A few questions regarding the &amp;quot;saadc_pca10040&amp;quot; example: 
 
 If I read one analog pin then what is the meaning of this matrix of values : 
 
 &amp;quot;static nrf_saadc_value_t m_buffer_pool[2][SAMPLES_IN_BUFFER]; &amp;quot; 
 (less important but I wonder why to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 19 May 2020 07:50:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/61531/questions-regarding-saadc-example" /><item><title>RE: questions regarding saadc example</title><link>https://devzone.nordicsemi.com/thread/250592?ContentTypeID=1</link><pubDate>Tue, 19 May 2020 07:50:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:85a0bbb2-3d57-4e3a-bf0e-38cdf9faa0f2</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Ziv,&lt;/p&gt;
[quote user="ziv123"]thanks for reply[/quote]
&lt;p&gt;No problem at all, I am happy to help!&lt;/p&gt;
[quote user="ziv123"]1. can i read the analog input value each time to one uint16_t parameter instead of using a buffer (its ok for me if i miss some data i don&amp;#39;t need to be very sensitive in that measurement?[/quote]
&lt;p&gt;&amp;nbsp;Yes, you could supply the SAADC with a buffer of size 1, which would generate the&amp;nbsp;&lt;em&gt;NRF_DRV_SAADC_EVT_DONE&lt;/em&gt; event every time a sample is retrieved.&lt;/p&gt;
[quote user="ziv123"]2. how does the sample task _addr &amp;quot;&amp;nbsp;uint32_t saadc_sample_task_addr&amp;nbsp; &amp;nbsp;= nrf_drv_saadc_sample_task_get();&amp;quot;&amp;nbsp; related to the &amp;quot;saadc_init() or &amp;quot;saadc_callback()&amp;quot; its not very clear[/quote]
&lt;p&gt;saadc_init() is the function that initializes the use of the SAADC module. It configures the SAADC (channel(s) that the SAADC should sample, and channel parameters) as well as providing the SAADC with the buffers in which to place the samples taken. All of the above must be done in order to use any of the SAADC functionality at all.&lt;br /&gt;The saadc_callback function is the function that will be called when SAADC events is generated, and is necessary for anything to actually happen with the data you are collecting.&lt;br /&gt;&lt;br /&gt;With the SAADC configured, it will have a sample_task address, as mentioned in the Tasks vs. event answer by my colleague. This task address must be linked to the timer event by PPI, so that the sample task triggers every time the timers compare event is generated. This connection is made in the saadc_sampling_event_init function.&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&amp;amp;m_timer,
                                                                                NRF_TIMER_CC_CHANNEL0);
    uint32_t saadc_sample_task_addr   = nrf_drv_saadc_sample_task_get();

    /* setup ppi channel so that timer compare event is triggering sample task in SAADC */
    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;m_ppi_channel);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
                                          timer_compare_event_addr,
                                          saadc_sample_task_addr);&lt;/pre&gt;&lt;br /&gt;Notice how the sampling task and timer compare event addresses are retrieved, before being linked together by the PPI channel.&lt;br /&gt;&lt;br /&gt;To gain a better understanding of how this works, I highly recommend that you sit down with the SAADC example I mentioned, and experiment with it. Make changes to the parameters, and see the changes reflected in the output data. Modify input channels, numbers, configurations, sample task triggers, etc. to familiarize yourself with the SAADC functionality.&lt;/p&gt;
[quote user="ziv123"]3. is there another way instead of instencing a timer, like use sys tick or other clock ?[/quote]
&lt;p&gt;There are multiple timers you could use. What in particular are you looking for?&lt;br /&gt;Using PPI you could link your sample task to any peripheral event.&lt;br /&gt;I recommend using with the app_timer module if you are planning on making it a periodic sampling.&lt;/p&gt;
[quote user="ziv123"]p.s. regarding section 2.. i would&amp;nbsp;&lt;span&gt;like to work with 3 adc inputs that each of their handler awake at different time periods via timer and ppi, how would this be implemented ?&amp;nbsp;&lt;/span&gt;[/quote]
&lt;p&gt;Then you must either use the scan mode of the SAADC to perform a sampling of all enabled channels - and then just retrieve the one sample you are interested in at that time, and disregard the others.&lt;br /&gt;Or, you may enable the SAADC channel in question each time its sample task triggers, and then disable it again when the sample has been collected.&lt;br /&gt;I would recommend the latter method of enabling and disabling the channels as you need them - mind you that this will require some CPU ticks each time it is done.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: questions regarding saadc example</title><link>https://devzone.nordicsemi.com/thread/250569?ContentTypeID=1</link><pubDate>Tue, 19 May 2020 05:51:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52c7b99c-ead6-467d-91c0-c27d50a29ce8</guid><dc:creator>ziv123</dc:creator><description>&lt;p&gt;p.s. regarding section 2.. i would&amp;nbsp;&lt;span&gt;like to work with 3 adc inputs that each of their handler awake at different time periods via timer and ppi, how would this be implemented ?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: questions regarding saadc example</title><link>https://devzone.nordicsemi.com/thread/250504?ContentTypeID=1</link><pubDate>Mon, 18 May 2020 15:25:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea442b63-57d9-4e41-937b-994827039d57</guid><dc:creator>ziv123</dc:creator><description>&lt;p&gt;hi Karl&lt;/p&gt;
&lt;p&gt;thanks for reply&lt;/p&gt;
&lt;p&gt;&lt;span&gt;1. can i read the analog input value each time to one uint16_t parameter instead of using a buffer (its ok for me if i miss some data i don&amp;#39;t need to be very sensitive in that measurement?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2. how does the sample task _addr &amp;quot;&amp;nbsp;uint32_t saadc_sample_task_addr&amp;nbsp; &amp;nbsp;= nrf_drv_saadc_sample_task_get();&amp;quot;&amp;nbsp; related to the &amp;quot;saadc_init() or &amp;quot;saadc_callback()&amp;quot; its not very clear&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;3. is there another way instead of instencing a timer, like use sys tick or other clock ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;best regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;ziv&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: questions regarding saadc example</title><link>https://devzone.nordicsemi.com/thread/250499?ContentTypeID=1</link><pubDate>Mon, 18 May 2020 15:12:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5707582e-5912-4104-bec3-f59fc60ffd95</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;By this, do you mean the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fsaadc.html&amp;amp;anchor=saadc_frontpage"&gt;SAADC documentation&lt;/a&gt;? Or the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__nrf__saadc.html"&gt;SAADC API reference&lt;/a&gt;?&lt;br /&gt;Both are valuable resources when familiarizing oneself with the SAADC.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: questions regarding saadc example</title><link>https://devzone.nordicsemi.com/thread/250498?ContentTypeID=1</link><pubDate>Mon, 18 May 2020 15:09:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a93655fd-eb65-4b77-84f3-a8dfad26805d</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;1. The SAADC peripheral example uses the Double buffering feature, which ensure that no samples is lost while the first buffer is processed after being filled up. The m_buffer_pool holds two arrays, so that it can switch to the next one immediately following reaching the end of a buffer.&lt;br /&gt;&lt;br /&gt;2. The line you are looking for is line 113 with the call to&amp;nbsp;&lt;em&gt;nrf_drv_ppi_channel_assign&amp;nbsp;&lt;/em&gt;which links the timer compare event address to the saadc sample task address.&lt;br /&gt;Following this, the sample task will occur when the timer compare event happens, through PPI(without needing the CPU to initiate the sampling).&lt;br /&gt;&lt;br /&gt;3. Yes, as can be seen in the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v16.0.0%2Fgroup__nrfx__timer.html&amp;amp;anchor=ga4ff72f2933ca09b483ebabb9bbd8cdbc"&gt;function documentation&lt;/a&gt; the argument may not be NULL.&lt;br /&gt;&lt;br /&gt;4. Please see the answer my colleague gave in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/6945/tasks-events-and-registers"&gt;this ticket&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: questions regarding saadc example</title><link>https://devzone.nordicsemi.com/thread/250496?ContentTypeID=1</link><pubDate>Mon, 18 May 2020 14:58:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2154bd5-2be7-4216-a1e9-b46159a8c813</guid><dc:creator>ziv123</dc:creator><description>&lt;p&gt;p.s. please be more helpfull then directing me to the saadc driver part in the data sheet, i went over it once all ready, it is not that stright forword and there is no API examples there for programers use except pins and registers numbering tables&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>