• 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.

Need some help with hardware interfacing for PIC

Status
Not open for further replies.

droid

New Member
Good day.

My final year project involves using a PIC16F876A to check the statuses of 44 switches which are connected in a matrix. (see attached picture)

The program is similar to interfacing a keypad to a PIC. The columns (top) are configured as outputs, while the rows (side) are configured as input. When the switch is not depressed, the PIC reads a logic high on that switch location (row,column). When it is depressed, the PIC reads a low.

Here's my problem:

With 1 switch depressed, the PIC successfully reads the switch status correctly which is logic low. When I measured the voltage when that particular switch was scanned, it was in the millivolts range.

With more than 1, or all, of the switches in the same column depressed, the PIC still successfully reads the switch status correctly.

A problem arises when more than 2 switches in the same row are depressed, the PIC reads logic high instead of logic low. When I checked the voltage level, I measured 2 volts!

It seems that the PIC gave an output of 2 volts (which is supposed to be 0) to the columns (output) and it reads the 2 volts on the rows (input).

Can anyone help me? For normal operation, the switches are depressed, so the PIC should read logic low on all the switches.

Do I need a buffer/driver for the output of the PIC?

Thanks
 

Attachments

Nigel Goodwin

Super Moderator
Most Helpful Member
It's because the other PIC outputs are set high, so when you press more than one button you short a high output (or up to three high outputs) to a low output - not a good thing to do!.

To cure the problem, you could fit blocking diodes in the output leads, cathodes to the PIC, anodes to the switches - this will prevent the PIC pulling the switches high.
 

motion

New Member
One easy way is to put diodes in series with each switch to prevent them from interacting.

Another way is to configure the active (low) column I/O line as output while configuring all other I/O lines as input. You can easily do this by manipulating the TRIS register instead of the PORT register. This will prevent two or more switches in the same row from interacting. However this will not prevent three switches from interacting when a switch shares both row and column line with the other two.
 

droid

New Member
It's because the other PIC outputs are set high, so when you press more than one button you short a high output (or up to three high outputs) to a low output - not a good thing to do!.
[email protected] how could i have missed that! *knocks head on wall* :lol:


To cure the problem, you could fit blocking diodes in the output leads, cathodes to the PIC, anodes to the switches - this will prevent the PIC pulling the switches high.
One easy way is to put diodes in series with each switch to prevent them from interacting.
could you guys post a diagram? i'm not sure i understand the connections.


thanks a lot...
 

Nigel Goodwin

Super Moderator
Most Helpful Member
As motion suggested, you could put a diode in series with every switch, but that's a lot of diodes (although it is common practice). Using one diode per output line means less diodes, see the attached small section of diagram. As he also suggested, you could set the TRIS register as you scan the switches to make the unused ones inputs.

So basically the choices are:

Slight hardware mods, software untouched.

Slight software mods, hardware untouched.

It's up to you which you consider 'best'.
 

Attachments

motion

New Member
could you guys post a diagram? i'm not sure i understand the connections.
44 diodes for 44 switches.

BTW, PC keyboards with 100+ keys don't use diodes and still you can use CTRL+ALT+DEL keys.
 

Attachments

droid

New Member
thanks!

i pick the one with the diodes on the outputs, so that there'll only be slight modification to the hardware

thank you both..
 

Alucard

New Member
Question

motion said:
44 diodes for 44 switches.

BTW, PC keyboards with 100+ keys don't use diodes and still you can use CTRL+ALT+DEL keys.
I'm doing a MIDI keyboard for my final year project, which has abt 50+ keys, I am using decoders to scan the keys one by one based on the output of the PIC portD register.. and using the diodes approach too..

BTW I noticed on a keyboard monitor software that not =all= keys can be pressed together and register. At most 5-7 can be pressed together, which keys these are, depends on individual keyboards. I'd opened up a few keyboards, I think this is because a series of keys share the same tracks (I didn't check thoroughly). However I supposed control keys like Ctrl, Shift and Alt would be designed so that they can work with any other key.

Q. So I was interested to hear that the PC keyboards don't use diodes to prevent the 'keycrossing', so how do they do it? Entirely in software?

Thanks for answering my question.
 

RonH

New Member
PIC keyboard

I just built a Keyboard Encoder 6x8. PIC 16F877
I have 48 keys and no "Key ghosting" at all, also I didn't use any diodes, the simplest way was with the Tris register, I can have as many keys as one can press all at once and it will still accept all the keys (to the limit of the Bios).
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top