组合逻辑always块中敏感向量表要全
1.对于如下代码块:
-
always @(nstate /*or master_din or master_dout_reg*/) begin
-
//initial;
-
master_din_reg = 0;
-
master_dout = 0;
-
cs = 1'b0;
-
wr_done = 1'b0;
-
rd_done = 1'b0;
-
sck_en = 1'b0;
-
case (nstate)
-
IDEL: begin
-
cs = 1'b1;
-
wr_done = 1'b0;
-
rd_done = 1'b0;
-
end
-
LOAD: begin
-
cs = 1'b0;
-
master_din_reg = master_din;
-
end
-
SEND: begin
-
sck_en = 1'b1;
-
end
-
FINISH: begin
-
cs = 1'b1;
-
wr_done = 1'b1;
-
rd_done = 1'b1;
-
sck_en = 1'b0;
-
master_dout = master_dout_reg;
-
end
-
default: begin
-
master_din_reg = 0;
-
master_dout = 0;
-
cs = 1'b0;
-
wr_done = 1'b0;
-
rd_done = 1'b0;
-
sck_en = 1'b0;
-
end
-
endcase //case
-
end
对于master_din和变量master_dout_reg,两者在组合always块中使用读取,但没有在敏感向量表中,将会导致如下错误:
Warning (10235): Verilog HDL Always Construct warning at spi_ms.v(149): variable "master_din" is read inside the Always Construct but isn't in the Always Construct's Event Control
Warning (10235): Verilog HDL Always Construct warning at spi_ms.v(159): variable "master_dout_reg" is read inside the Always Construct but isn't in the Always Construct's Event Control
2.解决方法是补全敏感向量表,避免产生不必要的锁存器:
-
always @(nstate or master_din or master_dout_reg) begin
-
//initial;
-
master_din_reg = 0;
-
master_dout = 0;
-
cs = 1'b0;
-
wr_done = 1'b0;
-
rd_done = 1'b0;
-
sck_en = 1'b0;
-
case (nstate)
-
IDEL: begin
-
cs = 1'b1;
-
wr_done = 1'b0;
-
rd_done = 1'b0;
-
end
-
LOAD: begin
-
cs = 1'b0;
-
master_din_reg = master_din;
-
end
-
SEND: begin
-
sck_en = 1'b1;
-
end
-
FINISH: begin
-
cs = 1'b1;
-
wr_done = 1'b1;
-
rd_done = 1'b1;
-
sck_en = 1'b0;
-
master_dout = master_dout_reg;
-
end
-
default: begin
-
master_din_reg = 0;
-
master_dout = 0;
-
cs = 1'b0;
-
wr_done = 1'b0;
-
rd_done = 1'b0;
-
sck_en = 1'b0;
-
end
-
endcase //case
-
end
锁存器则会导致时序不稳定