Sign in to follow this  
Followers 0
Chris Elston

Relay Logic Brain Teaser

34 posts in this topic

So most of you know that I mentor on a USFIRST robotics team... Anyway, one of my electrical kids, 14 years old comes up hands us a momentary button, and two relays, each with normally open and normally closed contacts. He wanted to be able to create a toggle on, toggle off mode with this N.O. momentary button. Of course we said just use a maintained switch and be done with this. Not good enough for a 14 year old mind. So two of us scribbled on paper for awhile trying to use two relays, three relays, whatever.... to create a toggle mode using only NO and NC relays. Best we could do was make a buzzer...where are those one-shot electrical devices at? Can we buy those? LOL... Then the electronic guys got involved with a capacitor and resistor and things started to get pretty deep after that... Have you ever made a toggle using only contacts?

Share this post


Link to post
Share on other sites
Best I could come up with is two relays, but the PB needs two sets of contacts.

Share this post


Link to post
Share on other sites
Does this look familiar??? Basic Toggle Button 1.0

Share this post


Link to post
Share on other sites
Yup sure does....except in that example, "my example" uses a ONE SHOT.... Trying to wire up this example using only hard contacts, no PLC. Do you know how to wire up a one-shot? If you do, teach me. Without the one-shot, the hard contact wiring becomes an awesome door bell buzzer with the relays.

Share this post


Link to post
Share on other sites
Check out this site. http://www.cpemma.co.uk/flipflop.html

Share this post


Link to post
Share on other sites
Newark Electronics shows 26 single shot timing relays. Edit, I found this: Two Relay Flip Flop You could also use a latching relay (maintained contacts with two coils, set and reset). Newark has those too. Its easy to do with one relay if you want to add a couple of tranistors. It could be a good exercise for the students to understand. Edited by Alaric

Share this post


Link to post
Share on other sites
Never done it. However, the key to what you are describing is a clocked flip flop. They are so ubiquitous in the digital logic world that nobody thinks twice about them. Perhaps check the digital logic text books for either the gate logic to make a clocked flip flop, and then convert that over to relay logic? SR logic is obviously very easy as you just use one relay as an inverter (wire input to coil, use NC output) and then insert that into the conventional "3-wire control" (START/STOP button) circuit that we're all familiar with. Pretty much any clocked flip flop would do as you can always cross-couple the output to the input in the right polarity (NOT gates are "free" with relays) to cause it to change state at every clock pulse once you get over the clock issue. Methinks an old TI 7400 series digital logic book may contain the basic gate circuits. Not sure anymore. It's been close to 20 years since I've even looked at that stuff.

Share this post


Link to post
Share on other sites
thinking about this, and i've realized... scan time is such a beautiful thing. you could probably create a hardwired ONS with a time delay relay...

Share this post


Link to post
Share on other sites
Try this. It takes 4 relays and and two contacts on the PB but it doesn't require a oneshot. Keith Hardware_Toggle.pdf

Share this post


Link to post
Share on other sites
usfirst robotics eh? i was just providing some help for one local team... anyway... there are several solutions but since it is usally desirable to have button with just one contact, here is solution with three relays and hopefully it's simple enough to remember. once upon a time man discovered electricity and immediately first button was created. not much later man invented relay. for some time relays were the coolest things to play with so someone came up with start/stop logic one can make three such circuits - start, stop and output. start and stop are interlocked and will only work when additional interlock (button) is active. those two circuits will be used to operate third circuit (output) now since most relays combine one NO and one NC contact into inverting contact, one can also relocate one of the NC contacts (either in start or stop circuit) for simpler wiring. circuit function will not change (in this case start relay has NO and NC contacts next to each other):

Share this post


Link to post
Share on other sites
I'm going to have to wire that one up on Monday and try it, panic_mode. That will definitely work in a plc but I'm not sure it will work with hardware relays. It looks like it relies on specific timing to work, which you can't guarantee with relays. Keith

Share this post


Link to post
Share on other sites
Been thinking about it some more. We need to think of this in terms of logic design. And yes, delays are a concern. There are probably simpler solutions with fewer relays but what I'm going to suggest below is a standard method that will always result in a solution that works. You can comfortably use the method for relatively simple digital logic. First, we need a clocked inverter. Draw a Karnaugh map for this. If you don't know what Karnaugh maps are, google them. It will have two inputs, A & B. A will represent our input and B will represent the clock. The map is as follows where X is a 1 and O is a ZERO. Upper case A represents 1 and lower case represents 0. -aA bOX BXO As you can see, this is an XOR. To use relays, we'll need 3 (two working as AND and one OR). Second, we need a gate that triggers on the "zero" of the clock. That would be as follows: -aA bXO BOX So it's just an inverted XOR. Same 3 relays needed. I realize that I'm not counting inverted inputs but you will see shortly that those are "free". We did not include logic to make this strictly transition logic (where it triggers on the edge and nothing else) first because we won't need it and second because that requires some timing tricks to make it work. Instead, we'll design the circuit interconnects to avoid this issue. Now, wire the push button to a relay. This will provide both inverted and regular outputs as needed. Wire the push button relay to the "clock" inputs. Wire the output of the XOR to the input of the inverted one and vice versa. It's a 7 relay solution. The fact that the delay through each gate is at least 2 relays and the push button is buffered by a relay inherently helps eliminate race conditions (unstable states) where you end up adding capacitors and such to try to stop it as long as you use relays that are roughly similar in size and speed. If you do this in DC you might get some inductive chatter or push button bounce (use standard techniques to minimize this). In AC, there's almost no chance of it. If you were doing this in digital logic such as RTL, TTL, PAL's, etc., the development path would be identical except that you could probably get a canned clocked flip flop (JK flip flops <$1 even for old 7400 series logic chips). Edited by paulengr

Share this post


Link to post
Share on other sites
Looking at that last picture as an electrical circuit, I don't understand how the stop relay will ever become energized...

Share this post


Link to post
Share on other sites
Look closely at B3:0/5 and remember that the pushbutton is momentary

Share this post


Link to post
Share on other sites
Doh... Yes, after studying it closely and thinking it through, that circuit should work just fine. And I can't see any way for it to become a buzzer... :)

Share this post


Link to post
Share on other sites
stability was recognised as a problem of simple flip-flop (RS for example) long time ago. this is how master-slave version for example came to life and this is why this circuit has third relay as additional stage. required functionality (toggle or flip flop) could be achieved with all kinds of devices but this one is using pure relay contacts (conventional relays). if you want something simple, cheap, quick and dirty - try simple D type FF (just feed inverted output into D and use button to triger clock, simple RC should do as debounce). for battery operation CMOS is better suited.

Share this post


Link to post
Share on other sites
Hey guys; I agree with Keith that the circuit will work as drawn in a PLC but may run into relay lag time errors when the relays get old and start to wear. I do work a fair bit with older relay systems, (are there any other kind? ), and the activation for each relay will need to be consistent and fast for one to close before the other opens during a handoff. Re-writing it with three contacts on the button with individual wired leads to each of the relays solves any relay errors by making each transition from on, to off, to on, a positive step. It still has thirteen total contacts, but two of them are moved to the button itself, as each of the button contacts in the three rungs are individually wired. A N/O contact would be mounted onto the toggled relay for the output that you want to switch. Alternatively, you could mount it on the set relay, if you want the output to come on only after the button is released. This is identical to the toggle rung circuit I use all the time in my code, except for the addition of the reset relay on the set relay rung, which is added to eliminate any backdriving or relay lag problems. Both methods will work, but I think this one will work without any issues when parts get old. What do you think? Speakerman Hardwire_Toggle.pdf

Share this post


Link to post
Share on other sites
hi speakerman thank you for posting another solution. that certainly looks robust and i don't see it becomming buzzer either. you made good point about wear of the componets and depending on type of component problem every circuit could eventually become unreliable and fail. concern in all of the relay based toggle circuits is operating speed of the components (can be eliminated by circuit design) and syncronization of all contacts on given device (relay or button). here are circuits by keith menges and speakerman any more ideas?

Share this post


Link to post
Share on other sites
I knew you guys would not let a 14 year old boy stump us! Now I have to have him make one of these and post a video or something...

Share this post


Link to post
Share on other sites
Whoops, forgot to remove that redundant contact created when I put the jumper on the feed to Lamp 1. Here's the drawing again, with the redundancy removed. It's the smaller of the two files - couldn't delete the old one. Perhaps that better anyway. Cheers, Speakerman. Hardwired_Relay_Toggle.pdf Hardwired_Relay_Toggle.pdf Edited by speakerman

Share this post


Link to post
Share on other sites
Busted out the K-maps! Nice! Never seen 'em outside of Computer Science, specifically architecture or logic classes (or without De Morgan's) . They are useful, though. I'm impressed with your dedication Chako - good stuff! Edited by Nathan

Share this post


Link to post
Share on other sites
speakerman- I'm pretty sure that will work. However, playing the devil's advocate (as I am wont to do) I think you have a possible race condition on the reset latch. If the N/C Reset contact in the Set rung starts to open and drops the Set relay befor the N/O Reset contact in the Reset rung can pull in the Reset coil won't latch. Granted, I'd have to be standing on my head pressing the button with my toe on the fifth Tuesday of the 6th month during a blinding snowstorm for that to happen. Keith

Share this post


Link to post
Share on other sites
Hey Keith; Thanks for pointing that out. Totally missed it! My blond PLC roots are showing... It would eventually crop up, and probably more often than the yoga - inspired operating method you describe! BTW, is that an OSHA approved procedure? Do you need fall arrest? Looking at it in more detail, I see now how your circuit neatly uses the fourth relay to make the off/on transition stable in both directions, and that is absolutely robust. Although my design would probably work for a long time, as the reset relay will always be activated and already moving before the contact for the set relay breaks, it does have a definite path to failure, pun intended, which I do consider an unacceptable flaw. Well said, and thanks. Speakerman

Share this post


Link to post
Share on other sites
Hey Keith; Went back and looked at the code again, and I think I outsmarted myself in the first place! The close race condition was added to my usual code design with the intention of stopping any backdriving of the circuits - but that arose due to a planning error on my part, which showed such a possibility. Reviewing it, I don't think the circuit had any backdriving issues, so the N/C contact from R3 to R2 has been removed, and the circuit returned to the normal configuration that I generally use it. This now looks exactly like the standard PLC toggle chain for simple actions. The race condition has been reduced, as now R1 has to open it's contact, then R2 will start to open it's contact... it's still there, but R3 has a really good head start on R2 opening up. It could still lose the race, but you would need to be upside down, using your toe to hit the button, et al, and your pants must be on fire. The electrical drawing is still jazzed up for the fancy light show, but has been edited to match the refined toggle. Please put the fire-proof robes of litigation back on, and let me know if you think this circuit does the trick? Or have I made the all too common buzzer again, like all those ashtrays I made in woodshop...? Cheers, Speakerman Hardwired_Relay_Fixed.pdf Edited by speakerman

Share this post


Link to post
Share on other sites
That's definetely more robust. As you said it can still get tripped up. But with the extra little bit of hold you have on the reset relay now it would be pretty tough to mess up. Keith

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0