Shop OBEX P1 Docs P2 Docs Learn Events
Pfth Forth: How does create a push-button debounce in Forth words? — Parallax Forums

Pfth Forth: How does create a push-button debounce in Forth words?

LoopyBytelooseLoopyByteloose Posts: 12,537
edited 2014-04-15 12:51 in Propeller 1
Hello all,
I am rather clueless about how to begin. It seems some debounce code will do multiple i/o pins at the same time; and other code may be 'blocking' or 'no blocking'. I am not clear what blocking means or if that is good or bad.

I suppose a general solution that applies to all versions of Forth on the Propeller would be welcome.

Comments

  • D.PD.P Posts: 790
    edited 2014-04-15 10:49
    Hello all,
    I am rather clueless about how to begin. It seems some debounce code will do multiple i/o pins at the same time; and other code may be 'blocking' or 'no blocking'. I am not clear what blocking means or if that is good or bad.

    I suppose a general solution that applies to all versions of Forth on the Propeller would be welcome.

    "
    "Blocking" and "non-blocking" describe individual operations, or individual function calls (or system calls). A blocking operation is basically one that can take a long time. In particular, if you made a function that read data, and waited for data to arrive before returning, it would be a blocking operation, because it could take arbitrarily long before the data arrived, and the CPU would be idle. A non-blocking operation, on the other hand, would be one designed to return immediately, with some return value indicating that it does not have data at this time.
    "

    Better than I could have said it. You create the words for the debounce routine and choose whether they perform in a blocking or non-blocking fashion.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-04-15 11:55
    Thanks.
    So I suppose a de-bouncing that blocks would not take any action until the end of the de-bouncing delay. I can live with such a delay in this current project.

    I also suppose that what ever I do, the actual debouncing code is likely to require a PASM solution defined as a Forth word with some means to attach it do the i/o designated on the data stack.

    I am a bit unclear how to actually insert it into active code that is polling the state of an i/o input in an infinite loop. I just guess I'd have to accept that the loop would run slower.
  • Dave HeinDave Hein Posts: 6,347
    edited 2014-04-15 12:51
    You could run a non-blocking de-bounce in a separate cog. Or you could periodically call a non-blocking routine that runs a de-bouncing state machine, but you would have to ensure that you are constantly calling it. The de-bouncer could be written in PASM or in Forth, depending on your timing constraints. I'd suggest looking at the OBEX to see if there is code that you can convert to Forth. Maybe there is some existing Forth de-bouncer code for Tachyon or PropForth.
Sign In or Register to comment.