【发布时间】:2019-07-18 19:42:28
【问题描述】:
Sum:状态机名为“WaitS2”的部分仅将“count”递增一次。
我正在尝试在 systemverilog 中控制超声波传感器 HC-SR04。正如我在数据表中看到的那样,这个传感器会创建一个信号“trigger”来产生声音,并且在产生声音传感器后会创建逻辑“echo”,我需要计算时间,所以我创建了你可以在代码中看到的状态机,但问题是 count++ 没有像预期的那样工作,它只会增加一次 count 变量,不管回显信号有多长
我使用了来自互联网的另一个名为 32 位加法器的模块,它没有改变任何东西。
我将所有语句更改为非块语句它不起作用。
我什至尝试将count++ 更改为count = count + 1 不起作用
module sensorFSM(
input logic echo , clk ,reset,
output logic trig,
output logic[31:0] distance,
output logic[1:0] presentState
);
/*typedef enum logic[1:0] {BeginS , WaitS , ReturnS } states;
states presentState , nextState;
*/
logic[31:0] count , count1;
logic[1:0] BeginS , WaitS, WaitS2 , ReturnS , nextState;
assign BeginS = 2'b00;
assign WaitS = 2'b01;
assign WaitS2 = 2'b10;
assign ReturnS = 2'b11;
// clk and state change
always_ff @( posedge clk )
begin
if ( reset == 1'b1 )
presentState <= BeginS;
else
presentState <= nextState;
end
// real state changes
always_comb
begin
case(presentState)
BeginS:
begin
trig = 1'b1;
count = 32'b0;
nextState = WaitS;
end
WaitS:
begin
trig = 1'b0;
distance = 32'b0;
//#5000;
nextState = WaitS2;
end
WaitS2:
begin
if( echo == 1 )
begin
if ( count < 24'b101100111000000100100000 )
begin
// here is the problem count is only incrementing
//once
count++;
nextState = WaitS2;
end
else
begin
distance = count;
nextState = BeginS;
end
end
else // echo == 0
begin
nextState = ReturnS;
end
end
ReturnS:
begin
//count = count / 1470;
distance = count;
nextState = BeginS;
end
default:
nextState = BeginS;
endcase
end
endmodule
我预计模拟的计数大约为 1 miliion,但它始终输出 1,但我可以看到名为“WaitS2”的状态在 echo 也处于活动状态时存在很长时间
【问题讨论】:
标签: verilog system-verilog vivado