DSD Lab Manual
DSD Lab Manual
DEPARTMENT OF ELCTRONICS & COMMUNICATION ENGINEERING DRONACHARYA COLLEGE OF ENGINEERING KHENTAWAS, GURGAON 123506
13
19 22 25 28 31
34 35 38 41 44 47 49
Practical No. 1
Aim:- To Design Logic Gates using VHDL
LOGIC GATES: A logic gate performs a logical operation on one or more logic inputs and produces a single logic output. The logic normally performed is Boolean logic and is most commonly found in digital circuits. Logic gates are primarily implemented electronically using diodes or transistors,but can also be constructed using electromagnetic relays (relay logic), fluidic logic, pneumatic logic, optics, molecules, or even mechanical elements.
INPUT A B 0 0 AND 1 1 0 1 0 1 OUTPUT A AND B 0 0 0 1
OR
A+B
INPUT A B 0 0 0 1 1 0 1 1
OUTPUT A OR B 0 1 1 1
NOT
INPUT A 0 1
OUTPUT NOT A 1 0
In electronics a NOT gate is more commonly called an inverter. The circle on the symbol is called a bubble, and is generally used in circuit diagrams to indicate an inverted (active-low) input or output.
INPUT A B 0 0 0 1 1 0 1 1 OUTPUT A NAND B 1 1 1 0
NAND
NOR
XOR
INPUT A B 0 0 0 1 1 0 1 1
OUTPUT A XOR B 0 1 1 0
XNOR
or
INPUT A B 0 0 0 1 1 0 1 1
OUTPUT A XNOR B 1 0 0 1
Quiz Questions with answer. Q.1What is VHDL? Ans. VHDL is the VHSIC Hardware Description Language. VHSIC is an abbreviation for Very High Speed Integrated Circuit. Q.2How many truth table entries are necessary for a four-input circuit? Ans.16 Q.3What input values will cause an AND logic gate to produce a HIGH output? Ans. All inputs of AND gate must be HIGH. Q.4 Name all the basic gates. Ans. i) AND ii) OR iii) NOT Q.5 Name all the universal gates. Ans .i) NAND ii) NOR
OUTPUT:
RTL View
10
11
12
S1 0 0 1 1
S0 0 1 0 1
Y A B C D
13
14
15
I 0 1 1 1 1
S1 X 0 0 1 1
S0 X 0 1 0 1
16
architecture Behavioral of dm is signal p,q : STD_LOGIC; begin p <= not s0; q <= not s1; a<= i and p and q; b<= i and q and s0; c<= i and p and s1; d<= i and s1 and s0; end Behavioral;
OUTPUT:
RTL View
17
18
Practical No. 4
Aim:- To Design an Encoder using VHDL
Encoder : An encoder is a device, circuit, transducer, software program, algorithm or person that converts information from one format or code to another, for the purposes of standardization, speed, secrecy, security, or saving space by shrinking size.
A3
A2
A1
A0
F1
F0
0 0 0 1
0 0 1 0
0 1 0 0
1 0 0 0
0 0 1 1
0 1 0 1
19
end Behavioral;
OUTPUT:
RTL View
20
21
Practical No. 5
Aim:- To Design a 2 to 4 Line Decoder using VHDL
Decoder: A decoder is a device which does the reverse of an encoder, undoing the encoding so that the original information can be retrieved. The same method used to encode is usually just reversed in order to decode. In digital electronics, a decoder can take the form of a multiple-input, multipleoutput logic circuit that converts coded inputs into coded outputs, where the input and output codes are different.Decoding is necessary in applications such as data multiplexing, 7 segment display and memory address decoding. EN 0 1 1 1 1 S1 X 0 0 1 1 S0 X 0 1 0 1 Z0 0 1 0 0 0 Z1 0 0 1 0 0 Z2 0 0 0 1 0 Z3 0 0 0 0 1
22
23
24
Practical No. 6
Aim:- To Design a Down Counter using VHDL.
Down Counter: In a binary up counter, a particular bit, except for the first bit, toggles if all the lowerorder bits are 1's. The opposite is true for binary down counters. That is, a particular bit toggles if all the lower-order bits are 0's and the first bit toggles on every pulse. Taking an example, A4 A3 A2 A1 = 0100. On the next count, A4 A3 A2 A1 = 0011. A1, the lowest-order bit, is always complemented. A2 is complemented because all the lower-order positions (A1 only in this case) are 0's. A3 is also complemented because all the lower-order positions, A2 and A1 are 0's. But A4 is not complemented the lower-order positions, A3 A2 A1 = 011, do not give an all 0 condition.
25
26
27
Practical No. 7
Aim:- To Design a BCD to GRAY converter using VHDL
BCD to GRAY Converter: It is a digital circuit that converts BCD numbers into Gray codes.
2-bit Gray code 00 01 11 10
3-bit Gray code 000 001 011 010 110 111 101 100 4-bit Gray code 0000 0001 0011 0010 0110 0111 0101 0100 1100 1101 1111 1110 1010 1011 1001 1000
28
29
Simulation Waveform
30
Practical No. 8
Aim:- To Design a Toggle Flip Flop using VHDL.
T(Toggle) Flip Flop: If the T input is high, the T flip-flop changes state ("toggles") whenever the clock input is strobed. If the T input is low, the flip-flop holds the previous value. This behavior is described by the characteristic equation:
T Flip-Flop operation
Characteristic table
Excitation table
T Q Qnext
Comment
Q Qnext T
Comment
No change
No change
1 Complement
Toggle
1 Complement
31
32
33
Practical No. 9
Aim:-Implement Half Adder using FPGA & CPLD. Program:
---------------------------------------------------------------------------------library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; --use UNISIM.VComponents.all; entity ha is Port ( a : in STD_LOGIC; b : in STD_LOGIC; s : out STD_LOGIC; c : out STD_LOGIC); end ha; architecture Behavioral of ha is begin s <= a xor b; c <= a and b; end Behavioral;
Output
Outputs Inputs A 0 0 1 1 B 0 1 0 1 C 0 0 0 1 S 0 1 1 0
34
Practical No. 10
Aim:-Implement Full Adder using FPGA & CPLD.
Full adder A full adder is a logical circuit that performs an addition operation on three one-bit binary numbers often written as A, B, and Cin. The full adder produces a two-bit output sum typically represented with the signals Cout and S where . The full adder's truth table is: Truth Table: Inputs A 0 1 0 1 0 1 0 1 B 0 0 1 1 0 0 1 1 Ci 0 0 0 0 1 1 1 1 Outputs Co 0 0 0 1 0 1 1 1 S 0 1 1 0 1 0 0 1
35
36
37
Practical No. 11
Aim:- Implement Delay Flip-Flop using FPGA & CPLD.
Flip-Flops: In digital circuits, a flip-flop is a term referring to an electronic circuit (a bistable multivibrator) that has two stable states and thereby is capable of serving as one bit of memory. Today, the term flip-flop has come to mostly denote nontransparent (clocked or edge-triggered) devices A flip-flop is usually controlled by one or two control signals and/or a gate or clock signal. The output often includes the complement as well as the normal output. D(Delay) Flip-Flop: The D ip-op is the most common flip-flop in use today. It is better known as delay flip-flop The Q output always takes on the state of the D input at the moment of a positive edge (or negative edge if the clock input is active low).[7] It is called the D flip-flop for this reason, since the output takes the value of the Dinput or Data input, and Delays it by maximum one clock count. The D flip-flop can be interpreted as a primitive memory cell, zero-order hold, or delay line. Whenever the clock pulses, the value of Qnext is D and Qprevotherwise. Truth table: Clock Rising edge Rising edge Non-Rising D 0 1 X Q 0 1 Qprev Qprev X X
38
OUTPUT:
Clock Rising edge Rising edge Non-Rising D 0 1 X Q 0 1 Qprev Qprev X X
39
40
Practical No. 12
Aim:- Implement BCD to 7 segment Decoder using FPGA & CPLD. BCD to 7 segment Decoder:
It is a digital circuit that decodes BCD numbers into7 segment numbers that can be used for 7 segment displays and other applications.
INPUTS ABCD 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 A 1 0 1 1 0 1 1 1 1 1 B 1 1 1 1 1 0 0 1 1 1 C 1 1 0 1 1 1 1 1 1 1
OUTPUT d 1 0 1 1 0 1 1 0 1 1 e 1 0 1 0 0 0 1 0 1 0 f 1 0 0 0 1 1 1 0 1 1 G 0 0 1 1 1 1 1 0 1 1
41
42
43
Practical No. 13
Aim:- Implement an Up Counter using FPGA & CPLD.
Up Counter: A synchronous binary counter counts from 0 to 2N-1, where N is the number of bits/flip-flops in the counter. Each flip-flop is used to represent one bit. The flip-flop in the lowest-order position is complemented/toggled with every clock pulse and a flip-flop in any other position is complemented on the next clock pulse provided all the bits in the lower-order positions are equal to 1. Take for example A4 A3 A2 A1 = 0011. On the next count, A4 A3 A2 A1 = 0100. A1, the lowest-order bit, is always complemented. A2 is complemented because all the lower-order positions (A1 only in this case) are 1's. A3 is also complemented because all the lower-order positions, A2 and A1 are 1's. But A4 is not complemented the lower-order positions, A3 A2 A1 = 011, do not give an all 1 condition. To implment a synchronous counter, we need a flip-flop for every bit and an AND gate for every bit except the first and the last bit. The diagram below shows the implementation of a 4-bit synchronous up-counter. .
44
45
46
Practical No. 14
Aim:- Implement a 1-bit Comparator using FPGA & CPLD.
Comparator : In electronics, a comparator is a device which compares two voltages or currents and switches its output to indicate which is larger.
A 0 0 1 1
B 0 1 0 1
AGB 0 0 1 0
AEB 1 0 0 1
ALB 0 1 0 0
47
48
Practical No. 15
Aim:- Implement an ALU using FPGA & CPLD.
ALU : In computing, an arithmetic logic unit (ALU) is a digital circuit that performs arithmetic and logical operations. The ALU is a fundamental building block of the central processing unit (CPU) of a computer, and even the simplest microprocessors contain one for purposes such as maintaining timers. The processors found inside modern CPUs and graphics processing units (GPUs) accommodate very powerful and very complex ALUs; a single component may contain a number of ALUs. The inputs to the ALU are the data to be operated on (called operands) and a code from the control unit indicating which operation to perform. Its output is the result of the computation.
Program:
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; ---- Uncomment the following library declaration if instantiating ---- any Xilinx primitives in this code. --library UNISIM; entity alu_1 is Port ( a : in STD_LOGIC_VECTOR (3 downto 0); b : in STD_LOGIC_VECTOR (3 downto 0); op : in STD_LOGIC_VECTOR (2 downto 0); y : out STD_LOGIC_VECTOR (7 downto 0)); end alu_1; architecture Behavioral of alu_1 is begin y<=("0000"&a) + ("0000"&b) when op="000" else ("0000"&a) - ("0000"&b) when op="001" else a*b when op="010" else ("0000"&a) and ("0000"&b) when op="011" else ("0000"&a) or ("0000"&b) when op="100" else ("0000"&a) xor ("0000"&b) when op="101" else ("0000"&a) nor ("0000"&b) when op="110" else ("0000"&a) nand ("0000"&b) when op="111"; end Behavioral;
49