Expt No.:5 Verilog Program For 3 To 8 Decoder Date
Expt No.:5 Verilog Program For 3 To 8 Decoder Date
Expt No.:5 Verilog Program For 3 To 8 Decoder Date
:5
AIM:
To develop a Verilog program for a 3x8 decoder and to simulate and test the program using appropriate test bench
Verilog program.
Software used:
• https://www.edaplayground.com/
THEORY:
Decoder is a combinational circuit that has ‘n’ input lines and maximum of 2 n One of these outputs will be active
High based on the combination of inputs present, when the decoder is enabled. That means decoder detects a
particular code. The outputs of the decoder nothing but the min terms of ‘n’ input variables lines, when it is
enabled.
TRUTH TABLE :
LOGIC IMPLEMENTATION:
VERILOG PROGRAM:
STRUCTURAL MODELLING :
DESIGN:
module Decoder(A,B,C,D0,D1,D2,D3,D4,D5,D6,D7);
input A,B,C;
output D0,D1,D2,D3,D4,D5,D6,D7;
and a6(D6,A,B,Cbar);
and a7(D7,A,B,C);
endmodule
TEST BENCH:
module TestModule;
// Outputs wire D0; wire D1; wire D2; wire D3; wire D4; wire D5; wire D6; wire D7;
Decoder
uut(.A(A),.B(B),.C(C),.D0(D0),.D1(D1),.D2(D2),.D3(D3),.D4(D4),.D5(D5), .D6(D6),.D7(D7));
initial begin
//Dump waves
$dumpfile("dump.vcd");
$dumpvars(1);
// Initialize Inputs
A = 0;B = 0;C = 0;#10; A = 0;B = 0;C = 1;#10; A = 0;B = 1;C = 0;#10; A = 0;B = 1;C = 1;#10; A = 1;B = 0;C = 0;#10; A =
1;B = 0;C = 1;#10; A = 1;B = 1;C = 0;#10; A = 1;B = 1;C = 1;
end
endmodule
WAVEFORM:
SIMULATION OUTPUT:
BEHAVIOURAL MODELLING:
DESIGN:
output [7:0] y;
reg [7:0] y;
if(enable==0)
y = 8'b11111111;
if (x == 3'b000) //...then we check our inputs and give corresponding outputs y = 8'b00000001;
if (x == 3'b001)
y = 8'b00000010;
if (x == 3'b010)
y = 8'b00000100;
if (x == 3'b011)
y = 8'b00001000;
if (x == 3'b100)
y = 8'b00010000;
if (x == 3'b101)
y = 8'b00100000;
if (x == 3'b110)
y = 8'b01000000;
if (x == 3'b111)
y = 8'b10000000;
end endmodule
TEST BENCH:
module testbench_3to8decoder;
reg [2:0] x; //use reg not wire to assign values wire [7:0] y; //for the outputs
reg enable;
x = 3'b000;
x = 3'b001;
x = 3'b100;
#10; //wait some time x = 3'b101;
x = 3'b111; #10;
end
initial
begin
$dumpvars(0,testbench_3to8decoder);
$dumpfile("my.vcd");
endmodule
WAVEFORM:
SIMULATION OUTPUT:
DATAFLOW MODELLING:
DESIGN:
assign d[0] = ~x & ~y & ~z; assign d[1] = ~x & ~y & z; assign d[2] = ~x & y & ~z; assign d[3] = ~x & y & z; assign d[4] =
x & ~y & ~z; assign d[5] = x & ~y & z; assign d[6] = x & y & ~z; assign d[7] = x & y & z; endmodule
TEST BENCH:
reg x,y,z;
begin
$dumpfile("dump.vcd");
$dumpvars(1); x=0;y=0;z=0;
#10 x=0; y=0; z=1; #10 x=0; y=1; z=0; #10 x=0; y=1; z=1; #10 x=1; y=0; z=0; #10 x=1; y=0; z=1; #10 x=1; y=1; z=0; #10
x=1; y=1; z=1;
End
endmodule
WAVEFORM:
S IMULATION OUTPUT :
RESULT: Thus the verilog program for 3x8 decoder was implemented and results were obtained.