<?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 Scan Mode mixes channel buffers whan fast.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/20415/saadc-scan-mode-mixes-channel-buffers-whan-fast</link><description>Hi,
i have a strange problem which happens when i use scan mode to get 3 separate channels on saadc. 
 For example when i use uint32_t ticks = nrf_drv_timer_us_to_ticks(&amp;amp;m_timer, 200); everytihing is ok but whan i use 50us buffers get mixed up? 
 Is</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 20 Mar 2017 06:32:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/20415/saadc-scan-mode-mixes-channel-buffers-whan-fast" /><item><title>RE: SAADC Scan Mode mixes channel buffers whan fast.</title><link>https://devzone.nordicsemi.com/thread/79600?ContentTypeID=1</link><pubDate>Mon, 20 Mar 2017 06:32:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d4edaec-0799-4a32-ba8b-fab050d5728f</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;I use timer for microphone to measure noise. Which needs to be measured through period of 30s.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Scan Mode mixes channel buffers whan fast.</title><link>https://devzone.nordicsemi.com/thread/79599?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2017 12:43:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63167d16-2060-4d66-8165-d1f9a3efc14c</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;@schef:I don&amp;#39;t understand why you need a timer here, I assume you only need one sample per channel ?
The saadc example we used the timer just to show how this can be done automatically and periodically with the help of EasyDMA.
I&amp;#39;m not sure you need that for your use case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Scan Mode mixes channel buffers whan fast.</title><link>https://devzone.nordicsemi.com/thread/79604?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2017 06:14:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4c7a983f-1f82-462d-b9ac-97be320da00d</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;Here is what i have now and works for me. Didnt have a crash yet.&lt;/p&gt;
&lt;p&gt;I have one &lt;code&gt;saadc_sampling_event_init&lt;/code&gt; which has a timer in it.
For each channel i have separate &lt;code&gt;callback&lt;/code&gt; and &lt;code&gt;saadc_init&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;I have created a function&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void saadc_uninit(void)
{
  nrf_drv_saadc_uninit();
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which i call after the measurement.&lt;/p&gt;
&lt;p&gt;So for example one procedure may look like this.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void saadc_battery_level_callback(nrf_drv_saadc_evt_t const * p_event)
{
  if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
  {
    ret_code_t err_code;
    err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAMPLES_IN_BUFFER); APP_ERROR_CHECK(err_code);
    //SEGGER_RTT_printf(0, &amp;quot;buffa: %d\n&amp;quot;, p_event-&amp;gt;data.done.p_buffer[0]);
    battery_level_saadc_value = (uint16_t)caluclate_average_result(p_event-&amp;gt;data.done.p_buffer, SAMPLES_IN_BUFFER);
    set_data_ready(true);
  }
}

void battery_channel_enable()
{
  saadc_battery_level_init();
  saadc_sampling_event_enable();
}

void battery_channel_disable()
{
  saadc_sampling_event_disable();
  saadc_uninit();
}

static void wait_for_sample_data()
{
  while(!is_data_ready())
  {
    nrf_delay_ms(1);
    __WFE();
    __SEV();
    __WFE();
    nrf_delay_ms(1);
  }
  set_data_ready(false);
}


