<?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 manually starting/stopping scan mode</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/76670/nrf52-saadc-manually-starting-stopping-scan-mode</link><description>Hi, 
 I need the SAADC of the nRF52840 to do the following: 
 
 It should sample two channels as fast as possible for a certain time (or for a certain amount of samples). 
 The sampling should be started manually (not by an external timer). 
 After the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 15 Jul 2021 08:46:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/76670/nrf52-saadc-manually-starting-stopping-scan-mode" /><item><title>RE: nrf52 SAADC manually starting/stopping scan mode</title><link>https://devzone.nordicsemi.com/thread/320180?ContentTypeID=1</link><pubDate>Thu, 15 Jul 2021 08:46:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dcf3f61d-d980-402a-8da1-a663e2aeafa8</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Sorry for the late reply. I wasn&amp;#39;t aware that you needed a sample rate of 100kHz. In that case I agree it would be difficult to achieve without the use of TIMER.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;You can use &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Fgroup__nrf__drv__timer.html&amp;amp;anchor=gaeb7fd1f37ea70aa227c6de19efc6596b"&gt;nrf_drv_us_to_ticks&lt;/a&gt;() or you can set the ticks manually to have full control. For example 160 ticks will give you 100kHz if the timer runs on 16MHz, or 10 ticks if the timer runs on 1MHz. &lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52 SAADC manually starting/stopping scan mode</title><link>https://devzone.nordicsemi.com/thread/318517?ContentTypeID=1</link><pubDate>Sun, 04 Jul 2021 11:01:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66996f9d-249c-423a-ad3f-a67119f86311</guid><dc:creator>hypn0</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Thank you for your answer.&amp;nbsp;&lt;/p&gt;
