Resistive touch-buttons--how to use?
John Abshier
Posts: 1,116
How do these buttons work? I have code to light an LED and echo to PST screen when a button is touched. But the LEDs seldom light if I touch the button with my finger. I can get them to work, most of the time, if I touch the center stripe of the button with a jumper wire and the other end of the jumper wire is in the air.
John Abshier
John Abshier
CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 #1, HOME, #8, BKSP, TAB, LF, CLREOL, CLRLB, CR, #16, CLS ' PST formmatting control OBJ Sio : "FullDuplexSerialPlus" Pub Main | i Sio.start(31,30,0,115200) ' Rx,Tx, Mode, Baud dira[16..23]~~ dira[0..7]~ repeat outa[16..23] := ina[0..7] sio.dec(ina[0..7]) sio.tx(CR) waitcnt(clkfreq / 2 + cnt)
Comments
John Abshier
John Abshier
John, I'm sorry you haven't received a helpful reply so far.
I saw someone playing with a QuickStart board at UPEW so I know code is out there somewhere. Maybe it will show up here. Meanwhile, I'll try to help.
My touch button theory is a little dated, but here's what I think should happen:
You should note in the schematic (Thanks Leon) that the touchpads make up part of a series RC network. Your finger will behave like a capacitor when it is on a touchpad. To read touchpad on P0 you will first have to apply a voltage to it. That is: use dira[0]~~ and outa[0]~~ to set P0 to output logic high. Then you should set P0 to an input with dira[0]~ and read the pin with "somevariable" := ina[0]. If somevariable remains high after becoming an input, then you can light the LED else turn it off. Skin capacitance can vary.
http://www.microchip.com/en_us/technology/mtouchbuttons/applications.html
I would say you need to output first a high pulse and then switch the pin 0..7 to input and read the state.
If it is still high the button is not touched, if you read a low it is touched.
Try these changes to your code: Maybe you need a little delay after switching the pins to input, I can't try - my Quickstart has not arrived yet...
Andy
John Abshier
http://www.parallax.com/portals/0/downloads/docs/prod/prop/quickstart/TouchButtonsLEDDemov1.0.zip
best regards
Stefan
Looking at the code, it seems like it is looking for resistance to bleed off the pin's inherent capacitance.
But, it seems you could also to RC-time on each pin to detect an increased capacitance there too...
The one MAJOR flaw outside of this is a simple way to disconnect these. If you want to use external switches, you are still prone to problems from the pads. A jumper post should have been supplied to disable those inputs completely.. maybe one for the outputs as well.. at least a trace between vias so the user can cut it, install their own jumper posts or use it for other purposes.
Okay, one more... a place to put our own connections for power to use the on board IC. Also seems the 5mhz clock is not removable on this unit, but not a real issue.
Any recommendations for the buttons are greatly appreciated.
Velux
The thread where I posted my code also has several links to other threads which discuss the button pads.
I've also posted some pictures of a mezzanine board I'm working on.
I hope you give my code a try and let me know if it works for you.
Duane
Hey Velux,
Depending on how you want to power the board, there are a couple options:
a) You can use VIN (pin 40) to provide an unregulated supply. You will probably want to include a diode in series with this input to prevent any possible back-flow when connected to USB power if your VIN voltage drops too low. This post has a little more info about this: http://forums.parallax.com/showthread.php?132117-Quick-Start-Board-Questions&p=1011691&viewfull=1#post1011691
b) You could also power the 3.3V supply directly as long as you won't be plugging the device into USB power (or using VIN to provide power). The regulator should be able to tolerate being back driven when there is no input voltage; however you just wouldn't want to have an external 3.3v regulator trying to compete at the same time with the on-board 3.3v regulator.
Hope this helps. :-)