CD4013 on/off with momentary switch

Thread Starter

hrs

Joined Jun 13, 2014
394
Hi,

I'm trying to make an on/off button using a momentary switch and a CD4013, based on the attached diagram 4013_sch.gif taken from this site. Operation is unreliable as it will only change state some of the time. I was wondering if the debounce circuit is correct. If the switch bounces, C1 will get disconnected from CP and CP will get pulled to ground quickly through R1.

Therefore I tried another debounce circuit per second attachement, modified.png. After making the time constant R1*C1 much bigger than R2*C2 the circuit became somewhat more reliable but maybe that's just the luck of the draw. What is the purpose of the capacitor from data to ground anyway? I thought it might have something to do with flipflop racing but then I read somewhere that master-slave devices should not exhibit racing.

Would there be any benefit to putting a comparator between the debounce circuit and the clock input? Perhaps the edges are not fast enough?
 

Attachments

GopherT

Joined Nov 23, 2012
8,009
Hi,

I'm trying to make an on/off button using a momentary switch and a CD4013, based on the attached diagram 4013_sch.gif taken from this site. Operation is unreliable as it will only change state some of the time. I was wondering if the debounce circuit is correct. If the switch bounces, C1 will get disconnected from CP and CP will get pulled to ground quickly through R1.

Therefore I tried another debounce circuit per second attachement, modified.png. After making the time constant R1*C1 much bigger than R2*C2 the circuit became somewhat more reliable but maybe that's just the luck of the draw. What is the purpose of the capacitor from data to ground anyway? I thought it might have something to do with flipflop racing but then I read somewhere that master-slave devices should not exhibit racing.

Would there be any benefit to putting a comparator between the debounce circuit and the clock input? Perhaps the edges are not fast enough?

Your modified circuit is a real mess. Especially since the original is poor.

Focus on original schematic, try removing the capacitor and 100k resistor from the "Q-bar" output path. Connect "Q-bar" directly to "D" input.
 

crutschow

Joined Mar 14, 2008
34,285
Would there be any benefit to putting a comparator between the debounce circuit and the clock input? Perhaps the edges are not fast enough?
As you noted the first circuit is incorrect and does not do a debounce.

And yes, the clock edge speed could be the problem as seen here from the data sheet:

upload_2017-3-28_9-34-55.png

A comparator would help, but here's a debounce circuit that has a fast risetime, which should work also.
upload_2017-3-28_9-42-22.png
 

Thread Starter

hrs

Joined Jun 13, 2014
394
Thanks for your responses. Right now I can't get it to work, specifically the original circuit but with the debounce circuit suggested by crutschow, but I think it's a problem with the breadboard. I'll dig up another one later and redo the circuit.

One thing about the capacitor from D to ground, is it perhaps to keep D high or low just in case there's a glitch at CP?
 

crutschow

Joined Mar 14, 2008
34,285
One thing about the capacitor from D to ground, is it perhaps to keep D high or low just in case there's a glitch at CP?
Yes.
That's an alternate deglitch circuit.
With that you don't need (or want) a deglitch circuit on the clock input.
It works by delaying the change in the D input so that multiple clock pulses from switch bounce only cause a single FF change-of-state.

Here's an LTspice simulation of that.
Initially the FF only changes once in spite of the multiple simulated-bounce clock inputs, until the D signal reaches the logic low threshold after about a 78ms RC delay.
Thus, as long as the total period of the bounce pulses are <78ms, the FF will only change once per button push.

As can be seen, the delay inhibit works for both positive and negative transition of the flip-flop.

Note that I changed the resistor to 1 megΩ to increase the delay time and allow for a longer period of bounce pulses.

upload_2017-3-28_12-40-28.png

You might try that with no capacitor on the switch.
 

Thread Starter

hrs

Joined Jun 13, 2014
394
Thanks for confirming that, Cruschtow. I took out the deglitcher at D and replaced it with a link, but it still doesn't work, in the same way as before:
The LED starts in the off state. When I press the button the LED comes on. When I press again the LED goes off. When I de-press the LED comes on again.
I noticed that Q changes state between 0V and ~5.6V, Q bar changes state from rail to rail. I tried 3 different ones with the same result. Perhaps these are some of those out of spec devices from Ebay that people talk about. Or perhaps I'm still doing it wrong. I'll buy some new ones from a more reputable source and try again ...
 

Attachments

Thread Starter

hrs

Joined Jun 13, 2014
394
Oops, forgot to connect the decoupling capacitor to ground, but with it, it still doesn't work. Also, after swapping Q and Q bar, neither output changes state anymore.
 

crutschow

