<?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 use timer to get button pushed time?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/3632/how-to-use-timer-to-get-button-pushed-time</link><description>Hello, I want to get the millisecond of pushing a button, but I am confused about how to use the timer in S110. Is there any example?
thank you!</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 02 Sep 2014 01:10:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/3632/how-to-use-timer-to-get-button-pushed-time" /><item><title>RE: How to use timer to get button pushed time?</title><link>https://devzone.nordicsemi.com/thread/13175?ContentTypeID=1</link><pubDate>Tue, 02 Sep 2014 01:10:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bdd34a74-fbcb-47f2-88a5-3f0d32b939f5</guid><dc:creator>Ricky</dc:creator><description>&lt;p&gt;Thank you so much!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to use timer to get button pushed time?</title><link>https://devzone.nordicsemi.com/thread/13174?ContentTypeID=1</link><pubDate>Mon, 01 Sep 2014 13:48:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc24c195-2a44-42f9-ace2-4fa4a50d8d53</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I have attached an example that uses application timer to detect a button press. In the event handler for the button press, it is detected if the button is pressed or released. When the button_2 on the development board is pressed a timestamp is recorded and another timestamp is recorded when the button is released. You can see how this is done in the example, look at the button_event_handler in the main file. The app_timer library is used to get timestamps. The timestamp represents the counter of the RTC1, which is what the app_timer uses in the background. So if the difference between the two timestamps is 32768, then the button has been pressed for 1 second, because the tick frequency of the RTC1 is 32768Hz.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/ble_5F00_app_5F00_bps_5F00_test_5F00_button_5F00_push_5F00_duration.zip"&gt;ble_app_bps_test_button_push_duration.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The attached code example is based on the ble_app_bps example in the nRF51 SDK. To see exactly what I have added to the code, you can run a diff on the main file in the example and in the official ble_app_bps in the SDK.&lt;/p&gt;
&lt;p&gt;Note that the timing generated by the event handler of the app_button library is not very accurate. Usually, the accuracy should be a few microseconds, but the softdevice might delay execution of the button handler by 1ms - 6ms.  More on limitations for the app_button library on &lt;a href="https://devzone.nordicsemi.com/question/15696/nrf51822-sense-pin-in-port-mode-doesnt-solve-the-gpiote-overconsumption-in-event-mode/?comment=15962#comment-15962"&gt;this thread&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Hopefully you will find the above method adequeate for you scenario. Otherwise, in order to have a more accurate timing for a duration of a button press, you would have to enable a TIMER peripheral (TIMER1 or TIMER2, TIMER0 is blocked by the softdevice if you have the softdevice enabled). Enabling a TIMER perhipheral does however increase current consumption of the chip substantially, while measuring a button press duration with the app_timer does not add any current consumption.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>