<?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>SAADC Oversample acquisition time</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87290/saadc-oversample-acquisition-time</link><description>I have been doing some measurements on the execution time of my code and noticed something strange. 
 Currently, I am using an application timer to trigger the ADC to sample at 256Hz. 
 The code to trigger the ADC in the application timer interrupt handler</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 28 Apr 2022 08:39:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87290/saadc-oversample-acquisition-time" /><item><title>RE: SAADC Oversample acquisition time</title><link>https://devzone.nordicsemi.com/thread/365336?ContentTypeID=1</link><pubDate>Thu, 28 Apr 2022 08:39:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:320a7beb-08ec-4221-8b6c-b68ea7d0840b</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Ah, I didn&amp;#39;t notice in the previous replies, but the oversample configurations doesn&amp;#39;t belong to the NRF_SAADC-&amp;gt;CH[n].CONFIG registers. It belongs to the NRF_SAADC.OVERSAMPLE register.&lt;/p&gt;
&lt;p&gt;By writing SAADC_OVERSAMPLE_OVERSAMPLE_Over4x &amp;lt;&amp;lt; SAADC_OVERSAMPLE_OVERSAMPLE_Pos = 0x02 &amp;lt;&amp;lt; 0 = 0x02 you are setting a pullup resistor on the GPIO on CH[n].&lt;/p&gt;
&lt;p&gt;Try setting the oversampling setting to the oversample register:&lt;br /&gt;NRF_SAADC-&amp;gt;OVERSAMPLE = (SAADC_OVERSAMPLE_OVERSAMPLE_Over4x &amp;lt;&amp;lt; SAADC_OVERSAMPLE_OVERSAMPLE_Pos);&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Oversample acquisition time</title><link>https://devzone.nordicsemi.com/thread/365264?ContentTypeID=1</link><pubDate>Wed, 27 Apr 2022 18:14:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e6fe92a2-b219-439c-a79e-6edc7ab045cb</guid><dc:creator>bryanhsieh</dc:creator><description>&lt;p&gt;To see if oversampling was working, I set a pin to toggle in the ADC interrupt on done event and it was toggling only at the frequency set by the RTC. Reading the register as you have suggested, I found that I wasn&amp;#39;t setting the oversample register but instead overwriting to the first few bits of the config register with NRF_SAADC-&amp;gt;CH[1].CONFIG = {&amp;nbsp;SAADC_OVERSAMPLE_OVERSAMPLE_Over4x &amp;lt;&amp;lt; SAADC_OVERSAMPLE_OVERSAMPLE_Pos }.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After changing it, I can see now the pin is being toggled correctly.&lt;/p&gt;
&lt;p&gt;Thanks for the help!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Oversample acquisition time</title><link>https://devzone.nordicsemi.com/thread/365026?ContentTypeID=1</link><pubDate>Tue, 26 Apr 2022 18:28:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3cbf5478-a3ab-47f2-a361-207730699b9c</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Ok, in that case, please make sure that your&amp;nbsp;APP_TIMER_CONFIG_RTC_FREQUENCY is set to 0 in sdk_config.h.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Can you please try to print the CH[0].CONFIG and CH[1].CONFIG registers before you sample, and can you also please check your NRF_SAADC.OVERSAMPLE register?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;NRF_LOG_INFO(&amp;quot;settings:\nCH[0].CONFIG: 0x%08x\nCH[1].CONFIG: 0x%08x\nSAADC.OVERSAMPLE: 0x%08x&amp;quot;, NRF_SAADC-&amp;gt;CH[0].CONFIG,
                                                                                                NRF_SAADC-&amp;gt;CH[1].CONFIG,
                                                                                                NRF_SAADC-&amp;gt;OVERSAMPLE);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Oversample acquisition time</title><link>https://devzone.nordicsemi.com/thread/364984?ContentTypeID=1</link><pubDate>Tue, 26 Apr 2022 13:51:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c7e3f56-ba20-4a41-a90a-d88492863c1f</guid><dc:creator>bryanhsieh</dc:creator><description>&lt;p&gt;I used&amp;nbsp;app_timer as it was readily available and it uses RTC with the prescaler set to 0 so the resolution should be 30.5us.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And a tick count of 3 seems to match with 2 channels at 40us acquistion time (2*40 + conversion).&lt;/p&gt;
