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.sv
  4 // Function    : Pri Encoder using If
  5 // Coder      : Deepak Kumar Tala
  6 //-----------------------------------------------------
  7 module pri_encoder_using_if (
  8 output reg  [3:0]  binary_out , //  4 bit binary output
  9 input  wire [15:0] encoder_in , //  16-bit input 
 10 input  wire        enable       //  Enable for the encoder
 11 );
 12 //--------------Code Starts Here----------------------- 
 13 always_comb
 14 begin
 15   binary_out = 0;
 16   if (enable) begin
 17    if (encoder_in[0] == 1) begin
 18     binary_out = 1; 
 19    end else if (encoder_in[1] == 1) begin
 20     binary_out = 2; 
 21    end else if (encoder_in[2] == 1) begin
 22     binary_out = 3; 
 23    end else if (encoder_in[3] == 1) begin
 24     binary_out = 4; 
 25    end else if (encoder_in[4] == 1) begin
 26     binary_out = 5; 
 27    end else if (encoder_in[5] == 1) begin
 28     binary_out = 6; 
 29    end else if (encoder_in[6] == 1) begin
 30     binary_out = 7; 
 31    end else if (encoder_in[7] == 1) begin
 32     binary_out = 8; 
 33    end else if (encoder_in[8] == 1) begin
 34     binary_out = 9; 
 35    end else if (encoder_in[9] == 1) begin
 36     binary_out = 10; 
 37    end else if (encoder_in[10] == 1) begin
 38     binary_out = 11; 
 39    end else if (encoder_in[11] == 1) begin
 40     binary_out = 12; 
 41    end else if (encoder_in[12] == 1) begin
 42     binary_out = 13; 
 43    end else if (encoder_in[13] == 1) begin
 44     binary_out = 14; 
 45    end else if (encoder_in[14] == 1) begin
 46     binary_out = 15; 
 47    end
 48   end
 49 end
 50 
 51 endmodule  
You could download file sv_examples 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.sv
  4 // Function    : Pri Encoder using assign
  5 // Coder      : Deepak Kumar Tala
  6 //-----------------------------------------------------
  7 module pri_encoder_using_assign (
  8 output wire [3:0]  binary_out , //  4 bit binary output
  9 input  wire [15:0] encoder_in , //  16-bit input 
 10 input  wire        enable       //  Enable for the encoder
 11 );
 12 //--------------Code Starts Here----------------------- 
 13 assign  binary_out  = ( ! enable) ? 0 : (
 14     (encoder_in[0]) ? 0 : 
 15     (encoder_in[1]) ? 1 : 
 16     (encoder_in[2]) ? 2 : 
 17     (encoder_in[3]) ? 3 : 
 18     (encoder_in[4]) ? 4 : 
 19     (encoder_in[5]) ? 5 : 
 20     (encoder_in[6]) ? 6 : 
 21     (encoder_in[7]) ? 7 : 
 22     (encoder_in[8]) ? 8 : 
 23     (encoder_in[9]) ? 9 : 
 24     (encoder_in[10]) ? 10 : 
 25     (encoder_in[11]) ? 11 : 
 26     (encoder_in[12]) ? 12 : 
 27     (encoder_in[13]) ? 13 : 
 28     (encoder_in[14]) ? 14 : 15); 
 29 
 30 endmodule 
You could download file sv_examples 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