Propeller input pullups ?
Don Pomplun
Posts: 116
I just got a couple QuickStart boards. These have 8 pseudo-buttons which you ground through your conductive finger, each through a 100K resistor. I didn't think the Prop chip had any input-pullup option (like many PICs do). Parallax referred me to the Touch Button demo program. This uses a separate object running in its own cog. Reproduced herein:
<code>
CON
BUTTON_PINS = $FF ' The QuickStart's touch buttons are on the eight LSBs
SAMPLES = 32 ' Require 32 high redings to return true
VAR
long Results
PUB Start(Rate)
Results := Rate
cognew(@Entry, @Results) ' Launch a new cog to read samples
PUB State | Accumulator
Accumulator := Results ' Sample multiple times and return true
repeat constant(SAMPLES - 1) ' if every sample was highw
Accumulator &= Results
return Accumulator
DAT
org
Entry
rdlong WaitTime, par
mov outa, #BUTTON_PINS ' set TestPins high, but keep as inputs
mov Wait, cnt ' preset the counter
add Wait, WaitTime
Loop
or dira, #BUTTON_PINS ' set TestPins as outputs (high)
andn dira, #BUTTON_PINS ' set TestPins as inputs (floating)
mov Reading, #BUTTON_PINS ' create a mask of applicable pins
waitcnt Wait, WaitTime ' wait for the voltage to decay
andn Reading, ina ' clear decayed pins from the mask
wrlong Reading, par ' write the result to RAM
jmp #Loop
Reading res 1
WaitTime res 1
Wait res 1
</code>
The Repeat loop in the spin code just looks like debounce. It's what's going on in the assembly that I don't quite get.
1. Initially it sets the pins High, even though they are still defined as inputs. What does this do? Charge up something to make a non-grounded pad look like it's pulled up, I'd guess.
2. Then the loop repeatedly makes the pins into outputs, then immediately back into inputs. Since each cog defines I/O pin directions, this must somehow make the pin look pulled up to the primary cog?
3. This doesn't look complex enough to not be done *easily* in Spin. But not so far for me. Must not be getting how this works. Having it work would save installing a bunch of pullup resistors!
TIA,
Don
<code>
CON
BUTTON_PINS = $FF ' The QuickStart's touch buttons are on the eight LSBs
SAMPLES = 32 ' Require 32 high redings to return true
VAR
long Results
PUB Start(Rate)
Results := Rate
cognew(@Entry, @Results) ' Launch a new cog to read samples
PUB State | Accumulator
Accumulator := Results ' Sample multiple times and return true
repeat constant(SAMPLES - 1) ' if every sample was highw
Accumulator &= Results
return Accumulator
DAT
org
Entry
rdlong WaitTime, par
mov outa, #BUTTON_PINS ' set TestPins high, but keep as inputs
mov Wait, cnt ' preset the counter
add Wait, WaitTime
Loop
or dira, #BUTTON_PINS ' set TestPins as outputs (high)
andn dira, #BUTTON_PINS ' set TestPins as inputs (floating)
mov Reading, #BUTTON_PINS ' create a mask of applicable pins
waitcnt Wait, WaitTime ' wait for the voltage to decay
andn Reading, ina ' clear decayed pins from the mask
wrlong Reading, par ' write the result to RAM
jmp #Loop
Reading res 1
WaitTime res 1
Wait res 1
</code>
The Repeat loop in the spin code just looks like debounce. It's what's going on in the assembly that I don't quite get.
1. Initially it sets the pins High, even though they are still defined as inputs. What does this do? Charge up something to make a non-grounded pad look like it's pulled up, I'd guess.
2. Then the loop repeatedly makes the pins into outputs, then immediately back into inputs. Since each cog defines I/O pin directions, this must somehow make the pin look pulled up to the primary cog?
3. This doesn't look complex enough to not be done *easily* in Spin. But not so far for me. Must not be getting how this works. Having it work would save installing a bunch of pullup resistors!
TIA,
Don
Comments
Edit Yours code tags with [ ] instead of < >
Gotta use code tags to post spin code.
The Quickstart is a good choice for getting to know the Propeller.
I just posted my QuickStart pad driver in the push-on/push-off thread.
http://forums.parallax.com/showthread.php/144841-button-that-has-push-on-off
It's written in spin and I use it instead of the better ones,
You might read through it to get the overall idea.
Use it if you like it.
Touchpads work by charging the capacitance of the output cell
and then seeing if that will discharge in a certain time period.
No pull-up resistors required.
Making the pins outputs causes the precharged cell to dump into the external circuit.
In this case the Touch Pads, through that 100k R (and the C of the circuitry?)
So that charge will naturally decay over a certain time period.
Shorting the touchpad to ground with a finger bleeds the charge off a lot faster.
The rest is all timing- when to take the sample(s).
It's even worse that you suspected, Don.
With modern chips there is no advantage to pulling up over pulling down.
With a pull down resistor, the input bit sees positive logic instead of inverted.
Now getting out my drawer of 8.2K resistors. At least the QS board has a handy set of holes for the I/O for them - actually pretty handy!
just for future reference:
It's not an ambiguous state when sampled at the right time...
But good luck with it.
If you add 8.2k pullups your skin resistance must be lower than about 7 kOhm to see a Low at the input. I don't think this is the case otherwise the existing Touchbutton drivers and example codes should have worked fine for you. Normal skin resistance is in the MegaOhms so you would need pullups with 10..20MOhms. And then this will be as "ambiguous" as the existing solutions.
The problem is that these are resistive touchbuttons instead of capacitive ones. They just not work with all persons and environments.
Andy
Don