multiplexing with arduino and 4066 switches - the wrong solution?

Thread Starter

pgo1

Joined Nov 7, 2012
67
a little while ago I designed a simple circuit for a friend which involves 4x6 switches multiplexed with an arduino. Later she decided she wants to press more than one switch at a time, which causes problems as joining two of the group pins together pulls them both up to 5V. To get around this I though I would try one of the 74HC4066N analog switches I have lying around to switch each of the four group pins in so that any one group pin is connected only at the point when the arduino is checking that group (my multiplexing is just a simple routine to turn one group on, check each 6 pins in turn, turn the second group on, check the 6 pins again etc.) meaning that the group pins are now isolated from each other

however, when I connect two of the outputs of the 4066 together it locks up and i get pretty much 5V at both! Why might this happen? Should I persevere or is this the wrong chip for the job?

I have attached a screenshot to give a rough idea of how I have the chips connected - I haven't included all the switches, as this is how i've been testing the circuit. also the pic16f83 is actually an arduino but i didn't have one in the library....
 

Attachments

kubeek

Joined Sep 20, 2005
5,795
Where are the swhitches? What is the purpose of those two resistors?
Try drawing in the matrix keypad, you can just draw 4 and 6 wires crossing, we can imagine the switches at the intersections.
 

JohnInTX

Joined Jun 26, 2012
4,787
Where are the switches? What is the purpose of those two resistors?
Try drawing in the matrix keypad, you can just draw 4 and 6 wires crossing, we can imagine the switches at the intersections.
And in an X-Y matrix, you can detect and discriminate 2 switches pushed at the same time with the right firmware and no additional hardware. To detect 3 switches or more requires diodes in series with each switch to block sneak-paths.

As the firmware scans the XY matrix, keep track of up to 2 coincidences and emit the switch crossings in order. If you detect 3 or more, ignore everything until the matrix is clear.
 

JohnInTX

Joined Jun 26, 2012
4,787
You need the N-Key Rollover function, and you need 4*6=24 1n4148 diodes to keep each key can be work individually.
True enough for N-Key Rollover. For 2 Key rollover, you don't need diodes as long as the firmware is written to handle 0, 1 or 2 keys pressed for valid keys and more than that for an invalid state.

The old MM5740 encoded 90 keys with 2 key rollover with no diodes. I've accomplished 2 key rollover (which can handle the SHIFT function among others) in various setups up to 5x4 without diodes.

Have fun.
 

ScottWang

Joined Aug 23, 2012
7,409
True enough for N-Key Rollover. For 2 Key rollover, you don't need diodes as long as the firmware is written to handle 0, 1 or 2 keys pressed for valid keys and more than that for an invalid state.

The old MM5740 encoded 90 keys with 2 key rollover with no diodes. I've accomplished 2 key rollover (which can handle the SHIFT function among others) in various setups up to 5x4 without diodes.

Have fun.
The problem is that the OP isn't use the usb keyboard for computer, he must be design the software and hardware by himself.

I just tried my usb keyboard, it can be detected about 6 six keys in the same time, sometimes can be detected 7 keys.
 

Thread Starter

pgo1

Joined Nov 7, 2012
67
thanks, this is all very interesting. I'll do a bit of research into the schemes suggested

However, if we are to discuss the application - rather than the specific behaviour of the 4066 - I should explain my setup further. I have designed a 4x6 matrix controlled by arduino (pictured). This is made to detect when a key is pressed and released, sending a message of which key is pressed and what the action is (i.e. 11on or 32off). Now the problem I am having is not so much when keys are pressed at once (i should have worded it better) but rather as follows..

*active LOW

The A pins are sent low one after the other and the arduino checks group B 1,2,3,4,5,6 to see if there is a change from the last time they were checked - in this way a press or release of the switch is detected.

In the event that S11 is pressed and held, the program will register a press and send "11on". Now, if before the switch is released another switch in the same group B group is pressed (s21,s31,s41 but let's say s21 for this example) then pin A1,A2, and B1 are all connected together. This has the effect of pulling this node high, as one group A pin is always high when the other is low. So the switch pressed is S12, but instead of registering a change in S12 ("12on"), the program thinks s11 has been released (11off) as it has changed from 0 to 1.

So, my problem is how do i get around this from happening? The case where two switches are pressed at once is also a consideration, but not the most pressing one. I had hoped the 4066 chip would provide a good way of isolating the groupA pins from each other but it seems the function of this is more complicated than I expected...

kubeek - regarding the resistors - if only one switch is pressed the output locks up, i assume because of the output impedances/pull up resistors of the arduino pins
 

Thread Starter

pgo1

Joined Nov 7, 2012
67
the a group is connected pins 12-9 and the b group pins 8-3 on the arduino.

but somewhat embarrassingly, I just realised - I can isolate the group pins by just using diodes!

thanks for your help, and if anyone knows why 4066 chips lock up when you connect the outputs, i'd still be interested to know...
 

ScottWang

Joined Aug 23, 2012
7,409
the a group is connected pins 12-9 and the b group pins 8-3 on the arduino.

but somewhat embarrassingly, I just realised - I can isolate the group pins by just using diodes!

thanks for your help, and if anyone knows why 4066 chips lock up when you connect the outputs, i'd still be interested to know...
Normally you can't connecting any two outputs of logic gates together, unless they are open drain or open collector, you only can connecting the inputs together.

When you connecting two outputs together, if they are not open drain of open collector, then the outputs could be lock up or unstable, this will be happen when two status of inputs are changing to different status.
 

kubeek

Joined Sep 20, 2005
5,795
Adding on Scott's thoughts, you cannot connect outputs together, unless you are certain that there will be no more than one output active at any time. ANY time. Meaning you need to provide sufficient dead-time between one output driver turning off and another turning on to prevent any cross conduction between the two outputs.
 

ScottWang

Joined Aug 23, 2012
7,409
I'm not sure why you insist to use CD4066, there are some others that you can choose as :
74HC251 - 8-input multiplexer, 3-state.
74HC253 - Dual 4-input multiplexer, 3-state.
74HC257 - Quad 2-Input Data Selector/Multiplexer with 3-State Outputs.
 
Top