1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Multiplex switches

Discussion in 'Microcontrollers' started by AtomSoft, Mar 3, 2008.

  1. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Ok i have seen a ton of ASM to make keypads for 4x4 and 3x4. My question is simpler. How can i use 1 pin to get a possible of only 3 results? Like 1x3.

    I want it simple so if i need 3 switches why not use 3 diodes and 3 pull-ups?. I will be using 3 push buttons.

    I wanted to know 2 things really and i know im a pain in the as* but heh i get confused learning to fast. (btw everything i see correct i save it as a PDF so i can keep a copy and not bother more lol)

    Ok to the questions:
    1. How would i wire this up ? (using a 18F1320 or similar)
    2. How would i code it.

    I know it feels like im asking for the complete info and not trying to learn but thats not true. I dont even own a programmer or chip. I did order a Junebug which is on its way. So i just want to be ready to start programming and creating some cool stuff.

    Every post i read study and ask if i dont understand only to ensure that i will eventually :D :D
     
  2. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    For some reason I can not upload an attachment. Connection closed by remote server

    String 4 1K resistors in series. Attach one terminal of each switch to a junction common to 2 resistors. Attach one end resistor to gnd and the other to +5. Tie all the unused switch terminals together and then to an analog input pin. Use a weak pullup on the pin say 20K.

    When all the switches are open you read 5V. When one closes the voltage is fixed by the resistor network. Do an ADC to figure out which switch is closed.

    EDIT:
    I have provided a solution to use multiple keys on a single input. Another would be to use a keyboard encoder and a serial input stream.
    Better to use a PIC with enough pins so you can stay with digital inputs, use a tradition matrix where you scan row and column.
     
    Last edited: Mar 3, 2008
  3. I²R

    I²R New Member

    Joined:
    Mar 1, 2008
    Messages:
    86
    Likes:
    1
    Location:
    Richmond, VA
    It would go a long way, both towards gaining knowledge and getting help, if you at least made a significant effort towards some preliminary design work. I, for one, am certainly not going to design a circuit for you, but if you make a positive effort, I'll be more than happy to guide you in the right direction. I can't speak for anyone else here, but that's my position.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US

    ok ill make one based on info i know and hope you will stick to your word and help out .
     
  6. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    [​IMG]

    There we go just made some time to do this but 2 issues didnt find the right PIC18F1320(1220) is in same fam so i assume same pinout. Also Could not find normal switches so used some wierd ones closest to normal :D

    How would i program this to identify different presses? Like what exactly do i compare? and to what?

    just seen your comment 3v0 will do....
     
    Last edited: Mar 3, 2008
  7. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    Not quite. You have VDD shorted to ground so I take it one should ignore the bad label. Each resistor that is switched in forms half of a voltage divider. That should work. But the generated voltages could be further apart.

    This is what I was thinking of. The resistors act as a voltage divider with several taps. The voltages
    will be aprox 5V all open, (2/3)5V, (1/3)5V, and 0V. Ohms law ... Not too sure what the best value would be for the 100K all open pullup. Big is better so long as it is not so weak that it does not work.
    The resistors do not have to be 1K, just as long as they are the same size the voltages will work out the same. The higher the value the less current it will draw.

    You need to read up on ADC conversion. Good time to get cozy with the data sheet and the header/device/include file.
     

    Attached Files:

    Last edited: Mar 3, 2008
  8. I²R

    I²R New Member

    Joined:
    Mar 1, 2008
    Messages:
    86
    Likes:
    1
    Location:
    Richmond, VA
    Not bad, except as noted you have VDD connected to ground--you don't want to do that. What you have for your keys is a set of switched voltage dividers. Now, look at the values. Use Ohm's law and plug in your VDD voltage to determine what voltage the input at AN0 sees for each keypress. Are those good values?
     
  9. BeeBop

    BeeBop Active Member

    Joined:
    Dec 22, 2005
    Messages:
    1,281
    Likes:
    23
    Location:
    Vancouver Canada
    Well, close, but your resistors are in parallel.
    What 3v0 means is that you want a voltage divider, where each switch will give a different output voltage, which you can then read with an analog pin.
    Yours will work, but you won't have much variation in voltage between the switches. It would work better if you used 1k, 1k5, 2k, and 2k5 instead of 100, 150....

    Three of us replying at the same time.

    Yes, I missed Vdd connected to ground! :D
     
  10. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    oh ok i thought VDD was ground and Vss was V+
    VSS 5 5, 6 3, 5 P — Ground reference for logic and I/O pins.

    found that ok cool now i see it

    Sorry i guess i really have to double check things when actually making it.
    [​IMG]
     
    Last edited: Mar 3, 2008
  11. I²R

    I²R New Member

    Joined:
    Mar 1, 2008
    Messages:
    86
    Likes:
    1
    Location:
    Richmond, VA
    What is the purpose of the 20k series resistor in your second schematic? Remember that the four 1k resistors in series already form a voltage divider network. Think it through. Do you need that 20 k resistor?
     
  12. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    Because 3v0 said to
     
  13. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    Also when all the switches are open the input to the analog pin will be floating/undefined (not driven) tristated..
    You need a pull up or pull down to take care of that.
     
  14. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    Yes but you set it up as a current limiting resistor.
    See the schematic I added to my XXXX second post. And I am not sure what value would be best. At least 10K. I would try the 100K if it works.
     
  15. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    oh oh so it must return a value so we close the circuit no matter what and just care if the voltage is one of mines.
    Like

    [​IMG]

    found the switches:
    [​IMG]
     
    Last edited: Mar 3, 2008
  16. I²R

    I²R New Member

    Joined:
    Mar 1, 2008
    Messages:
    86
    Likes:
    1
    Location:
    Richmond, VA
    Sort of. A pullup resistor is used to maintain a small, stable voltage on an input pin. If you left it off, your circuit MIGHT work correctly, but the pin's voltage may fluctuate, causing unwanted false inputs.
     
  17. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    Hey we went from 3 to 4 switches :)

    You have the basic idea.
     
  18. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    I am not an EE. But I would have said steady voltage and small current?
     
  19. AtomSoft

    AtomSoft Well-Known Member

    Joined:
    Feb 7, 2008
    Messages:
    5,670
    Likes:
    41
    Location:
    Brooklyn, NY US
    ok cool. So there is no definite way to calculate the divided voltages right? Like i would have to place resistors and manually check each one to determine drop ?
    All i know in ohms law is how to get 1 value from 2 others. I don't know how to subtract like 100k ohms from 5v to determine the drop on the resistor.

    yeah the concept is in the head but the head doesnt know how to draw lol

    EDIT: Found this
     
    Last edited: Mar 3, 2008
  20. I²R

    I²R New Member

    Joined:
    Mar 1, 2008
    Messages:
    86
    Likes:
    1
    Location:
    Richmond, VA
    It's simple. Consider a 20 kOhm resistor in series with a 5 kOhm resistor, with 10 V applied across them. You want to determine the voltage at the point between them. First thing you do is calculate the current through the resistors:

    I = V / R

    I = 10 / (15 k + 5 k)

    I = .5 mA

    Now that you know that, you can calculate the voltage drop across each resistor:

    V = I x R

    V1 = .5 mA x 15 k

    V1 = 7.5 V

    V2 = .5 mA x 5 k

    V2 = 2.5 V

    Reality check: the two voltages should sum to the total supply voltage. 7.5 + 2.5 = 10. If you have more than two resistors, you can just extend this process. Now, work out your voltage drops.
     
  21. I²R

    I²R New Member

    Joined:
    Mar 1, 2008
    Messages:
    86
    Likes:
    1
    Location:
    Richmond, VA
    A negligible current. The inputs are high impedance and measure voltage, not current.
     

Share This Page