Verilog HDL Conditional Statement error at xxx.v(8): cannot match operand(s) in the condition to the

在学习Verilog时遇到状态机设计错误,错误出现在always块中对clr信号的处理。原本代码使用negedge clr触发,但在条件语句中误用if(clr),导致不匹配。正确做法应改为if(!clr)以匹配下降沿触发。修复此错误后,代码成功编译无误。总结了在always构造中处理posedge和negedge信号的注意事项。
摘要由CSDN通过智能技术生成

一、问题描述
在学习Verilog的过程中,使用Verilog进行状态机设计,验证书中的代码时,出现以下错误。

//FSM.v 代码
module FSM(clk,clr,out,start,step2,step3);
input clk,clr,start,step2,step3;
output[2:0] out;reg[2:0] out;
reg[1:0] state,next_state;
parameter state0=2'b00,state1=2'b01,state2=2'b11,state3=2'b10;/*状态编码,采用格雷编码方式*/

always@(posedge clk or negedge clr)		//该进程定义起始状态
	begin if(clr) state<=state0;		/* 出错位置!!!*/
			else state<=next_state;
	end
always@(state or start or step2 or step3)	//该进程实现状态的转换
	begin 
	case(state)
	state0:begin if(start) next_state<=state1;
					 else 	  next_state<=state0;
			 end
	state1:begin next_state<=state2;end
	state2:begin if(step2) next_state<=state3;
					 else 	  next_state<=state0;
			 end
	state3:begin if(step3) next_state<=state0;
					 else 	  next_state<=state3;
			 end
	default:next_state<=state0;		//default语句
	endcase
	end
always@(state)							//该进程定义组合逻辑输出(FSM的输出)
	begin case(state)
			state0:out=3'b001;
			state1:out=3'b010;
			state2:out=3'b100;
			state3:out=3'b111;
			default:out=3'b001;		//default语句,避免锁存器的产生
			endcase
	end
endmodule
			

Error (10200): Verilog HDL Conditional Statement error at FSM.v(8):cannot match operand(s) in the condition to the corresponding edges in the enclosing event control of the always construct。

翻译成中文:Verilog HDL条件语句错误:无法将条件中的操作数与always构造的封闭事件控制中的相应边缘相匹配。

错误分析
出错语句是:begin if(clr) state<=state0; 根据错误提示,错在:if(clr) 与 always中的negedge clr不匹配。
该语句 if(clr)中的条件操作数为“clr”;always中的“clr”是选择下降沿触发(negedge clr)。下降沿触发的话,if()语句应该改为if(!clr)才对。经过修改,重新编译,没有错误。

总结
(1)在always中,如果某个信号采用posedge方式触发(如 posedge clk ),那么在该语句下的判断语句中,只能使用if(clk)而不能使用if(!clk)
(2)在always中,如果某个信号采用negedge方式触发(如 negedge clr ),那么在该语句下的判断语句中,只能使用if(!clr)而不能使用if(clk)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

树下等苹果

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值