Breadboard exercises/ P2EnglishРусский

Exercise P2 · project · serial arithmetic

Bit-serial adder from gates and a flip-flop for the carry

The bit-serial adder of exercise P1, with its 4032 opened up: a full adder from five gates and one D flip-flop that keeps the carry from one clock to the next. This is what the 4032 has inside, built by hand.

10 chips2 × 4014, 4070, 4081, 4071, 4013, 4015, 3 × 4511
127 + 30 wireson and between the boards + leads to the modules
3 boardsA, B with the carry, the adder with the sum
~1 Hzone bit per clock

1What it is and why it matters

What it does. The same as exercise P1: buttons give A and B, LOAD through one blink of the clock module puts them into two 4014 serializers, and after four more blinks the sum display shows A + B. The difference is in the middle: the bits are added by gates, and the carry waits in a flip-flop.

How it works. The full adder of exercise M2 adds the bit of A, the bit of B and the carry C: P = A XOR B, the sum S = P XOR C, and the new carry C' = A AND B OR P AND C. Flip-flop 1 of a 4013 stores C' at every rising edge of the clock, so the carry of one bit is added to the next bit one clock later. LOAD resets the flip-flop at once, so every new pair of numbers starts with a carry of 0.

Where it is used. A full adder with a carry register is the arithmetic unit of every bit-serial machine, from early computers to the serial multipliers in today's signal-processing chips. In a parallel adder the same full adder is repeated for every bit and the carry flows through wires instead of through time.

Why learn it.

2The key elements: a full adder and a carry flip-flop

The full adder for all eight inputs:

ABCP = A⊕BS = P⊕CG = A·BT = P·CC' = G + T
00000000
00101000
01011000
01110011
10011000
10110011
11000101
11101101

The flip-flop turns the last column into the C of the next clock. With A = 5 and B = 3 the carries are 1, 1, 1 and then 0, and the sum bits 0, 0, 0, 1: the sum 8, as in the table of exercise P1. The display shows it after the fourth edge, for one period of the clock; choose A + B of at most 9, because the 4511 shows digits 0 to 9 only.

Waveforms

CLKLOADA059B038A→B→CS→401500001000010000001000010000100001
From the simulation of tb.sv in Icarus Verilog: 5 + 3, then 9 + 8. C is the carry flip-flop: LOAD clears it at once, and every edge stores the carry of the bit just added. · SVG · PNG

3Parts

PartIn this circuitQtyPriceSupplier
CD4511BCD-to-7-segment decoders for A, B and the sum3$0.65Elexp (elexp.com)
CD40148-stage parallel-in, serial-out registers: the serializers of A and B2$0.19Jameco (jameco.com)
CD4013dual D flip-flop: flip-flop 1 keeps the carry1$0.35Elexp (elexp.com)
CD4071quad OR: the carry out (one of four used)1$0.25Elexp (elexp.com)
CD4081quad AND: G and T (two of four used)1$0.55Elexp (elexp.com)
CD4070quad XOR: P and S (two of four used)1$0.45Elexp (elexp.com)
CD4015dual 4-stage shift register: register A is the deserializer of the sum1$0.35Elexp (elexp.com)
Button modulesA3-A0, B3-B0 and LOAD; the first pack of five5$0.66 / packaliexpress.us
Button modules4 more from the second pack4$2.03 / packaliexpress.us
555 clock modulethe clock, set to about 1 Hz1$0.53aliexpress.us
7-segment display, common cathodeA, B and the sum3$0.90elexp.com
Resistor, 560 Ω, ½ Wone per segment21$0.04elexp.com
Breadboard, 830 pointstwo boards, one above the other3$3.00amazon.com
Breadboard power module5 V on the rails1$1.00aliexpress.us
USB-to-DC cable, 9 Vpowers the module from a USB charger1$1.17aliexpress.us
Pre-cut jumper wires127 wires on the board (or male-male Dupont jumpers)127$11.95 / packjameco.com
Male-female Dupont jumpers30 leads to the clock module and the buttons30$1.30 / packaliexpress.us

Prices from the LSSK components sheet; these chips are in the Comprehensive kit.

4The chips, pin by pin

The chips are CMOS 4000B series: they work from 3 to 18 V, here from the 5 V of the power module. Every input must be connected to something, because a CMOS input left open picks up noise and can switch at random. The drawings show each chip from above with the notch on the left, as in the datasheet: pin 1 at the bottom left, pins numbered counter-clockwise. Blue arrows are inputs, orange arrows are outputs.

4014: 8-stage shift register, parallel in, serial out

1P82Q63Q84P45P36P27P18VSS9P/S10CLK11SER12Q713P514P615P716VDD40148-bit PISO register
CD4014B. · SVG · PNG

As in exercise P1: P8, P7, P6, P5 (pins 1, 15, 14, 13) get bits 0 to 3 of the number, PAR/SER (pin 9) is LOAD, CLOCK is pin 10, the stream comes out of Q8 (pin 3), and P4–P1 and SERIAL IN are at GND.

PinNameDirectionFunctionIn this circuit
1P8inputparallel input, stage 8A0
2Q6outputoutput of stage 6not connected
3Q8outputoutput of stage 8, the serial outputA→
4P4inputparallel input, stage 4GND
5P3inputparallel input, stage 3GND
6P2inputparallel input, stage 2GND
7P1inputparallel input, stage 1GND
8VSSpowerground, 0 VGND
9PAR/SERinput1 = load P1-P8 at the next clock edge, 0 = shift; works with the clock (synchronous)LOAD
10CLOCKinputeverything happens on the rising edgeCLK
11SERIAL INinputserial input: goes into stage 1 when shiftingGND
12Q7outputoutput of stage 7not connected
13P5inputparallel input, stage 5A3
14P6inputparallel input, stage 6A2
15P7inputparallel input, stage 7A1
16VDDpowersupply, +5 V (3 to 18 V allowed)+5V

4070: quad 2-input XOR

1A2B3J4K5C6D7VSS8E9F10L11M12G13H14VDD4070
CD4070B. · SVG · PNG

Two gates: P = A XOR B and S = P XOR C. The inputs of the other two are tied to GND.

PinNameDirectionFunctionIn this circuit
1Ainputinput of the gate with its output on pin 3B→
2Binputinput of the gate with its output on pin 3A→
3JoutputJ = A XOR BP
4KoutputK = C XOR DS→
5Cinputinput of the gate with its output on pin 4C
6Dinputinput of the gate with its output on pin 4P
7VSSpowerground, 0 VGND
8Einputinput of the gate with its output on pin 10tied to GND
9Finputinput of the gate with its output on pin 10tied to GND
10LoutputL = E XOR Fnot connected
11MoutputM = G XOR Hnot connected
12Ginputinput of the gate with its output on pin 11tied to GND
13Hinputinput of the gate with its output on pin 11tied to GND
14VDDpowersupply, +5 V (3 to 18 V allowed)+5V

4081: quad 2-input AND

1A2B3J4K5C6D7VSS8E9F10L11M12G13H14VDD4081
CD4081B. · SVG · PNG

Two gates: G = A AND B and T = P AND C.

PinNameDirectionFunctionIn this circuit
1Ainputinput of the gate with its output on pin 3tied to +5V
2Binputinput of the gate with its output on pin 3tied to +5V
3JoutputJ = A AND Bnot connected
4KoutputK = C AND DG
5Cinputinput of the gate with its output on pin 4B→
6Dinputinput of the gate with its output on pin 4A→
7VSSpowerground, 0 VGND
8Einputinput of the gate with its output on pin 10tied to GND
9Finputinput of the gate with its output on pin 10tied to GND
10LoutputL = E AND Fnot connected
11MoutputM = G AND HT
12Ginputinput of the gate with its output on pin 11P
13Hinputinput of the gate with its output on pin 11C
14VDDpowersupply, +5 V (3 to 18 V allowed)+5V

4071: quad 2-input OR

1A2B3J4K5C6D7VSS8E9F10L11M12G13H14VDD4071
CD4071B. · SVG · PNG

One gate: the new carry C' = G OR T.

PinNameDirectionFunctionIn this circuit
1Ainputinput of the gate with its output on pin 3tied to GND
2Binputinput of the gate with its output on pin 3tied to GND
3JoutputJ = A OR Bnot connected
4KoutputK = C OR Dnot connected
5Cinputinput of the gate with its output on pin 4tied to GND
6Dinputinput of the gate with its output on pin 4tied to GND
7VSSpowerground, 0 VGND
8Einputinput of the gate with its output on pin 10T
9Finputinput of the gate with its output on pin 10G
10LoutputL = E OR FC'
11MoutputM = G OR Hnot connected
12Ginputinput of the gate with its output on pin 11tied to +5V
13Hinputinput of the gate with its output on pin 11tied to +5V
14VDDpowersupply, +5 V (3 to 18 V allowed)+5V

4013: dual D flip-flop

1Q12Q13CLK14R15D16S17VSS8S29D210R211CLK212Q213Q214VDD40132 × D flip-flop
CD4013B. · SVG · PNG

As in exercise B4. Flip-flop 1 keeps the carry: D1 (pin 5) gets C', Q1 (pin 1) is C, CLOCK1 (pin 3) is the clock and RESET1 (pin 4) is LOAD. SET1 (pin 6) is at GND, and the inputs of flip-flop 2 are tied to the rails.

PinNameDirectionFunctionIn this circuit
1Q1outputflip-flop 1 outputC
2Q1outputflip-flop 1 output, invertednot connected
3CLOCK1inputflip-flop 1 stores D1 on the rising edge, 0 to 1CLK
4RESET1input1 sets Q1 = 0 at once, without the clock. Active highLOAD
5D1inputflip-flop 1 data inputC'
6SET1input1 sets Q1 = 1 at once, without the clock. Active highGND
7VSSpowerground, 0 VGND
8SET2input1 sets Q2 = 1 at once. Active hightied to +5V
9D2inputflip-flop 2 data inputtied to +5V
10RESET2input1 sets Q2 = 0 at once. Active hightied to +5V
11CLOCK2inputflip-flop 2 stores D2 on the rising edgetied to +5V
12Q2outputflip-flop 2 output, invertednot connected
13Q2outputflip-flop 2 outputnot connected
14VDDpowersupply, +5 V (3 to 18 V allowed)+5V

4015: dual 4-stage shift register

1CLKB2Q4B3Q3A4Q2A5Q1A6RA7DA8VSS9CLKA10Q4A11Q3B12Q2B13Q1B14RB15DB16VDD40152 × 4-bit shift register
CD4015B. · SVG · PNG

As in exercise P1: register A collects the sum bits, and LOAD clears it at once.

PinNameDirectionFunctionIn this circuit
1CLOCK Binputregister B shifts on the rising edgetied to +5V
2Q4Boutputregister B, stage 4 (the oldest bit)not connected
3Q3Aoutputregister A, stage 3Q3A
4Q2Aoutputregister A, stage 2Q2A
5Q1Aoutputregister A, stage 1 (the newest bit)Q1A
6RESET Ainput1 clears register A at once, without the clock. Active highLOAD
7DATA Ainputregister A, serial inputS→
8VSSpowerground, 0 VGND
9CLOCK Ainputregister A shifts on the rising edgeCLK
10Q4Aoutputregister A, stage 4 (the oldest bit)Q4A
11Q3Boutputregister B, stage 3not connected
12Q2Boutputregister B, stage 2not connected
13Q1Boutputregister B, stage 1not connected
14RESET Binput1 clears register B at once. Active hightied to GND
15DATA Binputregister B, serial inputtied to GND
16VDDpowersupply, +5 V (3 to 18 V allowed)+5V

4511: BCD to 7-segment decoder

1B2C3LT4BI5LE6D7A8VSS9e10d11c12b13a14g15f16VDD4511BCD → 7 segments
CD4511B. · SVG · PNG

As in exercise B7, three times, each with a display and seven resistors.

PinNameDirectionFunctionIn this circuit
1BinputBCD input, bit 1 (weight 2)A1
2CinputBCD input, bit 2 (weight 4)A2
3LTinputlamp test: 0 lights all segments. Active low+5V
4BIinputblanking: 0 turns all segments off. Active low+5V
5LEinputlatch enable: 0 = follow the inputs, 1 = hold the codeGND
6DinputBCD input, bit 3 (weight 8)A3
7AinputBCD input, bit 0 (weight 1)A0
8VSSpowerground, 0 VGND
9eoutputsegment e (bottom left); 1 = lit; drives up to 25 mA through a resistorA.e
10doutputsegment d (bottom); 1 = lit; drives up to 25 mA through a resistorA.d
11coutputsegment c (bottom right); 1 = lit; drives up to 25 mA through a resistorA.c
12boutputsegment b (top right); 1 = lit; drives up to 25 mA through a resistorA.b
13aoutputsegment a (top); 1 = lit; drives up to 25 mA through a resistorA.a
14goutputsegment g (middle); 1 = lit; drives up to 25 mA through a resistorA.g
15foutputsegment f (top left); 1 = lit; drives up to 25 mA through a resistorA.f
16VDDpowersupply, +5 V (3 to 18 V allowed)+5V

