<?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>Measuring execution time of saadc sampling</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/61598/measuring-execution-time-of-saadc-sampling</link><description>Hi everyone, 
 I want to measure the total execution time of saadc_sample() &amp;amp; saadc_callback() functions. I am using the application timer and I have inserted the app_timer_cnt_get() before and after the functions I want to measure as well as the app_timer_cnt_diff_compute</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 21 May 2020 04:50:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/61598/measuring-execution-time-of-saadc-sampling" /><item><title>RE: Measuring execution time of saadc sampling</title><link>https://devzone.nordicsemi.com/thread/251102?ContentTypeID=1</link><pubDate>Thu, 21 May 2020 04:50:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31909b0c-4b2d-4dbe-b23c-7a1787a78967</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Thank you very much Karl!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Measuring execution time of saadc sampling</title><link>https://devzone.nordicsemi.com/thread/251083?ContentTypeID=1</link><pubDate>Wed, 20 May 2020 22:29:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:16fe1509-da54-470d-866d-03833dde05c8</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello again Nick,&lt;br /&gt;&lt;br /&gt;Great, I am happy that my answer made things more clear.&lt;/p&gt;
[quote user="Nikosant03"]What is the purpose of all these acquisition times and how do I know which one fits better my application?[/quote]
&lt;p&gt;The Acquisition time indicates how long the capacitor is connected, when gathering the sample.&lt;br /&gt;The &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf52840%2Fsaadc.html"&gt;SAADC Documentation&lt;/a&gt;s section on Acquisition time reads:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span&gt;The acquisition time indicates how long the capacitor is connected, see TACQ field in CH[n].CONFIG register. The required acquisition time depends on the source resistance (R&lt;/span&gt;&lt;sub&gt;source&lt;/sub&gt;&lt;span&gt;). For high source resistance the acquisition time should be increased.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/em&gt;&lt;span&gt;In essence; if the resistance is larger(such that current is low) then the capacitor will reach the steady state voltage slower. In the case of a massive resistance, you would want to have the capacitor connected longer to ensure that you are getting correct measurements.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
[quote user="Nikosant03"]Yes, SAMPLES_IN_BUFFER = 1, is this somehow related?[/quote]
&lt;p&gt;&lt;span&gt;Not directly, I was just confirming that your intent was to measure the time it took to do and process exactly 1 sample(since the &amp;quot;end&amp;quot; variable was being captured at the end of the SAADC DONE EVT). The sample buffer size is not in any way related to the acquisition time parameter, sorry if this was confusing.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Measuring execution time of saadc sampling</title><link>https://devzone.nordicsemi.com/thread/251051?ContentTypeID=1</link><pubDate>Wed, 20 May 2020 15:04:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:17f53f09-5343-470e-aa1e-7ddc71c9e349</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Hi Karl,&lt;/p&gt;
&lt;p&gt;Yes I am using the&amp;nbsp;&lt;em&gt;NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE&amp;nbsp;&amp;nbsp;&lt;/em&gt;to initialize my channel and I am just changing the gain and reference voltage&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void saadc_init(void) {
  ret_code_t err_code;

  //na configure adc resolution
  nrfx_saadc_config_t adc_config = NRFX_SAADC_DEFAULT_CONFIG;
  adc_config.resolution = NRF_SAADC_RESOLUTION_12BIT;

  nrf_saadc_channel_config_t channel_config =
      NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN1); //na AIN0 is the pin P0.03 - https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fpin.html

  //na configure adc channel gain and vref
  channel_config.gain = NRF_SAADC_GAIN1_4;
  channel_config.reference = NRF_SAADC_REFERENCE_VDD4;

  //pd adc initialize with custom configuratiom
  err_code = nrf_drv_saadc_init(&amp;amp;adc_config, saadc_callback);
  APP_ERROR_CHECK(err_code);

  err_code = nrf_drv_saadc_channel_init(0, &amp;amp;channel_config);
  APP_ERROR_CHECK(err_code);

  err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], SAMPLES_IN_BUFFER); // na - designating the buffer in which to fill the samples produces by nrf_drv_saadc_sample or NRF_SAADC_TASK_SAMPLE.
  APP_ERROR_CHECK(err_code);

  err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], SAMPLES_IN_BUFFER);
  APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I didn&amp;#39;t notice the&amp;nbsp;acq_time parameter, so it makes sense that I cannot the execution time. I printed out the values of begin and end and indeed they have the same value. Also, I&amp;#39;ve noticed that I can further reduce the acquisition time &lt;span style="text-decoration:underline;"&gt;down to 3us&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/** @brief Analog-to-digital converter acquisition time. */
