我正在使用JK触发器编写2位计数器的verilog代码,计数0-3并返回0.我正在使用Xilinx EDA。但是我一直收到一个错误,我不知道这意味着什么?这里没有显示行号,但错误位于“always @(posedge clk)
”。
错误:HDLC编译器:1401 - “C:\ Users \ Eduardo \ Documents \ SFSU \ Fall 2014 \ Engr 378 \ Lab 3 \ TwoBitCounter \ twobitcounter.v”第30行:单元jkff中的信号q连接到以下多个驱动程序:
`timescale 1ns / 1ps
module twobitcounter( q_out, qbar_out, j,k, clk, reset);
input [1:0] j; input [1:0] k; input clk; input reset;
output [1:0] q_out;
output [1:0] qbar_out;
wire [1:0] q_out;
wire [1:0] qbar_out;
wire clk;
assign qbar_out[0] = ~q_out[0];
assign j[0] = 1;
assign k[0] = 1;
assign j[1] = q_out[0];
assign k[1] = q_out[0];
jkff M1(q_out[0], qbar_out[0], j[0], k[0], clk, reset);
jkff M2(q_out[1], qbar_out[1], j[1], k[1], qbar_out[0]);
endmodule
module jkff(output q_out, output qbar_out,
input j, input k, input clk, input reset);
reg q;
assign q_out = q;
assign qbar_out = ~q;
initial begin
q = 1'b0;
end
always @(posedge clk)
begin
case({j,k})
{1'b0, 1'b0}: begin
q = q;
end
{1'b0, 1'b1}: begin
q = 1'b0;
end
{1'b1, 1'b0}: begin
q = 1'b1;
end
{1'b1, 1'b1}: begin
q = ~q;
end
endcase
end
always @(posedge reset)
begin
q = 1'b0;
end
endmodule
答案 0 :(得分:1)
错误告诉您正在为不同的块分配q。这会产生错误。您要在initial
块和always
块中分配q。
绝不能在可综合代码中使用initial
块。
答案 1 :(得分:1)
问题是q
正在两个always
块中设置,这在合成中是不允许的。合并两个总是块。此外,q
是一个翻牌,因此应使用非阻止分配(<=
)进行分配,而不是阻止分配(=
)。
always @(posedge clk or posedge reset)
begin
if (reset == 1'b1) begin
q <= 1'b0;
end
else begin
case({j,k})
{1'b0, 1'b0}: begin
q <= q;
end
{1'b0, 1'b1}: begin
q <= 1'b0;
end
{1'b1, 1'b0}: begin
q <= 1'b1;
end
{1'b1, 1'b1}: begin
q <= ~q;
end
endcase
end
end
你几乎不应该在可综合代码中使用initial
块。大多数FPGA允许它进行初始化。然而,ASIC设计不支持它。对于这两种情况,如果存在异步复位/设置,则不应使用初始块。