我知道VHDL,现在我尝试做一些verilog。我有两个文件,一个包含一个计数器,另一个包含一个 32 位全加器。
计数器.v:
module counter (
input clk,
input enable,
input reset,
output reg [3:0] count
);
wire [31:0] temp2 = 0;
reg [31:0] clk_count = 0;
wire [31:0] test = 32'b1;
parameter integer number_of_clk_cycles = 15;
adder adder1(clk_count, test, temp2);
always @(posedge clk) begin
if (reset) begin
count = 0;
end else if (enable) begin
clk_count <= temp2;
if(clk_count == number_of_clk_cycles) begin
count <= count + 1;
clk_count <= 0;
end
end
end
endmodule
加法器.v:
module adder(
input [31:0] a,
input [31:0] b,
output [31:0] c
);
wire [32:0] cin; //The internal Carry signal
assign cin[0] = 0; //Force the carry line to 0, since the first adder has no carry
genvar i;
for(i=0; i<32;i = i + 1) begin
fa fa1( a[i], b[i], cin[i], c[i], cin[i+1]);
end
endmodule
module ha( a, b, s, c);
input a, b;
output s, c;
xor xor1(s ,a, b); //Output first, then inputs
and and1(c, a ,b); //Output first, then inputs
endmodule
module fa (a , b, cin, s, cout);
input a, b, cin;
output s, cout;
ha ha1(a, b, ha1_sum, ha1_cout); //Half adder 1
ha ha2(ha1_sum, cin, s, ha2_cout); //Half adder 2
or or1(cout, ha1_cout, ha2_cout); //Carry out
endmodule
我在 ModelSIM 中验证了我的完整加法器代码,它一直有效。但是当我尝试运行 counter.v 代码时,输出 adder1 始终为“X”(不在乎)。如果启用设置为“1”,则无关将通过加法器 ( clk_count <= temp1;
) 产生波动。我错过了什么?