typedef enum
{
    NRF_SAADC_ACQTIME_3US  = SAADC_CH_CONFIG_TACQ_3us,  ///&amp;lt; 3 us.
    NRF_SAADC_ACQTIME_5US  = SAADC_CH_CONFIG_TACQ_5us,  ///&amp;lt; 5 us.
    NRF_SAADC_ACQTIME_10US = SAADC_CH_CONFIG_TACQ_10us, ///&amp;lt; 10 us.
    NRF_SAADC_ACQTIME_15US = SAADC_CH_CONFIG_TACQ_15us, ///&amp;lt; 15 us.
    NRF_SAADC_ACQTIME_20US = SAADC_CH_CONFIG_TACQ_20us, ///&amp;lt; 20 us.
    NRF_SAADC_ACQTIME_40US = SAADC_CH_CONFIG_TACQ_40us  ///&amp;lt; 40 us.
} nrf_saadc_acqtime_t;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What is the purpose of all these acquisition times and how do I know which one fits better my application?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;From your code, I am assuming your SAMPLES_IN_BUFFER = 1?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Yes, SAMPLES_IN_BUFFER = 1, is this somehow related?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Nick&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Measuring execution time of saadc sampling</title><link>https://devzone.nordicsemi.com/thread/251033?ContentTypeID=1</link><pubDate>Wed, 20 May 2020 14:23:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22aa0c19-018a-4a5b-b460-1c739f5163ec</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Nick,&lt;br /&gt;&lt;br /&gt;What is your defined Acquisition time?&lt;br /&gt;If you are initializing your SAADC channel with the&amp;nbsp;&lt;em&gt;NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE&amp;nbsp;&lt;/em&gt;then the default acquisition time is 10 us.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(PIN_P) \
{                                                   \
    .resistor_p = NRF_SAADC_RESISTOR_DISABLED,      \
    .resistor_n = NRF_SAADC_RESISTOR_DISABLED,      \
    .gain       = NRF_SAADC_GAIN1_6,                \
    .reference  = NRF_SAADC_REFERENCE_INTERNAL,     \
    .acq_time   = NRF_SAADC_ACQTIME_10US,           \
    .mode       = NRF_SAADC_MODE_SINGLE_ENDED,      \
    .burst      = NRF_SAADC_BURST_DISABLED,         \
    .pin_p      = (nrf_saadc_input_t)(PIN_P),       \
    .pin_n      = NRF_SAADC_INPUT_DISABLED          \
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;[quote user=""][/quote]&lt;/p&gt;
&lt;p&gt;&lt;span&gt;1. Does this mean that the execution time is less than the resolution of app_timer which is&amp;nbsp;~30 us?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2. Does it make sense that the execution time of those functions is less than 30us?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes to both. If the timer has not had any ticks since last time, the difference will be 0. This makes sense unless you are using the 40 us SAADC channel acquisition time.&amp;nbsp;You could print out(using deferred logging for minimal impact) the values of&amp;nbsp;&lt;em&gt;begin&lt;/em&gt; and&amp;nbsp;&lt;em&gt;end&lt;/em&gt; to verify this.&lt;br /&gt;&lt;br /&gt;From your code, I am assuming your SAMPLES_IN_BUFFER = 1?&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>