<?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>RTC in repeat mode with no CPU involvement ( SDK v13 )</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87324/rtc-in-repeat-mode-with-no-cpu-involvement-sdk-v13</link><description>Hi Everyone, 
 The custom device I am working on is a BLE peripheral device and uses softdevice S132, 
 therefore to get accurate triggering of ADC sampling and to avoid periodic CPU blocking by the radio, 
 I am trying to get RTC to trigger the ADC without</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 05 May 2022 15:23:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87324/rtc-in-repeat-mode-with-no-cpu-involvement-sdk-v13" /><item><title>RE: RTC in repeat mode with no CPU involvement ( SDK v13 )</title><link>https://devzone.nordicsemi.com/thread/366529?ContentTypeID=1</link><pubDate>Thu, 05 May 2022 15:23:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b5ffe05d-8abc-43e7-b457-9687ed4fb531</guid><dc:creator>bryanhsieh</dc:creator><description>&lt;p&gt;Thanks for the detailed answer. I was able to implement the above with the RTC interrupt disabled as clarified.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC in repeat mode with no CPU involvement ( SDK v13 )</title><link>https://devzone.nordicsemi.com/thread/365390?ContentTypeID=1</link><pubDate>Thu, 28 Apr 2022 11:24:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:898c302b-32ed-4e29-8755-fe7965278b92</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="bryanhsieh"]The main thing I wanted to check was whether the compare flag would get retriggered once the counter of the RTC has been cleared via PPI, but looking at the hardware implementation of the RTC which is slightly different to other peripherals, it looks like event flag is latched by the register so has to be manually cleared by the CPU.[/quote]
&lt;p&gt;The event registers are usually latched when the event signal is generated by the HW peripheral, and needs to be cleared by the CPU. However, the peripheral can normally regenerate the signal event if the register is already set, see&amp;nbsp;&lt;a title="Events" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/peripheral_interface.html?cp=4_2_0_14_5#concept_awc_t4z_vr"&gt;Events&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&amp;quot;&lt;span&gt;&lt;em&gt;Events can be generated by the peripheral even when the event register is set to &amp;#39;1&amp;#39;.&lt;/em&gt;&amp;quot;&lt;/span&gt;&lt;/p&gt;
[quote user="bryanhsieh"]By disabling the interrupt wouldn&amp;#39;t the RTC stop running after the first compare event?[/quote]
&lt;p&gt;The event register needs to be cleared by the CPU in order to trigger a new interrupt, see&amp;nbsp;&lt;a title="Interrupts" href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/peripheral_interface.html?cp=4_2_0_14_7#interrupts"&gt;Interrupts&lt;/a&gt;. If interrupts are disabled, and the events are connected to tasks through PPI, there is no need to clear the event registers for a new event to be generated.&lt;/p&gt;
[quote user="bryanhsieh"]&lt;p&gt;My current implementation ( see attached file ) is this, I have 3 PPIs, one to trigger the ADC start task and forked to clear RTC counter.&lt;/p&gt;
&lt;p&gt;Another PPI to trigger the start sample task on&amp;nbsp;ADC&amp;nbsp;started event.&lt;/p&gt;
&lt;p&gt;And the final PPI to trigger the stop task on events end event.&lt;/p&gt;
&lt;p&gt;The RTC interrupt calls cc_set which clears the compare flag.&lt;/p&gt;
&lt;p&gt;The ADC interrupt clears each individual event and in the case of ADC stopped it uninits and restarts the ADC module before initializing it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For sanity check, with the above implementation would you agree that the ADC sampling would be accurate as long as the compare flag is cleared and ADC result is moved to an array before the next sampling period is up?&lt;/p&gt;[/quote]
&lt;p&gt;Most likely it will work and give accurate sampling time, but there may occur a race condition/issue in case your interrupt handling is delayed long enough. The RTC events/interrupts may be disabled right before the RTC hits the CC value, and enabled again after the CC value is passed. Since you do not clear the RTC in the event handler, the RTC will run until it overflows and hit the CC value value a second time before the event is generated.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC in repeat mode with no CPU involvement ( SDK v13 )</title><link>https://devzone.nordicsemi.com/thread/365252?ContentTypeID=1</link><pubDate>Wed, 27 Apr 2022 15:18:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c66f306-c6c5-496d-bead-9e3a230b4b65</guid><dc:creator>bryanhsieh</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/6661.main.c"&gt;devzone.nordicsemi.com/.../6661.main.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks Jorgen.&lt;/p&gt;
&lt;p&gt;The main thing I wanted to check was whether the compare flag would get retriggered once the counter of the RTC has been cleared via PPI, but looking at the hardware implementation of the RTC which is slightly different to other peripherals, it looks like event flag is latched by the register so has to be manually cleared by the CPU.&amp;nbsp; By disabling the interrupt wouldn&amp;#39;t the RTC stop running after the first compare event?&lt;/p&gt;
&lt;p&gt;My current implementation ( see attached file ) is this, I have 3 PPIs, one to trigger the ADC start task and forked to clear RTC counter.&lt;/p&gt;
&lt;p&gt;Another PPI to trigger the start sample task on&amp;nbsp;ADC&amp;nbsp;started event.&lt;/p&gt;
&lt;p&gt;And the final PPI to trigger the stop task on events end event.&lt;/p&gt;
&lt;p&gt;The RTC interrupt calls cc_set which clears the compare flag.&lt;/p&gt;
&lt;p&gt;The ADC interrupt clears each individual event and in the case of ADC stopped it uninits and restarts the ADC module before initializing it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For sanity check, with the above implementation would you agree that the ADC sampling would be accurate as long as the compare flag is cleared and ADC result is moved to an array before the next sampling period is up?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: RTC in repeat mode with no CPU involvement ( SDK v13 )</title><link>https://devzone.nordicsemi.com/thread/365227?ContentTypeID=1</link><pubDate>Wed, 27 Apr 2022 13:52:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a8f7051-29e2-4235-88b4-cfd7c883901c</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It is not required to call nrf_drv_rtc_cc_set() in the event handler to set the CC value, the reason that this function is called in the handler is to re-enable the event and interrupts. In the IRQ Handler in the RTC driver, the events and interrupts are disabled when the COMPARE event is detected:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrf_rtc_event_disable(p_reg,int_mask);
nrf_rtc_int_disable(p_reg,int_mask);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you disable the interrupt and clear the RTC through PPI (fork), the code in the interrupt handler will not be run, and the CC register will not be changed.&lt;/p&gt;
&lt;p&gt;Note that you will likely not be able to achieve low power SAADC sampling and sampling with precise timing at the same time. The SAADC will have high current consumption when it is STARTED, which is required in order to sample through PPI. We have some &lt;a href="https://github.com/NordicPlayground/nRF52-ADC-examples/tree/master/saadc_low_power"&gt;low power examples&lt;/a&gt;, but this will stop the SAADC between each sample, and it must be restarted by the software.&lt;/p&gt;
&lt;p&gt;You may be able to achieve something semi-precise and low power by triggering the START task through PPI and connect the SAADC STARTED event to the SAMPLE task, but I have not tested this. This approach is also not supported by the SAADC driver, so you would need to write your own custom implementation. In this solution, you need to make sure that the CPU provides a new buffer for the SAADC to sample to between the STARTED event and the next triggering of START task over PPI, to prevent the previous buffer from being overwritten.&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>