2015-11-04 101 views
-1

我已经用Verilog编写了这个程序,但是当我尝试模拟它时,它只显示XXXX ...在输出和输入变量上。我不明白我做错了什么...Verilog程序将不会读取输入

PS。在我给出的模拟文件中,例如值in = 16'b1101100100001111; #20;

module hamming_decoder(
output reg [10:0] out, 
output reg [3:0] error_index, 
output reg error, 
output reg uncorrectable, 
input [16:1] in 
); 

reg y; // in case "single error", gives the position of the error bit  
reg [1:0] check; // if check[0] = 0 - no error 
       // if check[0] = 1 and check[1] = 0 => double error 
       // if check[0] = 1 and check[1] = 1 => single error 


assign error_index[0] = in[16]^in[14]^in[12]^in[10]^in[8]^in[6]^in[4]^in[2]; 
assign error_index[1] = in[15]^in[14]^in[11]^in[10]^in[7]^in[6]^in[3]^in[2]; 
assign error_index[2] = in[13]^in[12]^in[11]^in[10]^in[5]^in[4]^in[3]^in[2]; 
assign error_index[3] = in[9]^in[8]^in[7]^in[6]^in[5]^in[4]^in[3]^in[2]; 

assign check[1] = in[1]^in[2]^in[3]^in[4]^in[5]^in[6]^in[7]^in[8]^in[9]^in[10]^in[11]^in[12]^in[13]^in[14]^in[15]^in[16]; 

always @(*) 
begin 
if (error_index[0] != 0 || error_index[1] != 0 || error_index[2] != 0 || error_index[3] != 0) 
    begin 
     check[0] = 1; 
     error = 1; 
    end 

if (check[0] == 0) 
    begin 
     error = 0; 
     uncorrectable = 0; 
     out[0] = in[1]; 
     out[1] = in[2]; 
     out[2] = in[3]; 
     out[3] = in[4]; 
     out[4] = in[5]; 
     out[5] = in[6]; 
     out[6] = in[7]; 
     out[7] = in[9]; 
     out[8] = in[10]; 
     out[9] = in[11]; 
     out[10] = in[13]; 
    end 
     else if(check[1] == 0) 
       begin 
        error = 1; 
        uncorrectable = 1; 
        out[0] = in[3]; 
        out[1] = in[5]; 
        out[2] = in[6]; 
        out[3] = in[7]; 
        out[4] = in[9]; 
        out[5] = in[10]; 
        out[6] = in[11]; 
        out[7] = in[12]; 
        out[8] = in[13]; 
        out[9] = in[14]; 
        out[10] = in[15]; 
       end 
      else if (check[1] == 1 && check[0] != 0) 
         begin 
          error = 1; 
          uncorrectable = 0; 
          y = error_index[0] + error_index[1] * 2 + error_index[2] * 4 + error_index[3] * 8; 
          out[0] = in[3]; 
          out[1] = in[5]; 
          out[2] = in[6]; 
          out[3] = in[7]; 
          out[4] = in[9]; 
          out[5] = in[10]; 
          out[6] = in[11]; 
          out[7] = in[12]; 
          out[8] = in[13]; 
          out[9] = in[14]; 
          out[10] = in[15]; 
          out[y-1] = !out[y-1]; // ? 
         end 
end 

endmodule 
+1

发布您的测试台代码。 – toolic

回答

1

这可能是与测试台端口连接有关的问题。你确定你的测试台实例吗?另外,为了提供正确的输入,您需要有一个用于周期性输入的时钟信号,否则所有的输入都将在设计时在零模拟时间传播。

此样本16'b1101100100001111显示为单个错误输入数据。如果您还要展示您的测试平台,那将是非常棒的。

我模拟了你的代码,并为它提供了一个测试平台。离开逻辑部分,设计似乎工作正常。测试台可用here

编辑:

是的,你的设计是一个组合电路。从输入到输出的转换应发生在零模拟时间。因此,只要发生在100ns,计算的值并且测试突然结束。 20ns延迟和中提琴后,只需添加in = 0 ..!

我在上面的EDAPlayground链接中附加了你的测试,只是添加了上述修改。关于测试平台编码基础知识的这个PDF可能是有用的。

+0

这是我的Verilog测试夹具文件:'时间刻度1ns/1ps 模块hamming_decoder_test; \t //输入: \t reg [16:1] in; \t //输出: \t wire [10:0] out; \t wire [3:0] error_index; \t电线错误; \t电线不可纠正; \t \t UUT hamming_decoder( \t \t .OUT(下), \t \t .error_index(error_index) \t \t .error(误差), \t \t .uncorrectable(不可校正), \t \t。in(in) \t); \t初始开始 \t \t \t 在= 0 \t; \t \t#100; \t \t \t \t in = 16'b1110101110001011; \t \t \t \t#20; \t年底 endmodule –

+0

遗憾:这里是该文件并显示结果的打印屏幕:根据您输入的修改我的答案http://we.tl/2ty5m8VbGZ –

+0

... – sharvil111