Help with the Simple Combination Lock

Discussion in 'The Projects Forum' started by derderppolo, Nov 27, 2012.

  1. derderppolo

    Thread Starter New Member

    Nov 19, 2012
    17
    0
    Hello,

    I am currently taking a computer engineering course and I am required to build a practical application of logic gates. For the activity, I have chosen to do a combination lock, with the use of DIP switches, logic gates, and more.

    I have found the AllAboutCircuits' simple combination lock schematic, which is http://www.allaboutcircuits.com/vol_6/chpt_7/7.html.

    In addition, I have also created a schematic in TINA, found here:

    http://i.imgur.com/pFdJp.png

    Finally, after the schematic being approved, I built the circuit. Here is how it looks:

    http://i46.tinypic.com/2ahccgn.jpg

    My teacher told me that the wiring is correct, however, the LED's are not lighting up. If I were to place an LED under a DIP switch, the LED would light, but not in the XOR gate's outputs.

    The logic chips I used are 74LS-series of logic gates. In the picture, certain wires may look as if they are not inserted, but are just stripped too much.

    I cannot seem to find what the problem is, or how to solve the issue. How can I make the LED's light up? Is the 9-to-5 V converter necessary? How can I get the DIP switches to work with logic gates?

    Thank you.
     
    Last edited: Nov 27, 2012
  2. antonv

    Member

    Nov 27, 2012
    149
    27
    For one thing consider whether there is anything that pulls the inputs low when the switches are open.
     
  3. derderppolo

    Thread Starter New Member

    Nov 19, 2012
    17
    0
    That's what I want, right? When testing the inputs with an LED, when the switch is open, the LED is off. When the switch is closed, the LED turns on. However, when I put the LED in the XOR gate's output, it does not turn on no matter what position the switches are at.
     
  4. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    When the switch(es) are open, the input to the IC is left unconnected. This does not guarantee the input is low or off. It is floating, meaning it may "see" a high voltage or a low voltage.

    In order to guarantee the inputs are low or off when your switches are open, you must use pull-down resistors. Look again at the schematic on the first link you posted and compare it to your schematic. You are missing the pull-down resistors (10kΩ connected between the input to the XOR gates and GND).

    You are also missing the pull-down resistor connected to the input of the left-most NOR gate.

    You appear to have replaced the diodes with NOT gates. These should be diodes, something like a 1N914 or 1N4148, not NOT gates. The diodes prevent shorts between the outputs of the XOR gates.

    I'm not sure why you have SW1 present - that should be a 10kΩ resistor connected to Vdd so the input to the last two NOR gates is high when switch "B" is not pressed.


    If you decide to use CMOS ICs like the ones called out in the first link:
    • Be sure any and all unused INPUTs are tied to Vdd or GND. Unused outputs can be left unconnected.
    • Put a 0.1uF capacitor across Vdd and GND for each and every IC as close to the IC as possible. CMOS ICs generate noise and can affect other ICs, so the caps are used to help minimize this noise.
     
  5. derderppolo

    Thread Starter New Member

    Nov 19, 2012
    17
    0
    Hey, thank you for the response.

    I have now added 10kΩ pull-down resistors after the DIP switch, to guarantee that my inputs are off or low.

    However, I am unsure of what you mean by "missing the pull-down resistor connected to the input of the left-most NOR gate." There is only 1 NOR gate, and I am confused as to where to put the pull-down resistor for it.

    I will ask my teacher if we have any 1N914 or 1N4148 diodes. If we do not, are there any alternatives that can accomplish the task?

    Finally, I am not sure if my components are CMOS IC's, and to be honest, I'm not sure what a CMOS IC is, or what is CMOS or not. (I'm new to engineering, just beginning to explore my passion).

    Once again, thank you for your help. I truly appreciate it.
     
  6. WBahn

    Moderator

    Mar 31, 2012
    17,737
    4,789
    I usually try to refrain from bad mouthing someone's teacher, but if your teacher either approved the schematic or told you that the wiring is correct (i.e., matches the schematic), then you really need to ask for a refund and find a different teacher. Even if you aren't paying anything for this class, you are not getting what you are paying for.

    I suspect that most of these have been covered over the course of the previous responses, but it might be helpful to see them put together and put in context.

    First, consider the switches in the schematic (See combo_switch.png). These are Single-Pole Double-Throw (SPDT) switches wired so that when the switch is in the UP position it puts a HI voltage (H) onto the wire going to the logic gates and when it is DOWN it puts a LO voltage (L) onto the wire.

    But in your actual circuit you are using Single-Pole Single Throw (SPST) switched wires such that when they are in one position they put a HI onto the wire but, in the other position, they leave the wire floating and, hence, in an undefined state.

    You are using, per your first post, 74LS logic. This is the low-power schottky family and is a variant of TTL (transistor-transistor logic). Ideally, an unconnected TTL input is internally pulled HI, but in practice it is not a good idea to rely on this. But let's assume it behaves like it is supposed to. When the switch is in one position you get a solid HI and when it is the other you get a weak HI due to internal pullup. Thus, you may not be able to make any of your inputs LO and, if you do, it is because the circuit is not behaving as it really should.

    The biggest mistake (and biggest reason to demand your money back) is that your schematic has the outputs of eight inverters all tied together. (See combo_wired_what.png). If you take the output of two logic gates and one is trying to assert a HI while the other is trying to assert a LO, what is the result on the wire supposed to be? I don't know. You don't know. This is called "contention" and is bad for a number of reasons. Most importantly, you don't know how it is going to behave. But, furthermore, it will generally result in excessive current draw from the gates and may even physically damage them (although most modern discrete gates have short-circuit protection, so they probably won't get damaged, but they won't work right, either).

    Next, your schematic has a switch and a pushbutton (see combo_short.png) such that if the switch is in the UP position (putting a HI to the two NOR gates) and you press the button, you end up with a direct short across the power supply. This is known as "a bad thing". Depending on the behavior you want (my guess is you want the pushbutton over override the switch and activate the two LED circuits), you need a pullup and/or pulldown resistor to protect the supply and permit one switch to safely override the other.

    Now, your circuit doesn't have this problem because neither of these switches is there. Instead, you have a slightly different circuit (see combo_lights.png). Notice that pins 2 and 5, while connected together, are floating. This is also bad.

    As near as I can tell, the two LEDs are connected to the positive supply, which would mean that you need the output of the NOR gate to go LO to turn on the corresponding LED. In your schematic, if the common signal coming up from the switch/button is HI, then the output will be LO regardless of the signal from the comparison logic, resulting in both buttons turning on. This might be useful for an LED test feature, but is that what you were wanting?

    I can't tell for sure, but if there are flat edges on the LED packages it appears light they must be on the bottom (in the picture). The flat side represents the cathode, which is the negative side of the LED. It doesn't look like you have the LEDs plugged into the ground side of the supply, but I can't tell for sure.
     
    derderppolo and elec_mech like this.
  7. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    10kΩ is too high for a 74LS input pulldown. With SPST switches, you would be better off using 10k pullups, and have the switches connect the inputs to ground when closed.
     
    derderppolo and elec_mech like this.
  8. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    You mentioned earlier you are using TTL ICs (7400 series), so the CMOS info doesn't apply to those. I put that in because the circuit you referenced used CMOS (4000 series).

    Definitely follow Ron's advice, I am not as familiar with TTL as I'd like to be, alas - tie the switch inputs to GND and use pull-up resistors on the inputs to the XOR gates. After some research, 74LS series ICs have some high internal pull-ups on the inputs, so trying to pull them down isn't very effective. Much better to pull them up then use the switches to put them low when needed.

    WBahn put things much clearer than I could - I'm still learning myself. I agree that the professor's approval of your circuit is a little worrisome.

    You can use any small signal diode such as 1N914, 1N918, 1N4148. You might get away with a 1N4001 but these will drop the voltage output by 0.7V or so which may affect the rest of the circuit. The small signal diodes only drop the voltage by 0.35V or so.

    Look at the original schematic again: http://www.allaboutcircuits.com/vol_6/chpt_7/7.html

    There are three NOR gates, both in the original schematic (and yours). In both, there are two on the right connected to the LEDs, then a third one to the left of these. The left one, as well as the right one connected to the green LED, accept the output from the XOR gates (through the diodes).

    Perhaps you are thinking about the IC itself (which has 4 NOR gates)?

    There is a pull-down resistor in the original schematic. When used with the diodes, this forms a 4-input OR gate. Take a look at this: http://hyperphysics.phy-astr.gsu.edu/hbase/electronic/diodgate.html#c2.

    Unfortunately, given 74LS series don't work well with pull-downs, I think some modification will be needed.

    WBahn, Ron - any thoughts? Since 74LS don't like pull-downs, I can't see a simple correction for this. The NOR, diodes, and corresponding pull-down resistor could be replaced with seven OR gates or a single 8-input OR gate, but I'm tapped for ideas after that.
     
    derderppolo likes this.
  9. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    I don't like diode logic mixed with standard logic, especially TTL. It eats up too much of the noise margins.

    Assuming the OP has to stay with TTL logic, the inverters with their outputs tied together is OK if you use open-collector inverters (74LS06), with a 10k pullup from the common output to vcc. That output will be high only if the data matches the password.

    The other way to do that is to use an 8-input NAND (74LS30), and set the data to be the complement of the password. If the password is 11011110, then the data would have to be 00100001 to get get a "match" at the NAND gate output. The output of the NAND gate will be low only if all of its inputs are high, which means that all XOR inputs have to be unequal. Hence the need for complement codes.

    You could alternately use XNOR gates (74LS266) with the 74LS30, and then the switch inputs would have to be set equal to get a match.

    I'm not going to address the NOR gates in the circuit, because I'm not clear about their purpose.
     
    Last edited: Nov 29, 2012
    elec_mech likes this.
  10. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    Or simply use a 74LS682, an 8-bit magnitude comparator.
     
  11. derderppolo

    Thread Starter New Member

    Nov 19, 2012
    17
    0
    Thanks for the responses everybody! I really appreciate your help.

    Fortunately, we have 1N4148 diodes, and I got 8 of them for this circuit. I've modified my circuit, and put them in place of the NOT gates

    Thank you for the advice. I've attached my inputs to the DIP switches to GND, and used 10kΩ pull-down resistors on the inputs of my XOR gates. Here is how that looks: (I've simplified my circuit until I can get it to work. Thus, I will only be using the 1st and 8th gates of each DIP switch, as opposed to all 8)

    http://i.imgur.com/PEkjU.jpg

    Did I place my pull-up resistors in the correct place?

    In addition, I have made some modifications to my circuit, adding the pull-down resistor found in the original circuit to the 3rd NOR gate. I've read your responses about how 74LS series don't work well with pull-down resistors, and might explain some issues I am having.

    Here is how my modified circuit looks:

    http://i.imgur.com/MO94c.jpg

    Combination is the same, thus, green LED:

    http://i.imgur.com/qeMIY.jpg

    Combination is different, thus, red LED:

    http://i.imgur.com/C0cuF.jpg

    Here are the issues I am having. When the combinations are different, the green LED may turn on:

    http://i.imgur.com/cGrrE.jpg
    (green LED is on, flushed out by the camera's flash)

    I've noticed the green LED turns on even though the combinations are wrong. Upon closer inspection, the green LED turns on as long as only 1 switch is incorrect. Here are some scenarios:

    http://i.imgur.com/UK1VQ.jpg
    http://i.imgur.com/AyUzk.jpg
    http://i.imgur.com/Ecw20.jpg

    When both switches are incorrect, then the red LED turns on. What might be the problem here?

    Also, I noticed I could fit all the components of my 3rd breadboard on the 2nd breadboard no problem. Haha.

    Once again, I thank you all for contributing and helping me with my project.
     
  12. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    I have to see a schematic. I don't have the patience to decipher breadboard photos.
     
  13. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    Here is how to use the diodes, if you must. If you try to make an OR gate (diodes reversed, resistor to ground), the resistor has to be low (≈1k), and TTL source current is too low to reliably drive 1k to a logic high, especially with a diode in series.
    Be aware that even with the diode AND gate, the circuit will not work with worst case in-spec TTL gates. It probably will work as a one-off, but no guarantees. I woould use the 74LS30, or the open-collector inverters I mentioned earlier.
     
    derderppolo likes this.
  14. derderppolo

    Thread Starter New Member

    Nov 19, 2012
    17
    0
    I'll try to build a schematic around my circuit, but it'll look tremendously similar to the circuit found in the simple combination lock here.

    I would like to say my circuit is not that bad that it'll take a long time to decipher. Then again, it just might be. :p

    Thank you for the guide, as I have learned something new about diodes!

    Is my current application of the diodes incorrect? You speak of using diode OR gates and diode AND gates; are they necessary for the completion and correct execution of the project? If they are, I am curious as to where these diode AND/OR gates should be placed.

    Thank you for the reponse, yet again.
     
  15. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    The circuit you linked to uses CMOS. It will work well with the diode circuit in it, because the supply voltage is 12 volts. TTL is restricted to 5V, and has lower noise margins than CMOS. That circuit will not work if you use TTL parts, for reasons I already mentioned.
    I showed you, in my schematic, where the diode AND gate goes. The circuit you linked to has a diode OR gate. I also already told you that the diode gate is not optimum, and would be better replaced by a TTL gate, if that's what your other gates are.
     
    Last edited: Nov 29, 2012
  16. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    I think we're trying to put too many band-aids onto the original CMOS circuit to make it work with TTL ICs.

    So the question is, would you prefer to stick with TTL (7400 series ICs) or can you get your hands on CMOS as called out in the original circuit, specifically 4001 and 4070?

    If you opt to stick with TTL, I've attached a possible alternate circuit using TTL ICs to do the same thing. I hope RonH will take a look at it and verify I didn't make any critical mistakes.

    Per RonH's advice, the inputs are pulled high and the switches connected to GND to work with the TTL ICs. XOR gates are still used.

    Since a high output of the XOR gate denotes a mismatch and low output denotes a match, OR gates were selected to compare the results of each of the eight selections after going through the XOR gates. Seven OR gates are used which will require two 74LS32 ICs or a single 74HC4078 IC.

    The single output is low if all the switches are in the same position and high if even one of the inputs is not correct. The output is attached to a switch so the LEDs will only light when the switch is pressed, similar to the original circuit.

    Since the 74LS32 is designed to sink current, not source it, the green LED is connected to 5VDC then through a resistor. If the output is low, the green LED will light. If it is high, the green LED will be off and the high signal will go through a NOT gate, also designed to sink current, to the red LED.

    I believe this will work, but again my experience in TTL logic is minimal.
     
    derderppolo likes this.
  17. derderppolo

    Thread Starter New Member

    Nov 19, 2012
    17
    0
    Absolutely, I would prefer to stick with 7400 series ICs instead of trying to get CMOS.

    Wow, thank you for that schematic! I am currently working on the circuit, and will update this post when completed.

    EDIT:I am a little confused with the end of the schematic, though. When the switch is pressed, regardless if the current is high or low, wouldn't both LED's turn on? It seems as though the current travels to the green LED, and also gets inverted and outputted to the red LED as well. I am also a bit confused as to what 5VDC means; is it 5Vs of power or ground? Since the green LED is connected to 5VDC, should the cathode be connected to ground, or power? Also, by 5VDC, that means I should use a 9-to-5 converter, right?

    Once again, thank you for the help, elec_mech and Ron H!
     
    • here.png
      here.png
      File size:
      25.3 KB
      Views:
      104
    Last edited: Nov 30, 2012
  18. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    Your circuit looks good. Going on the premise that 74LS32 and 74LS30 are equally unobtainable by our OP :D, I submit the attached schematic, which I described in an earlier post.
    The OP will probably learn a little from this if he understands it, namely that a data byte that is 2's complement to the code byte will make all XOR outputs high, which can be decoded by an AND or NAND gate.
     
    derderppolo likes this.
  19. derderppolo

    Thread Starter New Member

    Nov 19, 2012
    17
    0
    Thank you very much Ron H and elec_mech! I finally got the entire circuit to work properly!

    For anyone who may be curious, here it how the circuit looks:

    *Note, I only used the first 4 gates for the DIP switches, just to make sure everything works before spending all the time on all 8 gates. Also, I ran out of 10kΩ pull-up resistors.

    Overview: http://i.imgur.com/jw7ifl.jpg

    Correct combination: http://i.imgur.com/ikVItl.jpg

    Incorrect combination:http://i.imgur.com/YuqYil.jpg

    No issues so far! Everything looks great!

    I also learned quite a few things about TTL logic, CMOS, pull-up and pull-down resistors, and I can simply explain how the circuit works, and why it works. Elec_mech, I believe you may have also gained some experience with TTL logic through this whole experience too. ;)

    Once again, thanks everybody! I wish you all a splendid day/night.
     
  20. Ron H

    AAC Fanatic!

    Apr 14, 2005
    7,050
    657
    It's true that, with the switch not pressed, the LED on the output of the 74LS04 will be lit. That's probably not what you intended.
     
Loading...