|
|
|
|
|
|
|
|
|
|
|
|
Encoders
|
|
|
|
|
|
|
|
|
|
|
|
Encoder - Using if-else Statement
|
|
|
|
|
|
1 //-----------------------------------------------------
2 // Design Name : encoder_using_if
3 // File Name : encoder_using_if.sv
4 // Function : Encoder using If
5 // Coder : Deepak Kumar Tala
6 //-----------------------------------------------------
7 module 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 == 16'h0002) begin
18 binary_out = 1;
19 end if (encoder_in == 16'h0004) begin
20 binary_out = 2;
21 end if (encoder_in == 16'h0008) begin
22 binary_out = 3;
23 end if (encoder_in == 16'h0010) begin
24 binary_out = 4;
25 end if (encoder_in == 16'h0020) begin
26 binary_out = 5;
27 end if (encoder_in == 16'h0040) begin
28 binary_out = 6;
29 end if (encoder_in == 16'h0080) begin
30 binary_out = 7;
31 end if (encoder_in == 16'h0100) begin
32 binary_out = 8;
33 end if (encoder_in == 16'h0200) begin
34 binary_out = 9;
35 end if (encoder_in == 16'h0400) begin
36 binary_out = 10;
37 end if (encoder_in == 16'h0800) begin
38 binary_out = 11;
39 end if (encoder_in == 16'h1000) begin
40 binary_out = 12;
41 end if (encoder_in == 16'h2000) begin
42 binary_out = 13;
43 end if (encoder_in == 16'h4000) begin
44 binary_out = 14;
45 end if (encoder_in == 16'h8000) begin
46 binary_out = 15;
47 end
48 end
49 end
50
51 endmodule
You could download file sv_examples here
|
|
|
|
|
|
Encoder - Using case Statement
|
|
|
|
|
|
1 //-----------------------------------------------------
2 // Design Name : encoder_using_case
3 // File Name : encoder_using_case.sv
4 // Function : Encoder using Case
5 // Coder : Deepak Kumar Tala
6 //-----------------------------------------------------
7 module encoder_using_case(
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 ENCODER : begin
15 binary_out = 0;
16 if (enable) begin
17 case (encoder_in)
18 16'h0002 : binary_out = 1;
19 16'h0004 : binary_out = 2;
20 16'h0008 : binary_out = 3;
21 16'h0010 : binary_out = 4;
22 16'h0020 : binary_out = 5;
23 16'h0040 : binary_out = 6;
24 16'h0080 : binary_out = 7;
25 16'h0100 : binary_out = 8;
26 16'h0200 : binary_out = 9;
27 16'h0400 : binary_out = 10;
28 16'h0800 : binary_out = 11;
29 16'h1000 : binary_out = 12;
30 16'h2000 : binary_out = 13;
31 16'h4000 : binary_out = 14;
32 16'h8000 : binary_out = 15;
33 endcase
34 end
35 end
36
37 endmodule
You could download file sv_examples here
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|