WRITE VERILOG PROGRAM FOR 8 TO 3 ENCODER WITHOUT PRIORITY

An encoder is a digital circuit which performs the inverse of decoder.An encoder has 2^N input lines and N output lines.In encoder the output lines genrate the binary code corresponding to input value.The decimal to bcd encoder usually has 10 input lines and 4 ouput lines.The decoder decimal data as an input for decoder an encoded bcd ouput is available at 4 output lines.

 

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

use IEEE.STD_LOGIC_ARITH.ALL;

use IEEE.STD_LOGIC_UNSIGNED.ALL;

 

module encoder (din, dout);

input [7:0] din;
output [2:0] dout;
reg [2:0] dout;


always @(din)

begin

if (din ==8'b00000001) dout=3'b000;
else if (din==8'b00000010) dout=3'b001;

else if (din==8'b00000100) dout=3'b010;
else if (din==8'b00001000) dout=3'b011;
else if (din==8'b00010000) dout=3'b100;
else if (din ==8'b00100000) dout=3'b101;
else if (din==8'b01000000) dout=3'b110;
else if (din==8'b10000000) dout=3'b111;
else dout=3'bX;

end

endmodule