[quote userid="73427" url="~/f/nordic-q-a/76670/nrf52-saadc-manually-starting-stopping-scan-mode/317056#317056"]A call to nrf_drv_saadc_sample will trigge one sample per channel, you will need to call it 10 times to generate 20 results in the buffer if you have 2 channel actives. If you call it in a while loop then the next sample will be trigger as soon as the previous one is done.[/quote]
&lt;p&gt;As mentioned before, I want to collect as many samples as possible within a certain period of time (within two signal triggers), where the time between each sample should be constant for further signal processing. &lt;br /&gt;I could measure the&amp;nbsp;n samples by simply calling the&amp;nbsp;function &lt;span&gt;nrfx_saadc_sample()&amp;nbsp;n&lt;/span&gt;&amp;nbsp;times in a row, e.g:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void measure_samples(n)
{
  uint16_t i = 0; 
  for(i=0;i&amp;lt;n;i++)
  {
    nrf_drv_saadc_sample();
  }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I find it hard to believe that with such a solution the maximum sampling rate (in my case 100kHz) can be reached, since the for-loop needs execution time as well. Even if the execution time is certainly very fast, I have no more control over how fast the individual samples are actually sampled.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Another solution would be to call the function nrfx_saadc_sample() via a timer (e.g. with PPI Channel as in the peripheral/saadc example). With this approach the samples would be measured within a well defined time intervall.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the peripheral/saadc/ example, the timing interval is set in the saadc_sampling_event_init() function using the nrf_drv_timer_ms_to_ticks() function. But I want to set a timing interval which is faster than 1ms to get the desired 100kHz sampling rate. Can you tell me, how to achieve a faster timing intervall?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Or would you suggest to implement the solution with the for-loop?&lt;/p&gt;
&lt;p&gt;Thanks a lot for your answer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind Regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52 SAADC manually starting/stopping scan mode</title><link>https://devzone.nordicsemi.com/thread/317056?ContentTypeID=1</link><pubDate>Thu, 24 Jun 2021 14:59:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:862dc5ea-f23b-4cca-91d0-b9d4637936ef</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hi again,&lt;/p&gt;
[quote user="hypn0"]Is that correct?&amp;nbsp;Is it legitimate to assume that the sampling rate remains constant and is not dependent on the rest of the code?&amp;nbsp;[/quote]
&lt;p&gt;&amp;nbsp;Yes, correct.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="hypn0"]Question 2: How (or where) are the n samples (defined by&amp;nbsp;SAMPLES_IN_BUFFER&amp;nbsp;) sampled, when&amp;nbsp;nrfx_saadc_sample()&amp;nbsp; is called. How does nrf52 know, how many values have to be sampled and stored in the buffer.[/quote]
&lt;p&gt;&amp;nbsp;You set the buffer size in nrf_drv_saadc_buffer_convert().&lt;/p&gt;
&lt;p&gt;A call to nrf_drv_saadc_sample will trigge one sample per channel, you will need to call it 10 times to generate 20 results in the buffer if you have 2 channel actives. If you call it in a while loop then the next sample will be trigger as soon as the previous one is done.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="hypn0"]Question 3: How to turn it off and on again[/quote]
&lt;p&gt;&amp;nbsp;You may need to do an uninit and init to achieve low power. This case may be relevant for you:&lt;/p&gt;
&lt;div&gt;&lt;a title="https://devzone.nordicsemi.com/f/nordic-q-a/23867/nrf52-best-practise-for-ultra-low-power-saadc-4-channel-conversion/93906#93906" href="https://devzone.nordicsemi.com/f/nordic-q-a/23867/nrf52-best-practise-for-ultra-low-power-saadc-4-channel-conversion/93906#93906" rel="noopener noreferrer" target="_blank"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/23867/nrf52-best-practise-for-ultra-low-power-saadc-4-channel-conversion/93906#93906&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;Best regards,&lt;/div&gt;
&lt;div&gt;Marjeris&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52 SAADC manually starting/stopping scan mode</title><link>https://devzone.nordicsemi.com/thread/316825?ContentTypeID=1</link><pubDate>Wed, 23 Jun 2021 19:40:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:83bba256-9d05-409d-87a5-7007fff8d041</guid><dc:creator>hypn0</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for the reply.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I managed to edit the peripheral/saadc example. I simply&amp;nbsp;call the&amp;nbsp;saadc_init() function in the main routine and afterwards I periodically call nrf_drv_saadc_sample() in the while(1) loop.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This works fine, the callback function&amp;nbsp;saadc_callback() (which is the same as in the example) is called after n samples (per channel, which is defined by&amp;nbsp;SAMPLES_IN_BUFFER) are stored in the buffer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;However, there are still some questions:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Question 1: At what sampling rate are the channels sampled during scan mode (assuming aquisition time is known)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;At the moment,&amp;nbsp;&lt;span&gt;SAMPLES_IN_BUFFER is set to 20 and nrf_drv_saadc_sample() is called periodically (every 100ms after an idle wait, just for testing purposes). So I periodically receive 20 samples (first sample from channel 0, second from channel 1, third from channel 0 and so on), as it should be. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Can you tell me at what sampling rate these readings are sampled by the SAADC? &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I set the aquisition time for both channels to&amp;nbsp;NRF_SAADC_ACQTIME_3US, so I assume the sampling rate should be fs = 1/(3us+2us + 3us+2us) = 100kHz (the 2us is the conversion time tconv). &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Is that correct?&amp;nbsp;Is it legitimate to assume that the sampling rate remains constant and is not dependent on the rest of the code?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Question 2: How (or where) are the n samples (defined by&amp;nbsp;SAMPLES_IN_BUFFER&amp;nbsp;) sampled, when&amp;nbsp;nrfx_saadc_sample()&amp;nbsp; is called. How does nrf52 know, how many values have to be sampled and stored in the buffer.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;As far as I understand,&amp;nbsp;nrfx_saadc_sample() basically just triggers&amp;nbsp;NRF_SAADC_TASK_SAMPLE task. In the documentation it says : &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;NRF_SAADC_TASK_SAMPLE task. = &amp;quot;Take one ADC sample. If scan is enabled, all channels are sampled&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;According to my understanding, this means, that only ONE&amp;nbsp;value per channel is sampled when calling&amp;nbsp;nrfx_saadc_sample()&amp;nbsp;. However this is not the case in my example, I receive the whole buffer (which is&amp;nbsp;SAMPLES_IN_BUFFER samples long), after calling&amp;nbsp;nrfx_saadc_sample().&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Don&amp;#39;t get me wrong, I want that 20 samples per function call :-D &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Nevertheless, I am trying to understand what is going on and I could not figure out, where in the code the SAADC is told to sample&amp;nbsp;&lt;span&gt;SAMPLES_IN_BUFFER&amp;nbsp;samples.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;Can you explain the process to me?&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Question 3: How to turn it off and on again&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;I managed to start the sampling process and gather n samples from the saadc. After the sampling process I want to enter some low power mode to save battery power and restart the process after some time.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;What is the right way to turn off the SAADC and turn it on again?&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;One concern is, that the value from the two channels end up &amp;quot;in the right place&amp;quot; in the buffer after the saadc has been turned on again.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you in advance for your answer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind Regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52 SAADC manually starting/stopping scan mode</title><link>https://devzone.nordicsemi.com/thread/316821?ContentTypeID=1</link><pubDate>Wed, 23 Jun 2021 18:48:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f1d6daf-0733-4d03-8498-6ae8e234bfd6</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You can start with one of the SAADC examples in the SDK and modify it to your liking. For starting the sample manually you can use &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v17.0.2%2Fgroup__nrf__drv__saadc.html&amp;amp;anchor=gaf16a16c9de60276dd73cf1811c03ae73"&gt;nrf_drv_saadc_sample&lt;/a&gt;() function.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>