<?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>Triggering saadc with RTC2 compare channel - initially working and than stops</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/79693/triggering-saadc-with-rtc2-compare-channel---initially-working-and-than-stops</link><description>Hi, 
 I am working on nrf52832, s132, SDK17, trying to trigger the saadc with the RTC2 
 This is my setup : 
 
 what I am trying to do is to periodically trigger a series of samples and than stop them until the next cycle, I have done this successfully</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 22 Sep 2021 10:03:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/79693/triggering-saadc-with-rtc2-compare-channel---initially-working-and-than-stops" /><item><title>RE: Triggering saadc with RTC2 compare channel - initially working and than stops</title><link>https://devzone.nordicsemi.com/thread/330611?ContentTypeID=1</link><pubDate>Wed, 22 Sep 2021 10:03:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6727495a-c6ab-4f9b-b1c8-700a3a8ea46f</guid><dc:creator>Ron</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Vidar,&lt;/p&gt;
&lt;p&gt;I wrongly assumed that&amp;nbsp;resetting the CC (By nrf_drv_rtc_cc_set) will be enough and no&amp;nbsp;writing to the CC itself directly will not be required. anyway that fixed it,&lt;/p&gt;
&lt;p&gt;Thanks!&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Triggering saadc with RTC2 compare channel - initially working and than stops</title><link>https://devzone.nordicsemi.com/thread/329877?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 14:07:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc6f9689-82d1-4741-b461-375cb7348781</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;You also need to clear the counter from your adc_rtc2_start_sequence() function. Depending on your RTC configuration, It can take quite a while for the counter register to wrap over.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Triggering saadc with RTC2 compare channel - initially working and than stops</title><link>https://devzone.nordicsemi.com/thread/329875?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 14:04:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f596b41d-5462-400a-83b7-b78b6b8fd229</guid><dc:creator>Ron</dc:creator><description>&lt;p&gt;Hey,&lt;/p&gt;
&lt;p&gt;That is the handler,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am calling it exactly the same from a different place as well, a timer handler which is called cyclically&lt;pre class="ui-code" data-mode="c_cpp"&gt;void adc_rtc2_start_sequence(void)
{
	err_code = nrf_drv_rtc_cc_set(&amp;amp;rtc,0,COMPARE_COUNTERTIME * 200,true);
	APP_ERROR_CHECK(err_code);
}

static void meas_timeout_handler(void * p_context)
{
    adc_rtc2_start_sequence();
}