5Schematic 1: serializers, gates, deserializer

CLKLOADA3A2A1A0B3B2B1B04014 AP5P6P7P8P/SCLKQ8serializer4014 BP5P6P7P8P/SCLKQ8serializer40814511 ADCBAa–g40704511 BDCBAa–g4081407040714015 ADRCLKQ1Q2Q3Q4deserializerDRQ40134511 SDCBAa–gAdisplayBdisplayA + Bdisplay
The circuit as blocks and gates. This is what serial_adder_gates.sv describes. The line along the bottom brings the carry C back from the flip-flop to the gates. · SVG · PNG

6Schematic 2: connections between the chips

12345678910111213141516BCLTBILEDAedcbagf4511BCD → 7 segments4511 A12345678910111213141516P8Q6Q8P4P3P2P1P/SCLKSERQ7P5P6P740148-bit PISO register4014 Ae1d2CC3c4DP5b6a7CC8f9g10A12345678910111213141516BCLTBILEDAedcbagf4511BCD → 7 segments4511 B12345678910111213141516P8Q6Q8P4P3P2P1P/SCLKSERQ7P5P6P740148-bit PISO register4014 B1234567891011121314Q1Q1CLK1R1D1S1S2D2R2CLK2Q2Q240132 × D flip-flope1d2CC3c4DP5b6a7CC8f9g10B12345678910111213144071123456789101112131440811234567891011121314407012345678910111213141516CLKBQ4BQ3AQ2AQ1ARADACLKAQ4AQ3BQ2BQ1BRBDB40152 × 4-bit shift register12345678910111213141516BCLTBILEDAedcbagf4511BCD → 7 segments4511 Se1d2CC3c4DP5b6a7CC8f9g10A + BA.aA.bA.cA.dA.eA.fA.gB.aB.bB.cB.dB.eB.fB.gS.aS.bS.cS.dS.eS.fS.gCLKLOADA→B→PS→GTC'CA0A1A2A3B0B1B2B3Q1AQ2AQ3AQ4AA3A2A1A0B3B2B1B0LOADclock+5V
The same circuit as chips, pin by pin, one row per board. · SVG · PNG
NetFromToWire
CLK555 clock module, OUT4014 A 10 (CLK), 4014 B 10 (CLK), 4013 3 (CLK1), 4015 9 (CLKA)M-F, M-M
LOADbutton LOAD, OUT4014 A 9 (P/S), 4014 B 9 (P/S), 4013 4 (R1), 4015 6 (RA)M-F, M-M
A3button A3, OUT4014 A 13 (P5), 4511 A 6 (D)M-F, M-M
A2button A2, OUT4014 A 14 (P6), 4511 A 2 (C)M-F, M-M
A1button A1, OUT4014 A 15 (P7), 4511 A 1 (B)M-F, M-M
A0button A0, OUT4014 A 1 (P8), 4511 A 7 (A)M-F, M-M
B3button B3, OUT4014 B 13 (P5), 4511 B 6 (D)M-F, M-M (loose jumper)
B2button B2, OUT4014 B 14 (P6), 4511 B 2 (C)M-F, M-M
B1button B1, OUT4014 B 15 (P7), 4511 B 1 (B)M-F, M-M
B0button B0, OUT4014 B 1 (P8), 4511 B 7 (A)M-F, M-M
A→4014 A 3 (Q8)4070 2 (B), 4081 6 (D)M-M (loose jumper)
B→4014 B 3 (Q8)4070 1 (A), 4081 5 (C)M-M
P4070 3 (J)4070 6 (D), 4081 12 (G)M-M
G4081 4 (K)4071 9 (F)M-M
T4081 11 (M)4071 8 (E)M-M
C'4071 10 (L)4013 5 (D1)M-M (loose jumper)
C4013 1 (Q1)4070 5 (C), 4081 13 (H)M-M (loose jumper)
S→4070 4 (K)4015 7 (DA)M-M
Q1A4015 5 (Q1A)4511 S 6 (D)M-M
Q2A4015 4 (Q2A)4511 S 2 (C)M-M
Q3A4015 3 (Q3A)4511 S 1 (B)M-M
Q4A4015 10 (Q4A)4511 S 7 (A)M-M
A.a4511 A 13 (a)RaAM-M
A.b4511 A 12 (b)RbAM-M
A.c4511 A 11 (c)RcAM-M
A.d4511 A 10 (d)RdAM-M
A.e4511 A 9 (e)ReAM-M
A.f4511 A 15 (f)RfAM-M (loose jumper)
A.g4511 A 14 (g)RgAM-M (loose jumper)
A.a′—RaA, A 7 (a)
A.b′—RbA, A 6 (b)
A.c′—RcA, A 4 (c)
A.d′—RdA, A 2 (d)
A.e′—ReA, A 1 (e)
A.f′—RfA, A 9 (f)
A.g′—RgA, A 10 (g)
B.a4511 B 13 (a)RaBM-M
B.b4511 B 12 (b)RbBM-M
B.c4511 B 11 (c)RcBM-M
B.d4511 B 10 (d)RdBM-M
B.e4511 B 9 (e)ReBM-M
B.f4511 B 15 (f)RfBM-M
B.g4511 B 14 (g)RgBM-M (loose jumper)
B.a′—RaB, B 7 (a)
B.b′—RbB, B 6 (b)
B.c′—RcB, B 4 (c)
B.d′—RdB, B 2 (d)
B.e′—ReB, B 1 (e)
B.f′—RfB, B 9 (f)
B.g′—RgB, B 10 (g)
S.a4511 S 13 (a)RaSM-M (loose jumper)
S.b4511 S 12 (b)RbSM-M (loose jumper)
S.c4511 S 11 (c)RcSM-M
S.d4511 S 10 (d)RdSM-M
S.e4511 S 9 (e)ReSM-M
S.f4511 S 15 (f)RfSM-M
S.g4511 S 14 (g)RgSM-M
S.a′—RaS, A + B 7 (a)
S.b′—RbS, A + B 6 (b)
S.c′—RcS, A + B 4 (c)
S.d′—RdS, A + B 2 (d)
S.e′—ReS, A + B 1 (e)
S.f′—RfS, A + B 9 (f)
S.g′—RgS, A + B 10 (g)
+5V+5V4511 A 16 (VDD), 4014 A 16 (VDD), 4511 B 16 (VDD), 4014 B 16 (VDD), 4013 14 (VDD), 4071 14 (VDD), 4081 14 (VDD), 4070 14 (VDD), 4015 16 (VDD), 4511 S 16 (VDD), 4511 A 4 (BI), 4511 A 3 (LT), 4511 B 4 (BI), 4511 B 3 (LT), 4013 11 (CLK2), 4013 10 (R2), 4013 9 (D2), 4013 8 (S2), 4071 13 (H), 4071 12 (G), 4081 2 (B), 4081 1 (A), 4015 1 (CLKB), 4511 S 4 (BI), 4511 S 3 (LT)
GNDGND4511 A 8 (VSS), 4014 A 8 (VSS), 4511 B 8 (VSS), 4014 B 8 (VSS), 4013 7 (VSS), 4071 7 (VSS), 4081 7 (VSS), 4070 7 (VSS), 4015 8 (VSS), 4511 S 8 (VSS), A 3 (CC), 4511 A 5 (LE), 4014 A 4 (P4), 4014 A 5 (P3), 4014 A 11 (SER), 4014 A 6 (P2), 4014 A 7 (P1), B 3 (CC), 4511 B 5 (LE), 4014 B 7 (P1), 4014 B 6 (P2), 4014 B 11 (SER), 4014 B 5 (P3), 4014 B 4 (P4), 4013 6 (S1), 4071 1 (A), 4071 2 (B), 4071 5 (C), 4071 6 (D), 4081 8 (E), 4081 9 (F), 4070 8 (E), 4070 9 (F), 4070 12 (G), 4070 13 (H), 4015 14 (RB), 4015 15 (DB), 4511 S 5 (LE), A + B 3 (CC)
not connected4014 A 2 (Q6), 4014 A 12 (Q7), 4014 B 2 (Q6), 4014 B 12 (Q7), 4013 2 (Q1), 4013 12 (Q2), 4013 13 (Q2), 4071 3 (J), 4071 4 (K), 4071 11 (M), 4081 3 (J), 4081 10 (L), 4070 10 (L), 4070 11 (M), 4015 2 (Q4B), 4015 11 (Q3B), 4015 12 (Q2B), 4015 13 (Q1B), A 5 (DP), A 8 (CC), B 5 (DP), B 8 (CC), A + B 5 (DP), A + B 8 (CC)

7Schematic 3: the breadboards

−+−+123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263abcdefghijBoard 1−+−+123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263abcdefghijBoard 2−+−+123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263abcdefghijBoard 35V5VPOWER MODULE · 5V9V USB-DC4511 A4014 A4511 B4014 B401340714081407040154511 SABA + BA.aA.bA.cA.dA.eA.fA.gB.aB.bB.cB.dB.eB.fB.gS.aS.bS.cS.dS.eS.fS.gCLKCLKCLKLOADLOADA→A→B→B→S→GTC'CA0A1A2A3B0B0B1B1B2B2B3B3Q1AQ2AQ3AQ4A+OUT−A3+OUT−A2+OUT−A1+OUT−A0+OUT−B3+OUT−B2+OUT−B1+OUT−B0+OUT−LOAD−OUT+555CLOCK 555~1 Hz
Every wire in its hole, on three boards one above the other: A on the top board; B and the carry flip-flop in the middle; the gates, the 4015 and the sum on the bottom board with the power module. The rail jumpers on the right bring power to the other two boards. Wires drawn as loose arcs could not be laid flat. · SVG · PNG
CLKLOADA3A2A1A0B3B2B1B0A→B→PGTC'CS→Q1AQ2AQ3AQ4AA.aA.bA.cA.dA.eA.fA.gA.a′A.b′A.c′A.d′A.e′A.f′A.g′B.aB.bB.cB.dB.eB.fB.gB.a′B.b′B.c′B.d′B.e′B.f′B.g′S.aS.bS.cS.dS.eS.fS.gS.a′S.b′S.c′S.d′S.e′S.f′S.g′+5VGND

Build it step by step

  1. Do the getting-started steps first: how the breadboard is connected inside, the power module with both jumpers on 5 V, how a chip sits across the gap.
  2. Split the work as in exercise P1: one student per board. Agree first on the wires between the boards: the clock, LOAD, the two streams, the carry C and C'.
  3. Insert the chips across the gap: the 4511 A turned around, notch to the right, pin 1 in hole 27e of board 1; the 4014 A, notch to the left, pin 1 in hole 35f of board 1; the 4511 B turned around, notch to the right, pin 1 in hole 25e of board 2; the 4014 B turned around, notch to the right, pin 1 in hole 39e of board 2; the 4013, notch to the left, pin 1 in hole 43f of board 2; the 4071, notch to the left, pin 1 in hole 4f of board 3; the 4081 turned around, notch to the right, pin 1 in hole 18e of board 3; the 4070 turned around, notch to the right, pin 1 in hole 27e of board 3; the 4015 turned around, notch to the right, pin 1 in hole 37e of board 3; the 4511 S turned around, notch to the right, pin 1 in hole 47e of board 3. Read the numbers on the chips: many look alike. A chip turned around has pin 1 at the top right: it puts the pins this circuit needs next to its neighbours.
  4. Power: for each chip a red wire from its VDD pin (14, or 16 on a 16-pin chip) to the + rail and a black wire from its VSS pin (7 or 8) to the − rail, each to the rail on its own side of the gap. On a chip turned around VDD is on the bottom row and VSS on the top row. Make sure no wire touches + and − at the same time.
  5. The rail jumpers on the right: they bring +5V and GND from the bottom board to the other two.
  6. Each display unit: the 4511, its display and the seven resistors, as in exercise B7.
  7. The fixed inputs and the signal wires, board by board, following the checklist. Tick each wire as you insert it.
  8. With the power off, the modules: A3–A0, B3–B0, LOAD and the clock module above the top board.
  9. Turn the power on and set the clock module to its slowest.

Wiring checklist

