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

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

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1970|回复: 1

[求助] 亲们,这个状态机跳不出状态是怎么回事呢

[复制链接]
发表于 2013-5-30 18:30:16 | 显示全部楼层 |阅读模式

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

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

x
always @ (posedge clk or negedge rst_n)
begin
  if(~rst_n)
  begin
     buf_order <= 1023'd0;
   order_cnt <= 10'd0;
   order_ok <= 1'b0;
   order_state <= 0;
   next <= 0;
  end
  else
  begin
     case (order_state)
   0:
     begin
    buf_order <= 1023'd0;
        order_cnt <= 0;
        order_ok <= 1'b0;
    if(order_en & ~next)
      order_state <= 1;
   end
   1:
     begin
      next <= 1;
    buf_order <= 1023'd0;
        order_cnt <= offs_value;
        order_ok <= 1'b0;
    order_state <= 2;
   end
   2:
     begin
    if(order_cnt > 999)
    begin
     buf_order <= {fsk_data[22:0],fsk_data[1022:23]};
     order_cnt <= order_cnt - 10'd1000;
    end
    else if(order_cnt > 899)
    begin
     buf_order <= {fsk_data[122:0],fsk_data[1022:123]};
     order_cnt <= order_cnt - 10'd900;
    end
    else if(order_cnt > 799)
    begin
     buf_order <= {fsk_data[222:0],fsk_data[1022:223]};
     order_cnt <= order_cnt - 10'd800;
    end
    else if(order_cnt > 699)
    begin
     buf_order <= {fsk_data[322:0],fsk_data[1022:323]};
     order_cnt <= order_cnt - 10'd700;
    end
    else if(order_cnt > 599)
    begin
     buf_order <= {fsk_data[422:0],fsk_data[1022:423]};
     order_cnt <= order_cnt - 10'd600;
    end
    else if(order_cnt > 499)
    begin
     buf_order <= {fsk_data[522:0],fsk_data[1022:523]};
     order_cnt <= order_cnt - 10'd500;
    end
    else if(order_cnt > 399)
    begin
     buf_order <= {fsk_data[622:0],fsk_data[1022:623]};
     order_cnt <= order_cnt - 10'd400;
    end
    else if(order_cnt > 299)
    begin
     buf_order <= {fsk_data[722:0],fsk_data[1022:723]};
     order_cnt <= order_cnt - 10'd300;
    end
    else if(order_cnt > 199)
    begin
     buf_order <= {fsk_data[822:0],fsk_data[1022:823]};
     order_cnt <= order_cnt - 10'd200;
    end
    else if(order_cnt > 99)
    begin
     buf_order <= {fsk_data[922:0],fsk_data[1022:923]};
     order_cnt <= order_cnt - 10'd100;
    end
    else if(order_cnt > 89)
    begin
     buf_order <= {fsk_data[932:0],fsk_data[1022:933]};
     order_cnt <= order_cnt - 10'd90;
    end
    else if(order_cnt > 79)
    begin
     buf_order <= {fsk_data[942:0],fsk_data[1022:943]};
     order_cnt <= order_cnt - 10'd80;
    end
    else if(order_cnt > 69)
    begin
     buf_order <= {fsk_data[952:0],fsk_data[1022:953]};
     order_cnt <= order_cnt - 10'd70;
    end
    else if(order_cnt > 59)
    begin
     buf_order <= {fsk_data[962:0],fsk_data[1022:963]};
     order_cnt <= order_cnt - 10'd60;
    end
    else if(order_cnt > 49)
    begin
     buf_order <= {fsk_data[972:0],fsk_data[1022:973]};
     order_cnt <= order_cnt - 10'd50;
    end
    else if(order_cnt > 39)
    begin
     buf_order <= {fsk_data[982:0],fsk_data[1022:983]};
     order_cnt <= order_cnt - 10'd40;
    end
    else if(order_cnt > 29)
    begin
     buf_order <= {fsk_data[992:0],fsk_data[1022:993]};
     order_cnt <= order_cnt - 10'd30;
    end
    else if(order_cnt > 19)
    begin
     buf_order <= {fsk_data[1002:0],fsk_data[1022:1003]};
     order_cnt <= order_cnt - 10'd20;
    end
    else if(order_cnt > 9)
    begin
     buf_order <= {fsk_data[1012:0],fsk_data[1022:1013]};
     order_cnt <= order_cnt - 10'd10;
    end
    else if(order_cnt > 8)
    begin
     buf_order <= {fsk_data[1013:0],fsk_data[1022:1014]};
     order_cnt <= order_cnt - 10'd9;
    end
    else if(order_cnt > 7)
    begin
     buf_order <= {fsk_data[1014:0],fsk_data[1022:1015]};
     order_cnt <= order_cnt - 10'd8;
    end
    else if(order_cnt > 6)
    begin
     buf_order <= {fsk_data[1015:0],fsk_data[1022:1016]};
     order_cnt <= order_cnt - 10'd7;
    end
    else if(order_cnt > 5)
    begin
     buf_order <= {fsk_data[1016:0],fsk_data[1022:1017]};
     order_cnt <= order_cnt - 10'd5;
    end
    else if(order_cnt > 4)
    begin
     buf_order <= {fsk_data[1017:0],fsk_data[1022:1018]};
     order_cnt <= order_cnt - 10'd5;
    end
    else if(order_cnt > 3)
    begin
     buf_order <= {fsk_data[1018:0],fsk_data[1022:1019]};
     order_cnt <= order_cnt - 10'd4;
    end
    else if(order_cnt > 2)
    begin
     buf_order <= {fsk_data[1019:0],fsk_data[1022:1020]};
     order_cnt <= order_cnt - 10'd3;
    end
    else if(order_cnt > 1)
    begin
     buf_order <= {fsk_data[1020:0],fsk_data[1022:1021]};
     order_cnt <= order_cnt - 10'd2;
    end
    else if(order_cnt > 0)
    begin
     buf_order <= {fsk_data[1021:0],fsk_data[1022:1022]};
     order_cnt <= order_cnt - 10'd1;
    end
    else
    begin
       next <= 0;
     buf_order <= fsk_data[1022:0];
     order_cnt <= order_cnt - 10'd0;
     order_ok <= 1;
     order_state <= 0;
    end
      end
  defaultrder_state <= 0;
  endcase
