Unable to toggle SN74HC109

digital-logicflipflop

I'm a complete amateur, I've probably gotten a million things wrong with this already. I'm using an SN74HC109 dual j-k" flip-flop chip. I'm trying to toggle the led (forgot to add a resistor in the diagram, ah, also forgot to add a line from 5V to Vcc.) with a momentary switch. When the circuit is powered, the led turns on but does not toggle when the momentary switch is pressed and released.

enter image description here

Best Answer

Please build the following circuit:

schematic

simulate this circuit – Schematic created using CircuitLab

There are a number of things to learn from it.

1) With CMOS, ALWAYS tie unused inputs (not outputs) directly to ground or VCC. There are exceptions, with some circuits incorporating a built-in pull-up or pull-down resistor, but unless the data sheet mentions these, assume they don't exist. Leaving unused pins floating (particularly with CMOS) can produce amazingly intermittent, bizarre and maddening errors. And don't think that you can ignore the inputs of an unused part of the circuit, such as the unused flip-flop in your 74HC109. Don't even think about it. Sometimes that works, and sometimes it doesn't. Tie them all high or low.

2) C2, a 0.1 uF ceramic cap, should be connected as close as humanly possible to the ground and power pins of at least 1 IC, in this case the 74HC109. For larger circuits, particularly CMOS on a PCB with a ground plane, a minimum of 1 cap per 5 ICs is OK for CMOS, but for other logic families, or at high speeds, 1 cap per IC is a very good idea. Caps are cheap and don't take up much space, but the problems arising from not enough of them can be hard to diagnose. If you're using a solderless breadboard, do NOT use jumpers from the IC pins to the cap. Connect the cap directly to the sockets nearest the IC power and ground pins.

3) Never tie an LED directly to any low impedance output, and particularly don't tie one directly to the connection between an output and an input. On the one hand, it will try to draw too much current in the on state, and will also clamp the output to a low voltage which the input will not recognize as high. In this case, a 470 ohm resistor, combined with the LED voltage and the limited high output drive of the flip-flop will give you about 6 or 7 mA LED current when on. Just to show what I'm talking about, once you've got the circuit working, put an LED directly to ground on the flip-flop clock input, and watch what happens.

4) At microsecond to millisecond time scales, mechanical contacts such as switches and relay contacts will physically bounce as they close, and logic is fast enough to resolve those bounces into separate closures/openings. In this case, it will show up as intermittent operation of the flip-flop, depending on whether or not it got an even or odd number of contacts when you press the switch. For more complex circuits using counters or state machines you can get the most amazing errors.