·

#NetFromTo
Rails of the second board (from the board with the power module) · 8 wires
1+5Vboard 2: top + rail, column 2board 1: bottom + rail, column 2
2GNDboard 2: top − rail, column 4board 1: bottom − rail, column 4
3+5Vboard 1: top + rail, column 63board 1: bottom + rail, column 63
4GNDboard 1: top − rail, column 62board 1: bottom − rail, column 62
5+5Vboard 3: top + rail, column 2board 2: bottom + rail, column 2
6GNDboard 3: top − rail, column 4board 2: bottom − rail, column 4
7+5Vboard 2: top + rail, column 63board 2: bottom + rail, column 63
8GNDboard 2: top − rail, column 62board 2: bottom − rail, column 62
Power (red to +, black to −) · 20 wires
9+5Vboard 1: 27j (4511 A pin 16, VDD)board 1: bottom + rail, column 27
10GNDboard 1: 20a (4511 A pin 8, VSS)board 1: top − rail, column 20
11+5Vboard 1: 35a (4014 A pin 16, VDD)board 1: top + rail, column 35
12GNDboard 1: 42j (4014 A pin 8, VSS)board 1: bottom − rail, column 42
13+5Vboard 2: 25j (4511 B pin 16, VDD)board 2: bottom + rail, column 25
14GNDboard 2: 18a (4511 B pin 8, VSS)board 2: top − rail, column 18
15+5Vboard 2: 39j (4014 B pin 16, VDD)board 2: bottom + rail, column 39
16GNDboard 2: 32a (4014 B pin 8, VSS)board 2: top − rail, column 32
17+5Vboard 2: 43a (4013 pin 14, VDD)board 2: top + rail, column 43
18GNDboard 2: 49j (4013 pin 7, VSS)board 2: bottom − rail, column 49
19+5Vboard 3: 4a (4071 pin 14, VDD)board 3: top + rail, column 4
20GNDboard 3: 10j (4071 pin 7, VSS)board 3: bottom − rail, column 10
21+5Vboard 3: 18j (4081 pin 14, VDD)board 3: bottom + rail, column 18
22GNDboard 3: 12a (4081 pin 7, VSS)board 3: top − rail, column 12
23+5Vboard 3: 27j (4070 pin 14, VDD)board 3: bottom + rail, column 27
24GNDboard 3: 21a (4070 pin 7, VSS)board 3: top − rail, column 21
25+5Vboard 3: 37j (4015 pin 16, VDD)board 3: bottom + rail, column 37
26GNDboard 3: 30a (4015 pin 8, VSS)board 3: top − rail, column 30
27+5Vboard 3: 47j (4511 S pin 16, VDD)board 3: bottom + rail, column 47
28GNDboard 3: 40a (4511 S pin 8, VSS)board 3: top − rail, column 40
Fixed inputs: CMOS inputs must not float · 44 wires
29GNDboard 1: 10j (display A pin 3, CC)board 1: bottom − rail, column 10
30GNDboard 1: 23a (4511 A pin 5, LE)board 1: top − rail, column 23
31+5Vboard 1: 24a (4511 A pin 4, BI)board 1: top + rail, column 24
32+5Vboard 1: 25a (4511 A pin 3, LT)board 1: top + rail, column 25
33GNDboard 1: 38j (4014 A pin 4, P4)board 1: bottom − rail, column 38
34GNDboard 1: 39j (4014 A pin 5, P3)board 1: bottom − rail, column 39
35GNDboard 1: 40a (4014 A pin 11, SER)board 1: top − rail, column 40
36GNDboard 1: 40j (4014 A pin 6, P2)board 1: bottom − rail, column 40
37GNDboard 1: 41j (4014 A pin 7, P1)board 1: bottom − rail, column 41
38GNDboard 2: 8j (display B pin 3, CC)board 2: bottom − rail, column 8
39GNDboard 2: 21a (4511 B pin 5, LE)board 2: top − rail, column 21
40+5Vboard 2: 22a (4511 B pin 4, BI)board 2: top + rail, column 22
41+5Vboard 2: 23a (4511 B pin 3, LT)board 2: top + rail, column 23
42GNDboard 2: 33a (4014 B pin 7, P1)board 2: top − rail, column 33
43GNDboard 2: 34a (4014 B pin 6, P2)board 2: top − rail, column 34
44GNDboard 2: 34j (4014 B pin 11, SER)board 2: bottom − rail, column 34
45GNDboard 2: 35a (4014 B pin 5, P3)board 2: top − rail, column 35
46GNDboard 2: 36a (4014 B pin 4, P4)board 2: top − rail, column 36
47+5Vboard 2: 46a (4013 pin 11, CLK2)board 2: top + rail, column 46
48+5Vboard 2: 47a (4013 pin 10, R2)board 2: top + rail, column 47
49+5Vboard 2: 48a (4013 pin 9, D2)board 2: top + rail, column 48
50GNDboard 2: 48j (4013 pin 6, S1)board 2: bottom − rail, column 48
51+5Vboard 2: 49a (4013 pin 8, S2)board 2: top + rail, column 49
52GNDboard 3: 4j (4071 pin 1, A)board 3: bottom − rail, column 4
53+5Vboard 3: 5a (4071 pin 13, H)board 3: top + rail, column 5
54GNDboard 3: 5j (4071 pin 2, B)board 3: bottom − rail, column 5
55+5Vboard 3: 6a (4071 pin 12, G)board 3: top + rail, column 6
56GNDboard 3: 8j (4071 pin 5, C)board 3: bottom − rail, column 8
57GNDboard 3: 9j (4071 pin 6, D)board 3: bottom − rail, column 9
58GNDboard 3: 12j (4081 pin 8, E)board 3: bottom − rail, column 12
59GNDboard 3: 13j (4081 pin 9, F)board 3: bottom − rail, column 13
60+5Vboard 3: 17a (4081 pin 2, B)board 3: top + rail, column 17
61+5Vboard 3: 18a (4081 pin 1, A)board 3: top + rail, column 18
62GNDboard 3: 21j (4070 pin 8, E)board 3: bottom − rail, column 21
63GNDboard 3: 22j (4070 pin 9, F)board 3: bottom − rail, column 22
64GNDboard 3: 25j (4070 pin 12, G)board 3: bottom − rail, column 25
65GNDboard 3: 26j (4070 pin 13, H)board 3: bottom − rail, column 26
66GNDboard 3: 35j (4015 pin 14, RB)board 3: bottom − rail, column 35
67GNDboard 3: 36j (4015 pin 15, DB)board 3: bottom − rail, column 36
68+5Vboard 3: 37a (4015 pin 1, CLKB)board 3: top + rail, column 37
69GNDboard 3: 43a (4511 S pin 5, LE)board 3: top − rail, column 43
70+5Vboard 3: 44a (4511 S pin 4, BI)board 3: top + rail, column 44
71+5Vboard 3: 45a (4511 S pin 3, LT)board 3: top + rail, column 45
72GNDboard 3: 57j (display A + B pin 3, CC)board 3: bottom − rail, column 57
Resistors, 560 Ω (not wires: put each resistor in these two holes) · 21 resistors
RbA560 Ωboard 1: 12bboard 1: 16b
RaA560 Ωboard 1: 11aboard 1: 15a
RfA560 Ωboard 1: 9cboard 1: 14c
RcA560 Ωboard 1: 11jboard 1: 15j
RdA560 Ωboard 1: 9iboard 1: 14i
RgA560 Ωboard 1: 8aboard 1: 4a
ReA560 Ωboard 1: 8jboard 1: 4j
RbB560 Ωboard 2: 10bboard 2: 14b
RaB560 Ωboard 2: 9aboard 2: 13a
RfB560 Ωboard 2: 7cboard 2: 12c
RcB560 Ωboard 2: 9jboard 2: 13j
RdB560 Ωboard 2: 7iboard 2: 12i
RgB560 Ωboard 2: 6aboard 2: 2a
ReB560 Ωboard 2: 6jboard 2: 2j
RgS560 Ωboard 3: 55bboard 3: 51b
RfS560 Ωboard 3: 56aboard 3: 52a
RaS560 Ωboard 3: 58cboard 3: 53c
ReS560 Ωboard 3: 55jboard 3: 51j
RdS560 Ωboard 3: 56iboard 3: 52i
RbS560 Ωboard 3: 59aboard 3: 63a
RcS560 Ωboard 3: 58jboard 3: 62j
Signal wires · 55 wires
73A.aboard 1: 24i (4511 A pin 13, a)board 1: 15d (RaA)
74A.bboard 1: 23h (4511 A pin 12, b)board 1: 16e (RbA)
75A.cboard 1: 22g (4511 A pin 11, c)board 1: 15f (RcA)
76A.dboard 1: 21g (4511 A pin 10, d)board 1: 14g (RdA)
77A.eboard 1: 20j (4511 A pin 9, e)board 1: 4i (ReA)
78A.f (loose jumper)board 1: 26h (4511 A pin 15, f)board 1: 14d (RfA)
79A.g (loose jumper)board 1: 25h (4511 A pin 14, g)board 1: 4c (RgA)
80B.aboard 2: 22i (4511 B pin 13, a)board 2: 13d (RaB)
81B.bboard 2: 21h (4511 B pin 12, b)board 2: 14e (RbB)
82B.cboard 2: 20g (4511 B pin 11, c)board 2: 13f (RcB)
83B.dboard 2: 19g (4511 B pin 10, d)board 2: 12g (RdB)
84B.eboard 2: 18j (4511 B pin 9, e)board 2: 2i (ReB)
85B.fboard 2: 24g (4511 B pin 15, f)board 2: 12d (RfB)
86B.g (loose jumper)board 2: 23h (4511 B pin 14, g)board 2: 2c (RgB)
87S.a (loose jumper)board 3: 44h (4511 S pin 13, a)board 3: 53d (RaS)
88S.b (loose jumper)board 3: 43h (4511 S pin 12, b)board 3: 63c (RbS)
89S.cboard 3: 42j (4511 S pin 11, c)board 3: 62i (RcS)
90S.dboard 3: 41g (4511 S pin 10, d)board 3: 52f (RdS)
91S.eboard 3: 40g (4511 S pin 9, e)board 3: 51g (ReS)
92S.fboard 3: 46h (4511 S pin 15, f)board 3: 52d (RfS)
93S.gboard 3: 45i (4511 S pin 14, g)board 3: 51c (RgS)
94CLKboard 1: 41d (4014 A pin 10, CLK)board 2: 45g (4013 pin 3, CLK1)
95CLKboard 2: 45h (4013 pin 3, CLK1)board 2: 33g (4014 B pin 10, CLK)
96CLKboard 2: 33h (4014 B pin 10, CLK)board 3: 30g (4015 pin 9, CLKA)
97LOADboard 1: 42c (4014 A pin 9, P/S)board 2: 46g (4013 pin 4, R1)
98LOADboard 2: 46h (4013 pin 4, R1)board 2: 32h (4014 B pin 9, P/S)
99LOADboard 2: 32g (4014 B pin 9, P/S)board 3: 32d (4015 pin 6, RA)
100A→ (loose jumper)board 1: 37h (4014 A pin 3, Q8)board 3: 26c (4070 pin 2, B)
101A→board 3: 26b (4070 pin 2, B)board 3: 13b (4081 pin 6, D)
102B→board 2: 37c (4014 B pin 3, Q8)board 3: 27d (4070 pin 1, A)
103B→board 3: 27a (4070 pin 1, A)board 3: 14a (4081 pin 5, C)
104Pboard 3: 25d (4070 pin 3, J)board 3: 22d (4070 pin 6, D)
105Pboard 3: 22c (4070 pin 6, D)board 3: 16g (4081 pin 12, G)
106S→board 3: 24c (4070 pin 4, K)board 3: 31c (4015 pin 7, DA)
107Gboard 3: 15d (4081 pin 4, K)board 3: 9d (4071 pin 9, F)
108Tboard 3: 15g (4081 pin 11, M)board 3: 10c (4071 pin 8, E)
109C' (loose jumper)board 3: 8c (4071 pin 10, L)board 2: 47h (4013 pin 5, D1)
110C (loose jumper)board 2: 43h (4013 pin 1, Q1)board 3: 23b (4070 pin 5, C)
111Cboard 3: 23c (4070 pin 5, C)board 3: 17g (4081 pin 13, H)
112A0board 1: 35g (4014 A pin 1, P8)board 1: 21b (4511 A pin 7, A)
113A1board 1: 36d (4014 A pin 15, P7)board 1: 27d (4511 A pin 1, B)
114A2board 1: 37c (4014 A pin 14, P6)board 1: 26c (4511 A pin 2, C)
115A3board 1: 38b (4014 A pin 13, P5)board 1: 22b (4511 A pin 6, D)
116B0board 2: 39d (4014 B pin 1, P8)board 2: 19d (4511 B pin 7, A)
117B0board 2: 39c (4014 B pin 1, P8)board 1: 43b
118B1board 2: 38h (4014 B pin 15, P7)board 2: 25b (4511 B pin 1, B)
119B1board 2: 38i (4014 B pin 15, P7)board 1: 34b
120B2board 2: 37i (4014 B pin 14, P6)board 2: 24a (4511 B pin 2, C)
121B2board 2: 37j (4014 B pin 14, P6)board 1: 31e
122B3 (loose jumper)board 2: 36h (4014 B pin 13, P5)board 2: 20c (4511 B pin 6, D)
123B3board 2: 36j (4014 B pin 13, P5)board 1: 28e
124Q1Aboard 3: 33d (4015 pin 5, Q1A)board 3: 42d (4511 S pin 6, D)
125Q2Aboard 3: 34c (4015 pin 4, Q2A)board 3: 46c (4511 S pin 2, C)
126Q3Aboard 3: 35b (4015 pin 3, Q3A)board 3: 47b (4511 S pin 1, B)
127Q4Aboard 3: 31g (4015 pin 10, Q4A)board 3: 41a (4511 S pin 7, A)
Modules on male-female jumpers · 30 wires
128+5Vbutton A3, +board 1: top + rail, column 4
129A3button A3, OUTboard 1: 22a (4511 A pin 6, D)
130GNDbutton A3, −board 1: top − rail, column 6
131+5Vbutton A2, +board 1: top + rail, column 9
132A2button A2, OUTboard 1: 26a (4511 A pin 2, C)
133GNDbutton A2, −board 1: top − rail, column 11
134+5Vbutton A1, +board 1: top + rail, column 14
135A1button A1, OUTboard 1: 27a (4511 A pin 1, B)
136GNDbutton A1, −board 1: top − rail, column 16
137+5Vbutton A0, +board 1: top + rail, column 19
138A0button A0, OUTboard 1: 21a (4511 A pin 7, A)
139GNDbutton A0, −board 1: top − rail, column 21
140+5Vbutton B3, +board 1: top + rail, column 26
141B3button B3, OUTboard 1: 28a
142GNDbutton B3, −board 1: top − rail, column 27
143+5Vbutton B2, +board 1: top + rail, column 30
144B2button B2, OUTboard 1: 31a
145GNDbutton B2, −board 1: top − rail, column 32
146+5Vbutton B1, +board 1: top + rail, column 34
147B1button B1, OUTboard 1: 34a
148GNDbutton B1, −board 1: top − rail, column 37
149+5Vbutton B0, +board 1: top + rail, column 40
150B0button B0, OUTboard 1: 43a
151GNDbutton B0, −board 1: top − rail, column 42
152+5Vbutton LOAD, +board 1: top + rail, column 46
153LOADbutton LOAD, OUTboard 1: 42a (4014 A pin 9, P/S)
154GNDbutton LOAD, −board 1: top − rail, column 48
155GND555 clock module, −board 1: top − rail, column 52
156CLK555 clock module, OUTboard 1: 41a (4014 A pin 10, CLK)
157+5V555 clock module, +board 1: top + rail, column 54

