Shop OBEX P1 Docs P2 Docs Learn Events
Multiplexing 6 rotary hex encoders — Parallax Forums

Multiplexing 6 rotary hex encoders

Question
I need 6 hex rotary dip encoders as input on a propeller.
How can I get this working and save pins.

Firs I think easy, I put all the outputs in parallel as 4 inputs on the prop with pull down resistor.
Next I put the input of each switch from 1 to 6 high after each other, and read each time the inputs. Wrong
I try with diode in the input line, but still influences between switches

My trouble is when I use more as one switch.

It is not software, but hardware .



[C0DE]
Pub TallyDec

outa[RotTally..RotID] := 0 ' ALL LOW
outa[RotTally] := 1 ' Mesure High
case INA[Hex4..Hex1] ' READ 4 BITS
1..8 : Tally := INA[Hex4..Hex1] ' READ 4 BITS
other : ValidHex := -1
outa[RotTally] := 0 ' Mesure Low

Pub GpoDec

outa[RotTally..RotID] := 0 ' ALL LOW
outa[RotGpo] := 1 ' Mesure High
case INA[Hex4..Hex1] ' READ 4 BITS
1..8 : Gpio := INA[Hex4..Hex1] ' READ 4 BITS
other :ValidHex := -1
outa[RotGpo] := 0 ' Mesure Low
[/C0DE]

