Documente Academic
Documente Profesional
Documente Cultură
VERILOG Programs
Department of ECE(VCET)
Page 1
Y_NOT
1
1
0
0
Y_OR
0
1
1
1
Y_AND
0
0
0
1
Y_NOR
1
0
0
0
Y_NAND
1
1
1
0
Y_XOR
0
1
1
0
Y_XNOR
1
0
0
1
Department of ECE(VCET)
Page 2
Department of ECE(VCET)
Page 3
2. 8:1 MULTIPLEXER
Aim : To design a 8:1 multiplexer using behavioral model and verifying its functionality using
test bench
Tools : Xilinx 9.1i
1)simulation: ISE simulator
2)synthesis: XST tool
Truth table :
SEL 1
SEL 2
SEL 0
MUX_OUT
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
A
B
C
D
E
F
G
H
Department of ECE(VCET)
Page 4
Rtl schematic:
Department of ECE(VCET)
Page 5
Conclusion/result :
8:1 multiplexer is designed by using behavioral model and verified its functionality using test
bench
Department of ECE(VCET)
Page 6
3. 1x8 DE MULTIPLEXER
Aim : To design a 1:8 demultiplexer and verify its functionality and check its simulation report
Tools : 1) simulation : 9.2i ISE simulator
2) synthesis :9.2i XST
Truth table :
S2
0
0
0
0
1
1
1
1
S1
0
0
1
1
0
0
1
1
S0
0
1
0
1
0
1
0
1
Y[0]
din
0
0
0
0
0
0
0
Y[1]
0
din
0
0
0
0
0
0
Y[2]
0
0
Din
0
0
0
0
0
Y[3]
0
0
0
din
0
0
0
0
Y[4]
0
0
0
0
din
0
0
0
Y[5]
0
0
0
0
0
din
0
0
Y[6]
0
0
0
0
0
0
din
0
Y[7]
0
0
0
0
0
0
0
Din
Page 7
Rtl schematic :
Department of ECE(VCET)
Page 8
Page 9
4. 2 to 4 DECODER
Aim:To write a program for 2 to 4 decoder by using behavioral model and verifying its
functionality using testbench
Tools: xilinx 9.1i
1. Simulation: IES simulator
2. Synthesis: XST tool
Truth table:
Enable
1
0
0
0
0
Din1
X
0
0
1
1
Din0
X
0
1
0
1
Dout3
0
0
0
1
0
Dout2
0
0
0
1
0
Dout1
0
0
1
0
0
Dout0
0
1
0
0
0
Verilog code:
Module decoder 2_4(enable,din,dout);
Input enable;
Input[1:0]din;
Output[3:0]dout;
Reg[3:0]dout;
always@(enable,din)
begin
if(enable==1b1)
begin
dout=4b0000;
end
else
Department of ECE(VCET)
Page 10
Department of ECE(VCET)
Page 11
Conclusion/Result:
2 to 4 decoder is designed by using behavioral model and its functionality is verified by using
testbench.
Department of ECE(VCET)
Page 12
DIN7
X
X
X
X
X
X
X
X
1
DIN6
X
X
X
X
X
X
X
1
0
DIN5
X
X
X
X
X
X
1
0
0
DIN4
X
X
X
X
X
1
0
0
0
DIN3
X
X
X
X
1
0
0
0
0
DIN2
X
X
X
1
0
0
0
0
0
DIN1
X
X
1
0
0
0
0
0
0
DIN0
X
1
0
0
0
0
0
0
0
Department of ECE(VCET)
Page 13
Department of ECE(VCET)
Page 14
Conclusion/Result:
8-3 encoder with priority is desgined using behavioral model and its functionality is verified using
testbench.
Department of ECE(VCET)
Page 15
Page 16
Department of ECE(VCET)
Page 17
Conclusion/Result:
8-3 encoder is designed by using behavioral model and verified its functionality using test bench
Department of ECE(VCET)
Page 18
6. 4 BIT COMPARATOR
Aim: To write a program for 4 bit comparator using behavioral code and verifying its functionality using
test bench.
Tools: Xilinx 9.1i
A
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
0
1
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
0
1
B
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
1
1
1
1
1
0
0
0
0
1
1
1
1
0
0
0
0
0
1
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
0
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
0
1
aeb
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
alb
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
0
0
agb
0
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
Page 19
reg aeb,agb,alb;
always@(a,b,en)
begin
if(en==1)
if(a==b)
begin
aeb=1;
agb=0;
alb=0;
end
else if(a>b)
begin
aeb=0;
agb=1;
alb=0;
end
else
begin
aeb=0;
agb=0;
alb=1;
end
Department of ECE(VCET)
Page 20
Department of ECE(VCET)
Page 21
Conclusion/Result:
4 bit comparator is designed using behavioral model and its functionality is verified using testbench
Department of ECE(VCET)
Page 22
7. Code converters
Aim:
To design a code converter by using behavioral model and verifying its functionality using test bench.
Tools: xilinx9.1i
1.simulation: ISE simulator
2.Synthesis : XST tool
For conversion of binary to gray code:
Truth table:
Binary
Inputs
B3 B2 B1 B0
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
Program for binary to gray converter:
Gray
Outputs
G3 G2 G1 G0
0000
0001
0011
0010
0110
0111
0101
0100
1100
1101
1111
1110
1010
1011
1001
1000
Verilog code:
module converter(b, g);
input [3:0] b;
output [3:0] g;
reg [3:0]g;
always@(b)
Department of ECE(VCET)
Page 23
Department of ECE(VCET)
Page 24
Binary
outputs
B3 B2 B1 B0
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
Page 25
Department of ECE(VCET)
Page 26
Conclusion/result: a code converter by using behavioral model and verifying its functionality using test
bench is verified.
Department of ECE(VCET)
Page 27
Department of ECE(VCET)
Page 28
Department of ECE(VCET)
Page 29
Structural model:
module FA(a,b,cin,sum,cout);
input a;
input b;
input cin;
output sum;
output cout;
HA H1 (a,b,s0,c0);
Department of ECE(VCET)
Page 30
Department of ECE(VCET)
Page 31
Conclusion/result:
A HDL program for full adder is designed by using three modeling styles and its functionality is verified
by test bench.
Department of ECE(VCET)
Page 32
VHDL Programs
Department of ECE(VCET)
Page 33
Y_OR
0
1
1
1
Y_AND
0
0
0
1
Y_NOR
1
0
0
0
Y_NAND
1
1
1
0
Y_XOR
0
1
1
0
Y_XNOR
1
0
0
1
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity allgates is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
y_or : out STD_LOGIC;
y_nor : out STD_LOGIC;
y_and : out STD_LOGIC;
y_not : out STD_LOGIC;
y_nand : out STD_LOGIC;
y_xor : out STD_LOGIC;
y_xnor : out STD_LOGIC);
Department of ECE(VCET)
Page 34
Department of ECE(VCET)
Page 35
Department of ECE(VCET)
Page 36
CONCLUSION/RESULT:
A VHDL program for all gates by using behavioral model is designed and its functionality is verified by
test bench
Department of ECE(VCET)
Page 37
2.8x1 MULTIPLEXER
Aim: To write a VHDL program for 8:1 multiplexer by using behavioral model and verifying its
functionality by using test bench.
Tools: XILINX 9.1i
SEL2
0
0
1
1
0
0
1
1
SEL1
0
1
0
1
0
1
0
1
Y_OUT
A
B
C
D
E
F
G
H
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity mux8_1 is
Port ( y_out : out STD_LOGIC;
A : in STD_LOGIC;
B : in STD_LOGIC;
C : in STD_LOGIC;
D : in STD_LOGIC;
E : in STD_LOGIC;
F : in STD_LOGIC;
Department of ECE(VCET)
Page 38
Department of ECE(VCET)
Page 39
Department of ECE(VCET)
Page 40
Conclusion/result:
A VHDL program for 8:1 multiplexer is designed by using behavioral model and its functionality is
verified by test bench.
Department of ECE(VCET)
Page 41
3. 2 to 4 DECODER
Aim: To design a 2-4 decoder using behavioral model and verify its functionality using test
bench
Tools: Xilinx 9.1i
1)simulation: ISE simulator
2)synthesis: XST tool
Truth table:
Enable
1
0
0
0
0
Din1
X
0
0
1
1
Din0
X
0
1
0
1
Dout3
0
0
0
1
0
Dout2
0
0
0
1
0
Dout1
0
0
1
0
0
Dout0
0
1
0
0
0
Page 42
Department of ECE(VCET)
Page 43
Conclusion/Result:
A VHDL program for 2-4 decoder is designed by using behavioral model and its functionality is verified
by testbench.
Department of ECE(VCET)
Page 44
4. 1x8 Demultiplexer
Aim: To design a 2-4 decoder using behavioral model and verify its functionality using test
bench
Tools: Xilinx 9.1i
1)simulation: ISE simulator
2)synthesis: XST tool
Truth Table:-
S2
0
0
0
0
1
1
1
1
S1
0
0
1
1
0
0
1
1
S0
0
1
0
1
0
1
0
1
Y[0]
din
0
0
0
0
0
0
0
Y[1]
0
din
0
0
0
0
0
0
Y[2]
0
0
Din
0
0
0
0
0
Y[3]
0
0
0
din
0
0
0
0
Y[4]
0
0
0
0
din
0
0
0
Y[5]
0
0
0
0
0
din
0
0
Y[6]
0
0
0
0
0
0
din
0
Y[7]
0
0
0
0
0
0
0
Din
Department of ECE(VCET)
Page 45
RTL Schematic:
Department of ECE(VCET)
Page 46
Department of ECE(VCET)
Page 47
Conclusion/Result:A VHDL program for 1x8 Demultiplexer is designed by using behavioral model and its functionality is
verified by testbench.
Department of ECE(VCET)
Page 48
5.HALF ADDER
Aim: To write a VHDL program for half adder by bahavioral model and verifying its functionlity by using
testbench
Tools: Xilinx 9.1i
B
0
1
0
1
S
0
1
1
0
C
0
0
0
1
Page 49
Conclusion/result:
A VHDL program for hall adder is designed by using behavioral model and its functionality is verified by
using testbench.
Department of ECE(VCET)
Page 50