Shop OBEX P1 Docs P2 Docs Learn Events
Reading LARGE numbers of switch closures... without LARGE chip count? — Parallax Forums

Reading LARGE numbers of switch closures... without LARGE chip count?

xanatosxanatos Posts: 1,120
edited 2012-09-05 21:59 in General Discussion
I have to read 256 total switch closures (128 devices each with two switch-closure outputs). Obvious call for 74H165 Shift Registers, right? Except that I need 32 of them, meaning 32 latch lines, meaning 4 more 74H595s just to drive all those latch lines....

So I thought of using some 4066 analog switches to sequentially drop 8 lines at a time onto a single 'H165, but then I have 64 - 4066's with each 2 having a common enable, so I still have 32 enable lines, requiring 4 - 74H595s to drive those...

So then I thought - rather than switching the sense of the outputs, I could parallel the outputs, and just cycle through the commons using 74H595s to select 1 of the 128 common lines. This allows me to eliminate the input circuitry altogether, and all I need is 16 74H595s to get the 128 output common lines driven (which also means another pair of 74H595s to drive the latches on the other 16).

I am trying to reduce the chip count (and save my neck and back from being hunched over a dremel drill press for days drilling a thousand holes).

Is there anything out there that may do what I am trying to do with greater efficiency? Specifically meaning much smaller chip count? I even thought of trying to ID each sensor by a specific resistance value, but there is going to be a lot of wiring distance between the sensors and my circuitry...

Thanks for any ideas! :-)

