Debouncing QuickStart touch pads
Ron Czapala
Posts: 2,418
I have looked at many debouncing forum threads (google search) and tried several approaches including those from Beau Schwabe, JonnyMac, Duane Degn, etc
but I still get multiple hits almost every time.
Someone mentioned bitwise OR in debouncing but I could not find any posted code.
If anyone has a "foolproof" approach, I would love to see the code!
Thanks,
Ron
but I still get multiple hits almost every time.
Someone mentioned bitwise OR in debouncing but I could not find any posted code.
If anyone has a "foolproof" approach, I would love to see the code!
Thanks,
Ron
Comments
http://www.parallaxsemiconductor.com/sites/default/files/parallax/TouchButtonsLEDDemov1.0_1.zip
Thanks jazzed,
But that was one of first ones I tried but I just did it again and got 25 lines of ("Cogs used: 5") in the terminal window with a quick touch.
My program just counts available unused cogs when pad one is touched.
I think that's what the Touch Buttons PASM/Spin code does - looks like it checks 31 times
This approach gives good response. If your action takes long enough you can eliminate the first 1/16 second delay / stabilize pause. Some switches seem to bounce around for ages before they stabilize so the 1/16 second period may have to be lengthened.
Sandy
demo program to test touchpads
Thanks cavelamb. I can sort of get it to work if I stick a 20ms wait in my loop but I guess what I'm trying to come up with is a routine that gives me a single hit when a pad is touched.
I guess it needs to constantly compare the button states for a fixed period and only return a non-zero byte if button state bits are unchanged for the entire period but where it won't miss a button push (if that makes sense).
Sort of works
I thought the same thing at first, but it's a bit more involved that that.
Touchpad aren't switches.
The trouble you are experiencing is not "bounce".
It works like this:
First the touchpads are "charged up" but writing 1s to the pins as outputs.
Then the outputs are turned around to inputs.
Next, a short delay (word from our sponsor) to let that charge decay off a bit.
NOW we finally read the pin and check to see if it's touched or not.
Lastly, if the pad returns 0 (pressed) that bit is set (1) in the return byte.
for a project ...
I'd like to detect:
Short press
Long press
Double tap
I guess calling it bounce is technically not correct but the behavior is somewhat similar.
What I'm looking for is (do I dare say this on a Propeller forum?) something like a hardware interrupt.
Something that doesn't depend on long waits or give multiple hits for one brief touch.
Hmmmm - that can be problematic I see:
http://forums.parallax.com/showthread.php/126265-WAITPEQ-with-timeout
http://forums.parallax.com/showthread.php/99748-Forcing-exit-of-waitpeq-if-no-match-occurs
Thought that for a while too. But the Prop is "different".
That's what multiple cogs are for.
The touchpad routine could easily be started in another cog and left running.
Then all we would have to do is read the button byte and take action.
Small tight loop...
Try that drive I posted.
Shouldn't give you multiple hits.
It runs pretty smooth for me.
Its actually quite a bit more complicated than what you said.
Due to the conductivity of your finger, which can vary enormously, and the pressure of your !push! the decay time can vary greatly. Then, to top it all off, your finger also introduces a large 60 Hz AC signal into the node of unknown proportions.
So to read the pads reliably, with various users and humidity conditions, requires a somewhat complicated algorithm. I am developing an adaptive approach, but its not done yet.
Simple approaches such as timing may appear to work, but when users or conditions change, the results will vary. Hard long presses may give passable results, depending on your needs.
Cheers,
Peter (pjv)
Yes, I know that, p.
But the issue at hand is getting the guy "adapted" to the Propeller.
This set up has given me good service so far, but you are probably right that someone else probably has a
different "touch".
I'd be really interested in in seeing your driver when you get it working.
break
Ron, if it's really important, you can add real switches to the pad pins and read them
like real (bouncy) switches.
Here is the code I used and it does give multiple hits - especially if I remove the 20ms wait in the repeat loop.
How fast can you get your finger off of the pad?
Looks like you need to FLAG that a toughpad has happened,
and wait for it to be released before repeating the loop?
I considered using real buttons
I'm really just messing around and trying to familiarize myself with the QuickStart.
I would probably use real buttons if I wanted a more reliable trigger...
Thanks,
- Ron
I need to play around with it some more - maybe I can figure out a way to do what I want.
or it repeats
Yeah - got to be a better way to approach this.
I thought it might be neat to use the QuickStart (and it's touch pads) to set the date and time on a ChronoDot (DS3231 Real Time Clock) module.
Using the pads to advance the hour/min/sec etc would tricky unless I can get a more controlled button action.
http://forums.parallax.com/showthread.php/137879-Chrono-dot-interface?p=1073753&viewfull=1#post1073753
or - there's that LONG PRESS thing that would be real handy here for auto-increment
something like?
Maybe this will help.
Alarus.
Thanks
DUH!
Saving the buttons state byte into a variable (e.g. prevState) and only triggering the desired routine when the state changes pretty much eliminates the repeat action - as long as you make a firm, quick touch to the pad.
Holding your finger on the pad does not constitute a change either until you let go.
If you brush the pad or tentatively make contact you can get a repeat.
Try that driver from Alarus.
It's small and tight and works right nice.
Try the CD4047 if you really want to add hardware. But I'd prefer to not do so.
That's kinda what he did, but in software...