Author Topic: Latching toggle swithc with 555 or CD4013  (Read 13559 times)

0 Members and 1 Guest are viewing this topic.

Offline hafrseTopic starter

  • Regular Contributor
  • *
  • Posts: 144
  • Country: se
Latching toggle swithc with 555 or CD4013
« on: December 23, 2021, 04:02:00 pm »
Hello,

I am looking for a working design  for a Latching toggle switch with 555 or CD4013  to light a 20mA lamp when the push button is pressed and realeased (shorted when pressed) ,  pressing again should switch of the lamp.  I tried a couple of designs found on the net but did not work properly (attached in this post) .
The one with 555, works but not all the time., I need to press many times to execute the low or the high state.  The one with 4013 does not work.

Thanks
« Last Edit: December 23, 2021, 04:05:49 pm by hafrse »
 

Offline Leo Bodnar

  • Frequent Contributor
  • **
  • Posts: 849
  • Country: gb
Re: Latching toggle swithc with 555 or CD4013
« Reply #1 on: December 23, 2021, 04:55:57 pm »
 
The following users thanked this post: hafrse

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 17799
  • Country: fr
Re: Latching toggle swithc with 555 or CD4013
« Reply #2 on: December 23, 2021, 05:30:46 pm »
First - schematics with pin names instead of pin numbers are much easier to read. Having to check the pinout just to figure out the whole thing is annoying.