uint16_t get_battery_saadc_sample()
{
  battery_channel_enable();
  wait_for_sample_data();
  battery_channel_disable();
  return(battery_level_saadc_value);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What do you think about &lt;code&gt;nrf_delay_ms(1);&lt;/code&gt;. If i remove them i never got the data_ready.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Scan Mode mixes channel buffers whan fast.</title><link>https://devzone.nordicsemi.com/thread/79597?ContentTypeID=1</link><pubDate>Wed, 15 Mar 2017 06:03:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed839d2d-ed5d-4638-8b8c-d41e084bb891</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;I have 3 sensors. 1. is the IR sensor, 2. the microphone and 3. the battery measurement. IR sensor gave me around 400 and reacted to my movement. The microphone was around 1500 and the battery around 2200. So I took 3 channel but used one SEGGER_RTT_printf with filter like these: &lt;code&gt;if (i % 3 == 0) SEGGER_RTT_printf(0, &amp;quot;fill: %d: %d\n&amp;quot;, i, p_event-&amp;gt;data.done.p_buffer[i]);&lt;/code&gt;. Now. When i was measuring at the timer rate of &lt;code&gt;50us&lt;/code&gt; it was mixed (i got sometimes 2000, sometimes 1500, sometimes 400) but when i used &lt;code&gt;200us&lt;/code&gt; it NEVER got mixed up. So that was my conclusion.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Scan Mode mixes channel buffers whan fast.</title><link>https://devzone.nordicsemi.com/thread/79596?ContentTypeID=1</link><pubDate>Tue, 14 Mar 2017 16:02:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc3e9b47-8011-4b49-ae44-4e8f723d8641</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;@schef: Could you describe a little bit more what kind of mixed up /crash you got ?&lt;/p&gt;
&lt;p&gt;What was your source resistance ? This can affect the acquisition time as in 37.12.1 in the spec, and the time there is for each SAMPLE task.&lt;/p&gt;
&lt;p&gt;When do you print the result out with RTT ? If you printout on every sample  you got it may cause a problem since it&amp;#39;s not enough time to print I assume.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Scan Mode mixes channel buffers whan fast.</title><link>https://devzone.nordicsemi.com/thread/79603?ContentTypeID=1</link><pubDate>Mon, 13 Mar 2017 15:21:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:662dcdee-8c2c-4508-8b86-f587935bebd5</guid><dc:creator>tkorsdal</dc:creator><description>&lt;p&gt;If your source impedance allows it (See 37.9) you can lower the acquisition time (CH[x].CONFIG).&lt;/p&gt;
&lt;p&gt;You could maybe also have an &amp;quot;activated_channel_mask&amp;quot; that you update in the SAADC_EVENTS_END handling by enabling/disabling SAADC channels and interpret the content of the DMA buffer accordingly. (Haven&amp;#39;t tried this myself though).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Scan Mode mixes channel buffers whan fast.</title><link>https://devzone.nordicsemi.com/thread/79602?ContentTypeID=1</link><pubDate>Mon, 13 Mar 2017 13:19:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c64f4af1-962f-44a4-a6cd-c62db23da273</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;Thank you for pointing me to this section.
What do you suggest on doing else?
I don&amp;#39;t need all three channels at the sametime. But i tought it would be much cleaner to init saadc once then using the tehnique of &lt;code&gt;loop {init, sample, deinit}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I had a crash after many times of doing this. With signal interrupt and no backtrace.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Scan Mode mixes channel buffers whan fast.</title><link>https://devzone.nordicsemi.com/thread/79601?ContentTypeID=1</link><pubDate>Mon, 13 Mar 2017 12:23:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67d65d82-4ca0-4114-a648-0fc369d67723</guid><dc:creator>tkorsdal</dc:creator><description>&lt;p&gt;Yes it is possible - I have seen the same. You must have enough time between sample events to allow 3 acquisitions and 3 conversions. See 37.5.2 og nRF52832 Product Specification.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC Scan Mode mixes channel buffers whan fast.</title><link>https://devzone.nordicsemi.com/thread/79598?ContentTypeID=1</link><pubDate>Mon, 13 Mar 2017 11:41:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26607616-d30b-4b3c-adaf-84efc5e9a3fa</guid><dc:creator>schef</dc:creator><description>&lt;p&gt;I use:
&lt;code&gt;if (i % 3 == 0) SEGGER_RTT_printf(0, &amp;quot;fill: %d: %d\n&amp;quot;, i, p_event-&amp;gt;data.done.p_buffer[i]);&lt;/code&gt;
&lt;code&gt;if (i % 3 == 1) SEGGER_RTT_printf(0, &amp;quot;noise: %d: %d\n&amp;quot;, i, p_event-&amp;gt;data.done.p_buffer[i]);&lt;/code&gt;
&lt;code&gt;if (i % 3 == 2) SEGGER_RTT_printf(0, &amp;quot;battery: %d: %d\n&amp;quot;, i, p_event-&amp;gt;data.done.p_buffer[i]);&lt;/code&gt;
` to view the results.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>