Verilog 始终使用相同的值执行块
我有一个简单的模块,它使用几个不同的状态。我遇到的问题是,如果我想在多个时钟周期内保持相同的状态。 在这种情况下,我的当前状态是同步的,并按时钟周期更新。它执行从状态0->状态1开始的always块。然后,一旦pstate到达状态1,我尝试让它等待到达下一个状态。这样做的原因是从数据输入收集数据。我不在乎数据是什么,但我需要读取它2个时钟周期 但是我认为这不起作用,因为在第一种情况下,我将下一个状态设置为与以前相同的值,因此无法触发。我不认为我可以将'data_int'添加到触发器列表中,因为它可能在一个时钟周期内保持相同的值,因此always块不会触发 我想知道是否有其他方法可以做到这一点,我想基本上我需要的总是块重新触发时钟边缘以及Verilog 始终使用相同的值执行块,verilog,Verilog,我有一个简单的模块,它使用几个不同的状态。我遇到的问题是,如果我想在多个时钟周期内保持相同的状态。 在这种情况下,我的当前状态是同步的,并按时钟周期更新。它执行从状态0->状态1开始的always块。然后,一旦pstate到达状态1,我尝试让它等待到达下一个状态。这样做的原因是从数据输入收集数据。我不在乎数据是什么,但我需要读取它2个时钟周期 但是我认为这不起作用,因为在第一种情况下,我将下一个状态设置为与以前相同的值,因此无法触发。我不认为我可以将'data_int'添加到触发器列表中,因为它
module TestModule(
input clk, rst, data_int);
reg [2:0] pstate = 0;
reg [2:0] nstate = 0;
ref [2:0] count = 0;
always@(pstate) begin
//only fires when pstate is assigned to a different value?
//would I make a internal clock to constantly have this always run?
if(pstate == 0) begin
nstate <= 1;
end
else if(pstate == 1) begin
//stay at this state for multiple clock cycles
//collect data off of data_int
count = count + 1;
if(count > 2) begin
nstate <= 2;
end else begin
nstate <= 1;
end
end
end
always@(posedge clk, posedge rst) begin
if(rst) begin
pstate <= 0;
end
else begin
pstate <= nstate;
end
end
模块测试模块(
输入时钟、rst、数据输入);
reg[2:0]pstate=0;
reg[2:0]nstate=0;
参考[2:0]计数=0;
始终@(pstate)开始
//仅当pstate指定给其他值时激发?
//我会制作一个内部时钟,让它一直运行吗?
如果(pstate==0)开始
(2)开始
陈述
请注意=
和的用法,因此在clk的posedge上触发的东西会导致犯罪?感谢您的回复!很高兴知道。。那么,always块将继续运行吗?@joequest1这在LRM中被称为“隐式事件\表达式列表”。模拟器将在内部形成敏感度列表,然后触发该块的执行,就像我们显式地写下敏感度列表一样。
reg [2:0] pstate;
reg [2:0] nstate;
reg count; // 1-bit 'count' is enough to count 2 cycles
always@(posedge clk or posedge rst)begin
if(rst)begin
pstate <= 3'h0;
end
else begin
pstate <= nstate;
end
end
always@(*)begin
case(pstate)
3'h0: nstate = 3'h1;
3'h1:begin // lasts 2 cycles
if(count)begin
nstate = 3'h2;
end
else begin
nstate = 3'h1;
end
3'h2: (....)
default: (....)
end
endcase
end
always@(posedge clk or posedge rst)begin // 'count' logic
if(rst)begin
count <= 1'h0;
end
else if((pstate == 3'h1) & count)begin // this branch is needed if you don't
// count to the max. value of 'count'
count <= 1'b0;
end
else if(pstate == 3'h1)begin
count <= ~count; // if 'count' is multi-bit, use 'count + 1'
end
end