Professional Documents
Culture Documents
Encoder
Encoder
18251A04C0
Aim:to design and test the encoder using Structural, dataflow, behavioral models
Software :Edaplayground
//STRUCTURAL
// or browse Examples
module tb_encoder38struct;
reg [7:0] i;
wire [2:0] y;
wire en;
encoder38struct uut(i,y,en);
initial
begin
$dumpfile("dump.vcd");
$dumpvars();
#10 i = 8'b00000001;
#10 i = 8'b00000010;
#10 i = 8'b00000100;
#10 i = 8'b00001000;
#10 i = 8'b00010000;
#10 i = 8'b00100000;
#10 i = 8'b01000000;
#10 i = 8'b10000000;
end
initial#100;
endmodule
// Code your design here
module encoder38struct(
input [7:0] i,
output [2:0] y,
output en
);
endmodule
// DATAFLOW
// or browse Examples
module tb_en8data;
wire [2:0] y;
en8data uut(i,en,y);
initial
begin
$dumpfile("dump.vcd");
$dumpvars();
en=1;
#10 i = 8'b00000001;
#10 i = 8'b00000010;
#10 i = 8'b00000100;
#10 i = 8'b00001000;
#10 i = 8'b00010000;
#10 i = 8'b00100000;
#10 i = 8'b01000000;
#10 i = 8'b10000000;
end
initial#100;
endmodule
// Code your design here
endmodule
//BEHAVIOURAL
// or browse Examples
module tb_encoder83behave;
reg [7:0] i;
reg en;
wire [2:0] y;
encoder83behave uut(i,en,y);
initial
begin
$dumpfile("dump.vcd");
$dumpvars();
en=1;
#10 i = 8'b00000001;
#10 i = 8'b00000010;
#10 i = 8'b00000100;
#10 i = 8'b00001000;
#10 i = 8'b00010000;
#10 i = 8'b00100000;
#10 i = 8'b01000000;
#10 i = 8'b10000000;
end
initial#100;
endmodule
// Code your design here
begin
if(en==1)
begin
case (i)
8'b00000001: y=3'b000;
8'b00000010 : y=3'b001;
8'b00000100 : y=3'b010;
8'b00001000 : y=3'b011;
8'b00010000 : y=3'b100;
8'b00100000 : y=3'b101;
8'b01000000 : y=3'b110;
8'b10000000 : y=3'b111;
default : y = 3'bxxx;
endcase
end
end
endmodule
// PRIORITY ENCODER behavioural
// or browse Examples
module tb_priorityencoder83behave;
reg [7:0] i ;
reg en;
wire [2:0] y;
priorityencoder83behave uut(i,en,y);
initial
begin
$dumpfile("dump.vcd");
$dumpvars();
en=1;
#10 i = 8'b00000001;
#10 i = 8'b0000001x;
#10 i = 8'b000001xx;
#10 i = 8'b00001xxx;
#10 i = 8'b0001xxxx;
#10 i = 8'b001xxxxx;
#10 i = 8'b01xxxxxx;
#10 i = 8'b1xxxxxxx;
end
initial #100;
endmodule
// Code your design here
begin
if (en==1)
begin
case (i)
8'b00000001: y=3'b000;
8'b0000001x: y=3'b001;
8'b000001xx: y=3'b010;
8'b00001xxx: y=3'b011;
8'b0001xxxx: y=3'b100;
8'b001xxxxx: y=3'b101;
8'b01xxxxxx: y=3'b110;
8'b1xxxxxxx: y=3'b111;
default : y = 3'bxxx;
endcase
end
end
endmodule
Result : encoder is realized in data flow, behavioral, structural methods using eda software