4 Bit Adder With Selectable Output Type (decimal/base 10, Binary/base 2)
by Reisentinel in Circuits > Arduino
14 Views, 0 Favorites, 0 Comments
4 Bit Adder With Selectable Output Type (decimal/base 10, Binary/base 2)
This instructable teaches you how to make a 4 bit ripple carry adder with outputs on seven segment displays (for base 10/decimal output) and LEDs (for base 2/binary output) including the logic and code.
Supplies
1 XOR gate
2 AND gates
2 OR gates
2 7447 decoder chips
2 dip switches
1 slide switch
8 10kΩ resistors
7 330Ω resistors
5 LEDs
2 seven segment displays
2 breadboards
1 Arduino Uno or similar microcontroller
Wire (lots!)
Circuit Logic
In mathematics, numbers are added column by column from right to left, with each digit having a value determined by its position. When the sum of a column equals or exceeds the base number (10 in decimal), a carry is generated and added to the next column. This same principle applies to binary addition, except that binary operates in base 2, meaning a carry is generated whenever the sum in a column is equal to or greater than 2.
Binary numbers consist of only two digits: 0 and 1. When adding binary digits, combinations such as 0 + 0, 0 + 1, and 1 + 0 produce sums of 0 or 1 with no carry. However, adding 1 + 1 results in a sum of 2, which cannot be represented directly in binary. Instead, it is written as 10, producing a sum of 0 and a carry of 1 to the next column.
A basic binary adder, known as a half adder, adds two single bits and produces two outputs: a Sum (S) and a Carry (C). This functionality can be implemented using an XOR gate for the sum and an AND gate for the carry.
A full adder extends this concept by adding three bits: two input bits and a carry-in from the previous, less significant column. Like the half adder, it generates both a sum and a carry-out. Conceptually, a full adder can be constructed from two half adders, where the carry from the first is passed into the second.
To add multi-bit binary numbers, multiple full adders are connected in sequence, forming a ripple carry adder. Each full adder handles one bit position, and the carry-out from each stage becomes the carry-in for the next. This cascading effect causes the carry signal to “ripple” from the least significant bit (LSB) to the most significant bit (MSB).
For example, when adding two 4-bit numbers, four full adders are linked together. The first full adder produces the least significant sum and a carry that feeds into the second adder, and this process continues across all bit positions. This structure allows larger binary numbers to be added accurately and closely reflects the design and operation of the project described.
4 Bit Adder Assembly
Now that the theory has been covered, the next step is to assemble a 4-bit binary adder. Before beginning construction, it is essential to carefully plan the full wiring layout, as the limited space on a single breadboard can make corrections difficult once components are installed.
After planning, it is strongly recommended to build the adder one bit at a time, testing each stage before moving on to the next. This step-by-step approach greatly simplifies troubleshooting and makes it easier to identify and correct errors, rather than attempting to debug the entire 4-bit adder at once. Testing can be performed using LEDs connected to the sum and carry outputs.
Referring to the circuit diagram, this project implements a 4-bit ripple carry adder, where the carry-out from each 1-bit full adder is connected to the carry-in of the next, more significant bit. This cascading of carry signals allows the circuit to correctly perform multi-bit binary addition.
As long as binary addition and the full adder truth table are well understood, constructing the 4-bit adder should be a straightforward and logical process. When physically assembling the circuit, particular care must be taken with the DIP switches. Appropriate resistors must be used to prevent floating inputs and ensure each switch reliably outputs either a logic high or logic low when toggled.
Output Rig Assembly
The output rig is designed to display the result of the 4-bit ripple carry adder in both binary and decimal formats, allowing the operation of the adder to be easily observed and verified. This is achieved using five LEDs, two 7447 BCD-to-seven-segment decoder ICs, two seven-segment displays, and a toggle switch to select the display mode.
Binary Output (LED Display)
The adder produces a 5-bit result, consisting of four sum bits (S0–S3) and a final carry-out bit (C4). These outputs are connected to the Arduino’s analog input pins and read digitally by the Arduino. I chose to show my sum bits (S0-S3) with green LEDs and my carry bit (C4) with a red LED. This is completely optional but recommended if you would like to add reading effectiveness. It also helps with the initial testing of the 4 bit adder.
Decimal Output (Seven-Segment Display)
For decimal output, the 5 bit binary result is converted into a base 10 number ranging from 0 to 30. This is done by the code on the Arduino by combining the sum and carry bits into a single integer value. It is split into a units/ones digit (0-9) and a tens digit (0-3). Each digit is encoded in Binary Coded Decimal (BCD) format and sent to a separate 7447 decoder chip, one for the units display and one for the tens display.
Mode Selection (Slide Switch)
To change display modes, I incorporated a slide switch into the output rig to swap display modes from base 10 (decimal) or base 2 (binary). I coded it in a way such that only one mode is active at a time, for if I didn't it would beat the whole purpose of having a dual output system. Adding a toggle between modes also shows understanding (kind of) complex code and system conversions.
Code
Attached below is the code file for the output rig (note: using different pins for your rig will result in slightly different code). The main part of the code is the mode toggle (as well as the modes themselves), which is what I will be going over.
Base 2 (binary) display
When the toggle switch reads HIGH, the system operates in base 2 (binary) display mode. In this mode, the Arduino disables all outputs connected to the 7447 BCD-to-7-segment decoders so the 7-segment displays remain off (i.e. show zeros on both seven segments). The five adder output bits are then sent directly to individual LEDs, with each LED representing one bit of the binary result. An LED turns on when its corresponding bit is logic high and turns off when the bit is logic low, letting us view the exact binary value produced by the adder, including the carry bit.
Base 10 (decimal) display
When the toggle switch reads LOW, the system switches to base 10 (decimal) display mode. In this mode, all LEDs are turned off, and the Arduino combines the five adder output bits into a single numerical value. This value is converted from binary into decimal and separated into tens and units digits. Each digit is then converted into a 4 bit BCD value and sent to its respective 7447 decoder, which powers a seven segment display. As a result, the decimal equivalent of the adder output is shown on the two seven segment displays.
Downloads
Completed!
If you followed the instructable correctly, you should now have a functioning dual output 4 bit adder that accurately displays its results on the respective display mode. Although the project is simple in nature, it involves several complexities, important concepts and design considerations. A solid understanding of the seven segment decoder, binary to decimal conversion and the interaction between the Arduino and digital logic is essential for achieving reliable and correct operation in this project.