As to the 4013 version: I think the issue is that this design doesn't comply with the requirements for the clock input.
There is a max rise and fall time for the clock input - in the order of a few µs, depending on Vdd - at 12 V, that should be about 8 µs *max*. Due to the way the clock input is driven here, the rise time will essentially be defined by the mechanical characteristics of the pushbutton, and the fall time will be several tens of ms due to the RC (that's probably supposed to mitigate contact bouncing). So it can't meet  the specs for the clock input.

Note that TI's datasheet for the CD4013B exactly shows how to do it properly in "8.2 Typical Application", using a schmitt-trigger buffer between the button circuitry and the 4013.

For the NE555 one, I didn't check.
« Last Edit: December 23, 2021, 06:43:17 pm by SiliconWizard »
 

Online themadhippy

  • Super Contributor
  • ***
  • Posts: 4563
  • Country: gb
Re: Latching toggle swithc with 555 or CD4013
« Reply #3 on: December 23, 2021, 05:31:47 pm »
Quote
The one with 4013 does not work.
I built several based on the 4013,although much stripped down compared to the version posted,that worked flawlessly for many years.From memory  the switch went from +v to the clock,with a 10k from clock to negative,Q bar linked to D and output on Q .Cant remember if i used a transistor on the output (doubt it) .
 

Offline jfiresto

  • Super Contributor
  • ***
  • Posts: 1048
  • Country: de
Re: Latching toggle swithc with 555 or CD4013
« Reply #4 on: December 23, 2021, 06:16:15 pm »
The attached alternate action push button circuit works quite well. I recently adapted it to toggle a pair of goose neck lamps on and off. I substituted a 4093 NAND schmitt trigger and added an RC pair to keep things off at power up. I chose and adjusted the component values to ignore up to ~1/2 s power drop outs and to account for the 4093's hysteresis.
-John
 
The following users thanked this post: hafrse, Ian.M

Offline hafrseTopic starter

  • Regular Contributor
  • *
  • Posts: 144
  • Country: se
Re: Latching toggle swithc with 555 or CD4013
« Reply #5 on: December 24, 2021, 07:44:20 am »
Quote
The one with 4013 does not work.
I built several based on the 4013,although much stripped down compared to the version posted,that worked flawlessly for many years.From memory  the switch went from +v to the clock,with a 10k from clock to negative,Q bar linked to D and output on Q .Cant remember if i used a transistor on the output (doubt it) .
Thanks for the information, probably the CD4013 is faulty, when I press the Q output goes high, when I release, the Q output goes low it does not latch. 
I will replace the CD4013 with a new one. I think I found the simple schemtics
« Last Edit: December 24, 2021, 07:45:52 am by hafrse »
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1948
  • Country: gb
Re: Latching toggle swithc with 555 or CD4013
« Reply #6 on: December 24, 2021, 04:29:00 pm »
Remeber the cap across the switch.  Switches "bounce" so a single press will likely be several transitions that will toggle a flip flop several times, which can mean the final state its it is almost random.
Often button signals are cleaned up with a combination of RC and a schmitt trigger input (like a schmitt trigger input NOT or NAND gate), or "debounced" in software.
 
The following users thanked this post: hafrse

Offline hafrseTopic starter

  • Regular Contributor
  • *
  • Posts: 144
  • Country: se
Re: Latching toggle swithc with 555 or CD4013
« Reply #7 on: December 25, 2021, 11:07:29 am »
Remeber the cap across the switch.  Switches "bounce" so a single press will likely be several transitions that will toggle a flip flop several times, which can mean the final state its it is almost random.
Often button signals are cleaned up with a combination of RC and a schmitt trigger input (like a schmitt trigger input NOT or NAND gate), or "debounced" in software.
thanke, I will replace the suspected 4013 and test again.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 14126
Re: Latching toggle swithc with 555 or CD4013
« Reply #8 on: December 25, 2021, 01:54:38 pm »
That circuit is no good, and simply putting a capacitor across the switch wont fix it.   A CMOS 4013 dual flipflop typically does not have Schmitt trigger inputs, so the clock can still glitch as the charging capacitor voltage passes through the input transition zone, and if you directly short the capacitor with a switch with metal contacts, a very high transient current can flow which can glitch other nearby logic.

Essential reading: 'A Guide to Debouncing, or, How to Debounce a Contact in Two Easy Pages', by Jack Ganssle

Once you've read that, (especially part 2), if you *MUST* use a 4013, rather than the vastly preferable two inverter toggle latch suggested by Jfiresto, consider the attached circuits.  The top one is a little tricky - it uses half of a 4013 with input to PRE (Set) and CLR (Reset) tied low, as a non-inverting buffer, and adds positive feedback (R3, R4) for 10% hysteresis.  Also you must choose the value of C1 to get an appropriate time constant with R2 (button pressed) or R1 (button released) to cover the maximum expected contact bounce time.  It draws negligible current when the button is not pressed so is suitable for battery powered applications.

The lower circuit is much simpler and 100% reliable with no further thought required, however it requires a SPDT (changeover) button and draws current via R6 when the button is not pressed, so is not suitable for battery powered applications.  Its good as a general debounced button circuit when experimenting with logic circuits.

Edit: In spite of the note on the schematic, the bottom circuit is a debounced clock pulse generator.  Its output should NOT be connected direct to a power switching transistor as it does not hold its state when the switch is released.  *IF* you want to use it as a power switch, you'll need to use it to clock a toggle flipflop e.g. like the right half of the top circuit.
« Last Edit: December 26, 2021, 01:13:29 pm by Ian.M »
 
The following users thanked this post: hafrse

Offline rpiloverbd

  • Regular Contributor
  • *
  • Posts: 157
  • Country: bd
Re: Latching toggle swithc with 555 or CD4013
« Reply #9 on: December 26, 2021, 07:54:53 am »
5  years ago,  I did this task with a CD4027 J-K flip-flop. Unfortunately, that circuit diagram is no longer with me.
« Last Edit: December 26, 2021, 07:57:26 am by rpiloverbd »
 
The following users thanked this post: hafrse

Offline hafrseTopic starter

  • Regular Contributor
  • *
  • Posts: 144
  • Country: se
Re: Latching toggle swithc with 555 or CD4013
« Reply #10 on: December 26, 2021, 10:59:01 am »
That circuit is no good, and simply putting a capacitor across the switch wont fix it.   A CMOS 4013 dual flipflop typically does not have Schmitt trigger inputs, so the clock can still glitch as the charging capacitor voltage passes through the input transition zone, and if you directly short the capacitor with a switch with metal contacts, a very high transient current can flow which can glitch other nearby logic.

Essential reading: 'A Guide to Debouncing, or, How to Debounce a Contact in Two Easy Pages', by Jack Ganssle

Once you've read that, (especially part 2), if you *MUST* use a 4013, rather than the vastly preferable two inverter toggle latch suggested by Jfiresto, consider the attached circuits.  The top one is a little tricky - it uses half of a 4013 with input to PRE (Set) and CLR (Reset) tied low, as a non-inverting buffer, and adds positive feedback (R3, R4) for 10% hysteresis.  Also you must choose the value of C1 to get an appropriate time constant with R2 (button pressed) or R1 (button released) to cover the maximum expected contact bounce time.  It draws negligible current when the button is not pressed so is suitable for battery powered applications.

The lower circuit is much simpler and 100% reliable with no further thought required, however it requires a SPDT (changeover) button and draws current via R6 when the button is not pressed, so is not suitable for battery powered applications.  Its good as a general debounced button circuit when experimenting with logic circuits.

Thanks for the information, the reason is that I have 4013 but I will purchase the CD4093 and try that instead. Do I need to add things on the schemtic prposed by suggested by Jfiresto? thanks
 

Offline hafrseTopic starter

  • Regular Contributor
  • *
  • Posts: 144
  • Country: se
Re: Latching toggle swithc with 555 or CD4013
« Reply #11 on: December 26, 2021, 11:00:53 am »
The attached alternate action push button circuit works quite well. I recently adapted it to toggle a pair of goose neck lamps on and off. I substituted a 4093 NAND schmitt trigger and added an RC pair to keep things off at power up. I chose and adjusted the component values to ignore up to ~1/2 s power drop outs and to account for the 4093's hysteresis.
Thanks ! Will try it :) I will purchase  some CD4093, hopfully I get them early nest week.
 
 

