Counting pulses, whether time intervals or signals from sensors, buttons, and encoders, is often required. Today, I will describe how to count pulses forward and backward using digital chips.
Counting forward
Our first example is a stopwatch that counts to 30 or 60 seconds.
This is just a part of the electronic clock circuit we have assembled.
In the standard use case, half of the CD4518 dual binary decimal counter counts pulses arriving at the CLK input from 1 to 9 and then resets to 0.
Unlike the MC14553B used to make the frequency counter, the CD4518 has no separate output for the overflow signal or for shifting to the higher bit.
Yet, besides the CLOCK input, there is an ENABLE input. Any one of those can be used for clocking.
If the ENABLE input is logical, then the counter value will increment when the CLOCK input goes from low to high. This is the standard way to clock the counter.
The same thing will happen when the ENABLE input transitions from high to low if the CLOCK input is logic zero. This is exactly what happens to the Q4 most significant bit of the U1B counter during self-reset, from 9 = 0b1001 to 0 = 0b0000. Having received this signal at the ENABLE input, counter U1A increments its value.
In an electronic clock, seconds and minutes are always counted from 0 to 59, and at 60, the most significant bit is reset, and the pulse is transferred to the next counter in minutes or hours.
And our stopwatch can count up to both 60 and 30 seconds. In the first case, counter U1A should count to 6 = 0b0110, and in the second, to 3 = 0b0011. One can switch this stop condition using the S1 switch, made as a jumper.
When the specified number of seconds is reached, the counters are not reset. Instead, a logic zero is applied to the ENABLE U1B input, which denies pulse counting. If one completely removes the jumper, the counting will also stop.
The SW1 button is used to reset the counters, supplying high logical levels to the designated inputs of U1A and U1B. While it is pressed, both counters stay at zero even though the clock generator continues to send pulses every second.
The pulse generator is made according to a circuit that is very familiar to us at this point on the NE555D timer. It does not have quartz stabilization, but its accuracy is acceptable for a training model or kitchen timer.
At a higher supply voltage, timing capacitor C2 will be charged through R6 and R5 with a higher current. But thanks to the voltage divider of three 5 kOhm resistors built into the 555 chip, the thresholds for switching the charge and discharge modes of the capacitor will rise accordingly.
Thanks to the design of the 555 timer, the frequency of the second pulse does not depend on the circuit's supply voltage. This is why the 555 timer is called a precision one.
Counting back
The second version of the stopwatch also uses a clock generator on a 555 timer and CD4511 binary decimal decoders. But unlike the first one, it can count backward not from one of two fixed values but from any number of seconds in the range of 0 to 99.
Remember the post about flip-flops? One such flip-flop is assembled on two NAND gates of the CD4011 chip. If you press the START (SW3) button, logical zero will appear at input 1 of U7A.
Accordingly, output 3 will have a logical one, regardless of the state of input 2. After all, 0 AND X = 0, and NOT (0 AND X) = 1.
Through the resistor R2, this logical one from the output of the flip-flop is supplied to the ¬LOAD inputs of both CD40192 chips. This switches them from direct value loading mode to counting mode.
From the output of the same generator used in the first stopwatch on the NE555 (therefore, not shown in the diagram), second pulses are sent to the DOWN clock input of the U4 chip.
The generator has a pause button shunts the timing capacitor to the ground. While it is pressed, second pulses are not sent. Sending resumes when one releases the pause button.
U4 counts decremental until it reaches zero. At this moment, the chip supplies a logical zero to the borrow output BO, which then goes to the U1 clocking DOWN input—the high-register counter.
The next second pulse resets U4 to 9 (and not to 15 since the CD40192 is a BCD counter, unlike the purely binary CD40193). At the same time, the U4 BORROW output and, accordingly, the U1 decremental input go into a high logic-level state. Just at this moment, U1 counts down one second.
When U1 reaches zero, logic zero from its BORROW OUT will go to input 6 of logic gate U7B. At output 4, there will be NOT (1 AND 0) = 1, and accordingly, NOT (1 AND 1) = 0 at output 3 of U7A.
Logical zero at the ¬LOAD inputs will switch CD40192 chips from counting mode to direct value loading mode from microswitches SW1 and SW2.
At the same time, a low logic level at output 3 of U7A will cause LED D1 to light up and open PNP transistor Q1, which is connected to a common-emitter circuit. Buzzer BZ1 will go off.
The LED will stay lit, and the buzzer will beep until the SW3 START button is pressed again or the power is off.
Q1's base current is limited by R4 to less than one milliamp, and D1's LED current is limited by R3 to just over two milliamps.
If we were to turn on the buzzer BZ1 between the power supply positive and the emitter of transistor Q1, connecting the collector to the ground, we would get a circuit with a common collector that can limit the base current on its own. Then, it would be possible to do without R4, thereby saving ourselves one resistor.
Personally, I don’t like the buzzer beeping obnoxiously all the time when the countdown is not running. This would be exactly what you need for any speed competition. But in all the other cases, for the buzzer to go silent, you must turn off the power to the stopwatch or do two additional things: restart the countdown and pause the second pulse generator. So uncomfortable.
To make the buzzer sound for a limited time after the end of the countdown, one can use a monostable circuit on a 555 timer or an even simpler circuit from the post about decoders and demultiplexers.
This circuit ensures that a pair of LEDs light up and gradually fade to zero as capacitor C3 discharges. Our stopwatch will look like this:
The video shows the operation of both stopwatches and the process of installing components onto the PCB.
Hi! I'm Kevin! I am a very curious engineer :))
I'm the website founder and author of many posts.
I invite you to follow exciting experiments, research, and challenges.
Let's go on to new knowledge and adventures!