<?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>app_timer firing far too late, app_timer_cnt_get() gives weird results</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/28730/app_timer-firing-far-too-late-app_timer_cnt_get-gives-weird-results</link><description>Hi, 
 I&amp;#39;m using the nRF51 dongle with nRF SDK 12.3.0 and the S130 2.0.1 SoftDevice to implement a BLE central. The dongle repeatedly connects to a BLE peripheral, performs some tests, then disconnects. 
 I am using the app_timer module to delay some</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 05 Jan 2018 09:33:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/28730/app_timer-firing-far-too-late-app_timer_cnt_get-gives-weird-results" /><item><title>RE: app_timer firing far too late, app_timer_cnt_get() gives weird results</title><link>https://devzone.nordicsemi.com/thread/113855?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2018 09:33:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a45e59f5-bdb1-46b5-9228-dda290f525b9</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Thank you for reporting back the issue!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: app_timer firing far too late, app_timer_cnt_get() gives weird results</title><link>https://devzone.nordicsemi.com/thread/113854?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2018 08:33:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc25b653-0b35-4a96-9968-b60f24e1ef9f</guid><dc:creator>Alex Suzuki</dc:creator><description>&lt;p&gt;It seems the problem was that I was using the bsp library, and making liberal use of the LED indication routine bsp_led_indication. It seems internally the bsp library uses app_timer to do the blinking.&lt;/p&gt;
&lt;p&gt;After driving the LEDs directly through the bsp_board_led_on/bsp_board_led_off functions my timing code seems to work stable for now.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: app_timer firing far too late, app_timer_cnt_get() gives weird results</title><link>https://devzone.nordicsemi.com/thread/113852?ContentTypeID=1</link><pubDate>Wed, 03 Jan 2018 11:54:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc0adb62-9519-45ec-8b43-1a69ff8919d0</guid><dc:creator>Alex Suzuki</dc:creator><description>&lt;p&gt;And here is the log output of a &amp;#39;bad case&amp;#39;, where a timer that is set to fire after 100ms does not fire. The peripheral disconnects after 4.1 seconds of inactivity, so this is the next event that occurs. Note also that timestamps are printed correctly here, app_timer_cnt_get does not overflow here.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;APP:DEBUG:app_timer_cnt_get: 123774
APP:DEBUG:Services discovered after 602 ms
APP:DEBUG:app_timer_cnt_get: 129660
APP:DEBUG:Notifications enabled after 781 ms
APP:DEBUG:Will wait 100 ms before sending challenge
APP:DEBUG:Started timer1: 0
// ... nothing happens for 3.3s ..., peripheral disconnects due to inactivity
APP:DEBUG:disconnected, evt conn handle: 0, our conn handle: 0
APP:DEBUG:app_timer_cnt_get: 239751
APP:DEBUG:Disconnected after 4141 ms
APP:DEBUG:Stopped timer1: 0
APP:DEBUG:Stopped timer2: 0
APP:DEBUG:Stopped timer3: 0
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: app_timer firing far too late, app_timer_cnt_get() gives weird results</title><link>https://devzone.nordicsemi.com/thread/113853?ContentTypeID=1</link><pubDate>Wed, 03 Jan 2018 11:39:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3de718cb-c17b-40c8-95c1-d8627e678044</guid><dc:creator>Alex Suzuki</dc:creator><description>&lt;p&gt;Hi Jørgen, thanks for taking the time to comment.&lt;/p&gt;
&lt;p&gt;I use an APP_TIMER_PRESCALER value of 0, according to the docs this overflows after 512 seconds which is fine, I use timer timeouts between 100ms and 60s. It&amp;#39;s a bit difficult to measure because my timestamp function also exhibits strange behavior.&lt;/p&gt;
&lt;p&gt;The software I&amp;#39;m writing is a stress test for a BLE peripheral, which repeatedly connects/disconnects and performs some actions with random delays. I am starting/stopping the timers at the start / end of every test run, which is on average probably around every 10 seconds or so. Sometimes a timer will not be started, because zero delay is simulated, app_timer_stop is called nonetheless however, I read that this is fine too (calling stop on a not-started timer).&lt;/p&gt;
&lt;p&gt;I did notice however that the return value of app_timer_cnt_get() overflows whenever wrong timestamps are printed. I was under the assumption that app_timer_cnt_diff_compute will handle overflow? NRF_LOG output of a &amp;quot;bad case&amp;quot;, see timestamp at end.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;APP:DEBUG:app_timer_cnt_get: 641293
APP:DEBUG:Services discovered after 602 ms
APP:DEBUG:app_timer_cnt_get: 647180
APP:DEBUG:Notifications enabled after 781 ms
APP:DEBUG:Will wait 100 ms before sending X
APP:DEBUG:Started timer1: 0
APP:DEBUG:app_timer_cnt_get: 650459
APP:DEBUG:Sending X after 881 ms
APP:DEBUG:Will wait 4000 ms before sending Y      
APP:DEBUG:Stopped timer1: 0 
APP:DEBUG:Stopped timer2: 0
APP:DEBUG:Stopped timer3 0
APP:DEBUG:Disconnected, evt conn handle: 0, our conn handle: 0
APP:DEBUG:app_timer_cnt_get: 1958
APP:DEBUG:Disconnected after 99875 ms
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;About the the higher interrupt context, how would I go about debugging this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: app_timer firing far too late, app_timer_cnt_get() gives weird results</title><link>https://devzone.nordicsemi.com/thread/113851?ContentTypeID=1</link><pubDate>Tue, 02 Jan 2018 15:02:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:696ad90f-5147-47af-8162-08220a09bf4a</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;What is the value of APP_TIMER_PRESCALER? How often do you start/stop the timers? Could you measure the time between timeouts? Are you sure the application is not stuck in some higher interrupt context, delaying the handling of the timer timeout? What is the return value of app_timer_cnt_get etc.?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>