Joined Mar 14, 2008
34,285
I took out the deglitcher at D and replaced it with a link, but it still doesn't work, in the same way as before:
The circuit schematic doesn't seem to match the circuit breadboard picture you posted.
I suggested you carefully trace the circuit out and compare to the schematic.
 

Kjeldgaard

Joined Apr 7, 2016
476
To create an effective debounce feature, the easiest way is a smith-trigger input and a RC networks.

To my knowledge it's only Philips / NXP / Nexperia that almost consistently has smith trigger on the clock inputs of MOS4000 series. And most of their MOS4000 is also slightly faster than that seen with other manufacturers.

The diagram below shows what it takes to make a functioning toggle function. The IC must be HEF4013B from NXP, if the second flip/flop is not used, so these inputs must be tethered to ground or supply, and there should also be some decoupling of the supply (100uF and 100nF will be fine)

Many constructions, for decades, has shown me that 10 mSec is a good choice for the RC network. Below 5 mSec may be too short for some larger relay contacts and at over 30 mSec you can actually lose a pressing of small tactile keys.

PushBot_Togle_1.jpg
 

DickCappels

Joined Aug 21, 2008
10,152
With the slow rise and fall times of the 100k and 100 uf of post #13 you may experience unreliable toggling.
The table below is from the NPX HEF4013 datasheet. Placing a Schmitt trigger between the RC network and the clock input would help, but the time constants show would introduce a delay of something like ten seconds. I think Crutschow's circuit using A series CMOS (tends to not oscillate with slow inputs) shown in post #8 will work consistently.

upload_2017-3-29_16-12-28.png
 

Attachments

Kjeldgaard

Joined Apr 7, 2016
476
With the slow rise and fall times of the 100k and 100 uf of post #13 you may experience unreliable toggling.
In my schematic there is drawn a RC networks of 100K / 100nF, and I also write 10 mSec RC network in my accompanying text.

The only place I mention 100 uF, is as supply decoupling in parallel with a 100 nF capacitor.
 

DickCappels

Joined Aug 21, 2008
10,152
I apologize, the I took your "n" to be a mu. Maybe the 90° rotation was a contributor.

The 22 millisecond risetime is still beyond Philips's rating. It might be fine on an A series '4013. Just wanted to point that out for future reference.
 

Kjeldgaard

Joined Apr 7, 2016
476
@DickCappels: There is really nothing to apologize for.

I have various projects running with edge triggered HEF4xxxB ICs and RC networks in the the sizes I describe in post #13.

Right now I have no access to data sheets describing any details about the clock input of HEF4013B, no upper and lower switching levels or hysteresis voltage.

The only description is "The clock input’s Schmitt-trigger action makes the circuit highly tolerant of slower clock rise and fall times." from the "General description" section.

The oldest HEF4013B data sheet in PDF format from 1995, when it was called Philips, writes nothing about Transition Timing.

The latest HEF4013B data sheets with NXP or Nexperia. logo, has a standard table as that shown in post #14. Even a HEF4011B (Quad 2 input NAND gate) has the exact same table.
 

cornishlad

Joined Jul 31, 2013
242
What are you doing with the unused flip flops?

ALL unused inputs should be connected to ground. (Or Vcc)
If the other half of the 4013 is not used, could it not be wired as a non-retrigerable monostable with a period long enough to blank the "bounces" - perhaps 0.5 seconds. It only requires an R and a C.
BTW...if you google 4013 monostables for a circuit, beware this one :http://www.newtoncbraga.com/index.p...nostable-using-the-4013-flig-flop-cb129e.They have omitted the gnd connection to the "set" pin and in spite of being told, they say it is correct and have done nothing..
 

Thread Starter

hrs

Joined Jun 13, 2014
394
Just to be sure I redrew the diagram, the same I used in post #9. After breadboarding it again I think I ended up with the same thing except all unused inputs from the second flipflop are now tied to Vss as suggested by djfantasi. Since I use clipped leads for some of the links, I traced them over for clarity. The problem remains, when I de-press the button the LED comes on again. I traced it out and went over it numerous times but I can't spot the mistake.

When removing the load, i.e. removing R3 I see that Q1 changes state from rail to rail just fine, counter to what I said in post #9. So probably the 1k base resistor loads Q1 down too much.
 

Attachments

Thread Starter

hrs

Joined Jun 13, 2014
394
If the other half of the 4013 is not used, could it not be wired as a non-retrigerable monostable with a period long enough to blank the "bounces" - perhaps 0.5 seconds. It only requires an R and a C.
Thanks cornishlad, I have come across diagrams that use the second flipflop as a debounce, but if I can get this to work I would like to use the second FF as a toggle too.
 
Top