reading many switches

Discussion in 'Embedded Systems and Microcontrollers' started by sean_k, May 21, 2007.

  1. sean_k

    Thread Starter New Member

    May 21, 2007
    4
    0
    appreciate any advise I can get on this problem, or assistance:

    I am trying to design a board game that reads the state of 6X32 on/off switches.
    what's the best way of doing this ?
    first thooughts is to use a matrix switch, or a cluster of shoft registers ?...parallel in/serial out and then interface this to the micro processor.

    any ideas on how to do this easily ?

    regards
    Sean
     
  2. lightingman

    Senior Member

    Apr 19, 2007
    374
    22
    Hi..Use a PIC, and scan them then send the data out of an 8 bit port as binary, or 1 output as serial (ASCII).Or a couple of 4067's, a 4514, a few of counters (4029's), some gates and an oscillator (4047)..."I love knitting with CMOS" Daniel.
     
  3. sean_k

    Thread Starter New Member

    May 21, 2007
    4
    0
    hi Daniel,

    I have been out of this for about 20 years. I remember what a PIC looks like :p . Do you have a reference to a schematic of what you're talking about that I could learn from ?


    sean
     
  4. lightingman

    Senior Member

    Apr 19, 2007
    374
    22
    hi.If you can wait for a week or so, I will work something out for you over the bank holiday.I will work this out using both the PIC and CMOS.Just one other option for you to consider...What about using a old P.C. keyboard, as the I.C in them is a decoder for the 102 or so keys.The output of these is normaly a 7 bit serial ASCII code.You could then use a PIC with a simple program to convert the code into binary, HEX or whatever.Daniel.
     
  5. sean_k

    Thread Starter New Member

    May 21, 2007
    4
    0
    this is fantastic. Many thanks...I can Wait.
    In the mean time, I will start reading up on my switching theory.
    And start defining a truth table or other description.

    sean
     
  6. lightingman

    Senior Member

    Apr 19, 2007
    374
    22
    Well I have had a think about this one !!!!!!!!

    Here is an idea of one way that it could be done. Now I have not tested this, but it may be a basis on how to go about it using discrete logic IC's.
    This is the way that I would have done it before PIC's....
    The problem with this circuit is that it does not suppress key roll-over, I.E if more than one button is pressed then the output will change each time that button position is scanned. This could be done by stopping the scan on detection of a vlid button, and re-starting on button up (you could invert the latch pulse using the spare gate in the 4011, and send it to pin 9 of the 4047). Then the clock would be inhibited during the button down period.
    But I think you would have to take the clock out of pin 10 and not 13 of the 4047, and make the osc cap 10nF (pin 10 = OSC / 2)......

    Forgive me If I have made any errors.............I can put them rite later if I build it....

    I will over the next few days, work out a button scanner using a PIC.
    This will of course use many less components (a PIC and maybe 1 decoder).
    The only reason for using a decoder with the PIC, is that there are not enough I/O's on a 16F877 (33)......

    I have attatched a PDF here for you to look at. If you are serious about doing it this way, let me know and I will sit and build a prototype and test it......


    Daniel.
     
  7. sean_k

    Thread Starter New Member

    May 21, 2007
    4
    0
    Hi Daniel,

    Many thanks again. I am serious about it.

    I am trying to read the state of x of 192 switches that may be on. I got the impression that you understand that only 1 switch can be on at a given time. Actually many switches can be one for the same period of time.

    Your schematic suggest otherwise. Will take a closer look at it and revert. thanks for all the help.
     
  8. recca02

    Senior Member

    Apr 2, 2007
    1,211
    0
    although i m confident that mr lightingman wud come up with a wrokable solution
    (or perhaps he already did) as an alternative i just wanted to add that arranging the matrix of switches in 6x32 it might be possible to use a shift register PISO
    for rows and columns to get a binary equivalent indicating position of switches.
    (pardon me if that is the idea u r already working on i didnt take a look at the schematic or if m interfering)
     
  9. lightingman

    Senior Member

    Apr 19, 2007
    374
    22
    Hi all !!!

    Well I had a day off yesterday, so thought that I would do the PIC version.

    Here it is, it is the prototype and does work (I built and tested it).

    It will scan and read up to 255 switches, buttons or relays.

    It will output the data as 8 binary bit,s and serial. The serial data can be ASCII. HEX or sent as seperate bytes for each digit of the output result.

    There is also an output that goes to a logic 1 level whilst a button/switch is on.

    The next step is to add a set of DIP switches that are read at start-up, to select diferent functions such as:- Serial output type, serial continus/one shot, output data latch/no latch, One/multiple reads and so on..
    That then makes it universal.

    Incidentaly, I used my little 14 bit to 4 digit 7 seg project to display the data form the 8 bit outputs.

    I will do a PCB for both versions soon, both versions will be in TH and SMT...

    When I have finished the project (about a week) I will upload the code for the PIC. It is only about 120 lines or so (at the moment).

    Hope this may be usefull to some of you...

    Daniel.
     
  10. lightingman

    Senior Member

    Apr 19, 2007
    374
    22
    Hi..This is getting there..I have done the THP PCB, and the prototype is running fine.I will post the stuff that I have done so far a bit later today.When the code is finaly finished and tested, I will upload the file (few days).....Please bear with me... The world was not created in 7 days, I think he rested for six, and rushed it on the last day !!!!Daniel.
     
  11. lightingman

    Senior Member

    Apr 19, 2007
    374
    22
    Well I said it's getting there...

    Here are details, final schematic and PCB for the 4067 version.
    Also a little photo of the prototype.
    I have just got a bit more code to tidy up....

    Have fun looking for now........

    I have edited this post to include the HEX code for the PIC... IF! any of you should build this and find a problem, please let me know.....

    Daniel.
     
  12. lightingman

    Senior Member

    Apr 19, 2007
    374
    22
    Hi.....I am going to hold this project for a while, as there have not been many views, and I am a little busy over the next week or so. If anyone is desperate for it, please let me know..............Daniel.
     
Loading...