Shop OBEX P1 Docs P2 Docs Learn Events
Variable Debouncing Command — Parallax Forums

Variable Debouncing Command

JomsJoms Posts: 279
edited 2009-04-21 06:26 in Propeller 1
I am looking for a command in which I can use to debounce a variable.

I normally use this code when I have a button connected directly to the·prop so that the user has to press and release the button for the command to take place. Otherwise I was having problems with the command happening multiple times (if the users input was to send a serial command, it would send the command several times)

    if ina[noparse][[/noparse]21]
      waitpne(|<21,|<21,0)




That command works great if I am using an input pin directly on the prop, but how about if I need to do the same thing with a variable? I have a object that scans multiple 74165 shift registers that have buttons connected to them. I have been using a simple waitcnt command until now, but it just doesn't work very well if the user presses buttons in a row.

    if input.display3
      waitcnt((10_000_000 + cnt))




Basically, the command I am looking for would be 'Wait Until input.display3 := 0. From looking in the manual it appears the WAITPNE and WAITPEQ only work on the direct pins.

Any ideas?

Comments

  • John AbshierJohn Abshier Posts: 1,116
    edited 2009-04-21 03:26
    repeat until input.display3 == 0

    John Abshier
  • Brian FairchildBrian Fairchild Posts: 549
    edited 2009-04-21 06:26
    If you can, you really want to get away from waiting in things like debounce routines. It's a very good way of wasting processor time. Better to regularly check the inputs at a fixed interval, say every 10ms and then use a piece of code like this...

            if (new_input == old_input) {  //still the same
                count = 10;
            } else {  //changed
                if (--count == 0) { //wait until counter expires
                    old_input = new_input;
                    input_changed = TRUE;
                    count = 10;  //reset counter
                }
            }
    
    
    


    ...this code (in C) compares the new and old input values and will only update the old value once they have been different for 10 clock ticks. It also sets a flag (input_changed) to let the rest of the program know that it has a new value to process.
Sign In or Register to comment.