<?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>nRF52840 - SDK16 - RTC + SAADC + PPI does not work</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/85289/nrf52840---sdk16---rtc-saadc-ppi-does-not-work</link><description>Ηι 
 Hi everyone, 
 I have written a code to sample from an analog input using RTC and PPI. 
 The SAADC does not start on RTC compare event. 
 The RTC compare channel works fine. When I enable the interrupts, I capture the NRFX_RTC_INT_COMPARE0 in the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 02 Mar 2022 15:07:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/85289/nrf52840---sdk16---rtc-saadc-ppi-does-not-work" /><item><title>RE: nRF52840 - SDK16 - RTC + SAADC + PPI does not work</title><link>https://devzone.nordicsemi.com/thread/355864?ContentTypeID=1</link><pubDate>Wed, 02 Mar 2022 15:07:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:642ce759-3b5a-4754-9950-6d4341a7db26</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;I think this issue you are seeing is related to what I described in my previous answer, that the SAMPLE task will be triggered again by the 5th DONE/RESULTDONE event (and again for the 6th, 7th, 8th, etc.). Like I said, triggering the SAMPLE task between the END event and a START task may cause undesired/undefined behavior. I output the RESULTDONE event on a GPIOTE pin, and it is constantly triggering every ~11.75 us. Although you only start the SAADC every RTC event, this may cause problems. You need to implement some way to stop the triggering of the SAMPLE task after the 5th RESULTDONE event. This can be done by assigning the PPI channel to a PPI group, which can be enabled/disabled through PPI, either from the SAADC-&amp;gt;END event (but this may come too late), or from a COMPARE event from a TIMER configured in count mode (not low power).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - SDK16 - RTC + SAADC + PPI does not work</title><link>https://devzone.nordicsemi.com/thread/355790?ContentTypeID=1</link><pubDate>Wed, 02 Mar 2022 11:37:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4fd9d3b4-939c-4e0a-b73d-9828f7da1ce1</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Thank you Jorgen,&lt;/p&gt;
&lt;p&gt;I assigned the second PPI channel as you suggested but it didn&amp;#39;t work&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void ppi_init(void) {

  uint32_t err_code;
  uint32_t rtc_compare_event_addr; // variable to hold the address of rtc event
  uint32_t saadc_sample_task_addr; // variable to hold the address of saadc task

  rtc_compare_event_addr = nrfx_rtc_event_address_get(&amp;amp;rtc, NRF_RTC_EVENT_COMPARE_0); // get the address of COMPARE 0 event
  saadc_sample_task_addr = nrfx_saadc_sample_task_get();                              // getting the address of NRF_SAADC_TASK_SAMPLE. If low power is enabled it will get the address of NRF_SAADC_TASK_START

  err_code = nrfx_ppi_channel_alloc(&amp;amp;m_ppi_channel); // allocate the channel to start SAADC task on RTC comprare event
  APP_ERROR_CHECK(err_code);

  err_code = nrfx_ppi_channel_alloc(&amp;amp;m_start_SAADC_ppi_channel); // allocate a channel to start SAADC when conversion ends
  APP_ERROR_CHECK(err_code);

  err_code = nrfx_ppi_channel_assign(m_ppi_channel, rtc_compare_event_addr, saadc_sample_task_addr); // Start the SAADC on RTC COMPARE event
  APP_ERROR_CHECK(err_code);
  
  err_code = nrfx_ppi_channel_assign(m_start_SAADC_ppi_channel, nrf_saadc_event_address_get(NRF_SAADC_EVENT_RESULTDONE), nrf_saadc_task_address_get(NRF_SAADC_TASK_SAMPLE)); // Make sure that the SAADC is always started when it ends a conversion
  APP_ERROR_CHECK(err_code);

  err_code = nrfx_ppi_channel_enable(m_ppi_channel); // Enable the PPI channel
  APP_ERROR_CHECK(err_code);

  err_code = nrfx_ppi_channel_enable(m_start_SAADC_ppi_channel); // Enable the PPI channel
  APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Well, as soon as I enable the second PPI channel, it stop working as expected even for a buffer size = 1&lt;/p&gt;