Test it

If it does not work: if the sum is right only without carries, as in 1 + 2, the carry does not come back: check C' to D1 and Q1 to the gates. If a sum goes wrong only when you press LOAD in the middle of an addition, RESET1 does not get LOAD. If the sum is always 0, check the stream wires from the two Q8s.

8SystemVerilog: the generic design

serial_adder_gates.sv is the design of P1 with the full adder written as gates, one line per gate, and the carry as a flip-flop with an asynchronous reset, like the 4013. It is synthesizable.

serial_adder_gates.svfile
// Exercise P2: the bit-serial adder of P1, with the 4032 replaced by a full
// adder from gates and a D flip-flop for the carry.
//
// Generic version that matches schematic 1, not tied to any chip.
//
// load at a rising edge of clk puts a and b into the serializers.  At every
// later edge each serializer moves one bit out, lowest first, then zeros;
// the full adder adds the two bits and the carry, and the deserializer
// takes the sum bit.  load clears the carry flip-flop and the deserializer
// at once, as RESET of the 4013 and of the 4015 do.  After four edges sum
// holds a + b without the fifth bit, and later edges push it along.  Like
// the 4511, the decoders blank the codes 10-15.  Synthesizable.

module serial_adder_gates
(
    input  logic       clk,
    input  logic       load,
    input  logic [3:0] a,
    input  logic [3:0] b,

    output logic       serial_a,     // The bit of a on its way, like Q8 of the 4014
    output logic       serial_b,
    output logic       serial_sum,   // The sum bit
    output logic       carry,        // The carry flip-flop, like Q1 of the 4013

    output logic [3:0] sum,          // The deserializer, newest bit in sum [3]

    output logic [6:0] abcdefg_a,    // Segments a-g of each display: abcdefg [6] is a
    output logic [6:0] abcdefg_b,
    output logic [6:0] abcdefg_sum
);

    //------------------------------------------------------------------------
    // The serializers: the bits still to send, the next one at the bottom

    logic [3:0] shift_a, shift_b;

    always_ff @ (posedge clk)
        if (load)
        begin
            shift_a <= a;
            shift_b <= b;
        end
        else
        begin
            shift_a <= shift_a >> 1;
            shift_b <= shift_b >> 1;
        end

    assign serial_a = shift_a [0];
    assign serial_b = shift_b [0];

    //------------------------------------------------------------------------
    // The full adder of exercise M2 and a flip-flop for the carry

    wire p = serial_a ^ serial_b;   // 4070
    wire g = serial_a & serial_b;   // 4081
    wire t = p & carry;             // 4081

    assign serial_sum = p ^ carry;  // 4070

    always_ff @ (posedge clk or posedge load)
        if (load)
            carry <= 1'b0;
        else
            carry <= g | t;         // 4071, into D1 of the 4013

    //------------------------------------------------------------------------
    // The deserializer

    always_ff @ (posedge clk or posedge load)
        if (load)
            sum <= '0;
        else
            sum <= { serial_sum, sum [3:1] };

    //------------------------------------------------------------------------
    // Three decoders, like the 4511: codes 10-15 blank the display

    function automatic logic [6:0] decode (input logic [3:0] code);
        case (code)
        4'd0:    decode = 7'b111_1110;
        4'd1:    decode = 7'b011_0000;
        4'd2:    decode = 7'b110_1101;
        4'd3:    decode = 7'b111_1001;
        4'd4:    decode = 7'b011_0011;
        4'd5:    decode = 7'b101_1011;
        4'd6:    decode = 7'b001_1111;
        4'd7:    decode = 7'b111_0000;
        4'd8:    decode = 7'b111_1111;
        4'd9:    decode = 7'b111_0011;
        default: decode = 7'b000_0000;
        endcase
    endfunction

    assign abcdefg_a   = decode (a);
    assign abcdefg_b   = decode (b);
    assign abcdefg_sum = decode (sum);

endmodule

9SystemVerilog models of the chips

One module per chip, with ports named as in the datasheet and the pin number of each port in a comment. The models leave out the power pins: in SystemVerilog a wire simply has the value 0 or 1.

cd4511.svfile
// CD4511B: BCD-to-7-segment latch, decoder and driver.
//
// Ports in pin order, named as in the datasheet: BCD inputs A-D (A is the
// lowest bit), segment outputs a-g.  The power pins, VSS (8) and VDD (16),
// are left out.  Synthesizable; LATCH ENABLE makes a latch, which FPGA
// tools accept but warn about.
//
// The outputs drive a common-cathode display through resistors: 1 lights
// the segment.  Codes 10 to 15 blank the display.  The chip draws 6 without
// the top segment and 9 without the bottom one.
//
// LAMP TEST (active low) lights all segments; BLANKING (active low) turns
// them all off; LAMP TEST wins.  LATCH ENABLE: 0 = the decoder follows the
// inputs, 1 = it keeps the code it had when LATCH ENABLE rose.

module cd4511
(
    input  logic bcd_b,         // Pin 1
    input  logic bcd_c,         // Pin 2
    input  logic lamp_test_n,   // Pin 3:  0 = all segments on
    input  logic blank_n,       // Pin 4:  0 = all segments off
    input  logic latch_enable,  // Pin 5:  1 = hold the code
    input  logic bcd_d,         // Pin 6
    input  logic bcd_a,         // Pin 7
                                // Pin 8:  VSS
    output logic seg_e,         // Pin 9
    output logic seg_d,         // Pin 10
    output logic seg_c,         // Pin 11
    output logic seg_b,         // Pin 12
    output logic seg_a,         // Pin 13
    output logic seg_g,         // Pin 14
    output logic seg_f          // Pin 15
                                // Pin 16: VDD
);

    logic [3:0] code;

    // This is a latch, but Verilator 5 does not see it and warns
    // verilator lint_off NOLATCH

    always_latch
        if (~ latch_enable)
            code = { bcd_d, bcd_c, bcd_b, bcd_a };

    logic [6:0] abcdefg;

    always_comb
        if (~ lamp_test_n)
            abcdefg = 7'b111_1111;
        else if (~ blank_n)
            abcdefg = 7'b000_0000;
        else
            case (code)
            4'd0:    abcdefg = 7'b111_1110;
            4'd1:    abcdefg = 7'b011_0000;
            4'd2:    abcdefg = 7'b110_1101;
            4'd3:    abcdefg = 7'b111_1001;
            4'd4:    abcdefg = 7'b011_0011;
            4'd5:    abcdefg = 7'b101_1011;
            4'd6:    abcdefg = 7'b001_1111;  // No top segment
            4'd7:    abcdefg = 7'b111_0000;
            4'd8:    abcdefg = 7'b111_1111;
            4'd9:    abcdefg = 7'b111_0011;  // No bottom segment
            default: abcdefg = 7'b000_0000;  // 10-15: blank
            endcase

    assign { seg_a, seg_b, seg_c, seg_d, seg_e, seg_f, seg_g } = abcdefg;

endmodule
cd4014.svfile
// CD4014B: 8-stage static shift register, synchronous parallel or serial
// input, serial output.
//
// Ports in pin order, named as in the datasheet.  The power pins, VSS (8)
// and VDD (16), are left out.  Synthesizable.
//
// Everything happens on the rising edge of CLOCK.  With PARALLEL/SERIAL
// CONTROL = 1 the edge loads P1-P8 into the eight stages; with 0 it shifts:
// SERIAL IN goes into stage 1 and every stage takes the bit of the stage
// before it.  Q8, the output of the last stage, is the serial output; Q6 and
// Q7 are there too.  The chip has no reset.

module cd4014
(
    input  logic p8,               // Pin 1
    output logic q6,               // Pin 2
    output logic q8,               // Pin 3
    input  logic p4,               // Pin 4
    input  logic p3,               // Pin 5
    input  logic p2,               // Pin 6
    input  logic p1,               // Pin 7
                                   // Pin 8:  VSS
    input  logic parallel_serial,  // Pin 9:  1 = load, 0 = shift
    input  logic clock,            // Pin 10
    input  logic serial_in,        // Pin 11
    output logic q7,               // Pin 12
    input  logic p5,               // Pin 13
    input  logic p6,               // Pin 14
    input  logic p7                // Pin 15
                                   // Pin 16: VDD
);

    logic [8:1] stage;

    always_ff @ (posedge clock)
        if (parallel_serial)
            stage <= { p8, p7, p6, p5, p4, p3, p2, p1 };
        else
            stage <= { stage [7:1], serial_in };

    assign q6 = stage [6];
    assign q7 = stage [7];
    assign q8 = stage [8];

endmodule
cd4013.svfile
// CD4013B: dual D flip-flop with set and reset.
//
// Ports in pin order, named as in the datasheet.  The power pins, VSS (7)
// and VDD (14), are left out.  Synthesizable.
//
// Each flip-flop stores D at the rising edge of its clock.  SET and RESET
// are active high and asynchronous: they act at once, without the clock.
// With SET and RESET both high the chip sets both Q and ~Q high; the model
// does the same while they are both high.  Do not release them at the same
// moment: which of the two wins is not defined.

