<?xml-stylesheet type="text/xsl" href="https://community.element14.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/"><channel><title>The cost of a float in an ISR</title><link>/members-area/personalblogs/b/blog/posts/the-cost-of-a-float-in-an-isr</link><description>Goal Share a time problem when I uncarefully used an unintended float within my ISR. Description Searching about debouncing switch routines, I came across this solution while revising a blog I already knew wri...</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: The cost of a float in an ISR</title><link>https://community.element14.com/members-area/personalblogs/b/blog/posts/the-cost-of-a-float-in-an-isr</link><pubDate>Sun, 03 May 2020 16:12:56 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:1a3c031f-7a13-41a5-9ab9-b9dd64af72c7</guid><dc:creator>shabaz</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Hi &lt;span&gt;[mention:644257a509f549dfbcb0fed1601930d3:e9ed411860ed4f2ba0265705b8793d05]&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Nice reminder about keeping an eye on code execution time : ) There was a time the free PIC compiler was deliberately crippled, i.e. would not do certain optimizations, so maybe that made the problem worse in this case too : ( I don&amp;#39;t know if it&amp;#39;s still the case or not with the compiler.&lt;/p&gt;&lt;p&gt;One trick (not really a trick) is to send a message or signal to non-interrupt code, i.e. push out the code to outside the interrupt. The easiest way to send this signal is to use a global variable. So, the interrupt sets the variable, and the main code repeatedly checks to see if the variable is set, and does what it needs to do, and clears the variable. It still doesn&amp;#39;t help if overall execution time doesn&amp;#39;t meet requirements of course, but means the interrupt continues to do all other servicing it needs to.&lt;/p&gt;&lt;p&gt;Regarding debounce, sometimes the more advanced algorithms are not needed. I just take immediate action when a button is pressed, and then inhibit button presses for a period of time (like say 20 msec - could be extended it it&amp;#39;s unreliable with a switch) and then won&amp;#39;t clear the button until 20msec after I see a button release. To do all that requires a variable to store button state (and a timer, it doesn&amp;#39;t need to be dedicated it can be shared with other timed events in the code). That allows for debounce periods of 20msec on button push and button release. Also, this way an input is actioned slightly faster, rather than wait for an integration time.&lt;/p&gt;&lt;p&gt;For rotary mechanical controls : ) there&amp;#39;s another trick, which is to avoid the problem totally : ) Optical encoders don&amp;#39;t have such electrical bounce, and is far easier to manage. A lot more expensive though : ( but sometimes worth it.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=9216&amp;AppID=293&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item><item><title>RE: The cost of a float in an ISR</title><link>https://community.element14.com/members-area/personalblogs/b/blog/posts/the-cost-of-a-float-in-an-isr</link><pubDate>Sat, 02 May 2020 20:58:34 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:1a3c031f-7a13-41a5-9ab9-b9dd64af72c7</guid><dc:creator>genebren</dc:creator><slash:comments>1</slash:comments><description>&lt;p&gt;Nice troubleshooting. I believe that I too borrowed ideas from this article (being a big fan of Jack Ganssel).&amp;nbsp; Nice that you found your problem.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;ISR can be real tough to deal with when you are trying to minimize the amount of time spent in interrupt processing.&amp;nbsp; You really need to watch the code carefully, no function/subroutine calls, no excessive precision in math, no extra bells and whistles, just the minimum processing and go.&lt;/p&gt;&lt;img src="https://community.element14.com/aggbug?PostID=9216&amp;AppID=293&amp;AppType=Weblog&amp;ContentType=0" width="1" height="1"&gt;</description></item></channel></rss>