问题本身很简单。是否可以在 Verilog 中合成一个异步计数器?
更多解释:
例如,如果我有类似下面的代码,是否可以合成它?
always @(posedge clk) begin
//rst
if(!rst)begin
enable <=0;
end else begin
enable <= 1;
end
end
//action loop
always @(state) begin
case (state)
0:begin
cnt <= cnt
end
1: begin
cnt <= cnt + 1;
next_state <= 1;
end
default: begin
cnt <= cnt;
end
endcase
end
//state loop
always @(next_state, control, enable) begin
if(enable)begin
if(!control) begin
state <= next_state;
end else begin
state <= 0;
end
end
end
这里的总体思路是,当输入控制标志为 0 时,计数器将异步运行,如果为 1,则计数器将停止,直到输入控制标志再次变为 0。
注意:我知道我可以尝试合成代码,看看会发生什么。但在此之前,我想了解更多,看看人们是否尝试过。
感谢阅读!!
答案 0 :(得分:0)
您的动作循环无法正确合成。 当 state == 1 时它在做什么?
您的状态循环是可综合的,但您将产生一个锁存器(用于在 enable == 0 时存储值)。这个块是可以使用组合逻辑“=”而不是非阻塞赋值“<=”来完成的。