module cd4013
(
    output logic q1,      // Pin 1
    output logic q1_n,    // Pin 2:  ~Q1
    input  logic clock1,  // Pin 3
    input  logic reset1,  // Pin 4:  1 = Q1 goes to 0 at once
    input  logic d1,      // Pin 5
    input  logic set1,    // Pin 6:  1 = Q1 goes to 1 at once
                          // Pin 7:  VSS
    input  logic set2,    // Pin 8
    input  logic d2,      // Pin 9
    input  logic reset2,  // Pin 10
    input  logic clock2,  // Pin 11
    output logic q2_n,    // Pin 12: ~Q2
    output logic q2       // Pin 13
                          // Pin 14: VDD
);

    logic r1, r2;

    always_ff @ (posedge clock1 or posedge reset1 or posedge set1)
        if (reset1)
            r1 <= 1'b0;
        else if (set1)
            r1 <= 1'b1;
        else
            r1 <= d1;

    always_ff @ (posedge clock2 or posedge reset2 or posedge set2)
        if (reset2)
            r2 <= 1'b0;
        else if (set2)
            r2 <= 1'b1;
        else
            r2 <= d2;

    assign q1   =   r1 | (set1 & reset1);
    assign q1_n = ~ r1 | (set1 & reset1);
    assign q2   =   r2 | (set2 & reset2);
    assign q2_n = ~ r2 | (set2 & reset2);

endmodule
cd4070.svfile
// CD4070B: quad 2-input exclusive-OR (XOR) gate.
//
// Ports in pin order, named as in the datasheet.  The power pins, VSS (7)
// and VDD (14), are left out.  Synthesizable.
//
// The 4070, 4071 and 4081 have the same pinout: only the function of the
// gates differs.

module cd4070
(
    input  logic a,  // Pin 1
    input  logic b,  // Pin 2
    output logic j,  // Pin 3:  j = a ^ b
    output logic k,  // Pin 4:  k = c ^ d
    input  logic c,  // Pin 5
    input  logic d,  // Pin 6
                     // Pin 7:  VSS
    input  logic e,  // Pin 8
    input  logic f,  // Pin 9
    output logic l,  // Pin 10: l = e ^ f
    output logic m,  // Pin 11: m = g ^ h
    input  logic g,  // Pin 12
    input  logic h   // Pin 13
                     // Pin 14: VDD
);

    assign j = a ^ b;
    assign k = c ^ d;
    assign l = e ^ f;
    assign m = g ^ h;

endmodule
cd4081.svfile
// CD4081B: quad 2-input AND gate.
//
// Ports in pin order, named as in the datasheet.  The power pins, VSS (7)
// and VDD (14), are left out.  Synthesizable.
//
// The 4081, 4071 and 4070 have the same pinout: only the function of the
// gates differs.

module cd4081
(
    input  logic a,  // Pin 1
    input  logic b,  // Pin 2
    output logic j,  // Pin 3:  j = a & b
    output logic k,  // Pin 4:  k = c & d
    input  logic c,  // Pin 5
    input  logic d,  // Pin 6
                     // Pin 7:  VSS
    input  logic e,  // Pin 8
    input  logic f,  // Pin 9
    output logic l,  // Pin 10: l = e & f
    output logic m,  // Pin 11: m = g & h
    input  logic g,  // Pin 12
    input  logic h   // Pin 13
                     // Pin 14: VDD
);

    assign j = a & b;
    assign k = c & d;
    assign l = e & f;
    assign m = g & h;

endmodule
cd4071.svfile
// CD4071B: quad 2-input OR gate.
//
// Ports in pin order, named as in the datasheet.  The power pins, VSS (7)
// and VDD (14), are left out.  Synthesizable.

module cd4071
(
    input  logic a,  // Pin 1
    input  logic b,  // Pin 2
    output logic j,  // Pin 3:  j = a | b
    output logic k,  // Pin 4:  k = c | d
    input  logic c,  // Pin 5
    input  logic d,  // Pin 6
                     // Pin 7:  VSS
    input  logic e,  // Pin 8
    input  logic f,  // Pin 9
    output logic l,  // Pin 10: l = e | f
    output logic m,  // Pin 11: m = g | h
    input  logic g,  // Pin 12
    input  logic h   // Pin 13
                     // Pin 14: VDD
);

    assign j = a | b;
    assign k = c | d;
    assign l = e | f;
    assign m = g | h;

endmodule
cd4015.svfile
// CD4015B: dual 4-stage shift register, serial input, parallel output.
//
// Ports in pin order, named as in the datasheet.  The power pins, VSS (8)
// and VDD (16), are left out.  Synthesizable.
//
// Each register shifts on the rising edge of its clock: DATA goes into Q1,
// Q1 into Q2, Q2 into Q3, Q3 into Q4.  RESET is active high and
// asynchronous: it clears all four stages at once, without the clock.
// Connect Q4A to DATA B to make one 8-stage register.

module cd4015
(
    input  logic clock_b,  // Pin 1
    output logic q4b,      // Pin 2
    output logic q3a,      // Pin 3
    output logic q2a,      // Pin 4
    output logic q1a,      // Pin 5
    input  logic reset_a,  // Pin 6:  1 = Q1A-Q4A go to 0 at once
    input  logic data_a,   // Pin 7
                           // Pin 8:  VSS
    input  logic clock_a,  // Pin 9
    output logic q4a,      // Pin 10
    output logic q3b,      // Pin 11
    output logic q2b,      // Pin 12
    output logic q1b,      // Pin 13
    input  logic reset_b,  // Pin 14: 1 = Q1B-Q4B go to 0 at once
    input  logic data_b    // Pin 15
                           // Pin 16: VDD
);

    logic [4:1] ra, rb;  // ra [1] is Q1A, ra [4] is Q4A

    always_ff @ (posedge clock_a or posedge reset_a)
        if (reset_a)
            ra <= '0;
        else
            ra <= { ra [3:1], data_a };

    always_ff @ (posedge clock_b or posedge reset_b)
        if (reset_b)
            rb <= '0;
        else
            rb <= { rb [3:1], data_b };

    assign { q4a, q3a, q2a, q1a } = ra;
    assign { q4b, q3b, q2b, q1b } = rb;

endmodule

10SystemVerilog: the chip-level design

serial_adder_gates_chips.sv connects the chip models exactly as schematic 2 and the breadboard connect the chips, with the same ports as serial_adder_gates.sv. Unused inputs are tied to vdd or gnd as on the breadboard, and unused outputs go to wires named unused_…. The file is generated from the breadboard wire list after a pin-level check of that list, so the code, the drawings and the checklist cannot disagree.

serial_adder_gates_chips.svfile
// Exercise P2, chip-level version: the chips and wires of schematic 2 and
// of the breadboard.  Same ports as serial_adder_gates.sv.
//
// Generated by tools/bb_lib.py from the checked breadboard wire list;
// change the layout in tools/bb_p2.py, not this file.  Synthesizable.

