<?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>How to implement a simple non-blocking delay on nRF51822 with SoftDevice</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/9405/how-to-implement-a-simple-non-blocking-delay-on-nrf51822-with-softdevice</link><description>Using nrf_delay_ms() can be energy consuming and indeterministic. I am trying to use application timers (from &amp;quot;app_timer.h&amp;quot;) in nRF SDK 8.0. The way I did could be partially described as follows: 
 #define LED_DURATION_IN_MS 400 
#define LED_DURATION_TICKS</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 25 Sep 2015 16:24:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/9405/how-to-implement-a-simple-non-blocking-delay-on-nrf51822-with-softdevice" /><item><title>RE: How to implement a simple non-blocking delay on nRF51822 with SoftDevice</title><link>https://devzone.nordicsemi.com/thread/34710?ContentTypeID=1</link><pubDate>Fri, 25 Sep 2015 16:24:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:124fc5ac-223a-4271-ba2d-d0399403cdfe</guid><dc:creator>diode</dc:creator><description>&lt;p&gt;@Anders That makes sense. Thanks for your explanation!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to implement a simple non-blocking delay on nRF51822 with SoftDevice</title><link>https://devzone.nordicsemi.com/thread/34709?ContentTypeID=1</link><pubDate>Fri, 25 Sep 2015 07:42:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f5f7f30f-2377-4dad-bc46-9d54bd0a141c</guid><dc:creator>Anders Strand</dc:creator><description>&lt;p&gt;If the LED being set indicates success, i believe your code behaves exactly how it should be :)
If you call app_sched_execute() before power_manage(), this happens: power_manage()-&amp;gt;Timer event-&amp;gt;app_sched_execute-&amp;gt;lazy_wait_handler-&amp;gt;power_manage(). It never escaped the while loop, it will sleep forever inside power manage. If you call it after: power_manage()-&amp;gt;Timer event-&amp;gt;app_sched_execute-&amp;gt;lazy_wait_handler-&amp;gt;While loop checking flag -&amp;gt;escape while loop. See the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk51.v9.0.0/group__app__scheduler.html"&gt;scheduler docs&lt;/a&gt; for some more info.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to implement a simple non-blocking delay on nRF51822 with SoftDevice</title><link>https://devzone.nordicsemi.com/thread/34708?ContentTypeID=1</link><pubDate>Thu, 24 Sep 2015 16:38:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2db900a8-486d-4eb9-8a28-d42c83cf3bb0</guid><dc:creator>diode</dc:creator><description>&lt;p&gt;@Anders Thanks for your suggestions. Changing the app scheduling to &amp;quot;false&amp;quot; works. For the second option, it only works when I call app_sched_execute() after power_manage() in the while loop containing &amp;quot;lazy_wait_flag&amp;quot;. It doesn&amp;#39;t work if app_sched_execute() is called before power_manage(). Why is that? Also, what are the pros and cons of disabling scheduling of app timers? I have some app timers and also app buttons which use app timers elsewhere in the code. I just wonder how they will affect the deterministicity of the delay.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to implement a simple non-blocking delay on nRF51822 with SoftDevice</title><link>https://devzone.nordicsemi.com/thread/34711?ContentTypeID=1</link><pubDate>Thu, 24 Sep 2015 14:20:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4dc669c-cfc7-452a-a984-d007f41ad0e6</guid><dc:creator>Anders Strand</dc:creator><description>&lt;p&gt;Hello.
Your last parameter in APP_TIMER_APPSH_INIT is &amp;quot;True&amp;quot;, which means that you intend to use the scheduler. However, the scheduler is not run in your while loop. Try setting the last parameter to &amp;quot;False&amp;quot;, or run app_sched_execute() in the while loop.&lt;/p&gt;
&lt;p&gt;Edit:  About using the app_scheduler:&lt;/p&gt;
&lt;p&gt;The main reason to use this module, is to execute some procedure from main context (low priority) instead of the interrupt context (higher priority). If your procedure is short and  have real time timing requirements, you should execute it directly in the interrupt handler and not use the scheduler. If your procedure takes some time, and timing is not critical, the scheduler is a good way to ensure that you procedure does not interfere with more important tasks.&lt;/p&gt;
&lt;p&gt;The documentation of the app_scheduler can be found &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk51.v9.0.0%2Fgroup__app__scheduler.html"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to implement a simple non-blocking delay on nRF51822 with SoftDevice</title><link>https://devzone.nordicsemi.com/thread/34707?ContentTypeID=1</link><pubDate>Thu, 24 Sep 2015 01:59:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e2bc6fe-6ee4-4d25-8566-b734d62c9dc3</guid><dc:creator>diode</dc:creator><description>&lt;p&gt;If you mean something like &amp;quot;SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_RC_250_PPM_TEMP_4000MS_CALIBRATION, false);&amp;quot;, I did it when initialization BLE stack. I also had other app timers in this code (which I didn&amp;#39;t show above), and they were all working okay. I set a breakpoint in lazy_wait_handler(), and it was not reached. So I assumed for some reason ISR was not called and the lazy_wait_flag was not cleared properly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to implement a simple non-blocking delay on nRF51822 with SoftDevice</title><link>https://devzone.nordicsemi.com/thread/34706?ContentTypeID=1</link><pubDate>Thu, 24 Sep 2015 01:16:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2691182c-9820-4e64-8c98-102d706f62d8</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;Do you start an LF clock source somewhere in the elided code? Have you put a breakpoint into the timer routine to check and see if it&amp;#39;s being called or not to determine whether your timer code is wrong or your waiting code is wrong?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>