Offline hafrseTopic starter

  • Regular Contributor
  • *
  • Posts: 144
  • Country: se
Re: Latching toggle swithc with 555 or CD4013
« Reply #12 on: December 26, 2021, 11:07:11 am »
The attached alternate action push button circuit works quite well. I recently adapted it to toggle a pair of goose neck lamps on and off. I substituted a 4093 NAND schmitt trigger and added an RC pair to keep things off at power up. I chose and adjusted the component values to ignore up to ~1/2 s power drop outs and to account for the 4093's hysteresis.
Can you please describe  the RC pair you added for the state on power up ? I am using 13.5V , how can I adjust the components values to ~1/2 s ?
 

Offline jfiresto

  • Super Contributor
  • ***
  • Posts: 1048
  • Country: de
Re: Latching toggle swithc with 555 or CD4013
« Reply #13 on: December 26, 2021, 12:37:20 pm »
I have attached one side of the circuit below; the other side using the two other 4093 NAND gates is the same. Q1 (and the other side's Q2), pick AZ6960, 12V 250mW relays, by pulling to ground.

The RC pair at the left reset both sides at power up. Its RC time is a few 50hz cycles long to insure the voltage on pin 8 is still low when VDD starts powering the 4093. (This is being conservative and lazy so that I only need a few common component values.) I sized the power supply, bulk filter capacitor so that when both relays are on and the power goes off, VDD stays above half of nominal for at least a half second: to insure the RC pair does not reset the circuit should the power return before then.



« Last Edit: December 26, 2021, 12:51:10 pm by jfiresto »
-John
 
The following users thanked this post: hafrse

Offline Steffalompen

  • Contributor
  • Posts: 31
  • Country: no
Re: Latching toggle swithc with 555 or CD4013
« Reply #14 on: January 04, 2022, 03:02:09 pm »
Took me a while to find it, but if any 555 enthusiast insist on using it I've had no problem with OP's circuit, however with slightly different values. No idea if that matters, perhaps I should try yours.
Disregard the diode, dunno what that was about. And R11 was in case of mosfet I think I remember, so disregard that too.
I just tried it for hundreds of toggles. Seems rugged with both short and very long button press. At first I connected 6-2 floating by mistake, and it became super erratic, naturally.
-Does your load interfere with VCC and thus threshold, perchance?
(PS. I now see it's just 20mA, so no)
C8 could conceivably keep 6-2 steady while button is pressed, and while VCC drops or there are transients, and thus throw off the threshold?
« Last Edit: January 04, 2022, 03:06:48 pm by Steffalompen »
 

Offline Steffalompen

  • Contributor
  • Posts: 31
  • Country: no
Re: Latching toggle swithc with 555 or CD4013
« Reply #15 on: January 04, 2022, 06:54:49 pm »
Ok so I tried the OP 555 values.
Are you sure it's wise to dissipate 600mW through R4?
Feedback should improve a bit as well with a higher value.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 14126
Re: Latching toggle swithc with 555 or CD4013
« Reply #16 on: January 04, 2022, 07:24:37 pm »
It wont dissipate 600mW.  The NE555 output cant drive higher than two Vbe drops below its supply, and there's another Vbe drop in the external transistor, so at 12V Vcc, there will be about 10V across and under 500mW dissipation in R4.  Use a 1/2W resistor and it will run hot but within its ratings.  That's the disadvantage of using an external BJT rather than a MOSFET.

However the O.P's circuit and indeed your version still suck, due to the quiescent current when off.   The internal reference divider chain is nominally 5K each section, so there's 15K across the supply internally, + the quiescent current of the rest of the chip, totaling typically 8mA at 12V, and the current through the external divider biassing threshold and trigger.   Switching to a CMOS 555 would get that down to under half a mA, so a bit under 1mA total with the external divider.   That's comparable to the typical equivalent self-discharge current of a 20AH SLA at room temperature, so unless you've got a *BIG* battery and are using a CMOS 555,  the 555 based circuits are only suitable for switching the output of mains PSUs.
 

Offline Steffalompen

  • Contributor
  • Posts: 31
  • Country: no
Re: Latching toggle swithc with 555 or CD4013
« Reply #17 on: January 04, 2022, 09:09:29 pm »
I am using 13.5V
That would bring us back above, Ian.M. Perhaps try and read a bit more and write a bit less.

However the O.P's circuit and indeed your version still suck, due to the quiescent current when off.
Yesyes.  :=\ I wrote "If any 555 enthusiast insists on using it"
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

-->