module serial_adder_gates_chips
(
    input  logic       clk,
    input  logic       load,
    input  logic [3:0] a,
    input  logic [3:0] b,
    output logic       serial_a,
    output logic       serial_b,
    output logic       serial_sum,
    output logic       carry,
    output logic [3:0] sum,
    output logic [6:0] abcdefg_a,
    output logic [6:0] abcdefg_b,
    output logic [6:0] abcdefg_sum
);

    // Connections between the chips that are not ports

    wire co;
    wire t;
    wire g;
    wire p;

    // The power rails of the breadboard, for tied-off inputs

    wire gnd = 1'b0;
    wire vdd = 1'b1;

    // Outputs that go nowhere

    wire unused_usa_q6;
    wire unused_usa_q7;
    wire unused_usb_q6;
    wire unused_usb_q7;
    wire unused_uff_q1_n;
    wire unused_uff_q2_n;
    wire unused_uff_q2;
    wire unused_uo_j;
    wire unused_uo_k;
    wire unused_uo_m;
    wire unused_ua_j;
    wire unused_ua_l;
    wire unused_ux_l;
    wire unused_ux_m;
    wire unused_u15_q4b;
    wire unused_u15_q3b;
    wire unused_u15_q2b;
    wire unused_u15_q1b;

    //------------------------------------------------------------------------

    // UDA: CD4511 BCD-to-7-segment latch, decoder and driver, pin 1 in column 20 of board 1

    cd4511 i_uda
    (
        .bcd_b        ( a [1]         ),  // Pin 1 <- button A1
        .bcd_c        ( a [2]         ),  // Pin 2 <- button A2
        .lamp_test_n  ( vdd           ),  // Pin 3 <- +5V
        .blank_n      ( vdd           ),  // Pin 4 <- +5V
        .latch_enable ( gnd           ),  // Pin 5 <- GND
        .bcd_d        ( a [3]         ),  // Pin 6 <- button A3
        .bcd_a        ( a [0]         ),  // Pin 7 <- button A0
        .seg_e        ( abcdefg_a [2] ),  // Pin 9 -> A.e
        .seg_d        ( abcdefg_a [3] ),  // Pin 10 -> A.d
        .seg_c        ( abcdefg_a [4] ),  // Pin 11 -> A.c
        .seg_b        ( abcdefg_a [5] ),  // Pin 12 -> A.b
        .seg_a        ( abcdefg_a [6] ),  // Pin 13 -> A.a
        .seg_g        ( abcdefg_a [0] ),  // Pin 14 -> A.g
        .seg_f        ( abcdefg_a [1] )   // Pin 15 -> A.f
    );

    //------------------------------------------------------------------------

    // USA: CD4014 8-stage shift register, parallel or serial in, serial out, pin 1 in column 35 of board 1

    cd4014 i_usa
    (
        .p8              ( a [0]         ),  // Pin 1 <- button A0
        .q6              ( unused_usa_q6 ),  // Pin 2, unused output
        .q8              ( serial_a      ),  // Pin 3 -> A→
        .p4              ( gnd           ),  // Pin 4 <- GND
        .p3              ( gnd           ),  // Pin 5 <- GND
        .p2              ( gnd           ),  // Pin 6 <- GND
        .p1              ( gnd           ),  // Pin 7 <- GND
        .parallel_serial ( load          ),  // Pin 9 <- button LOAD
        .clock           ( clk           ),  // Pin 10 <- 555 clock module
        .serial_in       ( gnd           ),  // Pin 11 <- GND
        .q7              ( unused_usa_q7 ),  // Pin 12, unused output
        .p5              ( a [3]         ),  // Pin 13 <- button A3
        .p6              ( a [2]         ),  // Pin 14 <- button A2
        .p7              ( a [1]         )   // Pin 15 <- button A1
    );

    //------------------------------------------------------------------------

    // UDB: CD4511 BCD-to-7-segment latch, decoder and driver, pin 1 in column 18 of board 2

    cd4511 i_udb
    (
        .bcd_b        ( b [1]         ),  // Pin 1 <- button B1
        .bcd_c        ( b [2]         ),  // Pin 2 <- button B2
        .lamp_test_n  ( vdd           ),  // Pin 3 <- +5V
        .blank_n      ( vdd           ),  // Pin 4 <- +5V
        .latch_enable ( gnd           ),  // Pin 5 <- GND
        .bcd_d        ( b [3]         ),  // Pin 6 <- button B3
        .bcd_a        ( b [0]         ),  // Pin 7 <- button B0
        .seg_e        ( abcdefg_b [2] ),  // Pin 9 -> B.e
        .seg_d        ( abcdefg_b [3] ),  // Pin 10 -> B.d
        .seg_c        ( abcdefg_b [4] ),  // Pin 11 -> B.c
        .seg_b        ( abcdefg_b [5] ),  // Pin 12 -> B.b
        .seg_a        ( abcdefg_b [6] ),  // Pin 13 -> B.a
        .seg_g        ( abcdefg_b [0] ),  // Pin 14 -> B.g
        .seg_f        ( abcdefg_b [1] )   // Pin 15 -> B.f
    );

    //------------------------------------------------------------------------

    // USB: CD4014 8-stage shift register, parallel or serial in, serial out, pin 1 in column 32 of board 2

    cd4014 i_usb
    (
        .p8              ( b [0]         ),  // Pin 1 <- button B0
        .q6              ( unused_usb_q6 ),  // Pin 2, unused output
        .q8              ( serial_b      ),  // Pin 3 -> B→
        .p4              ( gnd           ),  // Pin 4 <- GND
        .p3              ( gnd           ),  // Pin 5 <- GND
        .p2              ( gnd           ),  // Pin 6 <- GND
        .p1              ( gnd           ),  // Pin 7 <- GND
        .parallel_serial ( load          ),  // Pin 9 <- button LOAD
        .clock           ( clk           ),  // Pin 10 <- 555 clock module
        .serial_in       ( gnd           ),  // Pin 11 <- GND
        .q7              ( unused_usb_q7 ),  // Pin 12, unused output
        .p5              ( b [3]         ),  // Pin 13 <- button B3
        .p6              ( b [2]         ),  // Pin 14 <- button B2
        .p7              ( b [1]         )   // Pin 15 <- button B1
    );

    //------------------------------------------------------------------------

    // UFF: CD4013 dual D flip-flop with set and reset, pin 1 in column 43 of board 2

    cd4013 i_uff
    (
        .q1     ( carry           ),  // Pin 1 -> C
        .q1_n   ( unused_uff_q1_n ),  // Pin 2, unused output
        .clock1 ( clk             ),  // Pin 3 <- 555 clock module
        .reset1 ( load            ),  // Pin 4 <- button LOAD
        .d1     ( co              ),  // Pin 5 <- UO pin 10 (L)
        .set1   ( gnd             ),  // Pin 6 <- GND
        .set2   ( vdd             ),  // Pin 8 <- +5V, unused input
        .d2     ( vdd             ),  // Pin 9 <- +5V, unused input
        .reset2 ( vdd             ),  // Pin 10 <- +5V, unused input
        .clock2 ( vdd             ),  // Pin 11 <- +5V, unused input
        .q2_n   ( unused_uff_q2_n ),  // Pin 12, unused output
        .q2     ( unused_uff_q2   )   // Pin 13, unused output
    );

    //------------------------------------------------------------------------

    // UO: CD4071 quad 2-input OR, pin 1 in column 4 of board 3

    cd4071 i_uo
    (
        .a ( gnd         ),  // Pin 1 <- GND, unused input
        .b ( gnd         ),  // Pin 2 <- GND, unused input
        .j ( unused_uo_j ),  // Pin 3, unused output
        .k ( unused_uo_k ),  // Pin 4, unused output
        .c ( gnd         ),  // Pin 5 <- GND, unused input
        .d ( gnd         ),  // Pin 6 <- GND, unused input
        .e ( t           ),  // Pin 8 <- UA pin 11 (M)
        .f ( g           ),  // Pin 9 <- UA pin 4 (K)
        .l ( co          ),  // Pin 10 -> C'
        .m ( unused_uo_m ),  // Pin 11, unused output
        .g ( vdd         ),  // Pin 12 <- +5V, unused input
        .h ( vdd         )   // Pin 13 <- +5V, unused input
    );

    //------------------------------------------------------------------------

    // UA: CD4081 quad 2-input AND, pin 1 in column 12 of board 3

    cd4081 i_ua
    (
        .a ( vdd         ),  // Pin 1 <- +5V, unused input
        .b ( vdd         ),  // Pin 2 <- +5V, unused input
        .j ( unused_ua_j ),  // Pin 3, unused output
        .k ( g           ),  // Pin 4 -> G
        .c ( serial_b    ),  // Pin 5 <- USB pin 3 (Q8)
        .d ( serial_a    ),  // Pin 6 <- USA pin 3 (Q8)
        .e ( gnd         ),  // Pin 8 <- GND, unused input
        .f ( gnd         ),  // Pin 9 <- GND, unused input
        .l ( unused_ua_l ),  // Pin 10, unused output
        .m ( t           ),  // Pin 11 -> T
        .g ( p           ),  // Pin 12 <- UX pin 3 (J)
        .h ( carry       )   // Pin 13 <- UFF pin 1 (Q1)
    );

    //------------------------------------------------------------------------

    // UX: CD4070 quad 2-input XOR, pin 1 in column 21 of board 3

    cd4070 i_ux
    (
        .a ( serial_b    ),  // Pin 1 <- USB pin 3 (Q8)
        .b ( serial_a    ),  // Pin 2 <- USA pin 3 (Q8)
        .j ( p           ),  // Pin 3 -> P
        .k ( serial_sum  ),  // Pin 4 -> S→
        .c ( carry       ),  // Pin 5 <- UFF pin 1 (Q1)
        .d ( p           ),  // Pin 6 <- UX pin 3 (J)
        .e ( gnd         ),  // Pin 8 <- GND, unused input
        .f ( gnd         ),  // Pin 9 <- GND, unused input
        .l ( unused_ux_l ),  // Pin 10, unused output
        .m ( unused_ux_m ),  // Pin 11, unused output
        .g ( gnd         ),  // Pin 12 <- GND, unused input
        .h ( gnd         )   // Pin 13 <- GND, unused input
    );

    //------------------------------------------------------------------------

    // U15: CD4015 dual 4-stage shift register, serial in, parallel out, pin 1 in column 30 of board 3

    cd4015 i_u15
    (
        .clock_b ( vdd            ),  // Pin 1 <- +5V, unused input
        .q4b     ( unused_u15_q4b ),  // Pin 2, unused output
        .q3a     ( sum [1]        ),  // Pin 3 -> Q3A
        .q2a     ( sum [2]        ),  // Pin 4 -> Q2A
        .q1a     ( sum [3]        ),  // Pin 5 -> Q1A
        .reset_a ( load           ),  // Pin 6 <- button LOAD
        .data_a  ( serial_sum     ),  // Pin 7 <- UX pin 4 (K)
        .clock_a ( clk            ),  // Pin 9 <- 555 clock module
        .q4a     ( sum [0]        ),  // Pin 10 -> Q4A
        .q3b     ( unused_u15_q3b ),  // Pin 11, unused output
        .q2b     ( unused_u15_q2b ),  // Pin 12, unused output
        .q1b     ( unused_u15_q1b ),  // Pin 13, unused output
        .reset_b ( gnd            ),  // Pin 14 <- GND, unused input
        .data_b  ( gnd            )   // Pin 15 <- GND, unused input
    );

    //------------------------------------------------------------------------

    // UDS: CD4511 BCD-to-7-segment latch, decoder and driver, pin 1 in column 40 of board 3

    cd4511 i_uds
    (
        .bcd_b        ( sum [1]         ),  // Pin 1 <- U15 pin 3 (Q3A)
        .bcd_c        ( sum [2]         ),  // Pin 2 <- U15 pin 4 (Q2A)
        .lamp_test_n  ( vdd             ),  // Pin 3 <- +5V
        .blank_n      ( vdd             ),  // Pin 4 <- +5V
        .latch_enable ( gnd             ),  // Pin 5 <- GND
        .bcd_d        ( sum [3]         ),  // Pin 6 <- U15 pin 5 (Q1A)
        .bcd_a        ( sum [0]         ),  // Pin 7 <- U15 pin 10 (Q4A)
        .seg_e        ( abcdefg_sum [2] ),  // Pin 9 -> S.e
        .seg_d        ( abcdefg_sum [3] ),  // Pin 10 -> S.d
        .seg_c        ( abcdefg_sum [4] ),  // Pin 11 -> S.c
        .seg_b        ( abcdefg_sum [5] ),  // Pin 12 -> S.b
        .seg_a        ( abcdefg_sum [6] ),  // Pin 13 -> S.a
        .seg_g        ( abcdefg_sum [0] ),  // Pin 14 -> S.g
        .seg_f        ( abcdefg_sum [1] )   // Pin 15 -> S.f
    );

endmodule

11Testbench and simulation scripts

tb.sv is the testbench of P1 with one more output to check, the carry, which it computes from the lower bits of A and B. Like the testbenches of Basics-Graphics-Music, it drives and checks signals only at rising clock edges. The output below is shortened.

tb.sv270 lines · show the codefile
// Testbench for exercise P2.
//
// Runs the generic design (serial_adder_gates.sv) and the chip-level design
// (serial_adder_gates_chips.sv) side by side and compares both with a reference
// model that knows the answer in advance: at LOAD it takes a + b, and the
// bit streams are the bits of the numbers and of the sum, lowest first.
// Works with Icarus Verilog, Verilator (--binary) and Questa.
//
// Like the testbenches of Basics-Graphics-Music, it drives and samples
// signals only at rising clock edges.  It adds chosen and pseudo-random
// pairs, holds LOAD for several edges once, and checks the bit streams,
// the carry, the deserializer and the three displays at every edge.

// Time units.  The design files have none: Yosys does not accept timeunit
// and timeprecision, and the Tiny Tapeout template sets `timescale 1ns / 1ps
// in its own testbench.  This line sets the same units here and for the
// design files compiled after it, so tb.sv comes first in the file list.

`timescale 1ns / 1ps

module tb;

    // load is a synchronous load and an asynchronous clear, as on the
    // breadboard

    // verilator lint_off SYNCASYNCNET

    logic       clk;
    logic       load = 1'b0;
    logic [3:0] a    = '0;
    logic [3:0] b    = '0;

    wire        serial_a,    serial_a_chips;
    wire        serial_b,    serial_b_chips;
    wire        serial_sum,  serial_sum_chips;
    wire        carry,       carry_chips;
    wire  [3:0] sum,         sum_chips;
    wire  [6:0] abcdefg_a,   abcdefg_a_chips;
    wire  [6:0] abcdefg_b,   abcdefg_b_chips;
    wire  [6:0] abcdefg_sum, abcdefg_sum_chips;

    serial_adder_gates i_generic
    (
        .clk         ( clk         ),
        .load        ( load        ),
        .a           ( a           ),
        .b           ( b           ),
        .serial_a    ( serial_a    ),
        .serial_b    ( serial_b    ),
        .serial_sum  ( serial_sum  ),
        .carry       ( carry       ),
        .sum         ( sum         ),
        .abcdefg_a   ( abcdefg_a   ),
        .abcdefg_b   ( abcdefg_b   ),
        .abcdefg_sum ( abcdefg_sum )
    );

    serial_adder_gates_chips i_chips
    (
        .clk         ( clk               ),
        .load        ( load              ),
        .a           ( a                 ),
        .b           ( b                 ),
        .serial_a    ( serial_a_chips    ),
        .serial_b    ( serial_b_chips    ),
        .serial_sum  ( serial_sum_chips  ),
        .carry       ( carry_chips       ),
        .sum         ( sum_chips         ),
        .abcdefg_a   ( abcdefg_a_chips   ),
        .abcdefg_b   ( abcdefg_b_chips   ),
        .abcdefg_sum ( abcdefg_sum_chips )
    );

    //------------------------------------------------------------------------
    // Clock with a period of 10 ns.
    // On the breadboard one period is about a second.

    initial
    begin
        clk = '0;

        forever
            # 5 clk = ~ clk;
    end

    //------------------------------------------------------------------------
    // Reference model: the numbers taken at the last LOAD edge, their sum,
    // and the number of edges since then

    logic [3:0] a_loaded, b_loaded;
    int         k;

    always @ (posedge clk)
        if (load)
        begin
            a_loaded <= a;
            b_loaded <= b;
            k        <= 0;
        end
        else
            k <= k + 1;

    wire [4:0] total = 5' (a_loaded) + 5' (b_loaded);

    function automatic logic bit_of (input logic [4:0] value, input int i);
        return i >= 0 && i < 5 ? value [i] : 1'b0;
    endfunction

    // After k edges the deserializer holds the sum bits k-1 (in sum [3])
    // down to k-4; LOAD at 1 clears it at once

    logic [3:0] sum_expected;

    always_comb
        for (int i = 0; i < 4; i ++)
            sum_expected [3 - i] = ~ load & bit_of (total, k - 1 - i);

    function automatic logic [6:0] digit (input logic [3:0] code);
        case (code)
        4'd0:    digit = 7'b111_1110;
        4'd1:    digit = 7'b011_0000;
        4'd2:    digit = 7'b110_1101;
        4'd3:    digit = 7'b111_1001;
        4'd4:    digit = 7'b011_0011;
        4'd5:    digit = 7'b101_1011;
        4'd6:    digit = 7'b001_1111;
        4'd7:    digit = 7'b111_0000;
        4'd8:    digit = 7'b111_1111;
        4'd9:    digit = 7'b111_0011;
        default: digit = 7'b000_0000;
        endcase
    endfunction

    // The carry into bit k: the carry out of the lower k bits.  LOAD at 1
    // clears the carry flip-flop at once, as RESET of the 4013.

    function automatic logic carry_into (input logic [3:0] x, input logic [3:0] y, input int i);
        logic [4:0] low;

        low = i <= 0 ? 5'd0 : i >= 5 ? 5' (x) + 5' (y) : 5' (x & 4' ((1 << i) - 1)) + 5' (y & 4' ((1 << i) - 1));
        return i >= 1 && i <= 4 ? low [i] : 1'b0;
    endfunction

    wire carry_expected = ~ load & carry_into (a_loaded, b_loaded, k);

    wire serial_a_expected = bit_of (5' (a_loaded), k);
    wire serial_b_expected = bit_of (5' (b_loaded), k);

    wire [28:0] expected = { serial_a_expected, serial_b_expected,
                             serial_a_expected ^ serial_b_expected ^ carry_expected, carry_expected,
                             sum_expected, digit (a), digit (b), digit (sum_expected) };

    wire [28:0] out       = { serial_a, serial_b, serial_sum, carry, sum, abcdefg_a, abcdefg_b, abcdefg_sum };
    wire [28:0] out_chips = { serial_a_chips, serial_b_chips, serial_sum_chips, carry_chips, sum_chips,
                              abcdefg_a_chips, abcdefg_b_chips, abcdefg_sum_chips };

    wire ok_generic = out       === expected;
    wire ok_chips   = out_chips === expected;

    //------------------------------------------------------------------------
    // Checking at every rising clock edge, from the first LOAD on.  At the
    // edge both designs and the model still show the clock cycle that ends
    // there, the same values that a flip-flop would sample.

    // Initial values are fine in a testbench, and the checker samples load
    // at the clock edge on purpose, although it clears the deserializer at
    // once

    // verilator lint_off PROCASSINIT

    logic was_loaded = 1'b0;
    logic done       = 1'b0;  // Set by the stimulus before $finish

    int cycle    = 0;
    int n_checks = 0;
    int n_errors = 0;
    int n_sums   = 0;  // Complete sums seen in the deserializer
    int n_carry  = 0;  // Sums with a fifth bit

    always @ (posedge clk)
    begin
        if (load)
            was_loaded <= 1'b1;

        if (was_loaded & ~ done)
        begin
            cycle    <= cycle + 1;
            n_checks <= n_checks + 2;
            n_errors <= n_errors + (ok_generic ? 0 : 1) + (ok_chips ? 0 : 1);

            if (~ load && k == 4)
            begin
                n_sums  <= n_sums + 1;
                n_carry <= n_carry + (total [4] ? 1 : 0);
            end

            $display ("%5d  %b     %2d  %2d   %b  %b  %b  %b   %b  %s  %s",
                cycle + 1, load, a, b, serial_a, serial_b, carry, serial_sum, sum,
                ok_generic ? "ok     " : "WRONG  ", ok_chips ? "ok" : "WRONG");
        end
    end

    //------------------------------------------------------------------------
    // Driving the inputs

    // One addition: set the buttons, press LOAD through one or more edges,
    // then let six edges pass

    task automatic add (input logic [3:0] x, input logic [3:0] y, input int load_edges);
        a    <= x;
        b    <= y;
        load <= 1'b1;
        repeat (load_edges) @ (posedge clk);
        load <= 1'b0;
        repeat (6) @ (posedge clk);
    endtask

    logic [31:0] seed = 32'd13;

    initial
    begin
        $dumpfile ("tb.vcd");

        `ifdef __ICARUS__
            $dumpvars (0, tb);  // Without a scope Icarus also tries to dump $unit
        `else
            $dumpvars;
        `endif

        $display ("cycle  LOAD   A   B   A> B> C  S>  4015  generic  chips");

        // Before the first LOAD the registers are unknown, as after power-up

        repeat (2) @ (posedge clk);

        add ( 5,  3, 1);  // The example of section 2
        add ( 9,  8, 1);  // 17: a fifth bit
        add (15, 15, 1);
        add ( 0,  0, 1);
        add ( 7,  2, 3);  // LOAD held for three edges

        // Pseudo-random pairs, the same in every simulator

        for (int i = 0; i < 10; i ++)
        begin
            seed = seed * 32'd1664525 + 32'd1013904223;
            add (seed [31:28], seed [27:24], 1);
        end

        // Stop checking one clock edge before $finish, so that every
        // simulator reports the same number of checks

        done <= '1;
        @ (posedge clk);

        $finish;
    end

    //------------------------------------------------------------------------

    final
    begin
        if (n_errors == 0 && n_sums == 15 && n_carry >= 2)
            $display ("PASS: %0d checks, no errors", n_checks);
        else
            $display ("FAIL: %0d errors in %0d checks, %0d sums, %0d with a fifth bit", n_errors, n_checks, n_sums,
                      n_carry);
    end