Dave

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-08-25 07:29
    xanatos wrote: »
    ... I even thought of trying to ID each sensor by a specific resistance value, but there is going to be a lot of wiring distance between the sensors and my circuitry......


    Would something like this be of any help?

    http://pdfserv.maxim-ic.com/en/ds/DS2401.pdf
  • xanatosxanatos Posts: 1,120
    edited 2012-08-25 07:51
    Electronic serial number on each sensor - cool idea! And at only $1.64 each (prob. less at 256!) - it's in the budget. Still open to ideas, though, but that is a NICE idea! :-)

    Dave
  • Mike GreenMike Green Posts: 23,101
    edited 2012-08-25 08:00
    Other 1-Wire solutions are possible like this with 2 I/O pins per device.
  • LeonLeon Posts: 7,620
    edited 2012-08-25 08:00
    The tiny PIC10 MCUs are a lot cheaper. Each of them could monitor four switches.

    Another option would be an MCU with two 16-bit ports or four 8-bit ports, with the switches arranged as a 16x16 matrix.
  • kwinnkwinn Posts: 8,697
    edited 2012-08-25 10:57
    If you have access to both sides of the switch (common and no or nc) you can do this with two '595 and two '165. Even better would be a prop or some micro with 32 I/o pins (16 output and 16 input). Some pins would have to be dual use to communicate switch status to external circuitry.
  • xanatosxanatos Posts: 1,120
    edited 2012-08-25 14:16
    All these ideas have been fantastic, and I never even knew about the electronic serial number chips before... but:

    Kwinn Wins! The matrix reduces my chip count from 36 to 4! That means instead of 576 holes I only have to drill 64, and this makes me very happy :-)

    Thanks everybody!

    Dave
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-08-25 14:56
    xanatos wrote: »
    ...

    Kwinn Wins!...

    Is this for a calorimeter?
  • xanatosxanatos Posts: 1,120
    edited 2012-08-25 15:38
    Lol no :-) overfill alarm/safety system.

    Dave
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2012-08-25 16:02
    I know you mentioned not wanting to drive the latch lines with additional 74H595s, so here is a way to do it by modulating the polarity of the power supply to switch modes between LOAD/SHIFT. This allows you to cascade several 74H165s with a repeatable 4-conductor (telephone cord) scheme.
    1024 x 436 - 49K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-25 16:16
    There's one big catch with a matrix arrangement, though: you need a separate diode for each switch.

    -Phil
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-08-25 16:29
    Plus 16 pull down resisters in addition to the 256 diodes..

    Duane J
  • kwinnkwinn Posts: 8,697
    edited 2012-08-25 16:39
    I know you mentioned not wanting to drive the latch lines with additional 74H595s, so here is a way to do it by modulating the polarity of the power supply to switch modes between LOAD/SHIFT. This allows you to cascade several 74H165s with a repeatable 4-conductor (telephone cord) scheme.

    Thanks Beau, that's a great idea for times when only 4 conductors are available.
  • xanatosxanatos Posts: 1,120
    edited 2012-08-25 17:59
    There's one big catch with a matrix arrangement, though: you need a separate diode for each switch.

    -Phil

    Actually, I have a programmatic method of using the 165s and 595s such that each switch is polled separately in a matrix arrangement, and it doesn't require diodes. Yes, pulldowns, no diodes. Happy camper!

    Dave
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-08-25 18:23
    The only way you can do it in a 16 x 16 array of Normally Open switches without isolation diodes if you can guarantee that one and only one switch is pressed at a time. If more than 2 switch are pressed you can't tell which of 4 switches were pressed.

    Duane J
  • xanatosxanatos Posts: 1,120
    edited 2012-08-25 18:45
    The way I have it set up, only one column is energized at a time, only one row is sensed at a time. Honestly... It works!

    Dave
  • LawsonLawson Posts: 870
    edited 2012-08-25 18:49
    xanatos wrote: »
    I have to read 256 total switch closures (128 devices each with two switch-closure outputs). Obvious call for 74H165 Shift Registers, right? Except that I need 32 of them, meaning 32 latch lines, meaning 4 more 74H595s just to drive all those latch lines....

    So I thought of using some 4066 analog switches to sequentially drop 8 lines at a time onto a single 'H165, but then I have 64 - 4066's with each 2 having a common enable, so I still have 32 enable lines, requiring 4 - 74H595s to drive those...

    So then I thought - rather than switching the sense of the outputs, I could parallel the outputs, and just cycle through the commons using 74H595s to select 1 of the 128 common lines. This allows me to eliminate the input circuitry altogether, and all I need is 16 74H595s to get the 128 output common lines driven (which also means another pair of 74H595s to drive the latches on the other 16).

    I am trying to reduce the chip count (and save my neck and back from being hunched over a dremel drill press for days drilling a thousand holes).

    Is there anything out there that may do what I am trying to do with greater efficiency? Specifically meaning much smaller chip count? I even thought of trying to ID each sensor by a specific resistance value, but there is going to be a lot of wiring distance between the sensors and my circuitry...

    Thanks for any ideas! :-)

    Dave

    You do know the 74HC165 can be daisy chained? Tie Qh to Ser between chips, and use a common clock and latch line. For 'n' chips you'd need to toggle latch once, then clock in n*8 bits. Assuming an 80MHz clock and a 10MHz serial burst clock(requires using counters), you'd be able to read out one string of 32-chips in ~27uS.

    Lawson
  • jmgjmg Posts: 15,183
    edited 2012-08-25 19:21
    xanatos wrote: »
    The way I have it set up, only one column is energized at a time, only one row is sensed at a time. Honestly... It works!

    Yes, but the point was more to do with switch action.
    If you have only one switch on at a time, as in keyboard momentary, matrix scan works very well.
    If the 256 sense switches can ever produce many or all on at once, you need another approach.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-25 19:47
    xanatos wrote:
    The way I have it set up, only one column is energized at a time, only one row is sensed at a time. Honestly... It works!
    It will not work without diodes if you can turn more than one switch on at a time. Trust us. We know (from experience) what we're talking about.

    -Phil
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-08-25 21:24
    This illustrates the problems and the solution:
    SwitchMatrix.png

    Note, how the second switch shorts out the high from the first switch.
    And the ambiguity of S21 when 3 other switches are pressed.

    Duane J
    726 x 266 - 9K
  • jmgjmg Posts: 15,183
    edited 2012-08-25 22:31
    This illustrates the problem and the solution:
    Note how the second switch shorts out the high from the first switch.

    Even this is only a partial solution, - consider S11,S12,S22 all closed, now the system cannot tell if S21 is closed, or not - it reports it as closed.
    That is why the question of 'how many on at one time ' matters.
  • kwinnkwinn Posts: 8,697
    edited 2012-08-25 23:51
    Yes, diodes are required on each switch or push button if more than one is closed at the same time. You also need pulldown resistors on each input pin if the scan output pin is a high level, pullups if it is low. Otherwise you may get false readings when multiple switches are closed or you could short a high output to a low output.
  • xanatosxanatos Posts: 1,120
    edited 2012-08-26 05:51
    All switches are NO, tail-end of all matrix lines have pull-down resistors. Only one column is energized by the 595 at a time. I'll actually wire up an 8 x 8 test circuit when I get back from vacation, but I have run a dozen scenarios on paper to check my setup and I have had up to 4 other switches represented as closed and the read switch remains properly sensed. Perhaps I'm missing something, and if so, I'll catch it with a real circuit at home. I do appreciate all of your concern! :-)

    Dave

    PS., not sure if I mentioned this, but the matrix has no direct connection to either Vss or Vdd. The 595 is used to sequentially energize 1 column at a time; the 165 senses which positions in the row are passing the 595's logic 1. The 595 also has current limiting resistors to prevent 0 to 1 shorts...
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-26 09:21
    xanatos wrote:
    Perhaps I'm missing something, ...
    Most assuredly. :)

    -Phil
  • kwinnkwinn Posts: 8,697
    edited 2012-08-26 09:40
    xanatos wrote: »
    All switches are NO, tail-end of all matrix lines have pull-down resistors. Only one column is energized by the 595 at a time. I'll actually wire up an 8 x 8 test circuit when I get back from vacation, but I have run a dozen scenarios on paper to check my setup and I have had up to 4 other switches represented as closed and the read switch remains properly sensed. Perhaps I'm missing something, and if so, I'll catch it with a real circuit at home. I do appreciate all of your concern! :-)

    Dave

    You really do need the diodes. Lets say column 1 is pulled high by the '595 (or prop) and row 3 of col 1 is closed. If any other switch connected to row 3 is closed it will create a short to the column that switch is connected to. Since column 1 is high and the rest of the columns are low this will be a bit of a problem. The diodes prevent that short.

    PS., not sure if I mentioned this, but the matrix has no direct connection to either Vss or Vdd. The 595 is used to sequentially energize 1 column at a time; the 165 senses which positions in the row are passing the 595's logic 1. The 595 also has current limiting resistors to prevent 0 to 1 shorts...

    You do need the diodes. Lets say col1 is energized and the switch on row3 of col1 is closed. This will pull row3 high. If another switch (say row3 col4) is closed you will now have a short between col1 and col4. A diode on each switch avoids this since only the ones connected to the high column are forward biased.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-08-26 11:19
    Here's a simple schematic that illustrates what can happen if there are no diodes:

    attachment.php?attachmentid=95166&d=1346004809

    The drive voltage backs through the switch in the lower-righthand corner and sneaks onto the left-hand vertical bus, giving a false reading. What's possibly worse, if the unselected horizontal line were driven low, there would be a short.

    With diodes, this is prevented:

    attachment.php?attachmentid=95167&d=1346004810

    Like you, I once designed a switch array without diodes. It was for some sorting electronics that I had built, and I had flown across country to install it. Well, the fault in the top illustration bit me hard, and I knew immediately what the problem was. It was a big "D'oh!" moment in front of my customer, though. So, in the dead of winter, with a snowstorm bearing down on Kalamazoo, I was frantically searching for enough diodes to fix the problem. 'Ended up cleaning out the local Radio Shack associate store of every diode they had, but that was all it took to make it work. This is what I meant by "from experience."

    -Phil
    500 x 347 - 14K
    521 x 347 - 12K
  • xanatosxanatos Posts: 1,120
    edited 2012-09-05 20:05
    Just a quick note on this topic to say that my inability to see the issue may have actually had a medical reason - I was coming down with Cholera! Yes indeed, I now know that it is possible to get cholera from oysters, and I did just that. I didn't realize I had a 103.4 degree fever until after I left Maine and got home. I just thought I was getting a cold. So anyway - yes, couldn't think straight... diodes good. I think I was thinking... I don't even know. So just ignore me.

    Also - thank you all for working so hard to get my fever-addled brain to see what you were talking about.

    Still recovering, but much, much better. Don't eat raw oysters. Seriously.

    Apparently there were dozens of cases...

    Best,

    Dave
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-09-05 20:21
    Dave,

    Wow, man, I'm so glad you're in recovery! Raw oysters: yup, loved 'em myself! They taste like the salt air that you notice when you've been away from the ocean for awhile. 'Nothing like 'em! But times have changed, and the water isn't as clean as it used to be, even here in Washington's formerly pristine Hood Canal. I last ate a raw oyster about 25 years ago, after shucking it on the beach. The taste is a pleasant memory that lingers on my palate to this day, but it's not something I plan to experience again.

    Continue to heal!

    -Phil
  • ElectricAyeElectricAye Posts: 4,561
    edited 2012-09-05 21:59
    xanatos wrote: »
    ... I was coming down with Cholera! ....

    Dave,
    I've heard some amazing excuses for shirking good suggestions on this forum, but this Cholera thing you came up with is... hey, wait a second.... you DID remember to read the MSDS for PdCl2 didn't you?

    Ludlum-Model-12-4.jpg
Sign In or Register to comment.