<?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>Understandin SAADC example</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/47916/understandin-saadc-example</link><description>Hello, 
 I am having trouble understanding the SAADC example in the description. Can anybody tell me what do the following instructions in the code do? 
 1. NRF_SAADC-&amp;gt;SAMPLERATE = SAADC_SAMPLERATE_MODE_Task &amp;lt;&amp;lt; SAADC_SAMPLERATE_MODE_Pos; /* does this</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 Jun 2019 10:35:54 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/47916/understandin-saadc-example" /><item><title>RE: Understandin SAADC example</title><link>https://devzone.nordicsemi.com/thread/190726?ContentTypeID=1</link><pubDate>Tue, 04 Jun 2019 10:35:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2343ae5-7547-4681-9d32-e31168182651</guid><dc:creator>JohnnyMcMan</dc:creator><description>&lt;p&gt;I found the example somewhere on the forum, I do not remember where.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Understandin SAADC example</title><link>https://devzone.nordicsemi.com/thread/190725?ContentTypeID=1</link><pubDate>Tue, 04 Jun 2019 10:34:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fe96ce2-7eb3-4685-a8e1-58452dd3c02a</guid><dc:creator>JohnnyMcMan</dc:creator><description>&lt;p&gt;Thank you Very much Einar, i understand now&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Understandin SAADC example</title><link>https://devzone.nordicsemi.com/thread/190569?ContentTypeID=1</link><pubDate>Mon, 03 Jun 2019 14:34:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb08a811-b0bd-4a1d-8534-e4ade3a2c7d6</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Where does this example come from?&lt;/p&gt;
[quote user=""]1.&amp;nbsp;NRF_SAADC-&amp;gt;SAMPLERATE = SAADC_SAMPLERATE_MODE_Task &amp;lt;&amp;lt; SAADC_SAMPLERATE_MODE_Pos; /* does this mean that the sampling of the input voltage to the analog pin&amp;nbsp; &amp;nbsp; &amp;nbsp; will only happen when I set a certain bit?*/[/quote]
&lt;p&gt;Here you configure that sampling&amp;nbsp;is controlled by triggering the&amp;nbsp;SAMPLE task. So sampling will only occur when the SAMPLE task is triggered via PPI or SW.&lt;/p&gt;
[quote user=""]2. NRF_SAADC-&amp;gt;TASKS_SAMPLE = 1;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // does this instruction make the sampler sample the input voltage?&lt;br /&gt;&amp;nbsp; &amp;nbsp; while (NRF_SAADC-&amp;gt;EVENTS_END == 0);&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // what is this for?&lt;br /&gt;&amp;nbsp; &amp;nbsp; NRF_SAADC-&amp;gt;EVENTS_END = 0;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // what is this for?&amp;nbsp; &amp;nbsp; &amp;nbsp;[/quote]
&lt;p&gt;The first line writes 1 to the SAMPLE task, triggering it so that the SAADC to sample the input. The second line reads it back until it is actually set to 1. The third line writes it back to 0 so that it is ready to be triggered at a later stage.&lt;/p&gt;
[quote user=""]3.&amp;nbsp;NRF_SAADC-&amp;gt;TASKS_START = 1;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//why do i need these lines of code since i already enabled the SAADC? do I need to call them every time I make a sample?&lt;br /&gt;&amp;nbsp; &amp;nbsp; while (NRF_SAADC-&amp;gt;EVENTS_STARTED == 0);&lt;br /&gt;&amp;nbsp; &amp;nbsp; NRF_SAADC-&amp;gt;EVENTS_STARTED = 0; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[/quote]
&lt;p&gt;This triggers the START task in the same way as the SAMPLE task. It is triggered before the SAMPLE task, though (which is correct), but the order you ask about it might cause some confusion. You can read more details about the different tasks etc. in the &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/saadc.html?cp=3_0_0_5_22"&gt;SAADC chapter in the PS&lt;/a&gt;.&lt;/p&gt;
[quote user=""]5.&amp;nbsp; __WFE();&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//what does the waiting for event macro do in this example?[/quote]
&lt;p&gt;This makes the CPU enter low power sleep mode, where it sleeps until there is a new interrupt/event. It is not directly related to the usage of the SAADC.&lt;/p&gt;
[quote user=""]6.&amp;nbsp; NRF_SAADC-&amp;gt;RESULT.MAXCNT = 1;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //what does this line do?&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;NRF_SAADC-&amp;gt;RESULT.PTR = (uint32_t)&amp;amp;result;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//why doesn&amp;#39;t the result change its value, since I tried to print the value of it when I connect P0.02 to GND and then to VDD?[/quote]
&lt;p&gt;Specifies the maximum number of samples that can be written in RAM via DMA. Since it is just one, that means that you need to read the result after every sampling.&lt;/p&gt;
&lt;p&gt;The result doe snot change depending on P0.02 because you have not configured the SAADC to measure on P0.02. You have configured it to measure VDD using this line:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;NRF_SAADC-&amp;gt;CH[0].PSELP = SAADC_CH_PSELP_PSELP_VDD &amp;lt;&amp;lt; SAADC_CH_PSELP_PSELP_Pos;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>