Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Middle key not correctly recognized by 8051 processor

Status
Not open for further replies.

mik3ca

Member
circuit.png

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.
 

Attachments

  • keypress.asm
    1.7 KB · Views: 292
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?
 
Where do the buttons connect to the 8051... It looks to me like you are only connecting to
two pins..
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.

What capacitor values should I use?
 
the middle button is equivalent to the left and the right button pressed simultaneously.
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.
 
How much time are you allowing for switch de-bouncing?
 
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..

upload_2017-7-2_19-16-29.png
 
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?
 
Again... Which pins are you using..

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..
 
Again... Which pins are you using..

The actual pin numbers on the micro? I believe P1.3 and P1.4. I can't remember to be exact but I know its two pins between P1.2 and P1.7.

When using micro's you eliminate bounce in software... Its easier, It looks to me like you are trying to (do) both!

I also want to make it where the CPU doesn't spend too much time dealing with key presses.
 
ok I took the caps off but now I think I'll need to replace the diodes with ultra-fast types (faster than 1N914)
 
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?
 
How would a faster diode help? A finger press lasts many tens of mS. Switch bounce can also last tens of mS.
 
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?
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top