我试图通过实例化全加法器模块来模拟BCD加法器。在没有测试模块的情况下编译代码运行良好。然而,我目前对我的测试平台有问题。它显示了一个错误:
“
”附近的"tb_C":语法错误,意外标识符,期待.*或'.‘。
我目前正在努力学习HDL自上而下的方法。
//Half Adder (HA) module
module half_adder(output S, Co, input a, b);
xor U1(S, a, b);
and U2(Co, a, b);
endmodule
//Full Adder (FA) module
module full_adder(output S, Co, input a, b, cin);
wire ha_S0, ha_Co0, ha_Co1;
half_adder HA1(ha_S0, ha_Co0, a, b); //instance 1 of HA
half_adder HA2(S, ha_Co1, ha_S0, cin); //instance 2 of HA
or U3(Co, ha_Co0, ha_Co1);
endmodule
//4-bit Full Parallel Adder
module yonbit_pa(input [3:0]a, [3:0]b, cin, output [3:0]S, Cout);
wire [2:0]Co;
full_adder FA1(S[0], Co[0], a[0], b[0], cin);
full_adder FA2(S[1], Co[1], a[1], b[1], Co[0]);
full_adder FA3(S[2], Co[2], a[2], b[2], Co[1]);
full_adder FA4(S[3], Cout, a[3], b[3], Co[2]);
endmodule
//Single Digit BCD Adder
module bcd_adder(input [3:0]a, [3:0]b, cin, output C, [3:0]D);
supply0 gnd;
wire Co;
wire [3:0]S;
wire [2:0]orin;
fourbit_pa PA1(S[0], S[1], S[2], S[3], Co, a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3], cin);
and U4(orin[0], S[3], S[2]), U5(orin[1], S[3], S[1]);
or U6(orin[2], orin[1], orin[0]), U7(C, orin[2], Co);
fourbit_pa PA2(D[0], D[1], D[2], D[3], S[0], S[1], S[2], S[3], gnd, C, C, gnd, gnd);
endmodule
//Testbench
module mut_bcd_adder;
reg [3:0]a;
reg [3:0]b;
reg cin;
wire C;
wire [3:0]D;
bcd_adder mut_bcd_adder(.a(tb_a),.b(tb_b),.cin(tb_cin), tb_C, tb_D);
initial begin
$display(" Time a b cin C D");
$monitor($time,,"%b %b %b %b %b", tb_a, tb_b, tb_cin, tb_C, tb_D);
#0 tb_cin = 1'b0; tb_a = 4'b0000; tb_b = 4'b0000;
#5 tb_cin = 1'b0; tb_a = 4'b0011; tb_b = 4'b1001;
#5 tb_cin = 1'b0; tb_a = 4'b1000; tb_b = 4'b0111;
#5 tb_cin = 1'b0; tb_a = 4'b0100; tb_b = 4'b0100;
#5 tb_cin = 1'b0; tb_a = 4'b0111; tb_b = 4'b0010;
#5 tb_cin = 1'b1; tb_a = 4'b1001; tb_b = 4'b0110;
#5 tb_cin = 1'b1; tb_a = 4'b0011; tb_b = 4'b0011;
#5 tb_cin = 1'b1; tb_a = 4'b0111; tb_b = 4'b0111;
#5 tb_cin = 1'b1; tb_a = 4'b0010; tb_b = 4'b0110;
#5 $finish;
end
endmodule发布于 2022-09-29 09:46:34
如果您在EDA游乐场上的不同模拟器上运行您的代码,您将得到更有帮助的编译错误消息。综合起来,你就能更清楚地了解这个问题。例如,在VCS中:
Error-[MPC] Mixed port connection is not allowed
testbench.sv,
The two types of module port connections, by ordered list and by name, shall
not be mixed.
Please refer to Verilog LRM(1364-2001), section 12.3.6.
1 error更改:
bcd_adder mut_bcd_adder(.a(tb_a),.b(tb_b),.cin(tb_cin), tb_C, tb_D);至:
bcd_adder mut_bcd_adder(.a(tb_a),.b(tb_b),.cin(tb_cin), .C(tb_C), .D(tb_D));关键是您需要对所有端口使用相同的端口连接样式。
您还需要修复其他语法错误。您需要声明测试平台中的所有信号:tb_a、tb_b等。
https://stackoverflow.com/questions/73893253
复制相似问题