0% found this document useful (0 votes)
18 views17 pages

Encoder

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views17 pages

Encoder

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Sharon priyanka

18251A04C0

Aim:to design and test the encoder using Structural, dataflow, behavioral models

Software :Edaplayground

//STRUCTURAL

// Code your testbench here

// 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

);

or (y[0] , i[1] , i[3] , i[5] , i[7]);

or (y[1] , i[2] , i[3] , i[6] , i[7]);

or (y[2] , i[4] , i[5] , i[6] , i[7]);

or (en , i[0] , i[1] , i[2], i[3] , i[4] , i[5] , i[6] , i[7]);

endmodule
// DATAFLOW

// Code your testbench here

// or browse Examples

module tb_en8data;

reg [7:0] i; reg en;

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

module en8data(input[7:0] i,input en,output [2:0] y);

assign y[0]=(en & (i[1] | i[3] |i[5] | i[7]));

assign y[1]=(en & (i[2] | i[3] | i[6] | i[7]));

assign y[2]=(en & (i[4] | i[5] | i[6] | i[7]));

endmodule
//BEHAVIOURAL

// Code your testbench here

// 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

module encoder83behave(input[7:0] i, input en, output reg [2:0] y);

always @(i or en)

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

// Code your testbench here

// 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

module priorityencoder83behave(input [7:0] i,input en, output reg [2:0] y );

always @(i or en)

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

You might also like