<?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>Does Counter Mode Timer really need TASKS_START ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/32025/does-counter-mode-timer-really-need-tasks_start</link><description>[References] 
 In page 234 of nRF52832_PS_v1.4 it says &amp;quot;In both modes, the TIMER is started by triggering the START task, and stopped by triggering the STOP task.&amp;quot; 
 In this post stated: &amp;quot; You must start the timer with TASKS_START also in counter mode</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 15 Mar 2018 14:03:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/32025/does-counter-mode-timer-really-need-tasks_start" /><item><title>RE: Does Counter Mode Timer really need TASKS_START ?</title><link>https://devzone.nordicsemi.com/thread/124608?ContentTypeID=1</link><pubDate>Thu, 15 Mar 2018 14:03:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8aca94e1-d6e1-4b79-8f8b-3c64643e513f</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;yes, this seemed to work. I also confirmed this internally and I can confirm now that the low power mode for the timer in counter mode should work better (power consumption wise) if TASKS_START is not used. Please mark this answer as verified, if it has helped you.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Does Counter Mode Timer really need TASKS_START ?</title><link>https://devzone.nordicsemi.com/thread/124258?ContentTypeID=1</link><pubDate>Wed, 14 Mar 2018 04:59:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ee26bd0-cefe-4566-9e07-4c844fab8b85</guid><dc:creator>XavierYin</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/aryan"&gt;Susheel Nuguru&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static nrf_ppi_channel_t    ppi_channel_compare0;
static nrf_ppi_channel_t    ppi_channel_compare1;
static nrf_ppi_channel_t    ppi_channel_compare2;

void main(void)
{
    NRF_LOG_INIT(NULL);
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    nrf_drv_clock_init();
    nrf_drv_clock_lfclk_request(NULL);

    nrf_pwr_mgmt_init();

    NRF_RTC2-&amp;gt;TASKS_STOP        = 1;
    NRF_RTC2-&amp;gt;TASKS_CLEAR       = 1;
    NRF_RTC2-&amp;gt;EVENTS_TICK       = 0;
    NRF_RTC2-&amp;gt;EVENTS_OVRFLW     = 0;
    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;EVTENCLR          = 0xffffffff;
    NRF_RTC2-&amp;gt;EVTENSET          = RTC_EVTENSET_COMPARE0_Msk | RTC_EVTENSET_COMPARE1_Msk | RTC_EVTENSET_COMPARE2_Msk | RTC_EVTENSET_COMPARE3_Msk;
    NRF_RTC2-&amp;gt;INTENCLR          = 0xffffffff;
    NRF_RTC2-&amp;gt;INTENSET          = RTC_INTENSET_COMPARE3_Msk;
    NRF_RTC2-&amp;gt;PRESCALER         = 0;
    NRF_RTC2-&amp;gt;CC[0]             = 32768 * 1;
    NRF_RTC2-&amp;gt;CC[1]             = 32768 * 2;
    NRF_RTC2-&amp;gt;CC[2]             = 32768 * 3;
    NRF_RTC2-&amp;gt;CC[3]             = 32768 * 4;
    NVIC_ClearPendingIRQ(RTC2_IRQn);
    NVIC_EnableIRQ(RTC2_IRQn);

    NRF_TIMER4-&amp;gt;TASKS_CLEAR  = 1;
    NRF_TIMER4-&amp;gt;SHORTS       = 0;
    NRF_TIMER4-&amp;gt;INTENCLR     = 0xffffffff;
    NRF_TIMER4-&amp;gt;MODE         = TIMER_MODE_MODE_LowPowerCounter;
    NRF_TIMER4-&amp;gt;BITMODE      = TIMER_BITMODE_BITMODE_32Bit;
    NRF_TIMER4-&amp;gt;PRESCALER    = 0;
    NRF_TIMER4-&amp;gt;CC[0]        = 0;
    NRF_TIMER4-&amp;gt;CC[1]        = 0;
    NRF_TIMER4-&amp;gt;CC[2]        = 0;
    NRF_TIMER4-&amp;gt;CC[3]        = 0;
    NRF_TIMER4-&amp;gt;CC[4]        = 0;
    NRF_TIMER4-&amp;gt;CC[5]        = 0;
    NVIC_DisableIRQ(TIMER4_IRQn);

    nrf_drv_ppi_init();
    nrf_drv_ppi_channel_alloc(&amp;amp;ppi_channel_compare0);
    nrf_drv_ppi_channel_assign(ppi_channel_compare0, (uint32_t)&amp;amp;NRF_RTC2-&amp;gt;EVENTS_COMPARE[0], (uint32_t)&amp;amp;NRF_TIMER4-&amp;gt;TASKS_COUNT);
    nrf_drv_ppi_channel_alloc(&amp;amp;ppi_channel_compare1);
    nrf_drv_ppi_channel_assign(ppi_channel_compare1, (uint32_t)&amp;amp;NRF_RTC2-&amp;gt;EVENTS_COMPARE[1], (uint32_t)&amp;amp;NRF_TIMER4-&amp;gt;TASKS_COUNT);
    nrf_drv_ppi_channel_alloc(&amp;amp;ppi_channel_compare2);
    nrf_drv_ppi_channel_assign(ppi_channel_compare2, (uint32_t)&amp;amp;NRF_RTC2-&amp;gt;EVENTS_COMPARE[2], (uint32_t)&amp;amp;NRF_TIMER4-&amp;gt;TASKS_COUNT);

    nrf_drv_ppi_channel_enable(ppi_channel_compare0);
    nrf_drv_ppi_channel_enable(ppi_channel_compare1);
    nrf_drv_ppi_channel_enable(ppi_channel_compare2);
#ifdef DO_TIMER_TASKS_START
    NRF_TIMER4-&amp;gt;TASKS_START  = 1;
#endif
    NRF_RTC2-&amp;gt;TASKS_START       = 1;

    NRF_LOG_INFO(&amp;quot;start running&amp;quot;);

    while (1)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            nrf_pwr_mgmt_run();
        }
    }
}

