Push ON/Push OFF with a momentary switch

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
steve_y78
 
Posts: 8
Joined: Thu Jan 03, 2013 1:04 am

Push ON/Push OFF with a momentary switch

Post by steve_y78 »

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

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

Re: Push ON/Push OFF with a momentary switch

Post by steve_y78 »

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

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: Push ON/Push OFF with a momentary switch

Post by zener »

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

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: Push ON/Push OFF with a momentary switch

Post by adafruit_support_mike »

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.

User avatar
easternstargeek
 
Posts: 347
Joined: Mon Dec 13, 2010 1:39 pm

Re: Push ON/Push OFF with a momentary switch

Post by easternstargeek »

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!

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

Re: Push ON/Push OFF with a momentary switch

Post by steve_y78 »

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.

User avatar
johnyradio
 
Posts: 24
Joined: Fri Nov 15, 2013 4:52 am

Re: Push ON/Push OFF with a momentary switch

Post by johnyradio »

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!

User avatar
adafruit_support_mike
 
Posts: 67391
Joined: Thu Feb 11, 2010 2:51 pm

Re: Push ON/Push OFF with a momentary switch

Post by adafruit_support_mike »

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

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”