quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../../images/main/bullet_green_ball.gif Priority Encoders
   

space.gif

   

space.gif

  ../../images/main/bulllet_4dots_orange.gif Pri-Encoder - Using if-else Statement
   

space.gif


  1 //-----------------------------------------------------
  2 // Design Name : pri_encoder_using_if
  3 // File Name   : pri_encoder_using_if.v
  4 // Function    : Pri Encoder using If
  5 // Coder       : Deepak Kumar Tala
  6 //-----------------------------------------------------
  7 module pri_encoder_using_if (
  8 binary_out , //  4 bit binary output
  9 encoder_in , //  16-bit input 
 10 enable       //  Enable for the encoder
 11 );
 12 output [3:0] binary_out ;
 13 input  enable ; 
 14 input [15:0] encoder_in ; 
 15      
 16 reg [3:0] binary_out ;
 17       
 18 always @ (enable or encoder_in)
 19 begin
 20   binary_out = 0;
 21   if (enable) begin
 22    if (encoder_in[0] == 1) begin
 23     binary_out = 1; 
 24    end else if (encoder_in[1] == 1) begin
 25     binary_out = 2; 
 26    end else if (encoder_in[2] == 1) begin
 27     binary_out = 3; 
 28    end else if (encoder_in[3] == 1) begin
 29     binary_out = 4; 
 30    end else if (encoder_in[4] == 1) begin
 31     binary_out = 5; 
 32    end else if (encoder_in[5] == 1) begin
 33     binary_out = 6; 
 34    end else if (encoder_in[6] == 1) begin
 35     binary_out = 7; 
 36    end else if (encoder_in[7] == 1) begin
 37     binary_out = 8; 
 38    end else if (encoder_in[8] == 1) begin
 39     binary_out = 9; 
 40    end else if (encoder_in[9] == 1) begin
 41     binary_out = 10; 
 42    end else if (encoder_in[10] == 1) begin
 43     binary_out = 11; 
 44    end else if (encoder_in[11] == 1) begin
 45     binary_out = 12; 
 46    end else if (encoder_in[12] == 1) begin
 47     binary_out = 13; 
 48    end else if (encoder_in[13] == 1) begin
 49     binary_out = 14; 
 50    end else if (encoder_in[14] == 1) begin
 51     binary_out = 15; 
 52    end
 53   end
 54 end
 55 
 56 endmodule  
You could download file pri_encoder_using_if.v here
   

space.gif

  ../../images/main/bulllet_4dots_orange.gif Encoder - Using assign Statement
   

space.gif


  1 //-----------------------------------------------------
  2 // Design Name : pri_encoder_using_assign
  3 // File Name   : pri_encoder_using_assign.v
  4 // Function    : Pri Encoder using assign
  5 // Coder       : Deepak Kumar Tala
  6 //-----------------------------------------------------
  7 module pri_encoder_using_assign (
  8 binary_out , //  4 bit binary output
  9 encoder_in , //  16-bit input 
 10 enable       //  Enable for the encoder
 11 );
 12 
 13 output [3:0] binary_out ;
 14 input  enable ; 
 15 input [15:0] encoder_in ; 
 16 
 17 wire [3:0] binary_out ;
 18       
 19 assign  binary_out  = ( ! enable) ? 0 : (
 20     (encoder_in[0]) ? 0 : 
 21     (encoder_in[1]) ? 1 : 
 22     (encoder_in[2]) ? 2 : 
 23     (encoder_in[3]) ? 3 : 
 24     (encoder_in[4]) ? 4 : 
 25     (encoder_in[5]) ? 5 : 
 26     (encoder_in[6]) ? 6 : 
 27     (encoder_in[7]) ? 7 : 
 28     (encoder_in[8]) ? 8 : 
 29     (encoder_in[9]) ? 9 : 
 30     (encoder_in[10]) ? 10 : 
 31     (encoder_in[11]) ? 11 : 
 32     (encoder_in[12]) ? 12 : 
 33     (encoder_in[13]) ? 13 : 
 34     (encoder_in[14]) ? 14 : 15); 
 35 
 36 endmodule 
You could download file pri_encoder_using_assign.v here
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com