2017-09-29 24 views
0

2D配列の特定のビット(code [i] [k])に値を代入しようとしています。これはネットタイプです。しかし、assigned.reg [3:0]コード[0:3]でない値は、未知の論理値 'X'を取得します。ここ2D配列の特定のビットに値を代入する[システム - Verilog]

ループのコードスニペット

  for(k=0;k<len;k++) begin 
       if (tc[k] == 1'b0) begin 
        code[i][k]= 1'b0;//----> value is not assigning as expected 
       end else begin 
        code[i][k]= 1'b1;// ---> value is not assigning as expected 
       end 
      end 
      codeLen[i] = len; 

これはblock.Here、コードcodeLen出力型で常にに属しています。

output [3:0] code[0:3]; 
output [3:0] codeLen[0:3]; 
reg [3:0] code[0:3]; 
reg [3:0] codeLen[0:3]; 

codeLen [i]はコード[i]が[K]正しくなく割り当てられます。私はi番目のバイトのk番目のビットを割り当てようとしていました。

詳細 私は6入力を取り、出力として2つの2次元配列を返すモジュールを作成しました。

`timescale 1ns/1ps 
module generate_code(CLK,nRST,nodes,nodeCount,characters,charCount,code,codeLen); 
input CLK; 
input nRST; 
input integer nodeCount;//Total nodes in huffman tree 
input integer charCount;//Total unique characters 
input [6:0] characters[0:3]; 
input [23:0] nodes[0:6]; // total characters 

output [3:0] code[0:3]; //[2:0] max code length <= total characters 
output [3:0] codeLen[0:3]; 

reg [3:0] code[0:3]; 
reg [3:0] codeLen[0:3]; 

reg[3:0] tc;//temprary code reg. Holds a single bit in each byte 
integer len=0;//code length 
reg [23:0] tNode; 

function void FindRoot; 
    reg [23:0] aNode;//local 
    integer i; 
    begin 
    for (i=0; i<nodeCount;i++) begin // For all nodes 
     aNode= nodes[i]; // aNode is current node 
     if (tNode[23:16] == aNode[14:7]) begin 
      tc[len]= tNode[15];//15th bit of nodes is codebit 
      len++; 
     //aNode is parent of tNode. Is it root? 
      if(aNode[23:16]==8'b0000_0000) begin//or frequency==nodeCount or node_id = 8'b1111_1111 
       return; 
      end else begin 
       tNode=aNode; 
       FindRoot(); 
      end 
     end 
    end 
    end 
endfunction 

[email protected](posedge CLK or negedge nRST) 
begin 
    if(!nRST) begin 
    // init 
    end 
    else begin 
     // Do code generation 
     integer i,j,k; 
     for(i= 0;i < charCount;i++) begin // For all character we are going to find codeword 
      for(j=0; j<nodeCount; j++) begin 
       tNode= nodes[j];//current node 
       if (characters[i] == tNode[6:0]) begin 
       // Got the character. tNode is a leaf nodes. Lets back track to root. 
        break; 
       end 
      end 
      len=0; 
      FindRoot(); 
      for(k=0;k<len;k++) begin 
       if (tc[k] == 1'b0) begin 
        code[i][k]= 1'b0; 
       end else begin 
        code[i][k]= 1'b1; 
       end 
      end 
      //code[i]=2; 
      codeLen[i]= len; 
     end 
    end 
end 
endmodule 

I [] []を符号化するために値を割り当てています、次のループが実行されることが期待される:ここ

モジュールです。コード[] []のすべてのビットが設定されるわけではありません。デバッグ中に割り当てに来ると、値が割り当てられていないことがわかりました(code [i] [k] = 1または0)。その取得の未知の論理値X.

   for(k=0;k<len;k++) begin 
       if (tc[k] == 1'b0) begin 
        code[i][k]= 1'b0; 
       end else begin 
        code[i][k]= 1'b1; 
       end 
      end 

テストベンチ:

`timescale 1ns/1ps 
module generate_code_test; 

// Inputs 
reg CLK; 
reg nRST; 
integer nodeCount=7;//Total nodes in huffman tree 
integer charCount=4;//Total unique characters 
reg [6:0] characters[0:3]; 
reg [23:0] nodes[0:6]; // total characters 

// Outputs 
wire [3:0] code[0:3]; //[2:0] max code length <= total characters 
wire [3:0] codeLen[0:3]; 

generate_code uut (
    .CLK(CLK), 
    .nRST(nRST), 
    .nodes(nodes), 
    .nodeCount(nodeCount), 
    .characters(characters), 
    .charCount(charCount), 
    .code(code), 
    .codeLen(codeLen) 
); 

initial begin 
    // Initialize Inputs 
    CLK = 0; 
    nRST = 0; 
    nodeCount= 7; 
    charCount= 4; 
    characters[0]= 7'b110_0001; 
    characters[1]= 7'b110_0010; 
    characters[2]= 7'b110_0011; 
    characters[3]= 7'b110_0100; 

    nodes[0] = 24'b0000_0011_0_0000_0001_110_0001; 
    nodes[1] = 24'b0000_0011_1_0000_0010_110_0011; 
    nodes[2] = 24'b0000_0101_1_0000_0011_111_1111; 
    nodes[3] = 24'b0000_0101_0_0000_0100_110_0010; 
    nodes[4] = 24'b1111_1111_1_0000_0101_111_1111; 
    nodes[5] = 24'b1111_1111_0_0000_0110_110_0100; 
    nodes[6] = 24'b0000_0000_0_1111_1111_111_1111; 

    // Wait 10 ns for global reset to finish 
    #10; 
    nRST = 1; 

end 
parameter DELAY = 1; 
always 
    #DELAY CLK = ~CLK; 

endmodule 

コードは、私はちょうどのverilogを学び始めたのModelSim 2016 にコンパイルされています。だから、本当にあなたの助けを借りて私の間違いを見せてくれるでしょう。よろしくです。 よろしくお願いします。

+0

ようこそスタックオーバーフロー。私はその行動があなたが投稿していないコードによって引き起こされたと考えています。たとえば、 'k'と' len'とは何ですか?ループがゼロ回実行されている可能性がありますか? [MCVE](https://stackoverflow.com/help/mcve) - コンパイル可能なコードの小さなブロック - を投稿して、他の人があなたの問題を再現できるようにしてください。 –

+0

@MatthewTaylor、ありがとうございました。私はtestbenchと共にコンパイル可能なモジュールをアップロードしました。私は、コード[] []のビットを割り当てるとループが実行されると信じています。 kとlenはその時に必要な値を持つ必要があります。私はコードのすべてのビットを設定していませんが[] []。私がモジュールをデバッグしてその割り当てに来ると、行は実行されていますが、code [] []は割り当てられていません。 – rakibdana

+1

コードはコンパイルされません - [http://www.edaplayground.com/x/4uk4](http://www.edaplayground.com/x/4uk4)を参照してください。私はそれを修正し、シミュレーションは止まらなかった。あなたは(a)それをコンパイルして(MCVEの "C")、(b)余分なものをいくつか取り除いて問題を残すことができますか(MCVEの "M")? –

答えて

0

私は自分の問題を解決しました。 code [] []のすべてのビットが設定されているわけではありません。これは、ビットを設定した後でさえ、code [] []に未知の論理値をもたらします。 のコード[] []のすべてのビットを常に初期化した後に解決されます。ブロックは常にです。

関連する問題