Verilog 语法问题
按键消抖程序的一部分reg[2:0]key_r;always@(posedgeclkornegedger_est)beginif(!r_est)key_r<=3'b111...
按键消抖程序的一部分
reg [2:0] key_r;
always@(posedge clk or negedge r_est)
begin
if(!r_est) key_r <= 3'b111;
else key_r<={key_3,key_2,key_1};
end
像上边这样写没错
reg [2:0] key_r;
always@(posedge clk or negedge r_est)
begin
if(r_est) key_r<={key_3,key_2,key_1};
else key_r <= 3'b111;
end
改成这样写提示时钟信号有问题,我感觉两段意思是一样的啊,为什么不能互换啊 展开
reg [2:0] key_r;
always@(posedge clk or negedge r_est)
begin
if(!r_est) key_r <= 3'b111;
else key_r<={key_3,key_2,key_1};
end
像上边这样写没错
reg [2:0] key_r;
always@(posedge clk or negedge r_est)
begin
if(r_est) key_r<={key_3,key_2,key_1};
else key_r <= 3'b111;
end
改成这样写提示时钟信号有问题,我感觉两段意思是一样的啊,为什么不能互换啊 展开
1个回答
展开全部
你是不是错误提示:Error (10200): Verilog HDL Conditional Statement error at ……: cannot match operand(s) in the condition to the corresponding edges in the enclosing event control of the always construct
这是因为,你的“always@(posedge clk or negedge r_est)”表明在clk上升沿或r_est下降沿这两个敏感事件发生时always语句块得以触发;而always中的if条件语句必须至少有一个条件指向其中一个敏感事件(边界标识符);所以写成“if(r_est)...else...”就会出错。
你可以把“always@(posedge clk or negedge r_est)”改为“always@(posedge clk or posedge r_est)”再编译试试,应该就没问题了。
你右键该错误点击“Help”里是这么说的:
CAUSE: In a conditional statement at the specified location in a Verilog Design File (.v), you specified a condition that Quartus II Integrated Synthesis cannot use to classify the edges in the enclosing always construct's event control. When an event control contains multiple edges, Quartus II Integrated Synthesis distinguishes the asynchronous control signals from the clock by analyzing the conditional statements in the always construct. For example, the following code fragment contains an always construct whose event control contains three edges---two asynchronous resets and a clock.
always @ (posedge clk or posedge rst1 or posedge rst2)
begin
if ( rst1 || rst2 )
q <= 1'b0;
else
q <= d;
end
Quartus II Integrated Synthesis uses the if condition to identify the two asynchronous resets and, by implication, the clock. For edge classification, Quartus II Integrated Synthesis requires that a condition fall into one of two categories. It can refer to a single edge identifier (to match posedge events) or its complement (to match negedge events), for example, rst1, !rst1, rst1 == 1'b1, rst1 == 1'b0. It can also OR two or more expressions that each refer to a single edge identifier or its complement, for example, (rst1 || rst2), (!rst1 || !rst2).
You can receive this error if your condition tests for the wrong polarity, or if it tests for the value of a variable that is not an edge in the event control. For example, to match a posedge rst event, the condition must be rst or rst = 1'b1.
Finally, you can receive this error if you are attempting to use a single condition expression to test for both an asynchronous reset/set and a synchronous reset/set condition. The following code fragment contains an example of an illegal condition expression:
always @ (posedge clk or posedge rst)
begin
if ( rst || sync_rst )
q <= 1'b0;
else
q <= d;
end
Quartus II Integrated Synthesis generates this error message when compiling this design because it cannot match sync_rst to an edge on the sensitivity list.
其中关键的语句我摘译一下,不一定译得准确,不过大体意思我想你应该可以了解了:
原因:……指定了一个条件,Quartus II 综合器不能够将该条件用于在封闭的always结构的事件控制中对边界进行区分。当一个事件控制中包含多重边界,Quartus II 综合器通过分析always结构中的条件语句来对时钟和异步控制信号加以区分。……
Quartus II 综合器采用if条件来鉴别两个异步reset信号,并隐含地鉴别了clock信号。为了分类的需要,Quartus II 综合器需要有一个条件落入两个类别之一。它可以指向一个单独的边界标识符(以匹配posedge事件)或它的补语(以匹配negedge事件),例如, rst1, !rst1, rst1 == 1'b1, rst1 == 1'b0。它也可以是OR两个或更多的表达式,其中每一个指向一个单独的边界标识符或它的补语……
当你的条件测试发现错误极性,或者它测试变量的值,但该值在事件控制中并不是一个边界时,你会接到这个错误。例如,为了匹配一个posedge rst事件,条件必须是rst或rst = 1'b1。
编译错误时多看看Help,讲得很详细~
这是因为,你的“always@(posedge clk or negedge r_est)”表明在clk上升沿或r_est下降沿这两个敏感事件发生时always语句块得以触发;而always中的if条件语句必须至少有一个条件指向其中一个敏感事件(边界标识符);所以写成“if(r_est)...else...”就会出错。
你可以把“always@(posedge clk or negedge r_est)”改为“always@(posedge clk or posedge r_est)”再编译试试,应该就没问题了。
你右键该错误点击“Help”里是这么说的:
CAUSE: In a conditional statement at the specified location in a Verilog Design File (.v), you specified a condition that Quartus II Integrated Synthesis cannot use to classify the edges in the enclosing always construct's event control. When an event control contains multiple edges, Quartus II Integrated Synthesis distinguishes the asynchronous control signals from the clock by analyzing the conditional statements in the always construct. For example, the following code fragment contains an always construct whose event control contains three edges---two asynchronous resets and a clock.
always @ (posedge clk or posedge rst1 or posedge rst2)
begin
if ( rst1 || rst2 )
q <= 1'b0;
else
q <= d;
end
Quartus II Integrated Synthesis uses the if condition to identify the two asynchronous resets and, by implication, the clock. For edge classification, Quartus II Integrated Synthesis requires that a condition fall into one of two categories. It can refer to a single edge identifier (to match posedge events) or its complement (to match negedge events), for example, rst1, !rst1, rst1 == 1'b1, rst1 == 1'b0. It can also OR two or more expressions that each refer to a single edge identifier or its complement, for example, (rst1 || rst2), (!rst1 || !rst2).
You can receive this error if your condition tests for the wrong polarity, or if it tests for the value of a variable that is not an edge in the event control. For example, to match a posedge rst event, the condition must be rst or rst = 1'b1.
Finally, you can receive this error if you are attempting to use a single condition expression to test for both an asynchronous reset/set and a synchronous reset/set condition. The following code fragment contains an example of an illegal condition expression:
always @ (posedge clk or posedge rst)
begin
if ( rst || sync_rst )
q <= 1'b0;
else
q <= d;
end
Quartus II Integrated Synthesis generates this error message when compiling this design because it cannot match sync_rst to an edge on the sensitivity list.
其中关键的语句我摘译一下,不一定译得准确,不过大体意思我想你应该可以了解了:
原因:……指定了一个条件,Quartus II 综合器不能够将该条件用于在封闭的always结构的事件控制中对边界进行区分。当一个事件控制中包含多重边界,Quartus II 综合器通过分析always结构中的条件语句来对时钟和异步控制信号加以区分。……
Quartus II 综合器采用if条件来鉴别两个异步reset信号,并隐含地鉴别了clock信号。为了分类的需要,Quartus II 综合器需要有一个条件落入两个类别之一。它可以指向一个单独的边界标识符(以匹配posedge事件)或它的补语(以匹配negedge事件),例如, rst1, !rst1, rst1 == 1'b1, rst1 == 1'b0。它也可以是OR两个或更多的表达式,其中每一个指向一个单独的边界标识符或它的补语……
当你的条件测试发现错误极性,或者它测试变量的值,但该值在事件控制中并不是一个边界时,你会接到这个错误。例如,为了匹配一个posedge rst事件,条件必须是rst或rst = 1'b1。
编译错误时多看看Help,讲得很详细~
意法半导体(中国)投资有限公司
2023-06-12 广告
2023-06-12 广告
单片机,即单片微控制器,也称为单片微型计算机,是将中央处理器(CPU)、存储器(ROM,RAM)、输入/输出接口和其他功能部件集成在一块 在一个小块的集成电路上,从而实现对整个电路或系统的数字式控制。单片机不是完成某一个逻辑功能的芯片,而是...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询