<?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>8-bit MicrocontrollersのトピックCounting key presses concept - 68908GZ8</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Counting-key-presses-concept-68908GZ8/m-p/165369#M10404</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just working on a little something for home where I want to be able to control two relays to switch on some lights in a mode dependent on the number of key presses from one single button.&lt;/P&gt;&lt;P&gt;Relay 1 controls some front lights, Relay 2 controls some side lights.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The CPU I am using is a 68908GZ8 and I prefer assembler if someone wanted to post some example code &lt;A href="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif"&gt;&lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So what I want to do is something like this -&lt;/P&gt;&lt;P&gt;A) - If the lights are off, one key press turns Relay 1 on.&lt;/P&gt;&lt;P&gt;B) - If the lights are off, two key presses turns Relay 1 &amp;amp; 2 on.&lt;/P&gt;&lt;P&gt;C) - If either light is on, one key press turns both Relays off.&lt;/P&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;P&gt;Couple of questions, would using the Keyboard Module be necessary? Is the only way to do this by using timers and checking for 'x' time between key presses?&lt;/P&gt;&lt;P&gt;Obviously there would also need to be a time out function from A to skiping B and waiting for C.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice on which path to head down would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Ross&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by Bloodhound on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-03-22&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;11:21 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="local-time"&gt;Added p/n to subject.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by NLFSJ on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-03-26&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;04:11 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 22 Mar 2009 19:19:40 GMT</pubDate>
    <dc:creator>Bloodhound</dc:creator>
    <dc:date>2009-03-22T19:19:40Z</dc:date>
    <item>
      <title>Counting key presses concept - 68908GZ8</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Counting-key-presses-concept-68908GZ8/m-p/165369#M10404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just working on a little something for home where I want to be able to control two relays to switch on some lights in a mode dependent on the number of key presses from one single button.&lt;/P&gt;&lt;P&gt;Relay 1 controls some front lights, Relay 2 controls some side lights.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The CPU I am using is a 68908GZ8 and I prefer assembler if someone wanted to post some example code &lt;A href="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif"&gt;&lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So what I want to do is something like this -&lt;/P&gt;&lt;P&gt;A) - If the lights are off, one key press turns Relay 1 on.&lt;/P&gt;&lt;P&gt;B) - If the lights are off, two key presses turns Relay 1 &amp;amp; 2 on.&lt;/P&gt;&lt;P&gt;C) - If either light is on, one key press turns both Relays off.&lt;/P&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;P&gt;Couple of questions, would using the Keyboard Module be necessary? Is the only way to do this by using timers and checking for 'x' time between key presses?&lt;/P&gt;&lt;P&gt;Obviously there would also need to be a time out function from A to skiping B and waiting for C.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice on which path to head down would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Ross&lt;/P&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by Bloodhound on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-03-22&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;11:21 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="local-time"&gt;Added p/n to subject.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV class="message-edit-history"&gt;&lt;SPAN class="edit-author"&gt;Message Edited by NLFSJ on&lt;/SPAN&gt; &lt;SPAN class="local-date"&gt;2009-03-26&lt;/SPAN&gt; &lt;SPAN class="local-time"&gt;04:11 PM&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 22 Mar 2009 19:19:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Counting-key-presses-concept-68908GZ8/m-p/165369#M10404</guid>
      <dc:creator>Bloodhound</dc:creator>
      <dc:date>2009-03-22T19:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: Counting key presses concept</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/Counting-key-presses-concept-68908GZ8/m-p/165370#M10405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Ross,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since you have only a single switch input, and you require to monitor and time both the on and off states, the code will probably be more straightforward if you &lt;U&gt;don't&lt;/U&gt; make use of the KBI module, but simply monitor the switch state by testing the input state of the pin.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For each switching event, there will need to be a debounce interval (perhaps 25-50ms), followed by a switch timeout interval of say 500ms.&amp;nbsp; These timing periods would need to be applied to both states of the switch.&amp;nbsp; Timeout would occur both for a "held" switch, and following switch release.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The easiest way to implement these timing periods is probably as an integral number of TIM overflow cycles.&amp;nbsp; Enable TIM overflow interrupts, with an overflow period in the vicinity of say, 5 ms.&amp;nbsp; This timing is not critical, but would allow both intervals to be handled with an 8-bit counter.&amp;nbsp; Within the ISR code, the counter would be simply decremented, unless its value was already zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From within the main loop, a timeout period is started by setting the counter to the required value, and timeout will have occurred when the counter becomes zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems that, if one or both lights are already on, it might be a good idea to require that the switch be held on for greater than the timeout period, before the turn-off occurs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The operation of the code within the main loop would effectively become a simple "state machine".&amp;nbsp; The following is a possible sequence of events.&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Assuming the switch is currently off, wait for an on state, and then delay for the debounce period.&amp;nbsp; If the switch has reverted to off, start over again to wait for an on state.&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;If the debounced on state is present, start the 500ms timeout period, and then within a tight loop, test for either timeout (switch hold), or switch off. If switch hold occurs, turn on #1 light, and then wait for the switch to be released.&lt;/LI&gt;&lt;LI&gt;If the switch is released within the timeout period, apply a debounce period, followed by a further 500ms timeout period.&amp;nbsp; If timeout should occur, turn on #1 light.&lt;/LI&gt;&lt;LI&gt;However, if the switch becomes again active, wait a further debounce period, and then turn on both lights.&amp;nbsp; Then wait for the switch to be released.&lt;/LI&gt;&lt;/OL&gt;Steps 1 and 2 would be followed for the turn-off sequence.&amp;nbsp; If the switch is released prior to timeout occurring, there would be no action.&lt;BR /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mac&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Mar 2009 00:17:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/Counting-key-presses-concept-68908GZ8/m-p/165370#M10405</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2009-03-23T00:17:12Z</dc:date>
    </item>
  </channel>
</rss>

