Trung tâm đào tạo thiết kế vi mạch Semicon


  • ĐĂNG KÝ TÀI KHOẢN ĐỂ TRUY CẬP NHIỀU TÀI LIỆU HƠN!
  • Create an account
    *
    *
    *
    *
    *
    Fields marked with an asterisk (*) are required.
semicon_lab.jpg

Ví dụ về Verilog - Bộ Mã Hóa Ưu Tiên

E-mail Print PDF
Bộ Mã Hóa Ưu Tiên sử dụng diễn tả if-else
  1 //-----------------------------------------------------
2 // Design Name : pri_encoder_using_if
3 // File Name : pri_encoder_using_if.v
4 // Function : Pri Encoder using If
5 // Coder : -
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 == {{14{1'bx}},1'b1,{1{1'b0}}}) begin
23 binary_out = 1;
24 end else if (encoder_in == {{13{1'bx}},1'b1,{2{1'b0}}}) begin
25 binary_out = 2;
26 end else if (encoder_in == {{12{1'bx}},1'b1,{3{1'b0}}}) begin
27 binary_out = 3;
28 end else if (encoder_in == {{11{1'bx}},1'b1,{4{1'b0}}}) begin
29 binary_out = 4;
30 end else if (encoder_in == {{10{1'bx}},1'b1,{5{1'b0}}}) begin
31 binary_out = 5;
32 end else if (encoder_in == {{9{1'bx}},1'b1,{6{1'b0}}}) begin
33 binary_out = 6;
34 end else if (encoder_in == {{8{1'bx}},1'b1,{7{1'b0}}}) begin
35 binary_out = 7;
36 end else if (encoder_in == {{7{1'bx}},1'b1,{8{1'b0}}}) begin
37 binary_out = 8;
38 end else if (encoder_in == {{6{1'bx}},1'b1,{9{1'b0}}}) begin
39 binary_out = 9;
40 end else if (encoder_in == {{5{1'bx}},1'b1,{10{1'b0}}}) begin
41 binary_out = 10;
42 end else if (encoder_in == {{4{1'bx}},1'b1,{11{1'b0}}}) begin
43 binary_out = 11;
44 end else if (encoder_in == {{3{1'bx}},1'b1,{12{1'b0}}}) begin
45 binary_out = 12;
46 end else if (encoder_in == {{2{1'bx}},1'b1,{13{1'b0}}}) begin
47 binary_out = 13;
48 end else if (encoder_in == {{1{1'bx}},1'b1,{14{1'b0}}}) begin
49 binary_out = 14;
50 end else if (encoder_in == {1'b1,{15{1'b0}}}) begin
51 binary_out = 15;
52 end
53 end
54 end
55
56 endmodule
Bộ Mã Hóa - sử dụng diễn tả ASSIGN
  1 //-----------------------------------------------------
2 // Design Name : pri_encoder_using_assign
3 // File Name : pri_encoder_using_assign.v
4 // Function : Pri Encoder using assign
5 // Coder : -
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 == 16'bxxxx_xxxx_xxxx_xxx1) ? 0 :
21 (encoder_in == 16'bxxxx_xxxx_xxxx_xx10) ? 1 :
22 (encoder_in == 16'bxxxx_xxxx_xxxx_x100) ? 2 :
23 (encoder_in == 16'bxxxx_xxxx_xxxx_1000) ? 3 :
24 (encoder_in == 16'bxxxx_xxxx_xxx1_0000) ? 4 :
25 (encoder_in == 16'bxxxx_xxxx_xx10_0000) ? 5 :
26 (encoder_in == 16'bxxxx_xxxx_x100_0000) ? 6 :
27 (encoder_in == 16'bxxxx_xxxx_1000_0000) ? 7 :
28 (encoder_in == 16'bxxxx_xxx1_0000_0000) ? 8 :
29 (encoder_in == 16'bxxxx_xx10_0000_0000) ? 9 :
30 (encoder_in == 16'bxxxx_x100_0000_0000) ? 10 :
31 (encoder_in == 16'bxxxx_1000_0000_0000) ? 11 :
32 (encoder_in == 16'bxxx1_0000_0000_0000) ? 12 :
33 (encoder_in == 16'bxx10_0000_0000_0000) ? 13 :
34 (encoder_in == 16'bx100_0000_0000_0000) ? 14 : 15);
35
36 endmodule
Last Updated ( Saturday, 01 June 2013 15:38 )  
Chat Zalo