Author Topic: Flip Flop Toggle switch NE555 and CD4013  (Read 1241 times)

0 Members and 1 Guest are viewing this topic.

Offline JwillisTopic starter

  • Super Contributor
  • ***
  • Posts: 1716
  • Country: ca
Flip Flop Toggle switch NE555 and CD4013
« on: April 08, 2021, 05:52:04 am »
I'm just starting to learn about logic circuits .
I'm making a toggle switch with momentary push button for a project and I've run into a little problem with using the CD4013 .
Its really slow to turn on and off compared to the NE555 . The 555 only requires a tap of the momentary to switch between states and never fails .But the CD4013 requires a hold down on the momentary and sometimes won't switch states unless several presses are made.
I've tried different circuit designs and give the same results as the one I original settled on.
I know I'm doing something wrong but I can't figure it out . The CD4013 should be faster , shouldn't it?
 

Offline AndyC_772

  • Super Contributor
  • ***
  • Posts: 4228
  • Country: gb
  • Professional design engineer
    • Cawte Engineering | Reliable Electronics
Re: Flip Flop Toggle switch NE555 and CD4013
« Reply #1 on: April 08, 2021, 09:09:54 am »
The CD4013 is fast, and that's your problem.

You'll learn a lot if you can attach a scope to the clock input and logic outputs, and see what really happens when you push the button.

I'm 99% sure the problem here is contact bounce at the switch.
 
The following users thanked this post: Jwillis

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12865
Re: Flip Flop Toggle switch NE555 and CD4013
« Reply #2 on: April 08, 2021, 09:20:27 am »
You've just run head on into contact bounce aka switch bounce!  What you think is a single button press event is 'seen' by the circuit as many contact closure events.  The 555 circuit includes debouncing by design - C2 has to charge to the opposite 1/3:2/3 Vcc threshold via R2 before another switch closure can register.

Mechanical switches (and other switching contacts) bounce.*  They bounce when they close, and to some extent when they open.  This can most easily be seen with the switch in series with a pullup or pulldown, across a DC voltage supply, on a DSO in one-shot mode, set to capture for min. 10ms at the highest sample rate that it can do for a 10ms-20ms capture window and the trigger threshold set to 1/2 of your circuit's Vcc.  Set the trigger polarity to rising or falling depending on the pullup/pulldown configuration, and whether you want to capture contact closure bounce or contact opening bounce.  Ideally, set up the DSO for 5%-10% pretrigger in the capture window, so you can see any early disturbances that fail to reach the trigger threshold.   A logic analyser will be less informative than a DSO as it conceals the analog behavior of the switch output.

