0

Push ON/Push OFF with a momentary switch
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Push ON/Push OFF with a momentary switch

by steve_y78 on Sat Feb 09, 2013 4:13 am

Im looking for a circuit, simple if possible, to use a momentary switch for a Push ON/Push OFF use.

steve_y78
 
Posts: 8
Joined: Thu Jan 03, 2013 1:04 am

Re: Push ON/Push OFF with a momentary switch

by steve_y78 on Sat Feb 09, 2013 4:16 am

forgot to mention... This would be for a 12v system

steve_y78
 
Posts: 8
Joined: Thu Jan 03, 2013 1:04 am

Re: Push ON/Push OFF with a momentary switch

by zener on Sat Feb 09, 2013 4:43 am

There are switches that act that way. That would be a simple circuit: 1 switch! They are a little hard to search for since no one seems to agree what that switch function is called. You didn't give all the specs on your load but here is one switch I found:

http://www.digikey.com/product-search/e ... 09?k=7104d

zener
 
Posts: 3919
Joined: Sat Feb 21, 2009 2:38 am

Re: Push ON/Push OFF with a momentary switch

by adafruit_support_mike on Sat Feb 09, 2013 11:40 pm

Here's a circuit I use:

Image

It requires Schmitt trigger inverters, but works well.

The two inverters are arranged as a flip flop. Each one's output connects to the other one's input, and the signal gets inverted twice as it goes around the loop. Each inverter holds the other in its current state.

When the switch is open, the cap charges to whatever voltage is at the output of the upper inverter. When you close the switch, that voltage gets shorted to the upper inverter's input. By definition, that voltage will be the opposite of what was at the upper inverter's input before the switch closed, so closing the switch moves the flip flop to the opposite state.

It's kind of hard to see from the diagram, but when you close the switch, the two 1M resistors form a voltage divider between the outputs of the inverters. No matter which state the flip flop is in, the voltage at the center of that divider will be VCC/2. As long as you hold the switch closed, the cap's voltage will move toward VCC/2.

VCC/2 falls in a Schmitt inverter's hysteresis band, so holding the cap at that level doesn't do anything to the flip flop. When you release the switch, the cap will charge the rest of the way to the upper inverter's output voltage, and the whole thing will be ready to happen again.

Not only does the circuit toggle the output between HIGH and LOW each time you press the button, it also debounces the switch. The make-and-break connections of switch noise only happen while the cap is charging toward VCC/2, and the Schmitt triggers ignore everything that happens during that time.
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.

adafruit_support_mike
 
Posts: 43253
Joined: Thu Feb 11, 2010 2:51 pm

Re: Push ON/Push OFF with a momentary switch

by easternstargeek on Sun Feb 10, 2013 5:06 pm

While it's always great to examine all alternatives, simple is better, so I vote for the "push-on, push-off" switch.

Just for the sake of learning, however...

I would like to point out that the published Schmidt Trigger inverter circuit has a potentially problematic characteristic, depending on the OP's system. Such a circuit will wake up in an indeterminate state when power is first applied. With discrete logic circuits, a POR (power-on reset) circuit, usually in the form of an RC differentiator, is used to apply a momentary pulse to a logic gate input in order to ensure this doesn't happen.

An enhanced version of your circuit can be made using a 74LS132 chip, which is a quad 2-input NOR gate with Schmitt trigger inputs. The extra input gives you the flexibility to add a POR differentiator. If interest is there, I will post a circuit, but I don't have time right this second.

In any case, have fun with your project!

easternstargeek
 
Posts: 344
Joined: Mon Dec 13, 2010 1:39 pm
Location: Upper Eastern Tennessee

Re: Push ON/Push OFF with a momentary switch

by steve_y78 on Mon Feb 11, 2013 2:11 am

While it's always great to examine all alternatives, simple is better, so I vote for the "push-on, push-off" switch.

Just for the sake of learning, however...

I would like to point out that the published Schmidt Trigger inverter circuit has a potentially problematic characteristic, depending on the OP's system. Such a circuit will wake up in an indeterminate state when power is first applied. With discrete logic circuits, a POR (power-on reset) circuit, usually in the form of an RC differentiator, is used to apply a momentary pulse to a logic gate input in order to ensure this doesn't happen.

An enhanced version of your circuit can be made using a 74LS132 chip, which is a quad 2-input NOR gate with Schmitt trigger inputs. The extra input gives you the flexibility to add a POR differentiator. If interest is there, I will post a circuit, but I don't have time right this second.

In any case, have fun with your project!


Interest is peaked. would like to see that when you get the chance.

steve_y78
 
Posts: 8
Joined: Thu Jan 03, 2013 1:04 am

Re: Push ON/Push OFF with a momentary switch

by johnyradio on Wed Aug 09, 2017 2:50 am

adafruit_support_mike wrote:Here's a circuit I use:

Image

It requires Schmitt trigger inverters, but works well. The two inverters are arranged as a flip flop.


That's amazing! Would it be possible to feed this a 50% duty-cycle square wave, and get 1/2-frequency at output?

thx!
johnyradio
 
Posts: 1
Joined: Fri Nov 15, 2013 4:52 am

Re: Push ON/Push OFF with a momentary switch

by adafruit_support_mike on Thu Aug 10, 2017 3:35 am

Sure.. there would be some timing issues because you have to deal with the capacitors and resistors.

The circuit you're thinking about.. a flip-flop based divide-by-two counter.. is very common. It's normally made using a D-type flip flop like the 74HC74:

divide-by-2.jpg
divide-by-2.jpg (14.13 KiB) Viewed 59 times
Every time the CLK signal pulses, the flip-flop copies the signal at pin D to pin Q, and sets /Q to the opposite value. Connecting /Q back to D makes the output swap between high and low, but you only get one high/low transition per tick of CLK.

A full cycle of oscillation (the signal returns to its original value) takes two high/low transitions, so the signal at Q and /Q changes at half the frequency of the signal at CLK.

A side benefit is that CLK doesn't need to have a 50% duty cycle. The flip-flop only toggles on the falling edge of a pulse (for 74-series logic.. 4000-series flip-flops toggle on the rising edge), and it's often easier to make a pulse generator than it is to make a 50% oscillator. The f/2 output on Q and /Q will have a 50% duty cycle though. The only variation in duty cycles will occur if CLK changes frequency.

When you put a row of divide-by-two circuits in series you get a binary counter.

adafruit_support_mike
 
Posts: 43253
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.