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

导读:本篇文章讲解 Verilog HDL Conditional Statement error at xxx.v(8): cannot match operand(s) in the condition to the,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

一、问题描述
在学习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)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/73699.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!