multiplexing with arduino and 4066 switches - the wrong solution?

Discussion in 'General Electronics Chat' started by pgo1, Aug 14, 2014.

  1. pgo1

    Thread Starter New Member

    Nov 7, 2012
    23
    0
    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....
     
  2. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    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.
     
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,348
    1,029
    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.
     
  4. ScottWang

    Moderator

    Aug 23, 2012
    4,858
    767
    You need the N-Key Rollover function, and you need 4*6=24 1n4148 diodes to keep each key can be work individually.

    Another method is to use 4 74hc244 to input the key, each 74hc244 for 6 keys to input.
     
  5. JohnInTX

    Moderator

    Jun 26, 2012
    2,348
    1,029
    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.
     
  6. ScottWang

    Moderator

    Aug 23, 2012
    4,858
    767
    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.
     
  7. pgo1

    Thread Starter New Member

    Nov 7, 2012
    23
    0
    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
     
  8. ScottWang

    Moderator

    Aug 23, 2012
    4,858
    767
    1. How many keys could be pressed in the same time?
    2. Post the circuit of 4x6 matrix keys and label the names.
     
  9. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    Without the complete schematic it is really hard to imagine what your problem exactly is.
     
  10. pgo1

    Thread Starter New Member

    Nov 7, 2012
    23
    0
    oh yeah I forgot to attach the picture. Here it is - should make more sense now....
     
  11. ScottWang

    Moderator

    Aug 23, 2012
    4,858
    767
    So the group A was conneted to RA0~RA3(or D1~D4), The group B was connected to RB0~RB5?
     
  12. pgo1

    Thread Starter New Member

    Nov 7, 2012
    23
    0
    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...
     
  13. ScottWang

    Moderator

    Aug 23, 2012
    4,858
    767
    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.
     
  14. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,670
    804
    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.
     
  15. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,073
    3,856
  16. ScottWang

    Moderator

    Aug 23, 2012
    4,858
    767
    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.
     
  17. pgo1

    Thread Starter New Member

    Nov 7, 2012
    23
    0
    thanks for the information. very useful all round
     
Loading...