//---------------
#define BATTERY_MEAS_INTERVAL_FIRST     	APP_TIMER_TICKS((1000)) 
APP_TIMER_DEF(m_battery_timer_id);
//---------------
app_timer_create(&amp;amp;m_battery_timer_id, APP_TIMER_MODE_REPEATED, meas_timeout_handler);
app_timer_start(m_battery_timer_id, BATTERY_MEAS_INTERVAL_FIRST, NULL); &lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Triggering saadc with RTC2 compare channel - initially working and than stops</title><link>https://devzone.nordicsemi.com/thread/329872?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 13:57:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22354535-ba7e-43af-9ca7-66b497a10a5e</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I only see you calling nrf_drv_rtc_cc_set(&amp;amp;rtc,0,COMPARE_COUNTERTIME * 200,true); when you hit the else statement in rtc_handler() and not if you enter the first if statement.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Triggering saadc with RTC2 compare channel - initially working and than stops</title><link>https://devzone.nordicsemi.com/thread/329868?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 13:48:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:226c0df8-0eda-4c9f-a569-42fd41fe2d7c</guid><dc:creator>Ron</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote userid="4240" url="~/f/nordic-q-a/79693/triggering-saadc-with-rtc2-compare-channel---initially-working-and-than-stops/329862#329862"]Can you set the CC register to trigger the interrupt again in 1 second [/quote]
&lt;p&gt;Yes, after 1 sec I do call the same command again; I call it cyclically every 1 sec,&lt;pre class="ui-code" data-mode="text"&gt;err_code = nrf_drv_rtc_cc_set(&amp;amp;rtc,0,COMPARE_COUNTERTIME * 200,true);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But the interrupt does not appear again as in the first call, and I don&amp;#39;t know why&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Triggering saadc with RTC2 compare channel - initially working and than stops</title><link>https://devzone.nordicsemi.com/thread/329862?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 13:28:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cae8054c-acd5-44ea-8a4d-f6a17b737c77</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote userid="67544" url="~/f/nordic-q-a/79693/triggering-saadc-with-rtc2-compare-channel---initially-working-and-than-stops/329860#329860"]regrading the retriggering,&amp;nbsp;what if I want it to stop after 4 samples for example, and than start the cycle again in the future, say after 1 sec?[/quote]
&lt;p&gt;Can you set the CC register to trigger the interrupt again in 1 second then?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Triggering saadc with RTC2 compare channel - initially working and than stops</title><link>https://devzone.nordicsemi.com/thread/329860?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 13:27:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58ef2dee-3613-4ba7-80a9-a824af0ecff9</guid><dc:creator>Ron</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I understand regarding the rest,&lt;/p&gt;
&lt;p&gt;regrading the retriggering,&amp;nbsp;what if I want it to stop after 4 samples for example, and than start the cycle again in the future, say after 1 sec?&lt;/p&gt;
&lt;p&gt;Thanks again&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Triggering saadc with RTC2 compare channel - initially working and than stops</title><link>https://devzone.nordicsemi.com/thread/329852?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 12:57:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:85dc1182-a256-44a9-98ba-fac3449d3eff</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote userid="67544" url="~/f/nordic-q-a/79693/triggering-saadc-with-rtc2-compare-channel---initially-working-and-than-stops/329845#329845"]If I clear it, do I still need to do the following? :[/quote]
&lt;p&gt;The driver is responsible for clearing of these events. So no, you shouldn&amp;#39;t clear them in the application callback.&lt;/p&gt;
&lt;p&gt;You have to explicitly re-enable the event by calling nrf_drv_rtc_cc_set() after you have gotten a compare event if you want the compare event to trigger again. This is because the driver&amp;#39;s IRQ handler is disables it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Triggering saadc with RTC2 compare channel - initially working and than stops</title><link>https://devzone.nordicsemi.com/thread/329845?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 12:42:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:558dada1-2dbc-472b-8a85-ab60813a8228</guid><dc:creator>Ron</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;Thanks for your help,&lt;/p&gt;
&lt;p&gt;If I clear it, do I still need to do the following? :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;	NRF_RTC2-&amp;gt;EVENTS_COMPARE[0] = 0;
	NRF_RTC2-&amp;gt;EVENTS_COMPARE[1] = 0;
	NRF_RTC2-&amp;gt;EVENTS_COMPARE[2] = 0;
	NRF_RTC2-&amp;gt;EVENTS_COMPARE[3] = 0;
    NRF_RTC2-&amp;gt;EVENTS_TICK       = 0;
    NRF_RTC2-&amp;gt;EVENTS_OVRFLW     = 0;	&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Anyway I implemented the following code&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
{
    ret_code_t err_code;
		
		if (int_type == NRF_DRV_RTC_INT_COMPARE0)
		{
			nrf_drv_rtc_counter_clear(&amp;amp;rtc);
				
			//-------------------------------------
			if (rtc2_c0_counter &amp;gt;= ADC_BUFFER_SIZE)
			{
				rtc2_c0_counter = 0;
			}			
			else
			{
				err_code = nrf_drv_rtc_cc_set(&amp;amp;rtc,0,COMPARE_COUNTERTIME * 200,true);
				rtc2_c0_counter++;
			}		
		}
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It still does not work beyond the first series of samples, as long as I am&amp;nbsp;&lt;span&gt;resetting the the CC -&lt;/span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;nrf_drv_rtc_cc_set(&amp;amp;rtc,0,COMPARE_COUNTERTIME * 200,true);&lt;/pre&gt; it is working, but after I stop it on the&amp;nbsp;ADC_BUFFER_SIZE sample, it never starts again, clearing the RTC does not seems to fix it.&lt;/p&gt;
&lt;p&gt;Any ideas?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Triggering saadc with RTC2 compare channel - initially working and than stops</title><link>https://devzone.nordicsemi.com/thread/329829?ContentTypeID=1</link><pubDate>Thu, 16 Sep 2021 12:06:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9f93d1b3-1f53-42cf-9696-a898fc0564b7</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Looks like you are forgetting to clear the RTC counter from the driver callback?&lt;/p&gt;
&lt;p&gt;Please try to clear it like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
{
    uint32_t err_code; 

    if (int_type == NRF_DRV_RTC_INT_COMPARE0)
    {
        nrf_gpio_pin_toggle(COMPARE_EVENT_OUTPUT);
        
        nrf_drv_rtc_counter_clear(&amp;amp;rtc);
        err_code = nrf_drv_rtc_cc_set(&amp;amp;rtc,0 ,COMPARE_COUNTERTIME * 200,true);
        APP_ERROR_CHECK(err_code);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>