Help with CD4013 Flip Flop

Started by blueduck577, September 16, 2009, 07:53:14 PM

Previous topic - Next topic

blueduck577

Hi, I'm trying to use a 4013 in a toggle configuration to send control voltages to a fet-based switching system.  Here's the schematic I'm using to test the circuit:



It's pretty much the same as every D flip flop toggle schematic on the internet.  But here's the problem:

When the circuit first powers up, the LED is on.  Awesome.  I push the switch, and the LED turns off.  Good.  But, when I press the switch again, the LED will not turn on again.  I have to either unplug and replug the power, or send Vdd into the reset pin. 

Anyone have any idea why this is happening?  I have the circuit built on a breadboard, and yes, I'm using a momentary switch.

blueduck577

#1
Nevermind, figured it out:  when the momentary switch is open the clock is left floating, so the flip-flop never sees the falling edge of the clock pulse.  Duh!

andymac1962

Hi "blue"
You are nearly there.   A rule for CMOS logic ic's,   any input pin must NEVER be left open. You need a pull up or pull down resistor,   or it must be tied to either logic supply.

Add a 47k (anywhere between 10k & 220k will be ok) from CLK to 0V.
If you want the LED to be OFF when you power up, you will need to add a circuit to the R input.
From R input,   47k to 0V, 100n to +9V.   This will pull the R input high during power up & "reset" the D flip flop, so Q is off, & led is off.
You can use different values for the added resistor & capacitor, but if you use >100n, then add a 1N4148,  anode to R input, cathode to +9V.
Leave S input conencted to 0V

If you want the LED to be ON when you power up,   just connected this circuit to the S input instead and leave the R input connected to 0V

Processaurus

Switch debounce is crucial for this application, as every time the switch contact bounces as it is settling into being on (over a couple ms), it will clock the input several times, rather than once, cleanly.

Here's a link on stompswitch debouncing:
http://www.geocities.com/thetonegod/debounce/debounce.html

There is also some information at Geofex.com, in addition to the thousands of non-stompbox related de-bouncing articles on the web.

Hope that helps!

blueduck577

#4
Yeah, before I returned here I realized switch debounce was an issue that needed to be addressed.  This snippet is from the Dano Pepperoni Phaser:



I see the resistor and cap they've got on the one end of the switch.  Would this be sufficient to debounce even the worst low-quality switch (say, x-wing)?  I know that those miniature tactile switches that boss, dano, etc use have significantly less bounce than other switches.  space is at a premium right now in my build (I have about a 1x1 inch vertical space left!) so I'd like to keep the parts to a minimum.

I put together Dano's little switch debouncer and it seems to work ok, but sometimes it gets finicky.  Possible mods to the circuit?  Make the capacitor bigger?

cpm

a schmitt inverter makes for a good debouncer, you can use the other inverters on the chip to implement the latching so you dont need an aditional 4013.
I think its on that link for "thetonegod" pages.


Processaurus

#6
Here is the best type of debounce you can get, if your x-wing switch is spdt.  It uses the set/reset functionality of the other half of the 4013 to make a latch.  The most common version uses cross coupled nand gates, and you can use nor gates, as well as inverters.  Not commonly used as much as the more finicky cap debounce, as most electronics use cheap spst switches.

http://www.aronnelson.com/gallery/main.php/v/Processaurus/CMOS+Bypass+with+4013+debounce.jpg.html?g2_imageViewsIndex=1