集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 3240|回复: 6

关于状态机不运行的问题(急急急急)

[复制链接]
UFP 发表于 2010-6-26 00:10:37 | 显示全部楼层 |阅读模式
本帖最后由 fpgaw 于 2010-7-3 07:21 编辑

这个问题已经困扰我好久了。
我作了一个帧头检测的代码。就是每一帧有544个bit,其中帧头8bit为00110110,检测到一个00110110后,计数到543,如果仍然是帧头00110110,则认为帧头已经同步,syn_out输出1。
下面是我的代码。

always @(posedge Clk2176_In or negedge Reset_In )
  if (Reset_In == 0)
  begin
  next_state <= 3'b000;
  Sync_Out <= 0;
   Count_Reg <= 0;
  end
  else
  if(Enable_In )
  case(current_state)
  3'b000 :
    if(sync == 8'b00110110)//第一次检测到帧头,进入下一个状态
       next_state <= 3'b001;
    else
       next_state <= 3'b000;
  3'b001 :
    if(Count_Reg == 10'd543)
   begin
    Count_Reg <= 0;
   if (sync == 8'b00110110)//第二次检测到帧头,Sync_Out <= 1
   begin
          next_state <= 3'b001;
     Sync_Out <= 1;
        end
       else
   begin
    next_state <= 3'b000;
    Sync_Out <= 0;
       end
     end
   else
   Count_Reg <= Count_Reg + 1;
   default :
    begin
    next_state <= 3'b000;
    Sync_Out <= 0;
      end

assign current_state = next_state;

仿真都作了,没有问题,可是当下到芯片里,输出就是全0,( Count_Reg =0,Sync_Out = 0,next_state =0)
好像是状态机根本就没有运行,为什么呢?????
期望大侠指点一下!!!!!多谢多谢
CTT 发表于 2010-6-26 00:28:13 | 显示全部楼层
Enable_In和current_state是否正常,用示波器看
CTT 发表于 2010-6-26 00:33:05 | 显示全部楼层
板子的clock进去没有?
CCIE 发表于 2010-6-26 01:07:19 | 显示全部楼层
多谢!!<br>
现在这个问题已经解决了,只要把next_state 和current_state 改成1bit就可以了。运行完全正常,可是加入我想多检测一个状态,即检测到连续3个帧头的时候,syn_out输出为1。所以我又加了一段代码。可是这个时候状态机又不运行了,输出仍然是全0。<br>
<br>
always @(posedge Clk2176_In or negedge Reset_In )<br>
&nbsp; &nbsp; if (Reset_In == 0)<br>
&nbsp; &nbsp; begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;next_state &lt;= 2'b00 ;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Sync_Out &lt;= 0;<br>
&nbsp; &nbsp;&nbsp; &nbsp; Count_Reg &lt;= 0;<br>
&nbsp; &nbsp; end<br>
&nbsp; &nbsp; else<br>
&nbsp; &nbsp; if(Enable_In )<br>
&nbsp; &nbsp; case(current_state)<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;2'b00 :<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if(sync == 8'b00110110)&nbsp; &nbsp;//检测到第一个帧头,进入第二个状态<br>
&nbsp; &nbsp; &nbsp; &nbsp; next_state &lt;= 2'b01;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else<br>
&nbsp; &nbsp; &nbsp; &nbsp; next_state &lt;= 2'b00;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;2'b01 :<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if(Count_Reg == 10'd543)<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;begin<br>
&nbsp; &nbsp; &nbsp; &nbsp; Count_Reg &lt;= 0;<br>
&nbsp; &nbsp; &nbsp; &nbsp; if (sync == 8'b00110110)<br>
&nbsp; &nbsp; &nbsp; &nbsp; begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;next_state &lt;= 2'b10;&nbsp; &nbsp; //检测到第二个帧头,进入第三个状态<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; //Sync_Out &lt;= 1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;end<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;else<br>
&nbsp; &nbsp; &nbsp; &nbsp; begin <br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;next_state &lt;= 2'b00;<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//Sync_Out &lt;= 0;&nbsp;&nbsp;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;end <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;end <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;Count_Reg &lt;= Count_Reg + 1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;2'b10 :<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if(Count_Reg == 10'd543)<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;begin<br>
&nbsp; &nbsp; &nbsp; &nbsp; Count_Reg &lt;= 0;<br>
&nbsp; &nbsp; &nbsp; &nbsp; if (sync == 8'b00110110)<br>
&nbsp; &nbsp; &nbsp; &nbsp; begin<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;next_state &lt;= 2'b10;&nbsp;&nbsp;//检测到第三个帧头,保持并且Sync_Out &lt;= 1;<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Sync_Out &lt;= 1;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;end<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;else<br>
&nbsp; &nbsp; &nbsp; &nbsp; begin <br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;next_state &lt;= 2'b00;<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;Sync_Out &lt;= 0;&nbsp;&nbsp;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;end <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;end <br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;else<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;Count_Reg &lt;= Count_Reg + 1;<br>
<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;default :<br>
&nbsp; &nbsp; &nbsp; &nbsp; begin<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;next_state &lt;= 2'b00;<br>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Sync_Out &lt;= 0;<br>
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;end<br>
&nbsp; &nbsp;endcase<br>
<br>
assign&nbsp; &nbsp;current_state = next_state;<br>
<br>
[ 本帖最后由 yukisun 于 2006-2-27 11:41 编辑 ]
usd 发表于 2010-6-26 01:14:33 | 显示全部楼层
为了思路更加清晰,还是先大概画一个状态转换图,包括跳转条件,输出状态等。还有就是状态机的格雷码编码。如果状态机寄存器是两位,而且状态机正常变化时没有太多分枝,例如本例,最好采用00,01,11,10的编码方法。<br>
还有要考虑代码的可综合性,在状态&lsquo;01和&rsquo;10中都有一个加法器描述,为了避免综合成两个加法器,宜用一个单独的always语句对counter赋值。<br>
如果要改正,希望搂主能提供以下详细的描述。mail:
        shawnbak@126.com
<br>
<br>
[ 本帖最后由 luoher 于 2006-2-27 13:31 编辑 ]
interig 发表于 2010-6-26 02:49:55 | 显示全部楼层
是不是定义内部寄存器时,wire current_state, reg next_state啊?wire[1:0] current_state,reg[1:0] next_state。<br>
楼主用的是独热码,应该没问题。<br>

        Lattice电子设计大赛,一等奖8000元
<br>
<br>
[ 本帖最后由 yzhqbuaa 于 2006-2-27 13:34 编辑 ]
interige 发表于 2010-6-26 04:05:17 | 显示全部楼层
原帖由 yzhqbuaa 于 2006-2-27 13:24 发表<br>
是不是定义内部寄存器时,wire current_state, reg next_state啊?wire[1:0] current_state,reg[1:0] next_state。<br>
楼主用的是独热码,应该没问题。<br>
[url=http://www.edacn.net/bbs/get.php?id=41204]Lattice电 ... 最初我定义的<br>
wire[2:0] current_state,reg[2:0] next_state;<br>
<br>
运行的过程中就发现状态机根本不运行。<br>
后来我改写成wire&nbsp; &nbsp; current_state,reg&nbsp; &nbsp;next_state;<br>
发现运行就完全正确了,大概是因为实际上我只用了两个状态,1bit,当定义多了时候就不成了。<br>
我开始没有注意,以为综合的时候会自动综合掉的,没有想到害的我浪费了2天的时间。郁闷呀!!!
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

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

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2024-12-24 03:29 , Processed in 0.061838 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表