给我一个组合电路,我会为这个电路设计一个verilog码。是关于国家机器的。方程式是:
A(t+1)=A(t)+B(t);
B(t+1)=A(t)'+B(t);没有其他产出或投入。我尝试过很少的密码,但它们都不起作用。我对分配A、B、A_next、B_next作为输入、输出和连线感到困惑。有人能给我一点线索让我再试一次吗?
module statemac_posed(clk,a,b);
input clk;
output a,b;
reg a_next,b_next;
always@(posedge clk)
begin
a=a_next;
b=b_next;
a_next=a|b;
b_next=~a|b;
end
endmodule发布于 2014-12-25 13:44:22
触发器的输出是下一个值,作为同步逻辑,您只需编写:
对于FPGA,可以使用intial设置专用集成电路的初始值,采用有源低重置。
module statemac_posed(
input clk,
output reg a,
output reg b
);
initial begin
a = 'b0;
b = 'b0;
end
//On clock edge update a &b with new values based on previous a & b value
always@(posedge clk) begin
a <= a|b;
b <= ~a|b;
end
endmodule这相当于:
module statemac_posed(
input clk,
output reg a,
output reg b
);
reg a_next;
reg b_next;
//Combinatorial take outputs from flip-flops and combinatorial define next value
always @* begin
a_next = a|b;
b_next = ~a|b;
end
initial begin
a = 'b0;
b = 'b0;
end
//on Clock edge take the next values
always @(posedge clk) begin
a <= a_next;
b <= b_next;
end
endmodule分配给initial或always内部的任何变量都需要类型为reg。如果使用logic,则SystemVerilog也是有效的。不这样做是您在评论中提到的错误的原因。
这应该让我们了解一下如何使用verilog。
注意:使用阻塞(=)和组合(@*)。非阻塞(<=)与边缘触发(@(posedge clk)),以正确描述硬件.
https://stackoverflow.com/questions/27646216
复制相似问题