<?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>Unable to clear timer event flag</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/57572/unable-to-clear-timer-event-flag</link><description>I&amp;#39;m running the Nordic/Thread SDK 3.2 with an NRF52840 (Rigado BMD-340) on SES 4.42. 
 
 I&amp;#39;ve got a project using BLE + Thread and I&amp;#39;m having problems implementing a hardware timer interrupt. I&amp;#39;ve cut this down to bare bones to try to understand what</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 12 Feb 2020 13:27:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/57572/unable-to-clear-timer-event-flag" /><item><title>RE: Unable to clear timer event flag</title><link>https://devzone.nordicsemi.com/thread/233990?ContentTypeID=1</link><pubDate>Wed, 12 Feb 2020 13:27:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf6a717c-bf3a-469d-8c4d-247a649ea745</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Alternatively, you can use a larger Prescaler for the timer.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to clear timer event flag</title><link>https://devzone.nordicsemi.com/thread/233850?ContentTypeID=1</link><pubDate>Wed, 12 Feb 2020 00:44:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:170d8527-fbba-4b34-a5c1-425f5ce7fd81</guid><dc:creator>rogerarchibald</dc:creator><description>&lt;p&gt;My problem was with the timer configuration in sdk_config.h. &amp;nbsp;The timer was setup for 16-bit instead of 32-bit, and the rollovers were occurring at several hundred uS intervals instead of 750mS.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Once I put an oscilloscope on pin 31, I saw that I was entering the ISR very frequently. &amp;nbsp;Changing the Compare Register value would change the rollover time, but it was not logical (sometimes increasing the time value would shorten the rollover). &amp;nbsp;modifying sdk_config.h to specify 32-bit width has this working as expected.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to clear timer event flag</title><link>https://devzone.nordicsemi.com/thread/233735?ContentTypeID=1</link><pubDate>Tue, 11 Feb 2020 12:47:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ec50a70c-8f4b-42f0-b8db-f15fce1d8460</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;If you were stuck in the event handler you would not be able to call the event handler again as they are executing at the same priority.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
