在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 12516|回复: 6

[求助] 关于verilog 编译时latches的警告求助

[复制链接]
发表于 2012-10-26 16:48:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
各位我的状态机在状态机转移条件和最终状态机输出上面都引入了key这个变量值,结果编译时警告。代码是这样的:
module key1(key,i,sensor,clk,rst_n,rx_data);
input[3:0] key;//决定触发器被何种信号触发(PC串口,按键,传感器)

input[3:0] sensor;//传感器信号入口
input rst_n;
input[7:0] rx_data;
input clk;
output[3:0] i;

reg[3:0] i;
reg[3:0] freq;
wire[3:0] rx_data_l;
reg[15:0] state,nextstate;
assign  rx_data_l=rx_data[3:0];
//assign  rx_data_l=7;
parameter        s0=5'b0,
                KEYE=5'b00001,RS485E=5'b00010,
                SENSORE=5'b00100,
           FIREB=5'b01000,        
           FIRE=5'b10000;       
always        @(posedge clk or negedge rst_n)
begin       
        if(~rst_n)
                state<=s0;                        //复位
        else
           state<=nextstate;
end

always @(state or key)
        begin
                case(state)
                        s0:if(key==1)nextstate=KEYE;
                           else if(key==2)nextstate=RS485E;
                                else if(key==3)nextstate=SENSORE;
                                else nextstate=s0;                //状态s0
                        KEYE:if(key==1)
                                nextstate=KEYE;
                                         else if(key==2)
                                           nextstate=RS485E;
                                         else if(key==3)
                                nextstate=SENSORE;
                               else if((key==4)||(key==5)||(key==6)||(key==7))
                                     nextstate=FIREB;
                                    else
                                     nextstate=s0;                //状态s4
                        RS485E:if(key==1)
                                nextstate=KEYE;
                                         else if(key==2)
                                           nextstate=RS485E;
                                         else if(key==3)
                                nextstate=SENSORE;
                                   else
                                         nextstate=s0;                //状态s5
                        SENSORE:if(key==1)
                                nextstate=KEYE;
                                         else if(key==2)
                                           nextstate=RS485E;
                                         else if(key==3)
                                nextstate=SENSORE;
                                        else
                                          nextstate=s0;                //状态s6
                        FIREB:if(key==1)
                                nextstate=KEYE;
                                         else if(key==2)
                                           nextstate=RS485E;
                                         else if(key==3)
                                nextstate=SENSORE;
                               else if((key==4)||(key==5)||(key==6)||(key==7))
                                nextstate=FIREB;
                               else if((key==8)||(key==9))
                                nextstate=FIRE;                                          
                                         else
                                          nextstate=s0;                               
                        FIRE:if(key==1)
                                nextstate=KEYE;
                                         else if(key==2)
                                           nextstate=RS485E;
                                         else if(key==3)
                                nextstate=SENSORE;
                               else if((key==4)||(key==5)||(key==6)||(key==7))
                                nextstate=FIREB;                                          
                               else if((key==9)||(key==8))
                                nextstate=FIRE;
                                         else
                                          nextstate=s0;       
                        default:state=s0;
                endcase
end


always @(state or key or rst_n)
begin
   if(!rst_n) begin
                i=4'b0;
        end
        else begin
/*        if (state == KEYE)
            i=key-4'b0011;*/
         if (state == RS485E)
            i=rx_data_l;
         else if (state == SENSORE)         
       i=sensor[3:0];
         else if (state == FIREB)
            freq=key;
         else if (state == FIRE)         
       i=freq;
         else begin
            i=4'b0000;
           end
end
end

endmodule       


警告如下:Warning (10240): verilog hdl Always Construct warning at key.v(91): inferring latch(es) for variable "i", which holds its previous value in one or more paths through the always construct
Warning (10240): Verilog HDL Always Construct warning at key.v(91): inferring latch(es) for variable "freq", which holds its previous value in one or more paths through the always construct
        Warning (10240): Verilog HDL Always Construct warning at keyinput.v(144): inferring latch(es) for variable "key", which holds its previous value in one or more paths through the always construct
        Warning: Node: key1:key1|state.FIREB was determined to be a clock but was found without an associated clock assignment.
跪求大神指点迷津。
 楼主| 发表于 2012-10-26 16:50:45 | 显示全部楼层
回复 1# 江南炊烟


    代码其实就是状态机最常见的三段码,转移,输出分开,对于latch问题,我一直都很困惑,网上查到的英文资料看的也云里雾里,这周得把这个项目赶出来,求指点一下方向。
发表于 2012-10-26 18:01:56 | 显示全部楼层
输出的always 修改为always @( * ),这个always是组合逻辑,所以里面任何一个变量的变化都会反映到输出上面,但是你的敏感列表里面没有写全,所以导致有些变量变化时,就保持状态,就产生了锁存器
 楼主| 发表于 2012-10-26 18:21:00 | 显示全部楼层
回复 3# Gary.wang


    不明白,最后一个always没有写全?改变的条件都写全了啊
发表于 2012-10-26 20:24:00 | 显示全部楼层
第一个里面的default分支写错了。
第二个里面  下面地方是错的。
      else if (state == FIREB)
            freq=key;
 楼主| 发表于 2012-10-26 20:52:11 | 显示全部楼层
回复 5# tiangua
第二个为什么是错的?跪求指教
发表于 2012-10-26 21:45:27 | 显示全部楼层
这个分支没有对 i  赋值。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-9 06:10 , Processed in 0.035775 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表