2012-12-23 36 views
1

我正在編程一個N位非還原分頻器,但我遇到了一些小問題。未經考慮的1位鎖存(VHDL)

我有一個操作部分(組合)和一個控制部分(有限狀態機)。 控制部分有2個過程FSM,1個用於更新下一個狀態,1個用於「狀態序列」。

update:  process(clk_in, next_state) 
     begin 
      if rising_edge(clk_in) then 
       current_state <= next_state; 
      end if; 
     end process; 

這是第二種方法:

control: process(current_state, start, S_in, counted) 
      variable sub_tmp : STD_LOGIC := '0'; 
     begin 
          [...] 
      sub <= sub_tmp; -- sub is an output signal of my entity that goes in the Operative Part 

      case current_state is 
       when idle => 
        if start='1' then 
         next_state <= init; 
        else 
         next_state <= idle; 
        end if; 

       when init => 
              -- [...] 
        next_state <= subtract; 

       when subtract => 
        en_A <= '1'; 
        sub_tmp := '1'; 
        next_state <= test; 

       when test => -- shift 
        en_Q <= '1'; 

        if S_in='0' then 
         sub_tmp := '1'; 
        else 
         sub_tmp := '0'; 
        end if; 

        if counted=N/2-1 then 
         next_state <= finished; 
        else 
         next_state <= operation; 
        end if; 

       when operation => 
        en_A <= '1'; 
        next_state <= test; 

       when finished => 
        stop <= '1'; 
        next_state <= idle; 
      end case; 
     end process; 

正如你所看到的,我只需要改變2例(減和測試)子的價值,雖然我不在其他情況下必須改變。

問題是,當我嘗試綜合這段代碼時,事實證明sub_tmp是一個鎖存器,但我不想要一個鎖存器。 我需要做的是這樣的:

狀態1 =>子集爲「1」或「0」(取決於另一個輸入)

狀態2 =>做其他操作(但子必須保持前值設置),並返回到狀態1 等等

爲了澄清更多:在我的FSM的某些狀態(不是全部),我設置一個變量的值(我們稱之爲sub_tmp)。在其他國家,我不會改變它的價值。然後我們假設我有一個名爲「sub_out」的輸出PIN。現在,無論變量值如何,我都希望將其值輸出到此引腳(sub_out < = sub_tmp;或類似)。

我錯過了什麼?

回答

3

你缺少的是你描述的行爲IS一個鎖存器。任何帶有內存的東西(例如:「在其他狀態下,我不會改變它的值」)是鎖存器還是寄存器(觸發器)。如果你不想要一個鎖存器或一個寄存器,你需要爲每個代碼路徑中的信號分配一個特定的值,而不是讓它「記​​住」它以前的狀態。