Can't seem to make an RS (SR) flip flop work?

Discussion in 'The Projects Forum' started by jimshealy, Aug 3, 2010.

  1. jimshealy

    Thread Starter New Member

    Aug 3, 2010
    7
    0
    I'm in quite a predicament, I can't seem to get the flip flop circuit that's part of my project to work.

    Here's the overview:

    Basically I have a weighing machine that tries to keep a water storage tank filled. once the tank gets to a certain emptiness, the filtration system kicks on until it is full, which shuts the system down until the tank is empty again.

    I've gotten the load cell... amplification, and voltage comparator circuit to work. So, I do have 2 logical +5v signal going.

    One signal is low while the system is below 5lb, and high the rest of the time.
    The second is high unless the system is over 80lb.

    They're both High while it is between 80 and 5lb.


    So, I'm using 2 NAND gates to create just a simple flip flop circuit, so it will stay off until it gets below 5lb, and stay on until it gets above 80lb.


    Unfortunately something that should be very simple I'd think, just doesn't seem to be working. Maybe I'm just being obtuse, but really I'm very new to electronics, so I'm probably just missing something. PLEASE, I need resistor values, tie up/down resistors etc. most the schematics I've seen just skip that part.

    And just to re-iterate, this is a RS flipflop.

    Here's some pictures to clarify.

    I tried adding text, but it's not great... i hope it gets the point across, It's the front and back of the same chip.

    Note I put one input into A, the other into C. Out 1 was connected to D, and Out 2 was connected to B. Ground to ground, Source to +5v.

    Here's the datasheet:
    http://www.chipcatalog.com/TI/CD40107BE.htm

    Finally, on the outputs I'm getting .5v. Which is WAY too low to be right. What am I doing wrong?
     
  2. windoze killa

    AAC Fanatic!

    Feb 23, 2006
    605
    24
    Can you post a schematic of the circuit you have built?
     
  3. jimshealy

    Thread Starter New Member

    Aug 3, 2010
    7
    0
    I'm sorry I forgot to put that up. I attached a scan of the schematic. I currently have the inputs (A, C) tied to the +5v supply line via 1K ohm resistors. I found them tied to that line in a few schematics, and decided to do the same.

    Oh, and for those wondering, there are some LED's that I'm hoping to illuminate with the output of the Flip-Flop circuit to show what state the system is in. I have them wired each with its positive lead to it's respective signal feed, and the negative leads wired together. The negatives do not connect to ground yet.
     
  4. JoeJester

    AAC Fanatic!

    Apr 26, 2005
    3,373
    1,159
    Tell me .... what are the inputs to the CD40107 .... each gate and the outputs from each gate. Your schematic didn't have the two 100 ohm resistors, I suspose that's what they were, from A and C to ground. Are you starting with the container filled > 5 lbs and < 80 lbs vice an empty container?

    A window comparator would have done you better than a SR flip flop.
     
    Last edited: Aug 4, 2010
  5. jimshealy

    Thread Starter New Member

    Aug 3, 2010
    7
    0
    I realized I forgot to draw the 1000 Ohm resistors on the drawing.

    As for the window comparator, that actually is the chip directly above the Nand gates. I didn't tie the outputs together, as seen on this page: http://home.cogeco.ca/~rpaisley4/Comparators.html (the relevant picture I attached)

    so, as mentioned before, output 1 for the voltage comparitor is high for any value above 5lb, and output 2 is high for any value below 80lb

    This creates a window where both outputs are high between 5 and 80lbs.

    However, I need the circuit to stay off until it is below 5lb, and then turn off, running until the tank is filled to 80lbs. If I base the filtration system to run when the window is high, I'm afraid it'll cycle the system constantly around 80lbs, which will damage the filtration membrane used to fill the tank.


    I chose the NAND rs gate so that while the system is within the window, it won't cycle, only changing states when the tank is full, or is empty.


    Anyways, will I start with a container that's empty, yes. During use the tank may empty even while the filtration system is running as a result of excessive demand, (not ideal, but it can happen) so I do need the system to stay on unless the condition of it being full is met.
     
  6. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    The 40107B has an open drain output and as such the output can only sink to 0V but cannot pullup to +5V so your RS flipflop implementation fails.

    It is simple to rectify as shown in the attached image.

    [​IMG]
     
  7. jimshealy

    Thread Starter New Member

    Aug 3, 2010
    7
    0
    Ah, so I need to switch the resistors from the input to the output?

    I'm a bit confused by the terminology? If the output cannot pull up to 5v, will the gate be able to drive much of a a current? I need to drive a motor off of the output, (through a transistor and relay of course) will I need to make the transistor sink to the gate, or will the gate drive the transistor (basically do I need to use a PNP or NPN transistor)
     
  8. Wendy

    Moderator

    Mar 24, 2008
    20,766
    2,536
    You also need high value grounding resistors on the inputs. The output doesn't care, it will hold whatever level it is at. But the inputs need a reference to determine whether they are a 1 or a 0. Otherwise they oscillate, a really bad thing.

    This is true of all digital electronics.
     
    jimshealy likes this.
  9. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    No. The two added resistors are additional and has nothing to do with your existing input pullup resistors.

    You will have a slight problem if the relay coil rated voltage is higher than +5V. Let's assume for the moment you are using a 5V relay.

    Since the output sinking capacity of the 40107B is over 50mA at 5V, your best bet is to use a PNP transistor to drive a relay. The connection is emitter of the PNP to +5V, the collector to relay coil. The other end of relay coil connects to 0V. Connects the base of the PNP in series with a base bias resistor of 1KΩ then to one of the 40107B's outputs which is normally HIGH (between 5lb and 80lb).

    Remember also to use a diode across the relay coil.
     
  10. jimshealy

    Thread Starter New Member

    Aug 3, 2010
    7
    0
    Alright, I drew a diagram of what I think this circuit should look like, Am I right?

    By the way, the LED is in there for good measure. I'm not sure if it would affect anything. I don't Think it would, but I may be wrong.


    PS: Bill, so you're saying that the input resistors should be connected to ground?
     
    Last edited: Aug 4, 2010
  11. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    Your circuit should work fine.

    You can improve it by using a 220Ω pullup resistor instead of the 1KΩ on the output where the LED is connected. Also a "high intensity" type LED is best suited for this application as it takes only a few mAs.
     
  12. Wendy

    Moderator

    Mar 24, 2008
    20,766
    2,536
    Yes, for this circuit your inputs should be connected to ground through a pull down resistor. In other circuits a pull up might be more appropriate.

    Since CMOS is very high impedance the resistors can be very large, around 1MΩ or so. It is the floating condition that is the problem.

    TTL usually assumes a high if the input is open, but again, this is never a good idea. With TTL you need a more moderate resistor, since TTL is a medium current device, say around 4.7KΩ or so. When ever you see open inputs in a schematic your alarm bells should be ringing.
     
  13. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    I cannot agree to your reasoning regarding this very circuit.

    No pull down resistors is necessary as none of the NAND gate inputs is floating(or can somehow becomes floating) in the OP's circuit.
     
  14. jimshealy

    Thread Starter New Member

    Aug 3, 2010
    7
    0
    well, I tried pulling them down with the 1k resistors, and ran into a problem, because I pulled the outputs of the comparator up with 1k resistors, it seems it was causing the voltage to be divided or the like, and forcing the outputs to stay at 2.5V

    I took your advice and changed them to 1Mohm resistors and it fixed the problem! Thanks! The circuit works now!

    As for not needing it, I can't see how it would hurt.... but I really can't speak on it, as I really don't know.

    I'll try to get a video up of the LEDs i have indicating the on off signals.
     
  15. jimshealy

    Thread Starter New Member

    Aug 3, 2010
    7
    0
    I tried the circuit that I drew out previously, and I can't get it to work properly.

    Here's the problem, no matter what output the gate gives the transistor is still active turning on the relay. It seems there's some leakage causing the system to activate.

    Note that I chose to use a micro relay that requires 18mA of current at 9v (because it has an internal resistance of 500 ohms)

    The PNP transistor has a gain of 35 around 9v

    So, to saturate the output all I need is about .5ma of current.


    Now that I think about it, if I can get a +5v output, could I not just use an NPN transistor?

    Should I use 5K resistors instead?
     
    Last edited: Aug 10, 2010
  16. eblc1388

    Senior Member

    Nov 28, 2008
    1,542
    102
    The circuit you've drawn in post#10 shows +5V supply for the relay. :eek:

    I've already mentioned in post#9 that you will have a slight problem if you use a relay that is higher than 5V.

    Your problem is not caused by leakage. You just can't use a PNP to drive a 9V relay connects to a 9V power supply, with a 5V output drive voltage.

    yes, you can use a NPN transistor with 4K7 base resistor instead.
     
Loading...