<?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のトピックRe: switch + timer question</title>
    <link>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214840#M18617</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is the keypad debounce routine. The scheduler is to follow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Don't hesitate to ask if anything is unclear.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 27 Jul 2010 13:33:06 GMT</pubDate>
    <dc:creator>rocco</dc:creator>
    <dc:date>2010-07-27T13:33:06Z</dc:date>
    <item>
      <title>switch + timer question</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214831#M18608</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey everyone. &amp;nbsp;I’m about to start a new software project which requires a human UI with switches.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This particular UI will require two buttons. &amp;nbsp;Each button must capture a sense of “acceleration”, in that the longer the user presses the button, different stuff happens.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The MCU I was looking at, the JS16, only has one MTIM. &amp;nbsp;I’ve already allocated all the I/O pins, so I can’t dedicate any to input capture or output compare (the latter feature, I was under the impression could only be implemented by tying to an I?O pin).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My thought was to run a state machine for each switch. &amp;nbsp;When key #1 is pressed, it looks up the MTIM free running clock value as a reference point. &amp;nbsp;Then keep track of the TOFs to see just how long it was pressed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does that sound reasonable? &amp;nbsp;I’d rather to take advantage of the output compare, but can that feature be used internally instead of with a pin?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 24 Jul 2010 22:02:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214831#M18608</guid>
      <dc:creator>irob</dc:creator>
      <dc:date>2010-07-24T22:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: switch + timer question</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214832#M18609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have something that might help a little.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a module that scans two ports for button press/release (sixteen buttons). It uses an interrupt to "que" the scan "task" subroutine at some interval. I typically use 200 microseconds per scan, but sometimes piggie-back the scheduling of the scan off of some other periodic interrupt, like the ADC, to save a timer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The scan task has a debounce counter that you can set. It will not register a change until the IO-input has been stable for N sample periods. It then sticks the button "events" in a queue, for another "task" to extract and process.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The button events are:&lt;/P&gt;&lt;P&gt;KeyPressed: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; the key was pressed down&lt;BR /&gt;KeyClicked:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; the key was pressed and released quickly&lt;BR /&gt;KeyHeld:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; the key has been pressed long enough to be 'Held'&lt;BR /&gt;KeyRepeat: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; the key has been down for an additional 1/4 second&lt;BR /&gt;KeyHoldEnd: &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; the key was 'Held', but is now released&lt;BR /&gt;KeyReleased: &amp;nbsp; &amp;nbsp; &amp;nbsp; the key was let back up&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;For your application, the "KeyHeld" and "KeyRepeat" code might be able to be used as is, or modified to suit your needs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this might be more than you need, but let me know if you want to try it. I use a little pico-scheduler for my "tasks", and can include that if you would like.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Jul 2010 02:30:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214832#M18609</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2010-07-25T02:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: switch + timer question</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214833#M18610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rocco,&lt;/P&gt;&lt;P&gt;I would like to try your code also.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Jul 2010 03:39:56 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214833#M18610</guid>
      <dc:creator>marbomb</dc:creator>
      <dc:date>2010-07-25T03:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: switch + timer question</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214834#M18611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rob and Dan,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yet again, I forgot to mention that the code is written in assembly language, and not C (which is why we are still using HC08/S08).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if you still want it, and if you do, whether you want the pico-scheduler, which is macro-based.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Jul 2010 06:28:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214834#M18611</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2010-07-25T06:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: switch + timer question</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214835#M18612</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes Rocco,&lt;/P&gt;&lt;P&gt;I would like both.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Dan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Jul 2010 08:02:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214835#M18612</guid>
      <dc:creator>marbomb</dc:creator>
      <dc:date>2010-07-25T08:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: switch + timer question</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214836#M18613</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello irob,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For detection of manually actuated switch closures, where closure periods are likely to extend to "hundreds of milliseconds", and generally timing periods are not particularly critical, I would typically use a polling approach with respect to the closure timing.&amp;nbsp; This is usually consistent with the&amp;nbsp;testing of other inputs required by&amp;nbsp;a state machine.&amp;nbsp; Here, I would simply use an overflow interrupt associated with a TPM module, maybe 10-20 milliseconds period, and base my timing intervals on multiples of this amount.&amp;nbsp; Then, for each independent timing&amp;nbsp;function required, to provide a suitable variable which would decrement within the&amp;nbsp;overflow ISR, provided it is a&amp;nbsp;non-zero value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if (var1)&amp;nbsp; var1--;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if (var2)&amp;nbsp; var2--;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The state machine can then test for a zero value to determine the next state required&amp;nbsp;for a timeout condition.&amp;nbsp; With the debounce timing built into the state machine itself, it is possible to utilize the same variable, as for the other timing intervals required.&amp;nbsp; In your case, you might possibly need only two variables, one for each pushbutton.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following debounce timing, you would set the variable to correspond with the first timing threshold, and then subsequently test whether release occurred prior to timeout.&amp;nbsp;&amp;nbsp;If no release,&amp;nbsp;then set the variable for the next timing threshold (minus the first threshold value), and so on.&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 25 Jul 2010 20:57:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214836#M18613</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-07-25T20:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: switch + timer question</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214837#M18614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Great ideas, guys.&amp;nbsp; Thanks for the input. Bigmac, all of my human UI projects with switches have been state machine driven, so I'm more inclined to steer toward your suggestions.&amp;nbsp; Rocco, your idea sounds fairly sophisticated, but I wouldn't mind seeing your example code for reference.&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>Mon, 26 Jul 2010 20:50:24 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214837#M18614</guid>
      <dc:creator>irob</dc:creator>
      <dc:date>2010-07-26T20:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: switch + timer question</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214838#M18615</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello irob,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another thought is that there is probably little point in executing each state machine any more frequently than every 10-20 milliseconds.&amp;nbsp; On this basis, the decrement of the timing counters can be done within these functions, rather than within the overflow ISR.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ISR would need only to set a flag that would be visible within the main loop or the state machine functions, to determine that the state machine code be executed, rather than skipped.&amp;nbsp; Static local variables&amp;nbsp;could now&amp;nbsp;be used for the timing counters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if (OF_flag)&amp;nbsp; {&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; OF_flag = 0;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; FSM_button1();&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; FSM_button2();&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jul 2010 04:41:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214838#M18615</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2010-07-27T04:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: switch + timer question</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214839#M18616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry for the delay, but I haven't been back to the office to pack-up these files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe in a few hours.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jul 2010 12:53:36 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214839#M18616</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2010-07-27T12:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: switch + timer question</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214840#M18617</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is the keypad debounce routine. The scheduler is to follow.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Don't hesitate to ask if anything is unclear.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jul 2010 13:33:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214840#M18617</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2010-07-27T13:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: switch + timer question</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214841#M18618</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is the scheduler. It's small, but does need one byte of ram to support eight tasks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each task is just a subroutine. You put the subroutine's name in the task list, highest priority task first. Everything is built at compile-time by a couple of macros, so priorities are static.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can request a task to be run with the line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; QUE &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SubroutineName&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where "SubroutineName" is the same subroutine that was put in the task list with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TASK &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SubroutineName&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Each "TASK" line will use two byte of flash for a pointer, and assign one bit of ram for a semaphore. Each "QUE" line will generate one "BSET" instruction to set the semaphore.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Usually, an ISR or another task would QUE the task to run in order for it to do subsequent processing. Some examples might be the serial-port ISR requesting a command-line parser to run when a &amp;lt;CR&amp;gt; has been received, or a timer-interrupt scheduling a keypad to be scanned. The keypad-scanning task might then QUE a key-processing task to run once a key-press is detected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sure I'm forgetting important information, so just ask . . .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jul 2010 14:09:37 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214841#M18618</guid>
      <dc:creator>rocco</dc:creator>
      <dc:date>2010-07-27T14:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: switch + timer question</title>
      <link>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214842#M18619</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;bigmac, I went your direction and it's working very nicely for me.&amp;nbsp; Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 31 Jul 2010 04:19:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/8-bit-Microcontrollers/switch-timer-question/m-p/214842#M18619</guid>
      <dc:creator>irob</dc:creator>
      <dc:date>2010-07-31T04:19:09Z</dc:date>
    </item>
  </channel>
</rss>

