Pages

Tuesday, February 10, 2015

Verilog Behavioral Program for Encoder (with and without priority)

8 X 3 ENCODER WITHOUT PRIORITY :


module encwtoutprio(a,en,y);
input [7:0] a;
input en;
output reg [2:0] y;
always@(a or en)
begin
if(!en)
y<=1'b0;
else
case(a)
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;
endcase
end
endmodule

8 X 3 PRIORITY ENCODER :


module priorityencoder(a,en,y);
input [7:0] a;
input en;
output reg [2:0] y;
always@(a or en)
begin
if(!en)
y<=1'b0;
else
casex(a)
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;
Endcase
end
endmodule

0 comments:

Post a Comment

Receive all updates via Facebook. Just Click the Like Button Below...