Problems setting up a CD4027 Dual J-K as a toggle switch

Thread Starter

xox

Joined Sep 8, 2017
936
Having finally abandoned the idea of using op amp to implement a toggle switch (as Sgt. Wookie once pointed out, using an op amp as a comparator really is a bit like "pounding in screws with a hammer"), I decided to go with the CD4027.


CD4027.png


Wired up a preliminary circuit. No luck. I'd obviously done something wrong, so I just tore everything down and started again from scratch. Connected Vdd (Vcc) to 5V and Vss to ground. Repeatedly setting and resetting the flip-flop yielded very inconsistent results (and based on the above truth table, none of the other pins values should matter). Sometimes Q and ~Q would read correctly, sometimes not, and then other times they would fluctuate wildly for no apparent reason. What the heck?! I just don't know how to proceed at this point, honestly. :confused:
 

Thread Starter

xox

Joined Sep 8, 2017
936
Tie J and K HIGH and R and S LOW, apply signal to clock.
Thanks for the quick reply! Still some very odd behavior from this device (even swapped it out for a new one just to be sure). Basically what's happening now is that when I apply a signal to clock, ~Q goes high and Q stays low. Grounding clock only results in both ~Q and Q being held low. Looking at the truth table, that shouldn't ever happen!

EDIT: Also, what about the first set of odd measurements while testing S and R? I can't possibly see why it would do that to begin with.
 

Thread Starter

xox

Joined Sep 8, 2017
936
Okay, I think I have an idea of what's going on here. After setting up a momentary switch to trigger the clock signal, I noticed that when my hand goes within about a half a foot from the switch, ~Q goes high; move my hand away and it goes low. So it must have something to do with static electricity. I do know it's a CMOS IC, so I guess I'll look into ways to mitigate the stray fluctuations. Any ideas how I might go about doing that?
 

AlbertHall

Joined Jun 4, 2014
12,621
Don't leave any input floating at any time.
So your momentary switch connects the clock to the positive supply also needs a resistor to 0V.
Further your switch will bounce and generate multiple clocks resulting in indeterminate states for Q.
To avoid this you need a capacitor across the switch to eliminate the bounce like the circuit below.
upload_2017-12-28_9-35-49.png
 

Thread Starter

xox

Joined Sep 8, 2017
936
Don't leave any input floating at any time.
So your momentary switch connects the clock to the positive supply also needs a resistor to 0V.
Further your switch will bounce and generate multiple clocks resulting in indeterminate states for Q.
To avoid this you need a capacitor across the switch to eliminate the bounce like the circuit below.
View attachment 142626
Okay thanks, I'll give it a shot. :)
 

Thread Starter

xox

Joined Sep 8, 2017
936
God bless you man, it works! Just some minor glitchiness to iron out, but that should be easy.

Matter of fact, I've been mulling over the whole "floating switch issue" for days now. I just couldn't figure out the right technique. So yeah, your help was a true blessing. Resolves a lot of confusion.

Many thanks, Albert.
 
Last edited:

shortbus

Joined Sep 30, 2009
10,050
Don't leave any input floating at any time.
So your momentary switch connects the clock to the positive supply also needs a resistor to 0V.
Further your switch will bounce and generate multiple clocks resulting in indeterminate states for Q.
To avoid this you need a capacitor across the switch to eliminate the bounce like the circuit below.
Will that also work for 4000 series Cmos?
 

crutschow

Joined Mar 14, 2008
38,337
Here's an alternate way to do a toggle with a D flip-flop when driven by a mechanical switch.
It uses an RC delay on the D input feedback to provide the debounce function.
For the R1C1 values shown, the FF will not toggle again as long as the input switch bounce period is no more than about 70ms.

upload_2017-12-28_9-7-20.png
 

Janis59

Joined Aug 21, 2017
1,894
And second thing here: when I tried to repair-replace 4013 instead of 155TM2 (the russian copy-n-paste circuit) where one half was generating and other half was dividing it to two; there about week I lost trying to understand WHY so stupidly simple circuit just habituate like dead. The reason was more than prost - russian analog of 4013 is capable to generate with 100 kOhm in timing RC whilst 4013 the largest may have less than 75 kOhm. Thats pure experimental data on generator with two diodes and RC over the trigger.
So, I impose that PROBABLY that 1 MOhm may demolish the work in Your case, as it role is very the similar as mine case.
 

crutschow

Joined Mar 14, 2008
38,337
The slow rc rise time and possible oscillation.
As long as the switch bounce is done before the RC voltage crosses the D input logic level, there can be no oscillation.
The D-FF is edge-triggered by the clock signal.
As long as there is no clock signal change, there cannot be a change in the FF output.
 

eetech00

Joined Jun 8, 2013
4,704
As long as the switch bounce is done before the RC voltage crosses the D input logic level, there can be no oscillation.
The D-FF is edge-triggered by the clock signal.
As long as there is no clock signal change, there cannot be a change in the FF output.
Ok...removed.
 

crutschow

Joined Mar 14, 2008
38,337
Hmmm....can a CD4013B really source that much current with VDD = 5v?:confused:
The simulation shows the FF output dropping to a 3V output with that load.
But for worst-case operation you probably would want to add a buffer or use a MOSFET for driving such a low resistance load.
 
Top