I don't understand why my routine doesn't work. The left and right buttons (S1 and S3 in schematic) always function normally, but sometimes S2 (center) functions normally, and sometimes it functions as button S1. In the circuit, all resistors are 10K, all diodes are actually 1N914, and all capacitors are 2.2uF tantalum. I have attached source code to the function that is problematic. I'm not sure what strategy to use to rectify my problem, but I'm trying to eliminate the debouncing effects via software and capacitors in parallel with the buttons and if possible, I want to avoid redoing my circuit.
Any ideas what I can do to my code or whether I should add/remove parts to my circuit without changing PCB layout?
Also, the middle button is equivalent to the left and the right button pressed simultaneously.
Pressing S1 or S2 discharges only a single capacitor. Pressing S3 discharges all 3 caps. Are you sure your code allows enough time for that discharge and subsequent longer re-charge period?
The pins connect to the resistors. Yes I know there's only two GPIO pin connections, but with my method, I conserve pin usage on the micro. Middle button pressed means both pins are set to low.
Now I could use smaller capacitor values but at the same time, I don't want to create a jitter-effect. For example, I don't want it where when the button is pressed, the micro sees it as pressed for 2 microseconds then released for 2 microseconds when in fact the button is still held down.
The buttons I'm using are omron's B3F-40xx series.
No, the middle button is equivalent to one button indicating pressed a fraction of a second before the other. No two events in real life are exactly simultaneous.
I think you maybe need a second read of the buttons, after a short delay from first detecting button press.
In theory, Capacitors will discharge instantly, since you are shorting them out.
Maybe your formula works if you take R to be capacitor ESR. Maths and theory are not my strong points.
In reality, I have no idea regarding resistances and timing. Switch bounce is a pretty random phenomenon that varies with button, age and finger pressure.
Shorting out capacitors with every key press presumably affects the switches over time.
From my code, it detects when a key is pressed down right away but then it counts for at least 2 microseconds from the moment all buttons are released before the system believes a valid keypress is registered. Look at the code for details.
The pins connect to the resistors. Yes I know there's only two GPIO pin connections, but with my method, I conserve pin usage on the micro. Middle button pressed means both pins are set to low.
Looking through the code... Just tell me which pins are being used...
Tristating 8051 pins depends very much on the pins used... You only need a cap on the two pins.. Charge the caps then tristate the pins to read... It wont bode well ( IMO) if the caps are across the switches..
You are trying to ( after some delay ) read both pins, if switch one is pressed, then pin 1 will be low. if switch 2 is pressed then pin 2 will be low The middle just becomes pressing two at the same time..
Set pin1 and 2 high
Tristate them
delay 20mS+ and read..
Then count 250mS to allow the finger to be released..
my R1 and R2 are 10K each. But if I remove the capacitor across the keys, wouldn't weird things happen once a key is pressed such as the processor taking it as key pressed for 1us and key released for 1us and repeat? I thought by adding capacitors that I eliminate bouncing effects of the buttons?
When using micro's you eliminate bounce in software... Its easier, It looks to me like you are trying to both! Change the resistors to 1k and see if it's better... Then take the caps out and see if its better... Then place the software debounce in the chip..
Now I am baffled. I removed the caps and now no keys are being picked up properly. Is there something else I need to know regarding the debouncing of buttons that no one is telling me?
This is why I asked about the port pins.... The P1 and P3 port has "Extremely" weak pullups You will need to boost this
P0 has no pullups and P2 has controllable pullups.. Can you bolster the pin to Vcc by adding a 1k?