endmodule

Each script compiles the files, runs the simulation, writes a log and the waveform tb.vcd, and exits with an error unless the test passes. Run them from any directory: ./run_icarus.bash, ./run_verilator.bash or ./run_questa.bash; ./clean.bash removes what they make. The waveform opens in GTKWave or Surfer.

run_icarus.bash22 lines · show the codefile
#!/usr/bin/env bash

# Exercise P2: run the testbench with Icarus Verilog 12 or later.
# The output goes to icarus.log and the waveform to tb.vcd,
# for GTKWave or Surfer.

set -Eeuo pipefail

cd "$(dirname "$0")"

files=(tb.sv serial_adder_gates.sv serial_adder_gates_chips.sv cd4511.sv cd4014.sv cd4013.sv cd4071.sv cd4081.sv cd4070.sv cd4015.sv)

if ! command -v iverilog > /dev/null
then
    printf '%s\n' "$0: iverilog not found, install Icarus Verilog 12 or later" >&2
    exit 1
fi

iverilog -g2012 -o tb.vvp "${files[@]}"
vvp -n tb.vvp | tee icarus.log

grep -q '^PASS' icarus.log
run_verilator.bash29 lines · show the codefile
#!/usr/bin/env bash

# Exercise P2: run the testbench with Verilator 5.  --binary builds
# a simulator with the testbench's delays; it needs a C++20 compiler.
# The output goes to verilator.log and the waveform to tb.vcd.

set -Eeuo pipefail

cd "$(dirname "$0")"

files=(tb.sv serial_adder_gates.sv serial_adder_gates_chips.sv cd4511.sv cd4014.sv cd4013.sv cd4071.sv cd4081.sv cd4070.sv cd4015.sv)

# OSS CAD Suite unpacked in the home directory has Verilator too

if ! command -v verilator > /dev/null && [ -x "$HOME/oss-cad-suite/bin/verilator" ]
then
    PATH="$HOME/oss-cad-suite/bin:$PATH"
fi

if ! command -v verilator > /dev/null
then
    printf '%s\n' "$0: verilator not found, install Verilator 5" >&2
    exit 1
fi

verilator --binary -Wall --trace --top-module tb -o tb "${files[@]}"
obj_dir/tb | tee verilator.log

grep -q '^PASS' verilator.log
run_questa.bash64 lines · show the codefile
#!/usr/bin/env bash

# Exercise P2: run the testbench with Questa, for example the free
# Questa Starter Edition that comes with Quartus Prime Lite.
# The output goes to questa.log and the waveform to tb.vcd.

set -Eeuo pipefail

cd "$(dirname "$0")"

files=(tb.sv serial_adder_gates.sv serial_adder_gates_chips.sv cd4511.sv cd4014.sv cd4013.sv cd4071.sv cd4081.sv cd4070.sv cd4015.sv)

# When vsim is not in PATH, look for it where Quartus installs it

if ! command -v vsim > /dev/null
then
    for dir in "$HOME"/intelFPGA_lite/*/questa_fse/bin  \
               "$HOME"/altera_lite/*/questa_fse/bin     \
               /opt/intelFPGA_lite/*/questa_fse/bin     \
               /opt/altera_lite/*/questa_fse/bin
    do
        if [ -x "$dir/vsim" ]
        then
            PATH="$dir:$PATH"
            break
        fi
    done
fi

if ! command -v vsim > /dev/null
then
    printf '%s\n' "$0: vsim not found, install Questa or add it to PATH" >&2
    exit 1
fi

# The Starter Edition needs a free license file from the Intel
# licensing site; Quartus keeps it in ~/flexlm/license.dat

license="$HOME/flexlm/license.dat"

# ${SALT_LICENSE_SERVER-} is empty when the variable is not set,
# where a plain $SALT_LICENSE_SERVER would stop the script (set -u)
salt_license="${SALT_LICENSE_SERVER-}"

if [ -z "$salt_license" ] && [ -f "$license" ]
then
    export SALT_LICENSE_SERVER="$license"
fi

# Older Questa versions read LM_LICENSE_FILE; ${LM_LICENSE_FILE-}
# is empty when the variable is not set
lm_license="${LM_LICENSE_FILE-}"

if [ -z "$lm_license" ] && [ -f "$license" ]
then
    export LM_LICENSE_FILE="$license"
fi

rm -rf work
vlib work > /dev/null
vlog -sv -lint "${files[@]}"
vsim -c tb -do "run -all; quit -f" | tee questa.log

grep -q 'PASS' questa.log

Tested with Icarus Verilog 12.0 and 14.0 (development), Verilator 5.053 with -Wall and no warnings, and Questa Altera Starter FPGA Edition 2025.2 from Quartus Prime Lite 25.1. The code uses only what Icarus Verilog 13 supports. This is the output, from Icarus Verilog:

VCD info: dumpfile tb.vcd opened for output.
cycle  LOAD   A   B   A> B> C  S>  4015  generic  chips
    1  0      5   3   1  1  0  0   0000  ok          ok
    2  0      5   3   0  1  1  0   0000  ok          ok
    3  0      5   3   1  0  1  0   0000  ok          ok
    4  0      5   3   0  0  1  1   0000  ok          ok
    5  0      5   3   0  0  0  0   1000  ok          ok
    6  0      5   3   0  0  0  0   0100  ok          ok
    7  1      9   8   0  0  0  0   0000  ok          ok
    8  0      9   8   1  0  0  1   0000  ok          ok
    9  0      9   8   0  0  0  0   1000  ok          ok
   10  0      9   8   0  0  0  0   0100  ok          ok
   11  0      9   8   1  1  0  0   0010  ok          ok
   12  0      9   8   0  0  1  1   0001  ok          ok
   13  0      9   8   0  0  0  0   1000  ok          ok
   14  1     15  15   0  0  0  0   0000  ok          ok
   15  0     15  15   1  1  0  0   0000  ok          ok
   16  0     15  15   1  1  1  1   0000  ok          ok
   17  0     15  15   1  1  1  1   1000  ok          ok
   18  0     15  15   1  1  1  1   1100  ok          ok
   19  0     15  15   0  0  1  1   1110  ok          ok
   20  0     15  15   0  0  0  0   1111  ok          ok
   21  1      0   0   0  0  0  0   0000  ok          ok
   22  0      0   0   0  0  0  0   0000  ok          ok
   23  0      0   0   0  0  0  0   0000  ok          ok
   24  0      0   0   0  0  0  0   0000  ok          ok
   25  0      0   0   0  0  0  0   0000  ok          ok
   26  0      0   0   0  0  0  0   0000  ok          ok
   27  0      0   0   0  0  0  0   0000  ok          ok
   28  1      7   2   0  0  0  0   0000  ok          ok
  …
  105  0      5   4   0  0  0  0   1001  ok          ok
  106  0      5   4   0  0  0  0   0100  ok          ok
tb.sv:256: $finish called at 1095000 (1ps)
PASS: 212 checks, no errors

To see that the testbench catches mistakes, break something and run it again: replace g | t with g in serial_adder_gates.sv, or connect RESET1 of the 4013 to GND instead of LOAD in serial_adder_gates_chips.sv. The script reports FAIL and the trace shows the lines marked WRONG.

12On an FPGA board: lab_top in BGM

The Basics-Graphics-Music (BGM) repository runs the same labs on dozens of FPGA boards. Each lab has a lab_top module with the same ports on every board: clock, a 1 Hz slow_clk, reset, keys, LEDs, a 7-segment display.

  1. Copy labs/1_basics/1_07_shift_register to a new directory.
  2. Replace its lab_top.sv with bgm_lab/lab_top.sv from this exercise and add serial_adder_gates.sv. The BGM scripts compile every .sv file of the directory except tb.sv.
  3. Run ./03_synthesize_for_fpga.bash and ./04_configure_fpga.bash; the first run asks which board you have.

The design runs from slow_clk, which every BGM board makes at 1 Hz, so it steps once a second like the breadboard with the 555 module. BGM makes it in peripherals/slow_clk_gen.sv: a counter on the board clock toggles a flip-flop, and on AMD (Xilinx) and Intel (Altera) FPGAs a BUFG or global primitive puts that signal on the FPGA clock network, so it reaches all flip-flops like a real clock.

As in exercise P1: switches 3–0 are A, switches 7–4 are B, key 0 is LOAD. LEDs 3–0 show the deserializer, LEDs 6–4 the streams and LED 7 the carry. To run the chip-level design instead, add serial_adder_gates_chips.sv and the seven chip models and change the module name in the instance.

