Puzzle: 5 Switches 4pins available.
tonyp12
Posts: 1,951
My 6P add-on board standard only have 4 mcu pins, though I have an idea how to solve this want to see what others come up with.
You can not use HC165 etc, can not use analog output.
6 points: Only one Switch will even be pressed at one time
8 points:Two Switches my be pressed at the same time, two neighboring switches or 1 switch plus center switch(5)
10 points: Two neighboring Switches plus center(5) can be pressed at the same time.
diptrace schematic:https://skydrive.live.com/redir?resid=6D7787B33D967B1A!4006
The switch is a JS1300AQ
You can not use HC165 etc, can not use analog output.
6 points: Only one Switch will even be pressed at one time
8 points:Two Switches my be pressed at the same time, two neighboring switches or 1 switch plus center switch(5)
10 points: Two neighboring Switches plus center(5) can be pressed at the same time.
diptrace schematic:https://skydrive.live.com/redir?resid=6D7787B33D967B1A!4006
The switch is a JS1300AQ
Comments
Bonus1: If you can make it short circuit safe, if user by mistake put to many pins as output with 3.3v+gnd mixed, Jordan would only have to add two 1K resistors on two pins.
Bonus2: Not using diodes, they cost more than resistors but if you have to use them they count as 2 parts as lower part count is a bonus too.
Bonus3: One single hardware de-bounce that handles all 5 switches and preferred way is that a closed switch=high signal.
No need to go below 4 pins, though 3 and one for a led to show feedback would be cool.
The idea is that you read the I/O, and if it's Zero, you make the I/O an OUTPUT; HIGH, and then immediately back to an INPUT. If the I/O reads as a One, then leave the I/O as an INPUT.
Note1: The Key is to keep the above function in a deterministic loop.
Note2: The 4.7k resistor assumes that the I/O threshold is 1/2 Vdd
By monitoring the state of the input, i.e. how many 1's versus 0's , you should have a ratio-metric relationship that corresponds to the button press combination.
You might as well use 1% resistor values, since you'll need 1% resistors. 1/32 < 1/20, after all.
-Phil
You're only getting by with because your ratios are greater than two. If they were equal to two (i.e. 10K, 20K, 40K, 80K, 160K), you would need 1% resistors. Consider the case where the 10K resistor is 5% too high, and the others are 5% too low. The resistance of the 10K, then, is 10.5K, and the paralleled resistance of the others is 10.133K. Since 10.1333 < 10.5, the output will not be monotonic going from %01111 to %10000.
-Phil
If you limit it to one key press at a time you could wire each switch to more than one pin and read the value in binary;
switch one - pin one
switch two - pin two
switch three - pin one and two (double pole)
switch four - pin three
switch five - pin one and three (double pole)
that leaves your 4th pin free for feed back.
Oh! And if you act now I'll throw in two more switches for free,
switch six - pin two and three (double pole)
switch seven - pin one, two, and three (triple pole?)
-Phil
Regards,
sm
I think I can do it with two 4x resistor arrays.
S1 = J2
S2 = J1
S3 = J3 (after J2 as output)
S4 = J4 (after J1 as output)
S5 = J3 (after J1 as output)
So you start with 4 inputs, test states.
Set J1 as output, test state on J2,J3,J4
Set J2 as output, test state on J1,J3,J4
No short circuit possible, as Setting for example J2 high while S1 is pressed just connects Vcc to Vcc
May have to set J3 as ground to find some triple multi-press, not sure yet that is why I put 1K on S2 pull-up instead
You could use 6 switches with no more pins or components ( except the extra switch).
Set J1 HIGH test any combination of SW1, SW2, and SW3
Set J4 HIGH test any combination of SW4, SW5, and SW6
If you only want 5 switches just make SW3 and SW4 one DPST switch.
I had assumed 4pins available, meant connections, but I see you have added a Vcc label in there.
If you are not worried about cables, but want to save Port Pins, then you can scan 3 pairs of Switches, on an OR basis, with just 3 port pins (5 wires), or 4 port pins(5 wires), if you want to go for lowest idle power, no matter what keys are pressed.
Each pin has a Button+R to Vcc (or switched Vcc), and a Button+R to GND.
Button scan is to Enable Vcc, Drive Hi and flip to In and check if still Hi - If LOW, GND sw is on.
then Drive Low, and flip to In, and check if still Low. - If High, Vcc SW is on.
4 Drive:read combinations exist, only 2 are active buttons.
No pull downs are needed, but the scan relies on Rs * Cstray < ReadBack time, and Cstray * BoardLeakage > Readback time.
In 4 port pin design (6 buttons), up to 3 LEDs can be added for Free, if you want to signal info to the user.
During idle Scan, (> 99% of time) Pins drive to LEDs, During key-scan, LEDs are reverse biased
No added debounce C is needed.
It works due to 1 & 3 can not be pressed at the same time,
Problem1: Set J4 high Press S3 AND S1 it would confuse J2 thinking S5 was pressed. (but lucky 1<>3)
Problem2: Set J1 high Press S4 AND S5 then J2 will think S1 was pressed, but xor it with J4 you know it was that and not S1+S3 (as that combo is not physical possible)
Problem:3 Set J1 high Press S1 AND S4 AND S5 (valid key press) , how does it know it was not problem 2 above?
Update:
I changed it so S4 goes to J3 instead, should work better at S2 and S4 can not be pressed at the same time and power can not find a path from J1.
P.S If I wanted to use a IC, this tiny QFN HC238 should fit in somewhere.
http://www.mouser.com/ProductDetail/NXP/74HC238BQ115/?qs=%2fha2pyFadujxT%252bHyEDK6NmmiMIeuwAoc%252bmSnMJUCEVY%3d
http://forums.parallax.com/showthread.php/120970-Converting-serial-to-parallel?p=891726&viewfull=1#post891726