+92 332 4229 857 99ProjectIdeas@Gmail.com

Verilog Code For 8:3 Priority Encoder | Verilog Example Codes


Priority encoder is a special type of encoder in which multiple bits at the input can be asserted. The response at the output is however defined by the priority rule, defined previously. Priority encoders have vast application in different client-server systems. In client-server systems decision is made to grant a service based on the priority of any specific client. 
Here is a verilog code for an 8:3 priority encoder. It grants the highest priority to the "most left sided bit in the input word". For example in data word "00010101" the highest priority is carried by the most left sided one, appearing at the fourth (counting from left side). So all the other bits that come next to it will be discarded or in other words will not be taken into account. Verilog implementation has been done using "if-else" statement.
module priority_encoder (code, valid_data, data);
output [2:0] code;
output       valid data;
input  [7:0] data;
reg    [2:0] code;

assign valid_data= |data; // Use of "reduction or" operator
always @ (data)
begin
if(data[7]) code=7; else
if(data[6]) code=6; else
if(data[5]) code=5; else
if(data[4]) code=4; else
if(data[3]) code=3; else
if(data[2]) code=2; else
if(data[1]) code=1; else
if(data[0]) code=0; else
            code=3'bx;
end
 endmodule

0 comments: