我对Verilog并不熟悉。我正在尝试使用for循环创建RCA但是在尝试合成模块时遇到错误。
我得到的错误是
不允许对非注册i进行程序性分配
//1-bit full adder
module fadder (s, cout, a, b, cin);
input a, b, cin;
output s, cout;
assign s = (a ^ b) ^ cin;
assign cout = ((a & b) | ((a | b) & cin));
endmodule
//RCA Logic
module part1(s, cout, a, b, cin, clk);
parameter BIT_WIDTH = 128;
input [BIT_WIDTH-1:0] a, b;
input cin;
input clk;
output cout;
output [BIT_WIDTH-1:0] s;
wire [BIT_WIDTH:0] cin_wire;
assign cin_wire[0] = cin;
genvar i;
generate
always@(posedge clk)
begin
for(i = 0; i <= BIT_WIDTH-1; i = i + 1) //error is on this line
begin:
fadder fadder_inst (.s(s[i]), .cout(cin_wire[i+1]), .a(a[i]), .b(b[i]), .cin(cin_wire[i]));
end
end
endgenerate
assign cout = cin_wire[BIT_WIDTH];
endmodule
感谢任何帮助。感谢
答案 0 :(得分:1)
generate
for(i = 0; i <= BIT_WIDTH-1; i = i + 1)
begin
fadder fadder_inst (.s(s[i]), .cout(cin_wire[i+1]), .a(a[i]), .b(b[i]), .cin(cin_wire[i]));
end
endgenerate
您无法在始终阻止内部生成模块。
在连接到fadder_inst之前,你必须单独操作always block中的输入。
我猜测,RCA不依赖于时钟。它纯粹的异步电路。
答案 1 :(得分:0)
您无法在程序块中实例化模块(初始, 总是,always_comb,always_ff,always_latch,final,task,function)。
你可以这样做以达到你的目的。
module fadder (clk, s, cout, a, b, cin);
input a, b, cin, clk;
output reg s, cout;
always @ (posedge clk)
begin
s = (a ^ b) ^ cin;
cout = ((a & b) | ((a | b) & cin));
end
endmodule
//RCA Logic
module part1(s, cout, a, b, cin, clk);
parameter BIT_WIDTH = 128;
input [BIT_WIDTH-1:0] a, b;
input cin;
input clk;
output cout;
output [BIT_WIDTH-1:0] s;
wire [BIT_WIDTH:0] cin_wire;
assign cin_wire[0] = cin;
genvar i;
generate
begin
for(i = 0; i <= BIT_WIDTH-1; i = i + 1) //error is on this line
begin:
fadder fadder_inst (.clk(clk), .s(s[i]), .cout(cin_wire[i+1]), .a(a[i]), .b(b[i]), .cin(cin_wire[i]));
end
end
endgenerate
assign cout = cin_wire[BIT_WIDTH];
endmodule
答案 2 :(得分:0)
正如其他人所指出的那样,你无法在always块中实例化模块。需要分离并需要创建一条新线来连接这两者。
在下面的示例中,cout
和s
是reg
类型输出。添加了导线s_wire
(遵循基于cin_wire
的命名约定),该导线连接到s
实例的fadder_inst
输出。 part1
的{{1}}和s
输出分别同步分配给cout
和s_wire
。请注意,它们被分配了非阻塞分配(cin[BIT_WIDTH]
)。
<=