<?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>nrf51822 Timer calculation</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/27640/nrf51822-timer-calculation</link><description>Hello Everyone, 
 Maybe this is a very silly question.
I am trying to implement timer in nrf51822 with S130, SDK11. 
 Code snippet: 
 void TIMER1_IRQHandler(void)

{
 
if ((NRF_TIMER2-&amp;gt;EVENTS_COMPARE[0] != 0) &amp;amp;&amp;amp; ((NRF_TIMER2-&amp;gt;INTENSET &amp;amp; TIMER_INTENSET_COMPARE0_Msk</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 10 Dec 2018 09:07:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/27640/nrf51822-timer-calculation" /><item><title>RE: nrf51822 Timer calculation</title><link>https://devzone.nordicsemi.com/thread/160893?ContentTypeID=1</link><pubDate>Mon, 10 Dec 2018 09:07:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ae97b31-b337-4af2-9265-c586859c3116</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Please post your request in a new question, to avoid filling this question with too much information.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf51822 Timer calculation</title><link>https://devzone.nordicsemi.com/thread/160872?ContentTypeID=1</link><pubDate>Mon, 10 Dec 2018 07:07:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3dc20fc6-56ed-41b4-a391-43e6a766a8a5</guid><dc:creator>ps_anu</dc:creator><description>&lt;p&gt;hi...jorgen ... how does timer works ....... if i want to execute the data for 1 minute ..where i have declare the time ?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf51822 Timer calculation</title><link>https://devzone.nordicsemi.com/thread/109146?ContentTypeID=1</link><pubDate>Mon, 04 Dec 2017 11:03:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb8345ec-501d-402b-8669-edbeffc376a8</guid><dc:creator>Dhiraj</dc:creator><description>&lt;p&gt;Hello Jorgen,
I haven&amp;#39;t tried RTC yet.
But I used another method in which I made timer of 1 milli second using TIMER1. And when interrupt is fired i.e., 1 milli sec are over, a &amp;quot;counter&amp;quot; variable is incremented. As the counter reaches 8000, 8 seconds are over.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf51822 Timer calculation</title><link>https://devzone.nordicsemi.com/thread/109145?ContentTypeID=1</link><pubDate>Mon, 04 Dec 2017 08:48:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0b8e95a-f1c2-4cc5-b39e-09b35e8b1d05</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;You are correct, I only considered the calculation, not which timer instance you were using. Have you considered using &lt;a href="http://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.1.pdf#page=103"&gt;RTC&lt;/a&gt; for generating the periodic timer? RTC have 24-bit registers and runs at 32.768 kHz, which is more suited for such long periods like 8s.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf51822 Timer calculation</title><link>https://devzone.nordicsemi.com/thread/109147?ContentTypeID=1</link><pubDate>Thu, 30 Nov 2017 08:33:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fb13f29c-8960-4f78-a68b-77371511e02e</guid><dc:creator>Dhiraj</dc:creator><description>&lt;p&gt;Hello Jørgen,&lt;/p&gt;
&lt;p&gt;The timer 1 cannot operate in 32bit mode.
So I think such higher count of CC have no effect on the timer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf51822 Timer calculation</title><link>https://devzone.nordicsemi.com/thread/109144?ContentTypeID=1</link><pubDate>Wed, 29 Nov 2017 07:26:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6890d56-994d-4b1c-aafe-2c8abd43b391</guid><dc:creator>Dhiraj</dc:creator><description>&lt;p&gt;Here I am trying to toggle the led state for every 8 sec.
I see that even if I change the value of NRF_TIMER2-&amp;gt;CC[0] to 1000000, there is no change.
When I keep the prescalar at 4 it toggles fast. At prescalar 8, it toggles at ~2-3 seconds.
Am I missing something?&lt;/p&gt;
&lt;p&gt;There was mistake in code which I mentioned previously&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void start_timer(void)
{    
  NRF_TIMER2-&amp;gt;MODE = TIMER_MODE_MODE_Timer;  // Set the timer in Counter Mode
  NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;               // clear the task first to be usable for later
  NRF_TIMER2-&amp;gt;PRESCALER = 8;                             //Set prescaler. Higher number gives slower timer. Prescaler = 0 gives 16MHz timer
  NRF_TIMER2-&amp;gt;BITMODE = TIMER_BITMODE_BITMODE_32Bit;     //Set counter to 16 bit resolution
  NRF_TIMER2-&amp;gt;CC[0] = 500000;                             //Set value for TIMER2 compare register 0
    
  // Enable interrupt on Timer 2, both for CC[0] and CC[1] compare match events
  NRF_TIMER2-&amp;gt;INTENSET = (TIMER_INTENSET_COMPARE0_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE0_Pos) | (TIMER_INTENSET_COMPARE1_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE1_Pos);
  NVIC_EnableIRQ(TIMER2_IRQn);
    
  NRF_TIMER2-&amp;gt;TASKS_START = 1;               // Start TIMER2
}
    
/** TIMTER2 peripheral interrupt handler. This interrupt handler is called whenever there it a TIMER2 interrupt
 */
void TIMER2_IRQHandler(void)
{
  if ((NRF_TIMER2-&amp;gt;EVENTS_COMPARE[0] != 0) &amp;amp;&amp;amp; ((NRF_TIMER2-&amp;gt;INTENSET &amp;amp; TIMER_INTENSET_COMPARE0_Msk) != 0))
  {
    // toggle the led
    NRF_TIMER2-&amp;gt;EVENTS_COMPARE[0] = 0;           //Clear compare register 0 event 
  }

}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf51822 Timer calculation</title><link>https://devzone.nordicsemi.com/thread/109143?ContentTypeID=1</link><pubDate>Tue, 28 Nov 2017 13:32:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db8b8b7e-b469-41ff-89d6-a44e2623fdf2</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Did you try it out? Prescalar of 8 should give a CC value of 500 000 for 8 seconds timer ( (16 MHz / (2^PRESCALAR)) * 8 s = 500 000).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>