How does logic work? CD4060 Binary Counter

--

In the previous post (How does binary logic work? Shift registers), we controlled the CD40194 shift register modes by applying logical ones and zeros, high and low voltage levels, to its two control inputs, S1 and S0.

To do this, we assembled a simple circuit of two synchronous JK flip-flops on the CD4027 chip, which sequentially divides the frequency in half. In other words, it counts pulses in the binary number system.

What is a JK trigger, you may ask? We are familiar with the D flip-flop. It is synchronous; it reads the input state and saves it as the output state at the edge of the clock pulse.

And the RS flip-flop is asynchronous: a one at the reset input sets its output to zero, and a one at the specified input sets its output to one. When both inputs are zero, the output state does not change.

The JK flip-flop is synchronous and is similar to the RS flip-flop. It reacts to the input states only at the edge of the clock pulse. A high level at input J sets the flip-flop output to one, at input K to zero. At both inputs, J and K, it reverses the trigger state, dividing the clock frequency in half. And if the logic levels at both inputs are low, then the output state does not change.

Each press of the button switches the circuit from the previous state to the next one: 00 → 01 → 10 → 11 → 00, and so on.

So, the resulting circuit counts pulses! If one converts binary numbers to the decimal system, one gets 0 → 1 → 2 → 3 → 0…

If we’d like to count from 0 (000) to 7 (111), we’ll need a third flip-flop; to count from 0 (0000) to 15 (1111), four flip-flops will be required, and so on. One flip-flop corresponds to one binary digit.

Our circuit has four familiar D flip-flops of two CD4013 microchips forming a four-bit binary counter.

This counter is clocked not by pressing a button but by a pulse generator on the NE555 integrated timer.

Our third example will be two music boxes with lighting effects assembled according to the same circuit diagram. See how interesting this is! The algorithm for switching lights is the same. Still, you can take LEDs of different colors, place them in different ways, and get completely different effects!

The CD4060 binary counter chip is used here. The basis of its internal structure is a chain of 14 flip-flops forming a 14-bit counter. Pin outputs of the chip are not available for all the digits, only from the fourth to the tenth and from the twelfth to the fourteenth.

So, the CD4060 chip allows one to divide the frequency into 16, 32, 64, 128, 256, 512, 1024, 4096, 8192, and 16384. Huge numbers, right?

The CD4060 can be clocked from an external source via pin 11. But the chip also has a built-in clock generator. To enable it, just connect a capacitor and two resistors to pins 9, 10, and 11. This is exactly what is done in our diagram.

The oscillation period of the clock generator is set by a stage of capacitor C1, series-connected resistor R1, and potentiometer R3, allowing one to adjust the clock frequency and, subsequently, the speed of changing the lights.

The bases of transistors are connected to the outputs corresponding to frequency division by 32, 64, and 128, and these transistors toggle groups of LEDs. But should we connect the transistor’s base directly to the microcircuit’s logical output without a series resistor?

You should definitely avoid it if the transistor is connected to a circuit with a common emitter. Here, we have PNP transistors S9012 with the emitter circuit load. That means we have a circuit with a common collector. Such a circuit does not need a resistor to limit the base current of the transistor.

The LED groups will light up with a logical zero at the base of the transistor and turn off with a logical one.

The sequence of logical levels and lighting up groups of LEDs, numbered according to transistors Q1-Q3, is as follows:
000 → 001 → 010 → 011 → 100 → 101 → 110 → 000
321 → 32 → 31 → 3 → 21 → 2 → 1 → 321

Case 111, when none of the LEDs light up, is impossible in this circuit. More precisely, it happens so briefly that it’s hard to notice.

Diodes D1–D3 and resistor R4 together form an OR logic element. As long as at least one of the outputs Q5, Q6, or Q7 is logic low, the reset input of the CD4060 chip is pulled to ground through one or more diodes.

As soon as the counter reaches logic ones on all three outputs we use, the diodes stop shunting the reset input, a high logic level appears on it, and the microcircuit resets all its flip-flops to a low level.

Then, a logical zero appears again at the reset input, and the counter restarts again.

We could’ve saved three diodes and a resistor by simply connecting Q8 to the reset input. Or just never use the reset input at all and let the counter tick from 0 to 32767 and then from zero again.

But then, after the sequence reaches phase 110 with just the group of LEDs connected to transistor Q1 lit, all the LEDs will go out until the counter reaches 1000, and if a reset occurs.

Our magic musical lantern won’t be so beautiful working in such a way. Therefore, the developers added a 3OR gate with a resistor and three diodes.

The BJ1552 is a digital music chip in a transistor package, referred to as just a transistor in the diagram for simplicity’s sake. A melody is saved in memory and played whenever the chip is powered on.

Transistor Q5, which serves as an audio amplifier, unlike Q1-Q3, is an NPN-type connected in a common-emitter circuit. A resistor is needed here to limit the base current, and it is built into the BJ1552 chip.

We have already encountered the CD4060 when assembling an electronic clock with a digital display. That circuit used the CD4060’s ability to operate with a crystal frequency regulator.

In this case, a clock quartz is used; its resonant frequency is 32768 hertz, 2 to the 15th power. One needs to divide this frequency in half 15 times to get one pulse per second.

The CD4060 bifurcates the frequency only 14 times, so we needed an additional synchronous D-trigger U12A of the CD4013 chip for the fifteenth frequency division.

The SN74HC161N chip, on which the registers of our homemade microprocessor are built, is also a counter. But unlike the CD4060, it’s only 4-bit, not 14.

But SN74HC161N is not just a counter but a synchronous latch register with a counter feature. Or, in other words, a counter with the ability to input the desired value.

If we wanted to write a value to the CD4060, we would need to reset it and apply the number of clock pulses equal to the value we want to write to the counter. And the SN74HC161N supports synchronous parallel writing over four wires.

Another thing is that the SN74HC161N has no built-in clock generator, so we’ve made a clock generator on two inverting Schmitt triggers of the SN74HC14N chip.

This generator is designed in the same way as the one built into the CD4060, and in the same way, it requires a timing capacitor and two resistors.

As you can see, there are many different digital chips, each with a unique set of useful functions. We can choose those chips that are best suited for our task. And if some function is missing, you can always find a way to implement it.

--

--