<?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>Two interrupt events on TIMER0</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/399/two-interrupt-events-on-timer0</link><description>Hi, 
 This may be a silly question but I&amp;#39;m trying to generate two timed interrupt events using only TIMER0 (the MCU is nrf51822). My code is: 
 
#define TIMEOUT1 3000 //3s
#define TIMEOUT1 5000 //5s

 NRF_TIMER0-&amp;gt;TASKS_STOP = 1;
 // Create an Event</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 16 Apr 2014 07:01:49 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/399/two-interrupt-events-on-timer0" /><item><title>RE: Two interrupt events on TIMER0</title><link>https://devzone.nordicsemi.com/thread/2078?ContentTypeID=1</link><pubDate>Wed, 16 Apr 2014 07:01:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc3dc8f1-d8c2-4e2b-9bc3-3d3da9f86ac6</guid><dc:creator>kk</dc:creator><description>&lt;p&gt;good!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Two interrupt events on TIMER0</title><link>https://devzone.nordicsemi.com/thread/2083?ContentTypeID=1</link><pubDate>Wed, 27 Nov 2013 13:32:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbd16d4c-d205-403f-83b2-e832d0692878</guid><dc:creator>Bastiaan</dc:creator><description>&lt;p&gt;If you are to use the COMPARE0, you should add that as well.&lt;/p&gt;
&lt;p&gt;-H&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Two interrupt events on TIMER0</title><link>https://devzone.nordicsemi.com/thread/2084?ContentTypeID=1</link><pubDate>Wed, 27 Nov 2013 13:32:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:36fab055-a903-4d0d-9fda-9816d26fa591</guid><dc:creator>Guest</dc:creator><description>&lt;p&gt;If you are to use the COMPARE0, you should add that as well.&lt;/p&gt;
&lt;p&gt;-H&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Two interrupt events on TIMER0</title><link>https://devzone.nordicsemi.com/thread/2082?ContentTypeID=1</link><pubDate>Wed, 27 Nov 2013 10:58:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8385507e-4b87-47cf-b4e0-a124922fea0e</guid><dc:creator>Manlio</dc:creator><description>&lt;p&gt;NRF_TIMER0-&amp;gt;SHORTS      = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled &amp;lt;&amp;lt; TIMER_SHORTS_COMPARE1_CLEAR_Pos);&lt;/p&gt;
&lt;p&gt;Why only clear the COMPARE1?
Do COMPARE0 need be cleared?&lt;/p&gt;
&lt;p&gt;Do need add the code
NRF_TIMER0-&amp;gt;SHORTS      = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled &amp;lt;&amp;lt; TIMER_SHORTS_COMPARE0_CLEAR_Pos);
?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Two interrupt events on TIMER0</title><link>https://devzone.nordicsemi.com/thread/2081?ContentTypeID=1</link><pubDate>Tue, 03 Sep 2013 06:47:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f9423d4-8f09-4706-a5b6-3ef4ed724d90</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;This is to be expected. If you want them to fire every time, do like this in your interrupt:
if (NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] != 0)
{
static uint32_t cc_0 = TIMEOUT1 * 1000;
cc_0 += TIMEOUT1 * 1000;
NRF_TIMER0-&amp;gt;CC[0] = cc_0;
}&lt;/p&gt;
&lt;p&gt;And the same for CC[1].&lt;/p&gt;
&lt;p&gt;BR
Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Two interrupt events on TIMER0</title><link>https://devzone.nordicsemi.com/thread/2080?ContentTypeID=1</link><pubDate>Tue, 03 Sep 2013 06:35:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e7add61-a2b8-4afb-a447-d2e532f745c2</guid><dc:creator>Florin</dc:creator><description>&lt;p&gt;Hmm, I&amp;#39;m afraid it still doesn&amp;#39;t work...
On the code above, try to change the timeouts to:
#define TIMEOUT1 2000    //2s
#define TIMEOUT2 10000    //10s&lt;/p&gt;
&lt;p&gt;Timeout1 should fire every 2s and TIMEOUT2 every 10s. What I observed is that Timeout2 fires first followed by Timeout1 after 2s, followed by 8s of pause. The cycle then repeats.
Is this expected?&lt;/p&gt;
&lt;p&gt;Best,
florin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Two interrupt events on TIMER0</title><link>https://devzone.nordicsemi.com/thread/2079?ContentTypeID=1</link><pubDate>Mon, 02 Sep 2013 15:46:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:053ead81-75b6-4f94-9050-2c0849af3fb1</guid><dc:creator>Florin</dc:creator><description>&lt;p&gt;It works now, good catch.&lt;/p&gt;
&lt;p&gt;Thanks!
florin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Two interrupt events on TIMER0</title><link>https://devzone.nordicsemi.com/thread/2077?ContentTypeID=1</link><pubDate>Mon, 02 Sep 2013 12:45:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03e6c077-2de4-4f3d-99f4-12df88960b90</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Tested your code, and it seems that you forgot to enable interrupt on COMPARE1.
Here&amp;#39;s my test code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
void init_timer(void)
{
    NRF_TIMER0-&amp;gt;TASKS_STOP = 1;
    // Create an Event-Task shortcut to clear TIMER0 on COMPARE[0] event
    NRF_TIMER0-&amp;gt;MODE        = TIMER_MODE_MODE_Timer;
    NRF_TIMER0-&amp;gt;BITMODE     = (TIMER_BITMODE_BITMODE_24Bit &amp;lt;&amp;lt; TIMER_BITMODE_BITMODE_Pos);
    NRF_TIMER0-&amp;gt;PRESCALER   = 4;  // 1us resolution

    NRF_TIMER0-&amp;gt;TASKS_CLEAR = 1;               // clear the task first to be usable for later
    NRF_TIMER0-&amp;gt;CC[0] = TIMEOUT1 * 1000; //first timeout
    NRF_TIMER0-&amp;gt;CC[1] = TIMEOUT2 * 1000;   //second timeout

    NRF_TIMER0-&amp;gt;INTENSET    = TIMER_INTENSET_COMPARE0_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE0_Pos;
    NRF_TIMER0-&amp;gt;INTENSET    = TIMER_INTENSET_COMPARE1_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE1_Pos;
    /* Create an Event-Task shortcut to clear TIMER0 on COMPARE[0] event. */
    NRF_TIMER0-&amp;gt;SHORTS      = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled &amp;lt;&amp;lt; TIMER_SHORTS_COMPARE1_CLEAR_Pos);
    NRF_TIMER0-&amp;gt;TASKS_START = 1;
}

int main(void)
{
    NVIC_EnableIRQ(TIMER0_IRQn);
    init_timer();
    while(1);
}

void TIMER0_IRQHandler(void) 
{
    if (NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] != 0)
    {
        NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0] = 0;
    }
    if (NRF_TIMER0-&amp;gt;EVENTS_COMPARE[1] != 0)
    {
        NRF_TIMER0-&amp;gt;EVENTS_COMPARE[1] = 0;
    }
}

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;BR
Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>