void RTC2_IRQHandler(void)
{
    nrf_drv_ppi_channel_disable(ppi_channel_compare0);
    nrf_drv_ppi_channel_disable(ppi_channel_compare1);
    nrf_drv_ppi_channel_disable(ppi_channel_compare2);

    NRF_RTC2-&amp;gt;EVTENCLR          = RTC_EVTENCLR_COMPARE3_Msk;
    NRF_RTC2-&amp;gt;INTENCLR          = 0xffffffff;
    NVIC_DisableIRQ(RTC2_IRQn);

    NRF_TIMER4-&amp;gt;TASKS_CAPTURE[0] = 1;
    NRF_LOG_INFO(&amp;quot;RTC2 EVENT: %u, %u, %u, %u&amp;quot;, NRF_RTC2-&amp;gt;EVENTS_COMPARE[0], NRF_RTC2-&amp;gt;EVENTS_COMPARE[1], NRF_RTC2-&amp;gt;EVENTS_COMPARE[2], NRF_RTC2-&amp;gt;EVENTS_COMPARE[3]);
    NRF_LOG_INFO(&amp;quot;TIMER4-&amp;gt;CC[0] = %u&amp;quot;, NRF_TIMER4-&amp;gt;CC[0]);
    NRF_LOG_INFO(&amp;quot;turned off all PPI, but keep RTC &amp;amp; TIMER running for current measurement&amp;quot;);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Do you think this demonstrates &amp;quot;&lt;em&gt;the worst case scenario&lt;/em&gt;&amp;quot;?&lt;br /&gt;Can you kindly share the results on your side?&lt;br /&gt;Do you&amp;nbsp;expect any&amp;nbsp;notable difference about energy consumption if softdevice is enabled (advertising)?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Does Counter Mode Timer really need TASKS_START ?</title><link>https://devzone.nordicsemi.com/thread/124219?ContentTypeID=1</link><pubDate>Tue, 13 Mar 2018 16:31:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:869887ac-3d02-4b9f-9540-c57b8baf7aa8</guid><dc:creator>XavierYin</dc:creator><description>&lt;p&gt;Thank you for prompt reply. Let me make sure if I understand correctly.&amp;nbsp;(I&amp;#39;ll do the test tomorrow anyway)&lt;/p&gt;
&lt;p&gt;&amp;nbsp; 1. After TASKS_START, resources for Timer peripheral are requested and this is the several uA we measured.&lt;br /&gt;&amp;nbsp; 2.&amp;nbsp;&lt;span&gt;TASKS_COUNT will only work while those resources are already requested (by TASKS_START or&amp;nbsp;any other &amp;quot;Luck&amp;quot;).&lt;br /&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp; 3. Whenever there is no&amp;nbsp;TASKS_COUNT, it is safe to use TASKS_STOP to release resources. If there are not other peripherals requesting resources, this will save those several uA in 1.. &lt;br /&gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp; 4. By repeating all 3 on above, Counter Mode Timer can be incremented correctly.&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Am I taking anything wrong on above?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Assuming TASKS_COUNT is triggered in a relatively long period, is the most energy optimized legal way to use Counter Mode Timer be&amp;nbsp;&lt;span&gt;&amp;quot;pre-triggering event (at least 0.25 us before?) -&amp;gt; PPI -&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;TASKS_START, riggering event&amp;nbsp;-&amp;gt; PPI -&amp;gt; TASKS_COUNT, post-triggering event (how long after?) -&amp;gt; PPI -&amp;gt; TASKS_STOP&lt;/span&gt;&lt;span&gt;&amp;quot; ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In this usage,&amp;nbsp;what are&amp;nbsp;the timing requirements between &amp;quot;TASKS_START &amp;lt;=&amp;gt;&amp;nbsp;TASKS_COUNT&amp;quot; &amp;amp;&amp;nbsp;&amp;quot;TASKS_COUNT &amp;lt;=&amp;gt;&amp;nbsp;TASKS_STOP&amp;quot; ? Is there a&amp;nbsp;definitive behavior we can take advantage by using PPI fork or something ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Does Counter Mode Timer really need TASKS_START ?</title><link>https://devzone.nordicsemi.com/thread/124141?ContentTypeID=1</link><pubDate>Tue, 13 Mar 2018 11:18:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14a63b54-f74b-4bc7-b35d-9f4ab2a08085</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Xavier,&lt;/p&gt;
&lt;p&gt;The counter task might work correctly when you are doing this test after the first reset. I call this kind of&amp;nbsp;result &amp;quot;getting lucky&amp;quot;. This is because this was not designed this way, but the internal implementation of it makes it possible to use it. The designers of the hardware always use TASKS_START and TASKS_STOP to request the peripheral resources and release them. In this case, the clock and voltage regulators that are required by the TIMER4 is already running since the CPU is running. Imagine a situation where you have configured your device in a way, that releases all the clocks and voltage regulators are OFF. This is a very common situation on sleep mode. Then not doing a TASKS_START means&amp;nbsp;missing the part where you properly register the module to resource manager.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I would recommend you one test.&lt;/p&gt;
&lt;p&gt;1) configure an RTC to generate a TICK every X seconds. (disable all interrupts on this RTC)&lt;/p&gt;
&lt;p&gt;2) use this tick event -&amp;gt; GPIOTE -&amp;gt; connect this task to the TASKS_COUNT&lt;/p&gt;
&lt;p&gt;3) Initialize your TIMER4 exactly like above except that TASKS_COUNT is coming from RTC.&lt;/p&gt;
&lt;p&gt;4) make the system to go to sleep __WFE()&lt;/p&gt;
&lt;p&gt;5) wakeup aftersometime and disable RTC ticks.&lt;/p&gt;
&lt;p&gt;6) check for the TIMER4 counter value&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Why are we doing this? Since we want to see that your &amp;quot;Lucky outcome&amp;quot; will survive the worst case scenario. This is not specified in spec, hence the TIMERS are not tested for this. But if you get a good result above, then you should be covered.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>