//第一部分说明初始状态,和current_state<=next_state
//每一个时钟沿产生一次可能的状态变化
always@(posedge clk or negedge rst_n)
if(!rst_n)
cstate <= INIT; //复位态
else
cstate <= nstate;
//第二部分,状态转移,产生下一状态的整合逻辑
//状态的跳转
always@(cstate or time_ones or pdh_ok or locked)
begin
case (cstate)
IF_PDH_OK: //PDH OK判断
begin
if(time_ones == T2S) //2s
begin
if(pdh_ok_count >= PDH_OK_COUNT_N) //真信号
nstate <= SEARCH_PDH_OK; //搜索到pdh
`else
nstate <= WAIT; //重新扫描
end
else
nstate <= IF_PDH_OK;
end
//第三段,产生输出
always@(posedge clk or negedge rst_n)
if(!rst_n)
begin
end
else
begin
case(nstate)
IF_PDH_OK: //PDH OK判断
begin
//锯齿波扫描延长2S
if(time_count == T1S) //1s
begin
time_ones <= time_ones + 1'b1;
time_count <= 32'd0;
end
else
time_count <= time_count + 1'b1;
//清寄存器
if(time_ones == T2S) //2s
begin
time_ones <= 0;
pdh_ok_count <= 0;
end
//pdh误触发处理
//开始延时
if(pdh_ok_delay_flag == START)
begin
if(pdh_time_count == T10MS) //ms
begin
pdh_ok_delay_flag <= END;
pdh_time_count <= 32'd0;
end
else
pdh_time_count <= pdh_time_count + 1'b1;
end
else
begin
if(pdh_ok == LOCK)
begin
pdh_ok_count <= pdh_ok_count + 1'b1;
pdh_ok_delay_flag <= START;
end
end
end
求助 ,
我在第二部分,状态转移,产生下一状态的整合逻辑 IF_PDH_OK: //PDH OK判断
time_ones == T2S 同时 pdh_ok_count >= PDH_OK_COUNT_N 时将状态改变成nstate <= SEARCH_PDH_OK; //搜索到pdh
但有时并没有被进行状态跳转 还是 在IF_PDH_OK 里 if(pdh_ok == LOCK) 时pdh_ok_count 还在计数
这是是为什么啊?
同时我在第三段,产生输出的 IF_PDH_OK: 状态里对pdh_ok_count清零,但pdh_ok_count并没有被清零,这是什么原因啊/
//清寄存器
if(time_ones == T2S) //2s
begin
time_ones <= 0;
pdh_ok_count <= 0;
end
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>