&lt;p&gt;It generates the DONE event one, three, five or six times before stopping&amp;nbsp;working&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1646220847538v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;I would like to share with you my project and the sdk_config file&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/5758.pca10056.zip"&gt;devzone.nordicsemi.com/.../5758.pca10056.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - SDK16 - RTC + SAADC + PPI does not work</title><link>https://devzone.nordicsemi.com/thread/355779?ContentTypeID=1</link><pubDate>Wed, 02 Mar 2022 10:44:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0dcc5568-43e9-4234-ba26-777e2a1286ae</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Yes, I meant similar to that, but NRF_SAADC_TASK_SAMPLE does not hold the register address, this is just an enum variable. Can you try with&amp;nbsp;nrf_saadc_task_address_get(NRF_SAADC_TASK_SAMPLE) to the last argument?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - SDK16 - RTC + SAADC + PPI does not work</title><link>https://devzone.nordicsemi.com/thread/355663?ContentTypeID=1</link><pubDate>Tue, 01 Mar 2022 22:36:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:409afbb8-d744-4479-9d37-404aed3a77aa</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Thank you for your time Jorgen!!&lt;/p&gt;
&lt;p&gt;I removed the second PPI channel and cleaned up the saadc callback function&lt;/p&gt;
&lt;p&gt;Now for low power mode and&amp;nbsp;buffer size equals to&amp;nbsp;1 it works fine.&lt;/p&gt;
&lt;p&gt;This is the new ppi_init function&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void ppi_init(void) {

  uint32_t err_code;
  uint32_t rtc_compare_event_addr; // variable to hold the address of rtc event
  uint32_t saadc_sample_task_addr; // variable to hold the address of saadc task

  rtc_compare_event_addr = nrfx_rtc_event_address_get(&amp;amp;rtc, NRF_RTC_EVENT_COMPARE_0); // get the address of COMPARE 0 event
  saadc_sample_task_addr = nrfx_saadc_sample_task_get();                              // getting the address of NRF_SAADC_TASK_SAMPLE. If low power is enabled it will get the address of NRF_SAADC_TASK_START

  err_code = nrfx_ppi_channel_alloc(&amp;amp;m_ppi_channel); // allocate the channel to start SAADC task on RTC comprare event
  APP_ERROR_CHECK(err_code);

  err_code = nrfx_ppi_channel_assign(m_ppi_channel, rtc_compare_event_addr, saadc_sample_task_addr); // Start the SAADC on RTC COMPARE event
  APP_ERROR_CHECK(err_code);

  err_code = nrfx_ppi_channel_enable(m_ppi_channel); // Enable the PPI channel
  APP_ERROR_CHECK(err_code);

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and this is the saadc callback function&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void saadc_callback(nrfx_saadc_evt_t const *p_event) {

  ret_code_t err_code;
  NRF_LOG_INFO(&amp;quot;Event type: %d&amp;quot;, p_event-&amp;gt;type);

  if (p_event-&amp;gt;type == NRFX_SAADC_EVT_DONE) {

    err_code = nrfx_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAMPLES_IN_BUFFER);
    APP_ERROR_CHECK(err_code);

    int i;
    NRF_LOG_INFO(&amp;quot;ADC event number: %d&amp;quot;, (int)m_adc_evt_counter);

    for (i = 0; i &amp;lt; SAMPLES_IN_BUFFER; i++) {

      NRF_LOG_INFO(&amp;quot;%d&amp;quot;, p_event-&amp;gt;data.done.p_buffer[i]);
    }
    m_adc_evt_counter++;
  }
  nrfx_rtc_counter_clear(&amp;amp;rtc);
  err_code = nrfx_rtc_cc_set(&amp;amp;rtc, COMPARE_CHANNEL_0, COUNTER_VALUE, false);
  APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;However,&amp;nbsp;when the buffer size is greater than one the&amp;nbsp;NRFX_SAADC_EVT_DONE is not produced. The problem is because I do not re-set the compare channel (I clear the counter and re-set the&amp;nbsp;&lt;span&gt;compare channel inside the saadc callback).&lt;/span&gt;&lt;/p&gt;
[quote userid="14926" url="~/f/nordic-q-a/85289/nrf52840---sdk16---rtc-saadc-ppi-does-not-work/355632#355632"]I&amp;#39;m not sure what the intention of this PPI channel was, but my guess would be that you want to fill the 5-sample buffer as quickly as possible when the RTC event triggers? In that case, you can try to pass the address of the SAADC SAMPLE task directly, and replace the DONE event with RESULTDONE event.[/quote]
&lt;p&gt;Yes this is my intention. Do you mean to retain the second PPI channel and assign like that?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;err_code = nrfx_ppi_channel_assign(m_start_SAADC_ppi_channel, nrf_saadc_event_address_get(NRF_SAADC_EVENT_RESULTDONE), NRF_SAADC_TASK_SAMPLE);
  APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I tried but it didn&amp;#39;t work&lt;/p&gt;
&lt;p&gt;How could I work around this issue?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - SDK16 - RTC + SAADC + PPI does not work</title><link>https://devzone.nordicsemi.com/thread/355632?ContentTypeID=1</link><pubDate>Tue, 01 Mar 2022 15:48:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33ee22cf-80bc-4b85-ab05-0dd043f0814f</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It would be useful to see your sdk_config.h file as well, but if your comments are correct, you have set &amp;quot;low power mode = true&amp;quot;. This mode will keep the SAADC peripheral in a low power state between sampling by delaying the triggering of the START task after an END event until the next sampling is triggered. By default, the driver will trigger the START task when the END event is received, to be ready for the SAMPLE task, but this will keep the SAADC peripheral in a state where EasyDMA is enabled, causing high current consumption. When low power mode is enabled, the function&amp;nbsp;nrfx_saadc_sample_task_get() will return the address of the START task, while triggering of the SAMPLE task is handled in the SAADC IRQ handler, when the STARTED event is generated. Triggering the START task multiple times before the END event is generated can cause undesired behavior.&lt;/p&gt;
&lt;p&gt;In you code you have setup a second PPI channel, which connects the&amp;nbsp;NRF_SAADC_EVENT_DONE event to the returned task address from&amp;nbsp;nrfx_saadc_sample_task_get(). The DONE event is generated when one sample have been captured, but possibly before the result is ready and transferred to RAM. The number of DONE events before the result is done depends on the OVERSAMPLE configuration. Anyway, if you have set the low power mode, this PPI channel will cause the START task to be triggered multiple times. I&amp;#39;m not sure what the intention of this PPI channel was, but my guess would be that you want to fill the 5-sample buffer as quickly as possible when the RTC event triggers? In that case, you can try to pass the address of the SAADC SAMPLE task directly, and replace the DONE event with RESULTDONE event. This PPI channel will also trigger the SAMPLE task on the 5th DONE/RESULTDONE event, which may cause issues as described in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/20291/offset-in-saadc-samples-with-easy-dma-and-ble/79053#79053"&gt;this thread&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>