end
end



一直停在了状态2,始终跳不出来,请大神们指导
 楼主| 发表于 2013-5-30 19:18:06 | 显示全部楼层
always @ (posedge clk or negedge rst_n)
begin
  if(~rst_n)
  begin
     buf_order <= 1023'd0;
   order_cnt <= 10'd0;
   order_ok <= 1'b0;
   order_state <= 0;
   next <= 0;
  end
  else
  begin
     case (order_state)
   0:
     begin
    buf_order <= 1023'd0;
        order_cnt <= 0;
        order_ok <= 1'b0;
    if(order_en & ~en_dly & ~next)
      order_state <= 1;
   end
   1:
     begin
      next <= 1;
    buf_order <= 1023'd0;
      //  order_cnt <= offs_value;
    order_cnt <= 578;
        order_ok <= 1'b0;
    order_state <= 2;
   end
   2:
     begin
    if(order_cnt > 999)
    begin
     buf_order <= {fsk_data[22:0],fsk_data[1022:23]};
     order_cnt <= order_cnt - 10'd1000;
    end
    else if(order_cnt > 899)
    begin
     buf_order <= {fsk_data[122:0],fsk_data[1022:123]};
     order_cnt <= order_cnt - 10'd900;
    end
    else if(order_cnt > 799)
    begin
     buf_order <= {fsk_data[222:0],fsk_data[1022:223]};
     order_cnt <= order_cnt - 10'd800;
    end
    else if(order_cnt > 699)
    begin
     buf_order <= {fsk_data[322:0],fsk_data[1022:323]};
     order_cnt <= order_cnt - 10'd700;
    end
    else if(order_cnt > 599)
    begin
     buf_order <= {fsk_data[422:0],fsk_data[1022:423]};
     order_cnt <= order_cnt - 10'd600;
    end
    else if(order_cnt > 499)
    begin
     buf_order <= {fsk_data[522:0],fsk_data[1022:523]};
     order_cnt <= order_cnt - 10'd500;
    end
    else if(order_cnt > 399)
    begin
     buf_order <= {fsk_data[622:0],fsk_data[1022:623]};
     order_cnt <= order_cnt - 10'd400;
    end
    else if(order_cnt > 299)
    begin
     buf_order <= {fsk_data[722:0],fsk_data[1022:723]};
     order_cnt <= order_cnt - 10'd300;
    end
    else if(order_cnt > 199)
    begin
     buf_order <= {fsk_data[822:0],fsk_data[1022:823]};
     order_cnt <= order_cnt - 10'd200;
    end
    else if(order_cnt > 99)
    begin
     buf_order <= {fsk_data[922:0],fsk_data[1022:923]};
     order_cnt <= order_cnt - 10'd100;
    end
    else if(order_cnt > 89)
    begin
     buf_order <= {fsk_data[932:0],fsk_data[1022:933]};
     order_cnt <= order_cnt - 10'd90;
    end
    else if(order_cnt > 79)
    begin
     buf_order <= {fsk_data[942:0],fsk_data[1022:943]};
     order_cnt <= order_cnt - 10'd80;
    end
    else if(order_cnt > 69)
    begin
     buf_order <= {fsk_data[952:0],fsk_data[1022:953]};
     order_cnt <= order_cnt - 10'd70;
    end
    else if(order_cnt > 59)
    begin
     buf_order <= {fsk_data[962:0],fsk_data[1022:963]};
     order_cnt <= order_cnt - 10'd60;
    end
    else if(order_cnt > 49)
    begin
     buf_order <= {fsk_data[972:0],fsk_data[1022:973]};
     order_cnt <= order_cnt - 10'd50;
    end
    else if(order_cnt > 39)
    begin
     buf_order <= {fsk_data[982:0],fsk_data[1022:983]};
     order_cnt <= order_cnt - 10'd40;
    end
    else if(order_cnt > 29)
    begin
     buf_order <= {fsk_data[992:0],fsk_data[1022:993]};
     order_cnt <= order_cnt - 10'd30;
    end
    else if(order_cnt > 19)
    begin
     buf_order <= {fsk_data[1002:0],fsk_data[1022:1003]};
     order_cnt <= order_cnt - 10'd20;
    end
    else if(order_cnt > 9)
    begin
     buf_order <= {fsk_data[1012:0],fsk_data[1022:1013]};
     order_cnt <= order_cnt - 10'd10;
    end
    else if(order_cnt > 8)
    begin
     buf_order <= {fsk_data[1013:0],fsk_data[1022:1014]};
     order_cnt <= order_cnt - 10'd9;
    end
    else if(order_cnt > 7)
    begin
     buf_order <= {fsk_data[1014:0],fsk_data[1022:1015]};
     order_cnt <= order_cnt - 10'd8;
    end
    else if(order_cnt > 6)
    begin
     buf_order <= {fsk_data[1015:0],fsk_data[1022:1016]};
     order_cnt <= order_cnt - 10'd7;
    end
    else if(order_cnt > 5)
    begin
     buf_order <= {fsk_data[1016:0],fsk_data[1022:1017]};
     order_cnt <= order_cnt - 10'd5;
    end
    else if(order_cnt > 4)
    begin
     buf_order <= {fsk_data[1017:0],fsk_data[1022:1018]};
     order_cnt <= order_cnt - 10'd5;
    end
    else if(order_cnt > 3)
    begin
     buf_order <= {fsk_data[1018:0],fsk_data[1022:1019]};
     order_cnt <= order_cnt - 10'd4;
    end
    else if(order_cnt > 2)
    begin
     buf_order <= {fsk_data[1019:0],fsk_data[1022:1020]};
     order_cnt <= order_cnt - 10'd3;
    end
    else if(order_cnt > 1)
    begin
     buf_order <= {fsk_data[1020:0],fsk_data[1022:1021]};
     order_cnt <= order_cnt - 10'd2;
    end
    else if(order_cnt > 0)
    begin
     buf_order <= {fsk_data[1021:0],fsk_data[1022:1022]};
     order_cnt <= order_cnt - 10'd1;
    end
    else    //为什么执行不到这里?
    begin
       next <= 0;
     buf_order <= fsk_data[1022:0];
     order_cnt <= order_cnt - 10'd0;
     order_ok <= 1;
     order_state <= 0;
    end
      end
  defaultrder_state <= 0;
  endcase
end
end

重新改了改代码,给order_cnt赋了个初值,结果倒是跳出了状态2,但做的减法不对,波形如图所示
2.png
1.png
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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


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

GMT+8, 2024-12-21 10:29 , Processed in 0.021499 second(s), 12 queries , Gzip On, Redis On.

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