<?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>Task delay faster that expected</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/43198/task-delay-faster-that-expected</link><description>Hi, 
 I am using nRF52832, SDK 15. My code is based on the freeRTOS code examples. 
 
 I am trying to Run my Task Every 10 ms. I tried to test this by using a counter to print every minute. And every minute ,the notification appears after 58.6 seconds</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 05 Feb 2019 09:19:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/43198/task-delay-faster-that-expected" /><item><title>RE: Task delay faster that expected</title><link>https://devzone.nordicsemi.com/thread/169442?ContentTypeID=1</link><pubDate>Tue, 05 Feb 2019 09:19:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a0b8d0a-81e2-4ca0-ba6f-55dee1afc757</guid><dc:creator>CheMax</dc:creator><description>&lt;p&gt;I think you can found answer in this topic:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/26517/what-is-void-dummy-nrf52840-sdk-14-0/104339#104339"&gt;about (volatile)dummy&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Good luck in your codding.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Task delay faster that expected</title><link>https://devzone.nordicsemi.com/thread/169420?ContentTypeID=1</link><pubDate>Tue, 05 Feb 2019 08:07:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76dba184-7ebc-4e39-abdb-40f310d4faf9</guid><dc:creator>ibrahim upright</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks a lot for you answer&amp;nbsp;&lt;/p&gt;
&lt;p&gt;i Have another question&amp;nbsp;why do i need this part in the code :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;volatile uint32_t dummy = NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0];&lt;br /&gt; (void)dummy;&lt;/p&gt;
&lt;p&gt;Thanks you CheMax&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Task delay faster that expected</title><link>https://devzone.nordicsemi.com/thread/169215?ContentTypeID=1</link><pubDate>Mon, 04 Feb 2019 06:42:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6d58f24-d869-487a-ac8d-b80bd3ff57b9</guid><dc:creator>CheMax</dc:creator><description>&lt;p&gt;This is a very simplified example written in a couple of minutes. But it shows the necessary basic functions.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*--------------------------------------------------------------------------------------*/
bool TimerCreate (void)
{ 
  NRF_TIMER1-&amp;gt;MODE       = TIMER_MODE_MODE_Timer&amp;lt;&amp;lt;TIMER_MODE_MODE_Pos;
  NRF_TIMER1-&amp;gt;BITMODE    = TIMER_BITMODE_BITMODE_32Bit;
  NRF_TIMER1-&amp;gt;PRESCALER  = 0x09;		// 16 MHz / 2^9 = 31.25 kHz
  NRF_TIMER1-&amp;gt;CC[0]      = 60*31250;    // 60 sec = 1 min
  NRF_TIMER1-&amp;gt;INTENSET   = TIMER_INTENSET_COMPARE0_Enabled&amp;lt;&amp;lt;TIMER_INTENSET_COMPARE0_Pos;  
  // Enable timer interupt
  NVIC_ClearPendingIRQ(TIMER1_IRQn);
  NVIC_EnableIRQ(TIMER1_IRQn);
  
  return NRF_SUCCESS;
}
/*--------------------------------------------------------------------------------------*/  
xTaskHandle hSomeTask;
bool CreateSomeTask (uint8_t StackSize, uint8_t Priority)
{
	return xTaskCreate(tSomeTask, &amp;quot;SomeTask&amp;quot;, StackSize, NULL, Priority, &amp;amp;hSomeTask);
}
/*--------------------------------------------------------------------------------------*/
void tSomeTask  (void *pvConext)
{
	// Init all what you need
	TimerCreate();	// Create 1min timer
	
	// Task Body
	for(;;)
	{
		// Wait notification
		xTaskNotifyWait(0x00, 0xffff, NULL, portMAX_DELAY);	
		
		/* do something*/
	}
}
/*--------------------------------------------------------------------------------------*/
/* Timer interupt handler */
void TIMER1_IRQHandler(void)
{
  if(NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0])
  { // Clear IRQ event flag
    NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0] = 0x0UL;
    volatile uint32_t dummy = NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0];
    (void)dummy;
	
	// Give Notification
	xTaskNotifyFromISR(hSomeTask);
  }
}
/*--------------------------------------------------------------------------------------*/&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Max&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Task delay faster that expected</title><link>https://devzone.nordicsemi.com/thread/169172?ContentTypeID=1</link><pubDate>Sun, 03 Feb 2019 09:49:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dd8b7b9e-499c-4d34-ae5e-756b437bf2a7</guid><dc:creator>ibrahim upright</dc:creator><description>&lt;p&gt;Thank you both for the answer ,&lt;/p&gt;
&lt;p&gt;May i have a sample code for the&amp;nbsp;&lt;strong&gt;hardware timer&lt;/strong&gt;&lt;span&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;strong&gt;direct task notification??&lt;/strong&gt;&lt;span&gt;.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks A lot&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;ibrahim&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Task delay faster that expected</title><link>https://devzone.nordicsemi.com/thread/169005?ContentTypeID=1</link><pubDate>Fri, 01 Feb 2019 09:27:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:96cbbb43-cd9a-4690-91c1-e3cb782fea1a</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;perfect answer., +1&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Task delay faster that expected</title><link>https://devzone.nordicsemi.com/thread/168905?ContentTypeID=1</link><pubDate>Thu, 31 Jan 2019 14:38:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c52ea252-7aac-44b2-8381-a76ce19fa96c</guid><dc:creator>CheMax</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I guess the problem will remain.&lt;br /&gt;The fact is that the RTS is used to clock the core of the RTOS. There is no possibility to choose a divider so that it gives 1ms.&lt;/p&gt;
&lt;p&gt;Currently divide 32 is used (if you look at the documentation, the divisor is given as a power of 2).&lt;br /&gt;37768 Hz / 32 = 1024 Hz&lt;/p&gt;
&lt;p&gt;Therefore, a context switch every 1000/1024 = 0.976 ms.&lt;br /&gt;From here and there is an error while waiting.&lt;/p&gt;
&lt;p&gt;If you need precisely deterministic delays, you can use the &lt;strong&gt;hardware timer&lt;/strong&gt; and &lt;strong&gt;direct task notification&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Max&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>