if you set up a CMOS counter IC with LEDs (+ resistors) on all outputs. and clock it from a mechanical switch as in your 4013 circuit (or if you've got some more 4013 chips, wire them (+ the spare flipflop in the existing one) to toggle (/Q to D) and clock each from the previous stage) you'll see it increment several to many times for each switch press.

A classic method of implementing a fully debounced switch for clocked logic experiments is to use a break before make SPDT switch, common to the rail, with NC and NO contacts feeding the S and R inputs of a SR flipflop, with pullups/pulldowns to keep them in their inactive state while the moving contact transitions. Which rail (Vcc or ground, the common connects to depends on whether the flipflop has active high or active low inputs.  For classic TTL, its almost invariably ground, as the current required to reliably pull a TTL input low is not insignificant, so pulldowns  are generally impractical.

For more details see: https://www.electronicdesign.com/technologies/analog/article/21155418/logiswitch-11-myths-about-switch-bouncedebounce

and for mitigation methods see: http://www.ganssle.com/debouncing.htm
which is *essential* reading for any tech or engineer who dabbles in logic or embedded programming.

*  *SOME* switching contacts do not bounce by design, however mercury wetted contacts (which are immune to bounce if properly designed) are now vanishingly rare, and elastomer contacts substitute ramping contact resistance for switch bounce, which when applied to a logic input without hysterisis, has much the same effect due to noise toggling the input as the switch resistance change sweeps  it through its threshold region.
« Last Edit: April 08, 2021, 02:06:37 pm by Ian.M »
 
The following users thanked this post: Jwillis

Online ledtester

  • Super Contributor
  • ***
  • Posts: 3039
  • Country: us
Re: Flip Flop Toggle switch NE555 and CD4013
« Reply #3 on: April 08, 2021, 01:46:02 pm »
Quote
I'm making a toggle switch with momentary push button ...

What kind of switch are you using?

I've found that the small tactile button switches exhibit very infrequent bounce.

1209072-0

 
The following users thanked this post: Jwillis

Offline JwillisTopic starter

  • Super Contributor
  • ***
  • Posts: 1716
  • Country: ca
Re: Flip Flop Toggle switch NE555 and CD4013
« Reply #4 on: April 08, 2021, 05:04:59 pm »
The CD4013 is fast, and that's your problem.

You'll learn a lot if you can attach a scope to the clock input and logic outputs, and see what really happens when you push the button.

I'm 99% sure the problem here is contact bounce at the switch.

:palm: This didn't occur to me at all. That would explain the  Schmitt-Trigger Buffer in the data sheet . CD4013
Couldn't see anything on the analog scope .

on a DSO in one-shot mode, set to capture for min. 10ms at the highest sample rate that it can do for a 10ms-20ms capture window and the trigger threshold set to 1/2 of your circuit's Vcc.  Set the trigger polarity to rising or falling depending on the pullup/pulldown configuration, and whether you want to capture contact closure bounce or contact opening bounce.  Ideally, set up the DSO for 5%-10% pretrigger in the capture window, so you can see any early disturbances that fail to reach the trigger threshold.   A logic analyser will be less informative than a DSO as it conceals the analog behavior of the switch output.

Suddenly I find myself with a serious case of DSO deficiency syndrome . I need to step up my game and get one if I want to work with logic circuits .
Need to save faster.

What kind of switch are you using?
I've found that the small tactile button switches exhibit very infrequent bounce.

The ones I'm using are larger 10mm simply for ease of use on a bread board.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12865
Re: Flip Flop Toggle switch NE555 and CD4013
« Reply #5 on: April 08, 2021, 06:54:30 pm »
Even the small elastomer contact tactile switches aren't *reliably* 'bounce' free over their useful service life.   I had one fail fairly recently in a mouse that had the effect of turning middle button clicks randomly into middle button double-clicks.   The mouse's USB controller chip had integral debouncing suitable for mechanical sub-miniature microswitches (its other four buttons), but the tactile switch had degraded sufficiently to exceed its debouncing capabilities.
 

Online ledtester

  • Super Contributor
  • ***
  • Posts: 3039
  • Country: us
Re: Flip Flop Toggle switch NE555 and CD4013
« Reply #6 on: April 08, 2021, 06:59:20 pm »
Quote
Suddenly I find myself with a serious case of DSO deficiency syndrome . I need to step up my game and get one if I want to work with logic circuits .
Need to save faster.

Some cheap ideas to observe key bounce...

- wire up a CD4017 with CLK tied low and the switch on the /EN input and LEDs on the Q- outputs (the CLK input has a Schmitt trigger gate which might make it more resilient to bounce)

- make a 2-bit binary counter with a CD4013 or a 4-bit counter with two of them:

https://www.petervis.com/dictionary-of-digital-terms/bcd-counter-using-d-flip-flop/bcd-counter-using-d-flip-flop.html

- program an Arduino to detect short transitions on one of its digital I/O inputs

- get a $10 usb logic analyzer such as: https://www.aliexpress.com/item/1005001417581550.html
 

Online ledtester

  • Super Contributor
  • ***
  • Posts: 3039
  • Country: us
Re: Flip Flop Toggle switch NE555 and CD4013
« Reply #7 on: April 08, 2021, 07:05:02 pm »
Quote
Even the small elastomer contact tactile switches aren't *reliably* 'bounce' free over their useful service life. ...

That's actually something I was curious about. In fact, just the other day I was brainstorming ideas for an automatic switch pusher to repeatedly actuate a push button switch.

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf