Digital Adders and Counters

Flip through the screenshots below to learn how to build a digital up-counter and down-counter.

Press / (forward slash) to begin a toolbox search and type "adder":

Click and drag a Digital 4-Bit Adder to your schematic:

This adder has two four-bit input ports A[3:0] and B[3:0], and a four-bit output S[3:0]. It also has a carry in (CI) and a carry out (CO) so it can be chained to make larger adders.

Press / (forward slash) to begin a toolbox search and type "0":

Click and drag a Digital 0 to the schematic. In fact, drag nine of them (one for each input) or use Ctrl+C and Ctrl+V to copy and paste, and press R to rotate:

We've now connected digital values to every input bit, and currently they're all zero, so the adder calculates that 0 + 0 + 0 = 0.

Click to select the bit connected to A1 and press Spacebar to toggle it to a 1:

Now we see that A1 represents the 2s bit of the 4-bit word A[3:0]. The tooltip over the adder shows "2 + 0 + 0 = 2".

Hover over the output bits and you'll see that only S1 shows a 1 output:

Now, click to select the bit on the carry input (CI), and hold Shift while you click to also select the bits B0 and B1. Press Spacebar to toggle all selected bits:

The adder shows 2 + 3 + 1 = 6. If you're not sure, it's a good idea to spend a minute understanding where each of these numbers comes from. The 2 comes from A[3:0], the 3 comes from B[3:0], and the 1 comes from CI.

Click Simulate at the bottom of the window:

In the DC tab, click + Add Expression and type "D(ADD1.nS[3:0])" and press Enter:

This shows the result, 6, of the multi-bit expression at the sum port of the adder.

Click + Add Expression and add "D(ADD1.nA[3:0])", "D(ADD1.nB[3:0])", and "D(ADD1.nCI)":

Using these digital query expressions, we can now see the adder's input and output values. You may toggle the values and explore how the adder works, but let's make things more interesting by turning this adder into a counter.

Click Build at the bottom of the window. Use Mousewheel to zoom out. Press / (forward slash) to begin a toolbox search, and type "flip". Drag four Digital D Flip-Flops onto the schematic:

The D-Flip Flop is a one-bit memory, and we'll use these to feed the adder's output back into its input, once per clock cycle.

Click to select the bit connected to CI, and then hold Shift while you drag to select the four bits connected to B[3:0]:

Press Backspace or Delete to remove these 5 bits:

Click and drag a wire from S0 into the D input of REG1:

Click and drag a wire from the Q output back to the B0 input of the adder:

Now, after a clock cycle, the old least-significant-bit (LSB) of the sum becomes the LSB of the adder's B input.

Click and drag wires to repeat the same for bits 1, 2, and 3 as shown:

Press / (forward slash) to begin a toolbox search, and type "clock". Then drag a Digital Clock onto your schematic:

Click and drag wires to connect the clock output to each register's CLK input as shown:

Click Simulate at the bottom of the window, and then expand the Time Domain tab:

Enter "100u" in Stop Time and "100n" in Time Step:

Under Outputs, click + Add Expression and add "D(CLK1.nOUT) - 2" and "D(ADD1.nB[3:0])":

Click Run Time-Domain Simulation. A plot window appears:

The counter is counting! Interestingly, the value is going up by two each time. That's happening because we left our A[3:0] input set to 2.

Click Build at the bottom of the window, then click while holding Shift to select the bits connected to the A1 and A0 inputs, and press Spacebar to toggle them:

Press F5 to repeat the simulation. A plot window appears:

Great! Now our counter is only counting up by 1 each clock cycle. Note that after 15, it wraps back to 0 because this is a 4-bit counter.

We can make the counter switch directions. Click Build to return to build mode, and click and drag another digital clock onto the schematic:

Double-click CLK2 and change its Frequency to "20k":

Drag to select the three 0s connected to A3, A2, and A1, and then press Backspace or Delete to remove them:

Now, drag a wire connecting CLK2 to A3, A2, and A1:

Press N to insert a node name and click to place it at CLK2's output. Double-click to name it "dir":

Click Simulate to open the simulation settings window. Click + Add Expression and add "D(dir) - 4" to the Outputs list:

Click Run Time-Domain Simulation. A plot window appears:

The counter now switches directions when V(dir) flips! It can be confusing because it also wraps around due to the 4-bit counter width, but you can try this with an 8-bit adder or try changing the clock frequency of CLK2 to see other possible effects.

That's it. You may now build and simulate digital adders and counters.

Click below to open the final circuit, or try it yourself from scratch (recommended).


« Return to Table of Contents

Search Documentation


About CircuitLab

CircuitLab is an in-browser schematic capture and circuit simulation software tool to help you rapidly design and analyze analog and digital electronics systems.