In part 6, we built a 1-bit full adder. In this part we’re going to expand upon that and build a complete 4-bit binary adder. I have made the assumption that you already know about the binary number system but in case you don’t, have a look here and do some searching to learn about it.
Back? Great, let’s get on with it. Grab your CPLD development board, a breadboard and the usual handful of LED, switches and resistors. We will need switches for this guide instead of buttons.
As you can see from the logic diagram on the right, the 4-bit adder is simply 4, 1-bit adders linked together. Remember the Carry-in and Carry-out? This time we’re actually going to use them properly. The carry-out from the first adder is fed directly to the carry-in of the next adder…… and so on. The last carry-out will connect to an extra LED. As we did with the full adder, the first carry-in will simply connect to ground. The reason we tie it to ground is to make sure that the carry-in is a 0 (i.e nothing). If we were to connect it to VCC, it would give us a carry-in of 1. We don’t want that. I really should have explained that in part 6. Sorry.
If you saved the full adder project from the previous part, you can save yourself some time inputting this schematic in Quartus II. All you need to do is select the whole thing then copy and paste it three times. Make sure you connect all the carry ins and outs as per the diagram shown. If you didn’t save the project, you’ll need to draw up another full adder and then copy it as described above.
Once you’ve compiled, assigned your pins, compiled and uploaded, you can move on to the hardware side of things. Building the hardware on the breadboard uses exactly the same components as the full-adder but uses more of them.
The hardest part is keeping it all tidy. My version is far from neat but it does work. I also made my own ground rail for the switches by soldering the ends of a row of pin connectors together.
Now you’ve got your design uploaded to your CPLD and built your circuit, you can start playing with your newly built 4-bit binary adder.
You can now select two 4-bit numbers and see the sum of them instantly on the LEDs. This is pretty much the beginnings of a CPU (well, an ALU at least). Pleased with yourself? You should be!!
In the photo below, you can see the adder working correctly. I have added 1000 to 1010 and the result is 10010 (8+10=18). The extra carry-out LED equals 16. Have some fun playing around with it and getting used to working with binary numbers.
Stay tuned for the next part where we will look at subtracting binary numbers.
Other articles in this series can be found here.