&lt;p&gt;However, the tick count doesnt change when I change the oversample rate, it does change when I change the acquistion time.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I will try with a timer later, but it will just have a better resolution so I dont think it will change the result as the RTC should not be limited by its resolution with 40us acquistion time and 4x oversample.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Oversample acquisition time</title><link>https://devzone.nordicsemi.com/thread/364979?ContentTypeID=1</link><pubDate>Tue, 26 Apr 2022 13:38:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:16a74e0d-7b3e-4246-87c7-d251a03631cf</guid><dc:creator>Edvin</dc:creator><description>[quote user="bryanhsieh"]I am using SDK v13, but in this case I am writing directly to the adc registers so the SDK version should not have an effect?[/quote]
&lt;p&gt;no, it shouldn&amp;#39;t. I just didn&amp;#39;t check all versions.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;however, since I found a function called nrfx_saadc_sample() in SDK17.1.0, I assumed it was a newer version of the saadc_sample. So I didn&amp;#39;t notice you had implemented that yourself.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Did you test using the TIMER peripheral directly like I suggested in the previous reply? I am not sure how you set up the app_timer. Perhaps the app_timer uses a different prescaler, causing it to have a different tick rate than what you think.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Oversample acquisition time</title><link>https://devzone.nordicsemi.com/thread/364865?ContentTypeID=1</link><pubDate>Tue, 26 Apr 2022 08:48:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6140b98-3887-499c-8f5d-2f22b20e6a2d</guid><dc:creator>bryanhsieh</dc:creator><description>&lt;p&gt;Hi Edvin thanks for replying.&lt;/p&gt;
&lt;p&gt;I am using SDK v13, but in this case I am writing directly to the adc registers so the SDK version should not have an effect?&lt;/p&gt;
&lt;p&gt;As you can see from the code provided saadc_sample is a custom function. And when that function is called it not only sets the sample task but also waits for the conversion to finish ie when the result buffer is full (events_end). So therefore shouldn&amp;#39;t the time taken measured be accurate?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Oversample acquisition time</title><link>https://devzone.nordicsemi.com/thread/364852?ContentTypeID=1</link><pubDate>Tue, 26 Apr 2022 08:11:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b259edfb-450a-4b90-83a1-d25a9add3f79</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;You are correct that the oversampling will cause the SAADC will take longer.&lt;/p&gt;
&lt;p&gt;Depending on what version of the SDK you are using, the answer may differ, but I am using the nRF5 SDK v17.1.0 for now. Please specify what SDK you are using for follow up questions.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The saadc_sample() function will only trigger the sampling task by setting the NRF_SAADC_TASK_SAMPLE register. This does not mean that the sampling is done when saadc_sample() has returned. When the sample is ready, it will trigger the callback that you have set up.&lt;/p&gt;
&lt;p&gt;If you want to measure the time the actual transfer takes, you can use a free timer to test this. Something like:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;test_timer_init()
{
    NRF_TIMER3-&amp;gt;BITMODE                 = TIMER_BITMODE_BITMODE_32Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos;
    NRF_TIMER3-&amp;gt;PRESCALER               = 0;
    NRF_TIMER3-&amp;gt;MODE                    = TIMER_MODE_MODE_Timer &amp;lt;&amp;lt; TIMER_MODE_MODE_Pos;
    NRF_TIMER3-&amp;gt;TASKS_START = 1;
}

static void timer_timeout_handler(void * p_context)
{
    NRF_TIMER3-&amp;gt;TASKS_CAPTURE[0] = 1; // Trigger first timestamp
	adc_sample();
  LED_drv_timer_update();
}

void saadc_callback() // The function where you get the SAADC result
{
    uint32_t timer_sample_a;
    uint32_t timer_sample_b;
    uint32_t timer_diff_ticks;
    NRF_TIMER3-&amp;gt;TASKS_CAPTURE[1] = 1; // Trigger second timestamp
    
    timer_sample_a = NRF_TIMER3-&amp;gt;CC[0];
    timer_sample_b = NRF_TIMER3-&amp;gt;CC[1];
    timer_diff_ticks = timer_sample_b - timer_sample_a; // clock freq 16MHz
    NRF_LOG_INFO(&amp;quot;diff ticks %d, %d us&amp;quot;, timer_diff, (timer_diff&amp;gt;&amp;gt;4)); // &amp;gt;&amp;gt;4 = /16
    ...
    // whatever you already had here.
    
    
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>