<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Best Way to Use Asynchronous KBI ISR to debounce in 8-bit Microcontrollers</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Best-Way-to-Use-Asynchronous-KBI-ISR-to-debounce/m-p/179121#M12802</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to detect key presses from tactile switches which are likely to bounce for milliseconds. I only need to detect presses (not releases) and do not have to measure how long the key is down.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking for the easiest way to implement debouncing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I came up with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Initially all 4 switch inputs to the KBI module can trigger an interrupt&amp;nbsp;using edge detection only. &amp;nbsp;When one or more switches is pressed, the ISR is called.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. The state of all 4 switch inputs are read, and global flags (contained in one byte) are updated to indicat which key(s)&amp;nbsp;&amp;nbsp;is (are) pressed. This occurs in the ISR. Higher level routines can use this flag and reset it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3.&amp;nbsp;Any key that is pressed will be masked off so it can cause another interrupt. A software timer associated with that key is started. This occurs within the ISR. In this case there will be four software&amp;nbsp;timers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. The KBI is ack'ed and the ISR returns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5. If a software timer associated with a certain key times out, that key input is un-masked&amp;nbsp; so that it can cause another KBI Int to occur.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a simpler or better way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 Nov 2011 21:56:17 GMT</pubDate>
    <dc:creator>PG1</dc:creator>
    <dc:date>2011-11-03T21:56:17Z</dc:date>
    <item>
      <title>Best Way to Use Asynchronous KBI ISR to debounce</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Best-Way-to-Use-Asynchronous-KBI-ISR-to-debounce/m-p/179121#M12802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to detect key presses from tactile switches which are likely to bounce for milliseconds. I only need to detect presses (not releases) and do not have to measure how long the key is down.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking for the easiest way to implement debouncing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is what I came up with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Initially all 4 switch inputs to the KBI module can trigger an interrupt&amp;nbsp;using edge detection only. &amp;nbsp;When one or more switches is pressed, the ISR is called.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. The state of all 4 switch inputs are read, and global flags (contained in one byte) are updated to indicat which key(s)&amp;nbsp;&amp;nbsp;is (are) pressed. This occurs in the ISR. Higher level routines can use this flag and reset it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3.&amp;nbsp;Any key that is pressed will be masked off so it can cause another interrupt. A software timer associated with that key is started. This occurs within the ISR. In this case there will be four software&amp;nbsp;timers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. The KBI is ack'ed and the ISR returns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;5. If a software timer associated with a certain key times out, that key input is un-masked&amp;nbsp; so that it can cause another KBI Int to occur.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a simpler or better way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Nov 2011 21:56:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Best-Way-to-Use-Asynchronous-KBI-ISR-to-debounce/m-p/179121#M12802</guid>
      <dc:creator>PG1</dc:creator>
      <dc:date>2011-11-03T21:56:17Z</dc:date>
    </item>
    <item>
      <title>Re: Best Way to Use Asynchronous KBI ISR to debounce</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Best-Way-to-Use-Asynchronous-KBI-ISR-to-debounce/m-p/179122#M12803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Step 3. has a typo.&amp;nbsp;&amp;nbsp;It should say --- Any key that is pressed will be masked off so it &lt;U&gt;&lt;STRONG&gt;cannot&lt;/STRONG&gt;&lt;/U&gt; cause another interrupt. A software timer associated with that key is started. This occurs within the ISR. In this case there will be four software&amp;nbsp;timers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Nov 2011 02:00:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Best-Way-to-Use-Asynchronous-KBI-ISR-to-debounce/m-p/179122#M12803</guid>
      <dc:creator>PG1</dc:creator>
      <dc:date>2011-11-04T02:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: Best Way to Use Asynchronous KBI ISR to debounce</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Best-Way-to-Use-Asynchronous-KBI-ISR-to-debounce/m-p/179123#M12804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think that one aspect needs to be addressed in more detail.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;PG1 wrote:&lt;BR /&gt;&lt;P&gt;5. If a software timer associated with a certain key times out, that key input is un-masked&amp;nbsp; so that it can cause another KBI Int to occur.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I will assume that this part of the&amp;nbsp;operation is a polling process within the main loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The active input cannot be unmasked until after the switch has been released.&amp;nbsp;&amp;nbsp;If&amp;nbsp;an unmasked&amp;nbsp;input is active, it is not possible to detect a closure at the other three inputs.&amp;nbsp; In this case the timeout period represents a delay until the &lt;U&gt;testing for&amp;nbsp;switch release&lt;/U&gt; commences.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To allow for further contact bounce when the switch is released, a further timout period should expire before the KBI input is unmasked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the de-bounce timing, I would tend to utilise a simple "tick" timer at say, 1 to 5 ms intervals.&amp;nbsp; Within the timer ISR, each debounce timing register would be tested, and it non-zero would be decremented.&amp;nbsp; You might allow for debounce intervals of 50 to100ms.&amp;nbsp; Therefore, timeout will have occurred when each register becomes zero - no additional timeout flags are required.&amp;nbsp; The timing uncertainty will be one tick interval.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that the debounce timing registers should be 8-bit so that the write process will be atomic.&amp;nbsp; Otherwise, interrupts would need to be globally disabled and re-enabled when the debounce timeout period was set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Nov 2011 14:11:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Best-Way-to-Use-Asynchronous-KBI-ISR-to-debounce/m-p/179123#M12804</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2011-11-04T14:11:17Z</dc:date>
    </item>
  </channel>
</rss>

