<?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>Confused about GPIOTE: pin toggle and  interrupt latency</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/17238/confused-about-gpiote-pin-toggle-and-interrupt-latency</link><description>Hi, 
 I have a pretty simple problem but I can&amp;#39;t get it right. This is what I want to do: 
 T=000, PIN_x = 0 
T=004, PIN_x = 1 
T=100, call a routine 
T=543, Start over (T=544=0) 
 (T is in cycles, 8MHz) 
 It seems like using PPI and GPIOTE is</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 26 Oct 2016 08:51:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/17238/confused-about-gpiote-pin-toggle-and-interrupt-latency" /><item><title>RE: Confused about GPIOTE: pin toggle and  interrupt latency</title><link>https://devzone.nordicsemi.com/thread/66220?ContentTypeID=1</link><pubDate>Wed, 26 Oct 2016 08:51:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d967b796-e28c-491f-b5ec-a0656b8d9ed2</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;That&amp;#39;s nice! Please click on the accept answer button.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Confused about GPIOTE: pin toggle and  interrupt latency</title><link>https://devzone.nordicsemi.com/thread/66219?ContentTypeID=1</link><pubDate>Wed, 26 Oct 2016 01:47:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fd9e0657-88f5-4bf8-9c35-07bbeb680e42</guid><dc:creator>turbog</dc:creator><description>&lt;p&gt;Thanks!&lt;/p&gt;
&lt;p&gt;That solved it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Confused about GPIOTE: pin toggle and  interrupt latency</title><link>https://devzone.nordicsemi.com/thread/66218?ContentTypeID=1</link><pubDate>Mon, 24 Oct 2016 14:07:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33d6f243-dead-4179-96e3-8af6c4d6314f</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;Yes, PPI and GPIOTE would be the correct way for this.&lt;/p&gt;
&lt;p&gt;You can use three compare registers for this, and set the prescaler to 1 (8MHz):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_TIMER0-&amp;gt;PRESCALER = 1;
NRF_TIMER0-&amp;gt;CC[0] = 40;
NRF_TIMER0-&amp;gt;CC[1] = 100;
NRF_TIMER0-&amp;gt;CC[2] = 544;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Use shorts to clear timer on &lt;code&gt;CC[2]&lt;/code&gt;. Timer becomes zero right away so it will start to count on 1 next cycle.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_TIMER0-&amp;gt;SHORTS = TIMER_SHORTS_COMPARE2_CLEAR_Enabled &amp;lt;&amp;lt; TIMER_SHORTS_COMPARE2_CLEAR_Pos;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can then use &lt;code&gt;CC[2] = 544&lt;/code&gt; to toggle the PIN (as in your &lt;strong&gt;T=000, PIN_x = 0&lt;/strong&gt;), and &lt;code&gt;CC[0] = 40&lt;/code&gt; to toggle the pin again (as in your &lt;strong&gt;T=040, PIN_x = 1&lt;/strong&gt;). Do this with PPI and GPIOTE:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_GPIOTE-&amp;gt;CONFIG[0] = (3 &amp;lt;&amp;lt; 0) | (PIN1 &amp;lt;&amp;lt; 8) | (3 &amp;lt;&amp;lt; 16) | (1 &amp;lt;&amp;lt; 20); //Task mode, PIN1, Toggle, init: 1
NRF_PPI-&amp;gt;CHENSET = 0x3; //enable two channels
NRF_PPI-&amp;gt;CH[0].EEP = (uint32_t) &amp;amp;NRF_TIMER0-&amp;gt;EVENTS_COMPARE[2];
NRF_PPI-&amp;gt;CH[0].TEP = (uint32_t) &amp;amp;NRF_GPIOTE-&amp;gt;TASKS_OUT[0];
NRF_PPI-&amp;gt;CH[1].EEP = (uint32_t) &amp;amp;NRF_TIMER0-&amp;gt;EVENTS_COMPARE[0];
NRF_PPI-&amp;gt;CH[1].TEP = (uint32_t) &amp;amp;NRF_GPIOTE-&amp;gt;TASKS_OUT[0];
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And yes, the time when this happen will be within the 8MHz clock cycle specified in the CC register (T=544/0 and T=40)&lt;/p&gt;
&lt;p&gt;Enable interrupt for the &lt;code&gt;CC[1]&lt;/code&gt; register:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NVIC_EnableIRQ(TIMER0_IRQn);
NRF_TIMER0-&amp;gt;INTENSET = (1 &amp;lt;&amp;lt; 17);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now you can do CPU stuff in the &lt;code&gt;TIMER0_IRQHandler()&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void TIMER0_IRQHandler(void){
    if(NRF_TIMER0-&amp;gt;EVENTS_COMPARE[1]){
        NRF_TIMER0-&amp;gt;EVENTS_COMPARE[1] = 0;
        do_stuff();
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The CPU would then start executing at T=100 + latency. Since the HF clock and 1.2V peripheral regulator is already running (because of TIMER) the only thing that is started is the 1.7V regulator which takes ~2us to startup (table 32 Power management in the PS). So then T = 100 cycles + 2us.&lt;/p&gt;
&lt;p&gt;Clear and start timer after init:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;NRF_TIMER0-&amp;gt;TASKS_CLEAR = 1;
NRF_TIMER0-&amp;gt;TASKS_START = 1;
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Confused about GPIOTE: pin toggle and  interrupt latency</title><link>https://devzone.nordicsemi.com/thread/66217?ContentTypeID=1</link><pubDate>Fri, 21 Oct 2016 22:13:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69156f80-a7c1-43de-9060-9dc3dec42fb2</guid><dc:creator>turbog</dc:creator><description>&lt;p&gt;Clarify&lt;/p&gt;
&lt;p&gt;T=000, PIN_x = 0&lt;/p&gt;
&lt;p&gt;T=040, PIN_x = 1&lt;/p&gt;
&lt;p&gt;T=100, call a routine&lt;/p&gt;
&lt;p&gt;T=543, start over&lt;/p&gt;
&lt;p&gt;T=544=0&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>