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

Thread Starter

jimshealy

Joined Aug 3, 2010
7
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?
 

Attachments

Thread Starter

jimshealy

Joined Aug 3, 2010
7
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.
 

Attachments

JoeJester

Joined Apr 26, 2005
4,390
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:

Thread Starter

jimshealy

Joined Aug 3, 2010
7
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.
 

Attachments

eblc1388

Joined Nov 28, 2008
1,542
I'm in quite a predicament, I can't seem to get the flip flop circuit that's part of my project to work.
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.

 

Attachments

Thread Starter

jimshealy

Joined Aug 3, 2010
7
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)
 

Wendy

Joined Mar 24, 2008
23,421
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.
 

eblc1388

Joined Nov 28, 2008
1,542
Ah, so I need to switch the resistors from the input to the output?
No. The two added resistors are additional and has nothing to do with your existing input pullup resistors.

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)
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.
 

Thread Starter

jimshealy

Joined Aug 3, 2010
7
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?
 

Attachments

Last edited:

eblc1388

Joined Nov 28, 2008
1,542
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
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.
 

Wendy

Joined Mar 24, 2008
23,421
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?
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.
 

eblc1388

Joined Nov 28, 2008
1,542
Yes, for this circuit your inputs should be connected to ground through a pull down resistor.
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.
 

Thread Starter

jimshealy

Joined Aug 3, 2010
7
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.
 

Thread Starter

jimshealy

Joined Aug 3, 2010
7
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:

eblc1388

Joined Nov 28, 2008
1,542
I tried the circuit that I drew out previously, and I can't get it to work properly.
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.

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.
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.

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?
yes, you can use a NPN transistor with 4K7 base resistor instead.
 
Top