Comments

  • I suspect your best option is going to be a hardware parallel to serial shift register. They're super cheap, easy to use, and can be daisy chained. They're made for exactly cases like this. In software you're always going to have trouble differentiating which thing changed if two or more change at once.

    You could, possibly, get tricky by reading them as analog. Put unique resistors on all but one knob. Say, 220 ohm, 330 ohm, 1K. Since the voltage read from a pin will be unique for each combination of resistance, you should be able to work out which switches are active.
  • LtechLtech Posts: 380
    edited 2016-02-03 18:12
    Thanks Jason it's wat I believe.
    But I dream somboddy get a trick for this.

    wat's go missed upstairs ?
    Pub TallyDec
    
       outa[RotTally..RotID] := 0 ' ALL LOW
       outa[RotTally] := 1 ' Mesure High
    
       case INA[Hex4..Hex1] ' READ 4 BITS
        1..8 : Tally := INA[Hex4..Hex1] ' READ 4 BITS
        other : ValidHex := -1
    
       outa[RotTally] := 0 ' Mesure Low
    
    Pub GpoDec
    
      outa[RotTally..RotID] := 0 ' ALL LOW
      outa[RotGpo] := 1 ' Mesure High
    
      case INA[Hex4..Hex1] ' READ 4 BITS
       1..8 : Gpio := INA[Hex4..Hex1] ' READ 4 BITS
       other :ValidHex := -1
    
      outa[RotGpo] := 0 ' Mesure Low
    
    
  • Are you trying to scan them like a matrix keypad? If so, you would need separate diodes on all four outputs of all six switches. You would need 24 diodes in all. You could use many-input OR gates instead of tons of diodes.

    However, as Jason Dorie said, the simplest and easiest thing to do would would probably be to use an I/O expander.
  • kwinnkwinn Posts: 8,697
    edited 2016-02-02 20:32
    As Electrodude posted you will need 24 diodes to do it this way, no way around that. It would also require 8 lines/pins. Better to use 3 '595 shift registers as suggested. That only requires 3 lines and 24 pulldown resistors.

    Sorry, that should have been '165 shift registers.
  • jmgjmg Posts: 15,173
    Ltech wrote: »
    ... Wrong
    I try with diode in the input line, but still influences between switches

    My trouble is when I use more as one switch.

    It is not software, but hardware .
    Simplest rotary encoders can short the lines, but you should be able to multiplex with 12 diodes, plus open drain scan. That drops 12 pins to 8 pins. not much of a saving, but 4 pins may be enough.

    2 x 4051 HW mux will drop 12 pins to 5, and can scan 16 contacts.

    You could use a HEF4894 or NPIC6C4894 (12 op shift register) to lower pin count further, but an irony there is a small MCU is today cheaper and smaller than a 12b shift register.

  • LtechLtech Posts: 380
    edited 2016-02-02 20:48
    I made a cad from my supposition
    1417 x 1169 - 161K
  • jmgjmg Posts: 15,173
    Ltech wrote: »
    I made a cad from my supposition
    That will not work as the BCD out can short in any combination.

    My post above assumed 6 rotary encoders, but I see you meant 4 bit Hex Switches.
    The problem is the same, you can use diodes on every output, (24 diodes) and open drain the common pin.
    With 6 x 4 bit Hex Switches you need 6+4 = 10 pins

    Or, 3 x 4051 can do this in 6 pins. (no diodes)
  • So no trick to expect

    Thank you for looking.

    @ jmg I only draw 4 of the 6 Hex encoders.

    My first draw was with lcd, menu and rotary encoder.
    But the users do not want to change from the ugly old way design they use now ....
    I have to push my design I guess.

  • kwinnkwinn Posts: 8,697
    It does not work because more than one switch in any row or column can be closed at any time. In the attached diagram the two switches in column D2 will short rows DS2 and DS3 together and cause the data read when DS3 is high to be wrong. If the diodes were not there it would also cause the DS2 and DS3 pins to be shorted with one high and one low.
    266 x 230 - 4K
  • I look for this lots of soldering ...
    1260 x 1210 - 180K
  • ElectrodudeElectrodude Posts: 1,657
    edited 2016-02-03 08:08
    You don't need the one diode in front of each encoder, just the four that you added in your newest diagram.

    You're probably better off using shift registers, though. It will be a lot less soldering, and there's probably already Spin code to read any of the shift register chips that have been listed here so far.
  • @Electrodude
    I think you need the one on the front to get a "try-state" pin
    Propeller pin is high, or low
    So if you are not reading the encoder it has to be low.
    The other encoders are connected trough ground, trough the first selected output values

    My last draw works, I build it and test ok
    So need 4 input pins, and 6 output pins, go high when read appropriate encoder
  • ElectrodudeElectrodude Posts: 1,657
    edited 2016-02-03 18:37
    No you don't. The diodes on the output would do it for you.

    Here's a schematic for a 3x3 scanner that I found via Google. Note that there are only diodes on one side of each switch, not both (The box on the left is the microcontroller):
    switch_matrix_schem_sm.jpg

    But why are you so insistent on using matrix scanning? Shift registers would be so much easier.
  • kwinnkwinn Posts: 8,697
    No you don't. The diodes on the output would do it for you.

    Here's a schematic for a 3x3 scanner that I found via Google. Note that there are only diodes on one side of each switch, not both (The box on the left is the microcontroller):

    But why are you so insistent on using matrix scanning? Shift registers would be so much easier.

    @Ltech

    Electrodude is right on both counts. You do not need the diodes to the left of the encoders in your diagram, and using three '165 parallel to serial shift registers is easier than 24 diodes. It also needs only three pins to read the data in.

    OTOH if you have the diodes, six output pins, and four input pins available you can do it that way.
  • Sorry, I was wrong = spear 6 diodes on this project

    I understand the parallel to serial, but it is for a proof of concept now on a breadboard.
    For the final I want to put a small lcd and a rotary push encoder + menu system or micro sd setup card read on boot-up.

    Strange nobody think about build a rotary hex encoder with build in diode ?

  • jmgjmg Posts: 15,173
    Ltech wrote: »
    Strange nobody think about build a rotary hex encoder with build in diode ?
    I've seen older Hex/Dec thumb-wheels with diode options, but they are much larger.

    A rotary hex encoder company makes switches, and the tracks take most of the space, adding diodes to a stamped lead frame is not easy, and adding a PCB would move outside standard footprints, and the market for these is already small & shrinking.
    ie not really a surprise.


  • kwinnkwinn Posts: 8,697
    Ltech wrote: »
    Sorry, I was wrong = spear 6 diodes on this project

    I understand the parallel to serial, but it is for a proof of concept now on a breadboard.
    For the final I want to put a small lcd and a rotary push encoder + menu system or micro sd setup card read on boot-up.

    Strange nobody think about build a rotary hex encoder with build in diode ?

    The rotary encoder can be done with diodes or shift registers. A lot of the older equipment I worked on used rotary encoders with diodes on the encoder board, and they worked well. Shift registers became more popular on later microcontroller based systems because they needed fewer I/O pins and it was easier to place one IC than 8 diodes on a board.
Sign In or Register to comment.