Laboratory Exercise 7
Laboratory Exercise 7
Introduction
Although most processors compute data in binary form, the input-output is generally done in some coded form.
Normally, we exchange information in decimal. Hence decimal numbers must be coded in terms of binary
representations. In the simplest form of binary code, each decimal digit is replaced by its binary equivalent. This
representation is called Binary Coded Decimal (BCD) or 8-4-2-1 (to indicate weight of each bit position). Because
there are only ten decimal digits, 1010 through 1111 are not valid BCD. Table below shows some of the widely used
binary codes for decimal digits. These codes are designed and used for communication reliability and error
detection.
TABLE I
MAIN BINARY CODES FOR DECIMAL DIGITS
The BCD and 6-3-1-1 codes are weighted codes of 4 binary digits (bits) because each bit is assigned a weight. In the
case of BCD the weights are 8, 4, 2 and 1. For the code 6-3-1-1, as the name implies, the weights are 6, 3, 1 and 1.
Thus, given the binary code 0111 it is possible to know that it represents 7 in BCD (0 × 8 + 1 × 4 + 1 × 2 + 1 × 1 =
7), and 5 in code 6-3-1-1 (0 × 6 + 1 × 3 + 1 × 1 + 1 × 1 = 5).
The excess code 3 is obtained from BCD by adding 3 to each code. The code 2 of 5 has the property that in each
code only 2 of the 5 bits are 1. On the other hand, in the Gray code each consecutive code differs in a single bit.
These last two codes are unweighted. That is, the decimal value of a digit encoded in code 2 of 5 or in Gray code
cannot be obtained from a formula as in the case of weighted codes.
Part I
Model a binary code "2-out-of-5" and display the 4-bit binary decimal input number set by the SW3-0 switches on
five LEDs. Also display on the 7-segment display HEX0 the value of the switches. Use data flow modeling.
d1
z
Comparator 0
5 1
7 6
Circuit B
m3 4 2 v[3:0] z m[3:0]
v3 0
0 1 3
0000 0 0000
0001 0 0001
0010 0 0010
d0 0011 0 0011
v2 0 m2 0 0100 0 0100
1
5 1
0101 0 0101
7-segment 7 6 0110 0 0110
decoder 0111 0 0111
4 2
1000 0 1000
v1 0 m1
3 1001 0 1001
1
1010 1 0000
1011 1 0001
1100 1 0010
v0 0 m0 1101 1 0011
1 1110 1 0100
1111 1 0101
Circuit A
(a) (b)
Fig. 1 a) Design of binary-to-decimal conversion circuit; b) Output values of the conversion
The intent of this exercise is to use simple VHDL assignment statements to specify the required logic functions
using Boolean expressions. Your VHDL code should not include any IF-ELSE, CASE, or similar statements.
Perform the following steps:
b a ci co s
ci
0 0 0 0 0
a s 0 0 1 0 1
ci
b s 0 1 0 0 1
a FA 0 1 1 1 0
co 1 0 0 0 1
0 b
co 1 0 1 1 0
1 1 1 0 1 0
1 1 1 1 1
(a) (b) (c)
b3 a3 c3 b2 a2 c2 b1 a1 c1 b0 a0 cin
FA FA FA FA
cout s3 s2 s1 s0
(d)
Fig. 2 a) Full adder circuit; b) Full adder symbol; c) Truth table of full adder; d) Ripple carry adder circuit
Write VHDL code that implements a 4-bit adder. Perform the following steps:
1. Create a new Quartus II project for the adder circuit. Write a VHDL entity for the full adder sub circuit and
write a top-level VHDL entity that instantiates four instances of this full adder.
2. Use switches SW7−4 and SW3−0 to represent the inputs a and b, respectively. Use SW8 for the carry-in (cin) of
the adder. Connect the SW8-0 switches to their corresponding red lights LEDR8-0, and connect the outputs of
the adder, cout and s, to the green lights LEDG4-0.
3. Include the necessary pin assignments for the DE1 board, compile the circuit, and download it into the
FPGA chip.
4. Test your circuit by trying different values for numbers a, b, and cin.
Pedagogical and Technological University of Colombia
Electronics Engineering School
Digital Electronics 1 Course
Laboratory Exercises
Part IV
Design a circuit that adds two BCD digits A and B with a drag, generating the result in two-digit BCD S1 and S0.
Reuse the models developed in parts II and III as necessary. Use data flow modeling. Note that the largest sum that
this circuit must handle is 9 + 9 + 1 = 19.
Part V
Design a circuit that can add two 2-digit BCD numbers, A1 A0 and B1 B0 to produce the three-digit BCD sum S2 S1
S0. Use two instances of your circuit from part IV to build this two-digit BCD adder. Perform the following steps:
1. Use switches into the GPIO connector extension to represent 2-digit BCD numbers A1 A0 and B1 B0,
respectively. Display the BCD sum S2 S1 S0 on the 7-segment displays HEX2, HEX1 and HEX0.
2. Make the necessary pin assignments and compile the circuit.
3. Download the circuit into the FPGA chip, and test its operation.
Part VI
Design a combinational circuit that converts a 6-bit binary number into a 2-digit decimal number represented in the
BCD form. Use switches SW5−0 to input the binary number and 7-segment displays HEX1 and HEX0 to display the
decimal number. Implement your circuit on the DE1 board and demonstrate its functionality.