bgm_lab/lab_top.sv114 lines · show the codefile
// Exercise P2 on an FPGA board with the Basics-Graphics-Music (BGM) labs:
// https://github.com/yuri-panchul/basics-graphics-music
//
// Copy labs/1_basics/1_07_shift_register to a new directory, replace its
// lab_top.sv with this file and add serial_adder_gates.sv.  For the
// chip-level design add serial_adder_gates_chips.sv and cd4014.sv,
// cd4070.sv, cd4081.sv, cd4071.sv, cd4013.sv, cd4015.sv, cd4511.sv instead,
// and change the module name below.
//
// The adder runs from slow_clk, 1 Hz on every BGM board.  Switches 3-0 are
// A, switches 7-4 are B, key 0 is LOAD: hold it through a tick of slow_clk.
// LEDs 3-0 show the deserializer, LEDs 6-4 the bit streams of A, B and the
// sum, LED 7 the carry.  The rightmost digit shows the deserializer as the
// 4511 would.

// LOAD is a synchronous load for the serializers and an asynchronous clear
// for the carry and the deserializer, as on the breadboard
// verilator lint_off SYNCASYNCNET

`include "config.svh"

module lab_top
# (
    parameter  clk_mhz       = 50,
               w_key         = 4,
               w_sw          = 8,
               w_led         = 8,
               w_digit       = 8,
               w_gpio        = 100,

               screen_width  = 640,
               screen_height = 480,

               w_red         = 4,
               w_green       = 4,
               w_blue        = 4,

               w_x           = $clog2 ( screen_width  ),
               w_y           = $clog2 ( screen_height )
)
(
    input                        clk,
    input                        slow_clk,
    input                        rst,

    // Keys, switches, LEDs

    input        [w_key   - 1:0] key,
    input        [w_sw    - 1:0] sw,
    output logic [w_led   - 1:0] led,

    // A dynamic seven-segment display

    output logic [          7:0] abcdefgh,
    output logic [w_digit - 1:0] digit,

    // Graphics

    input        [w_x     - 1:0] x,
    input        [w_y     - 1:0] y,

    output logic [w_red   - 1:0] red,
    output logic [w_green - 1:0] green,
    output logic [w_blue  - 1:0] blue,

    // Microphone, sound output and UART

    input        [         23:0] mic,
    output       [         15:0] sound,

    input                        uart_rx,
    output                       uart_tx,

    // General-purpose Input/Output

    inout        [w_gpio  - 1:0] gpio
);

    //------------------------------------------------------------------------

       assign red        = '0;
       assign green      = '0;
       assign blue       = '0;
       assign sound      = '0;
       assign uart_tx    = '1;

    //------------------------------------------------------------------------

    logic       serial_a, serial_b, serial_sum, carry;
    logic [3:0] sum;
    logic [6:0] abcdefg_a, abcdefg_b, abcdefg_sum;

    serial_adder_gates i_serial_adder
    (
        .clk         ( slow_clk    ),
        .load        ( key [0]     ),
        .a           ( sw [3:0]    ),
        .b           ( sw [7:4]    ),
        .serial_a    ( serial_a    ),
        .serial_b    ( serial_b    ),
        .serial_sum  ( serial_sum  ),
        .carry       ( carry       ),
        .sum         ( sum         ),
        .abcdefg_a   ( abcdefg_a   ),
        .abcdefg_b   ( abcdefg_b   ),
        .abcdefg_sum ( abcdefg_sum )
    );

    assign led      = w_led' ({ carry, serial_sum, serial_b, serial_a, sum });

    assign abcdefgh = { abcdefg_sum, 1'b0 };
    assign digit    = w_digit' (1);

endmodule

13On an FPGA board: hackathon_top in BGM

The hackathon setup of BGM uses a Tang Nano 9K with a 480×272 screen and a TM1638 board of keys, LEDs and digits. Its top module, hackathon_top, has simpler ports; the first line of the file names the board, so the scripts need no questions.

  1. Copy hackathon/problems/5_shift_register.
  2. Replace its hackathon_top.sv with bgm_hackathon/hackathon_top.sv and add serial_adder_gates.sv.
  3. Run ./03_synthesize_for_fpga.bash and ./04_configure_fpga.bash.

As in exercise P1, with 3-bit numbers: keys 2–0 are A, keys 5–3 are B and key 7 is LOAD. LED 7 shows the carry.

bgm_hackathon/hackathon_top.sv97 lines · show the codefile
// Board configuration: tang_nano_9k_lcd_480_272_tm1638_hackathon
// This module uses few parameterization and relaxed typing rules

// Exercise P2 in the hackathon setup of Basics-Graphics-Music (BGM):
// https://github.com/yuri-panchul/basics-graphics-music
//
// Copy a directory such as hackathon/problems/5_shift_register, replace its
// hackathon_top.sv with this file and add serial_adder_gates.sv.
//
// The adder runs from slow_clock.  Eight keys are not enough for two 4-bit
// numbers and LOAD, so A and B are 3 bits here: keys 2-0 are A, keys 5-3
// are B and key 7 is LOAD.  The LEDs and the rightmost digit are as in
// lab_top.  The screen shows the bit streams of A, B and the sum as three
// lamps on the left and the deserializer as four lamps on the right.

// LOAD is a synchronous load for the serializers and an asynchronous clear
// for the carry and the deserializer, as on the breadboard
// verilator lint_off SYNCASYNCNET

module hackathon_top
(
    input  logic       clock,
    input  logic       slow_clock,
    input  logic       reset,

    input  logic [7:0] key,
    output logic [7:0] led,

    // A dynamic seven-segment display

    output logic [7:0] abcdefgh,
    output logic [7:0] digit,

    // LCD screen interface

    input  logic [8:0] x,
    input  logic [8:0] y,

    output logic [4:0] red,
    output logic [5:0] green,
    output logic [4:0] blue,

    inout  logic [3:0] gpio
);

    //------------------------------------------------------------------------

    logic       serial_a, serial_b, serial_sum, carry;
    logic [3:0] sum;
    logic [6:0] abcdefg_a, abcdefg_b, abcdefg_sum;

    serial_adder_gates i_serial_adder
    (
        .clk         ( slow_clock         ),
        .load        ( key [7]            ),
        .a           ( { 1'b0, key [2:0] } ),
        .b           ( { 1'b0, key [5:3] } ),
        .serial_a    ( serial_a           ),
        .serial_b    ( serial_b           ),
        .serial_sum  ( serial_sum         ),
        .carry       ( carry              ),
        .sum         ( sum                ),
        .abcdefg_a   ( abcdefg_a          ),
        .abcdefg_b   ( abcdefg_b          ),
        .abcdefg_sum ( abcdefg_sum        )
    );

    assign led      = { carry, serial_sum, serial_b, serial_a, sum };

    assign abcdefgh = { abcdefg_sum, 1'b0 };
    assign digit    = 8'b0000_0001;

    //------------------------------------------------------------------------
    // The streams A, B, S on the left, top to bottom; the deserializer on
    // the right, bit 3 first.  Bright for 1, dim for 0.

    wire [2:0] stream = { serial_a, serial_b, serial_sum };

    always_comb
    begin
        red   = 0;
        green = 0;
        blue  = 0;

        for (int i = 0; i < 3; i ++)
            if (x >= 60 & x < 100 & y >= 9' (56 + i * 60) & y < 9' (96 + i * 60))
            begin
                green = stream [2 - i] ? 40 : 8;
                blue  = stream [2 - i] ? 31 : 6;
            end

        for (int i = 0; i < 4; i ++)
            if (x >= 9' (200 + i * 60) & x < 9' (240 + i * 60) & y >= 116 & y < 156)
                green = sum [3 - i] ? 63 : 12;
    end

endmodule

14On a chip: Tiny Tapeout

Tiny Tapeout makes real chips from student designs. Each design is a module with the ports below; on the demo board ui_in comes from DIP switches and uo_out drives a 7-segment display.

The demo board makes the project clock itself and can set it anywhere from 1 Hz to 66.5 MHz (see Clock in the Tiny Tapeout docs). Set it to 1 Hz, and project.v connects clk straight to the adder, just as the 555 module clocks the chips on the breadboard.

As in exercise P1: DIP switches 0–3 are A, switches 4–7 are B, and LOAD comes from BIDIR pin 0. The display shows the deserializer; the carry goes to BIDIR pin 1, the streams and the deserializer to pins 2–7.

tiny_tapeout/project.v67 lines · show the codefile
/*
 * Exercise P2 on Tiny Tapeout: a bit-serial adder from gates and a
 * flip-flop for the carry.  The 7-segment display of the demo board shows
 * the deserializer as a 4511 would.
 *
 * Add serial_adder_gates.sv to source_files in info.yaml next to project.v.
 * Rename the module to tt_um_<your GitHub name>_<project name> and use the
 * same name as top_module in info.yaml.
 */

`default_nettype none

// LOAD is a synchronous load for the serializers and an asynchronous clear
// for the carry and the deserializer, as on the breadboard
// verilator lint_off SYNCASYNCNET

module tt_um_example (
    input  wire [7:0] ui_in,    // DIP switches, INPUT Pmod, RP2350 GPIO17-24
    output wire [7:0] uo_out,   // 7-segment display, OUTPUT Pmod, RP2350 GPIO33-40
    input  wire [7:0] uio_in,   // BIDIR Pmod, RP2350 GPIO25-32
    output wire [7:0] uio_out,  //   (same pins)
    output wire [7:0] uio_oe,   //   1 = your design drives the pin
    input  wire       ena,      // set by the on-chip project mux, not a board pin
    input  wire       clk,      // RP2350 GPIO16
    input  wire       rst_n     // RP2350 GPIO14
);

    // The demo board makes the project clock; set it to 1 Hz.  DIP switches
    // 0-3 are A and switches 4-7 are B.  All eight are taken, so LOAD comes
    // from BIDIR pin 0: connect it to VCC through one tick of the clock.

    wire       serial_a, serial_b, serial_sum, carry;
    wire [3:0] sum;
    wire [6:0] abcdefg_a, abcdefg_b, abcdefg_sum;

    serial_adder_gates i_serial_adder (
        .clk         ( clk          ),
        .load        ( uio_in [0]   ),
        .a           ( ui_in  [3:0] ),
        .b           ( ui_in  [7:4] ),
        .serial_a    ( serial_a     ),
        .serial_b    ( serial_b     ),
        .serial_sum  ( serial_sum   ),
        .carry       ( carry        ),
        .sum         ( sum          ),
        .abcdefg_a   ( abcdefg_a    ),
        .abcdefg_b   ( abcdefg_b    ),
        .abcdefg_sum ( abcdefg_sum  )
    );

    // 7-segment display: uo_out [0] is segment a, ..., uo_out [6] is g; the
    // dot is the sum bit on its way

    assign uo_out  = { serial_sum, abcdefg_sum [0], abcdefg_sum [1], abcdefg_sum [2], abcdefg_sum [3],
                       abcdefg_sum [4], abcdefg_sum [5], abcdefg_sum [6] };

    // The deserializer, the streams of A and B and the carry on BIDIR pins
    // 1-7

    assign uio_out = { sum, serial_b, serial_a, carry, 1'b0 };
    assign uio_oe  = 8'b1111_1110;

    // List all unused inputs to prevent warnings

    wire _unused = & { ena, rst_n, uio_in [7:1], abcdefg_a, abcdefg_b, 1'b0 };

endmodule

In info.yaml set the clock to 1 Hz, list the files and use the module name as the top module:

project:
  clock_hz:   1                 # 1 Hz from the demo board
  top_module: "tt_um_example"   # rename to tt_um_<your GitHub name>_serial_adder_gates
  source_files:
    - "project.v"
    - "serial_adder_gates.sv"
No clock divider on a chip. BGM makes slow_clk with a counter, but on AMD and Intel FPGAs it routes that signal onto the clock network with BUFG or global (section 12). In an ASIC a counter bit used as a clock is bad practice: it is a second clock with its own clock tree, its edges come later than those of clk by a delay nobody controls, and every signal between the two clocks crosses clock domains. Here the board makes the 1 Hz clock, so no divider is needed. When a chip needs a slow tick from a fast clock, keep one clock and add a clock enable: a pulse one clock long that lets the slow logic change only on the edges where it is 1.

15Going further

Tasks for students

Files of this exercise

Sources

The exercise is in the Projects list of “An improved way of teaching school kids digital electronics” and in lesson 1.4 of the Habr article about the electronics course: “in the end the 4032 can be replaced by the full adder of the first group and a D flip-flop for the carry, a 4013; this shows what happens inside the 4032”. The chips are described in the Texas Instruments datasheets for the CD4014B, CD4070B, CD4081B, CD4071B, CD4013B, CD4015B and CD4511B.