[quote user="rogerarchibald"]With a 750mS rollover I should clearly see the transitions of pin 31 (and I do when I paste this code into the hardware timer example) but when I run this code in a project where I&amp;#39;ve added the timer files the voltage on pin 31 appears fixed at VDD/2 when viewed on a Fluke meter, telling me it&amp;#39;s switching relatively quickly.[/quote]
&lt;p&gt;This proves that you are in fact executing the event handler with a fixed period, most likely of 750ms, so you&amp;#39;re probably not stuck there.&amp;nbsp;&lt;br /&gt;What &lt;strong&gt;is&lt;/strong&gt; the sample rate of the Fluke multimeter? Does it have any averaging filter running, and if so, what&amp;#39;s the width in samples?&lt;br /&gt;&lt;br /&gt;I suggest you increase the timer period to at least&amp;nbsp;60 seconds, put a breakpoint at the end of your event handler, and see to what function you return to after the event handler and or ISR has finished.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to clear timer event flag</title><link>https://devzone.nordicsemi.com/thread/233720?ContentTypeID=1</link><pubDate>Tue, 11 Feb 2020 12:26:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8aa4c4e5-4d54-495a-9803-c02927eb2804</guid><dc:creator>rogerarchibald</dc:creator><description>&lt;p&gt;I realize that breakpoints in the ISR aren&amp;#39;t helpful when it comes to measuring time...I was just using them to verify whether or not the flag was being cleared.&lt;/p&gt;
&lt;p&gt;My main indication that I&amp;#39;m not getting beyond the ISR is the line where I&amp;#39;m toggling pin 31 every time I enter the ISR. &amp;nbsp;With a 750mS rollover I should clearly see the transitions of pin 31 (and I do when I paste this code into the hardware timer example) but when I run this code in a project where I&amp;#39;ve added the timer files the voltage on pin 31 appears fixed at VDD/2 when viewed on a Fluke meter, telling me it&amp;#39;s switching relatively quickly. &amp;nbsp;I haven&amp;#39;t put a scope on it to see the transition speed, but seeing VDD/2 coupled with the fact that my later initialization code isn&amp;#39;t running and I&amp;#39;m unable to clear the event flag makes me pretty confident that I&amp;#39;m hanging up here. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Again, if I copy that exact same code into an example that&amp;#39;s configured for the hardware timer then it works as expected. &amp;nbsp;For that reason, I assume that my problem has something to do with how I&amp;#39;m configuring the project, although I can&amp;#39;t imagine what step I am missing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to clear timer event flag</title><link>https://devzone.nordicsemi.com/thread/233672?ContentTypeID=1</link><pubDate>Tue, 11 Feb 2020 10:06:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0b4cdc3-262c-4346-8fb3-45d23a6f9087</guid><dc:creator>haakonsh</dc:creator><description>[quote user="rogerarchibald"]The nrf_timer_event_clear is being called somewhere behind the scenes [/quote]
&lt;p&gt;Aah, yes, that&amp;#39;s true. The TIMER ISR should clear that flag before or after calling the event handler. You will not need to clear the event in the event handler.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Even if the event is not cleared, for whatever reason, the&amp;nbsp;event handler won&amp;#39;t be called until another TIMER IRQ has been triggered.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Do note that at 750ms intervals you will appear to always be stuck in your event handler if you set a break-point in it due to pending interrupts. Try using a longer timer timeout, like 10 seconds.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to clear timer event flag</title><link>https://devzone.nordicsemi.com/thread/233623?ContentTypeID=1</link><pubDate>Tue, 11 Feb 2020 00:48:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:76a92771-8cca-4f06-96d8-ff4775ab5529</guid><dc:creator>rogerarchibald</dc:creator><description>&lt;p&gt;Thank you Haakonsh for the response.&lt;/p&gt;
&lt;p&gt;I should have been more specific...The Event flag never clears and so the instant that it leaves the ISR it returns immediately. &amp;nbsp;If I watch the Timer registers using a debugger, it appears that the flag is never cleared in hardware.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The nrf_timer_event_clear is being called somewhere behind the scenes (I can set a breakpoint on line 536 of timer.h and see where this is being called) and that line is actually clearing the flag in the hardware peripheral example, but it is not working with my configuration. &amp;nbsp;I added the lines you reference where I&amp;#39;m manually clearing the flag in the ISR after first discovering this issue.&lt;/p&gt;
&lt;p&gt;For my immediate needs I ended up using an additional APP_TIMER to achieve what I was working towards, but I would very much like to understand what is going on here, just for general future knowledge. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;I was curious if this issue was related to the SoftDevice or OpenThread utilizing timers 0 and 1, so I tried pasting the code above into the perisperhal-only led_softblink example project and I have the same issue. &amp;nbsp;For the softblink test, I had to copy in the timer sections (nrf and nrfx) to sdk_config.h&lt;/p&gt;
&lt;p&gt;If you have any thoughts or would like any further information please let me know. &amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to clear timer event flag</title><link>https://devzone.nordicsemi.com/thread/233504?ContentTypeID=1</link><pubDate>Mon, 10 Feb 2020 12:22:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef4ca76a-c409-4c65-b264-31c8f310200a</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;&amp;quot;&lt;span&gt;and the code just lives in the ISR.&amp;nbsp; &amp;quot;&lt;br /&gt;What do you mean exactly, that you&amp;#39;re stuck in a loop?&lt;br /&gt;&lt;br /&gt;This does look correct:&lt;br /&gt;NRF_TIMER2-&amp;gt;EVENTS_COMPARE[0] = 0;&lt;br /&gt; dummy = NRF_TIMER2-&amp;gt;EVENTS_COMPARE[0];&lt;br /&gt; dummy;&lt;br /&gt;&lt;br /&gt;Have you tried the HAL&amp;#39;s&amp;nbsp;&lt;a title="nrf_timer_event_clear" href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/group__nrf__timer__hal.html?cp=7_1_6_9_0_37_2_21#gaed8e0490ec32db29ea8643c5624383f0"&gt;nrf_timer_event_clear&lt;/a&gt;?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>