网站公告列表

  没有公告

加入收藏
设为首页
联系站长
您现在的位置: 61EDA中国电子网 >> 服务导航 >> 帮助中心 >> Xilinx >> 正文
  Notes: FSM Coding Style without latch           ★★★ 【字体:
Notes: FSM Coding Style without latch
作者:rickysu    文章来源:rickysu    点击数:    更新时间:2008-3-11    
背景:在做Blackjack Project时,做到FSM模块,由于涉及到的usersum和robotsum两个(时序的状态转换,组合的状态译码和组合的输出译码)时, usersum和robotsum形成Latch。并且map report中也显示生成门控时钟。宏观上,整个设计下载到试验板上状态机运行不正确。


分析:通过FPGA Editor查看生成门控时钟的模块,发现这种情况是由于生成了Latch,而驱动Latch的状态信号形成了门控时钟。产生这种状态的主要原因是输出译码模块是组合逻辑,没有保持功能,当需要保持一个值时,系统就自动产生了latch。由于门控时钟容易引起glitch,门控时钟控制的latch导致了usersum的不正常。

解决方法:将输出译码电路转换为时序逻辑,由时钟控制。将原来控制latch的信号转接到FF的CE端口。具体方法见示例代码。

原始代码结构:(按照ISE中的Language Templates)
  type state_type is (st1_, st2_, ...);
  signal state, next_state : state_type;
  --Declare internal signals for all outputs of the state machine
  signal _i : std_logic;  -- example output signal
  --other outputs

--Insert the following in the architecture after the begin keyword
  SYNC_PROC: process ()
  begin
     if ('event and = '1') then
        if ( = '1') then
           state <= st1_;
            <= '0';
        else
           state <= next_state;
            <= _i;
        -- assign other outputs to internal signals
        end if;        
     end if;
  end process;

  --MOORE State Machine - Outputs based on state only
  OUTPUT_DECODE: process (state)
  begin
     --insert statements to decode internal output signals
     --below is simple example
     if state = st3_ then
        _i <= '1';
     else
        _i <= '0';
     end if;
  end process;

  NEXT_STATE_DECODE: process (state, , , ...)
  begin
     --declare default state for next_state to avoid latches
     next_state <= state;  --default is to stay in current state
     --insert statements to decode next_state
     --below is a simple example
     case (state) is
        when st1_ =>
           if = '1' then
              next_state <= st2_;
           end if;
        when st2_ =>
           if = '1' then
              next_state <= st3_;
           end if;
        when st3_ =>
           next_state <= st1_;
        when others =>
           next_state <= st1_;
     end case;      
  end process;

修改后代码:
  SYNC_PROC: process ()
  begin
     if ('event and = '1') then
        if ( = '1') then
           state <= st1_;
           -- <= '0';
        else
           state <= next_state;
           -- <= _i;
        -- 第一个同步模块中去掉输出部分

        end if;        
     end if;
  end process;


  OUTPUT_DECODE: process ()
  begin
     if rising_edge(clk) then
        --insert statements to decode internal output signals
        --below is simple example
        if state = st3_ then
           _i <= '1';
        else
           _i <= '0';
        end if;
     end if;
  end process;
Tags:
文章录入:admin    责任编辑:admin 
  • 上一篇文章:

  • 下一篇文章: 没有了
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    没有相关文章
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    湘ICP备08001332号 站长:61EDA