1 引言 隨著微電子技術的迅速發展,人們對數字系統的需求也在提高。不僅要有完善的功能,而且對速度也提出了很高的要求。對于大部分數字系統,都可以劃分為控制單元和數據單元兩個組成部分。通常,控制單元的主體是一個有限狀態機,它接收外部信號以及數據單元產生的狀態信息,產生控制信號序列。MOORE型有限狀態機的設計方法有多種,采用不同的設計方法,雖然可以得到相同功能的狀態機,但它們的速度、時延特性、占用資源可能有較大的差異。在某些對速度要求很高的場合,如內存控制器,則需要針對速度進行優化設計。 2 MOORE型有限狀態機的幾種設計方法 2.1 輸出由狀態位經組合譯碼得到 它的實現方案是:現態與輸入信號經組合邏輯得到次態,在時鐘的上升沿到來時,狀態寄存器將次態鎖存得到現態,現態經過輸出組合邏輯譯碼得到輸出信號。如圖 1所示。由于輸出必須由現態的狀態位經過譯碼得到,這就需要在現態與輸出之間增加一級組合譯碼邏輯,從而加大了從狀態位到器件輸出管腳的傳輸延遲,同樣也增加了時鐘-輸出時延TCO。 假設一個簡單的內存控制器的狀態轉換圖如圖2所示。一個完整的讀寫周期是從空閑狀態idle開始。在ready信號有效之后的下一個時鐘周期轉移到判斷狀態decision,然后根據read_write信號再轉移到read或write狀態。則采用這種設計方法的VHDL源程序如下: signalpresent_state,next_state:std_logic_vector(1 downto 0); process(clk,ready,read_write,present_state) begin if(clk'eventandclk='1')then casepresent_stateis when idle=>oe<='0';wr<='0'; if ready='1' then next_state<=decision; else next_state<=idle; endif; when decision=>oe<='0';wr<='0'; if(read_write='1')then next_state<=read; else next_state<=write; endif; when read=>oe<='1';wr<='0'; if(ready='1')then next_state<=idle; else next_state<=read; endif; when others=>oe<='0';wr<='1'; if(ready='1')then next_state<=idle; else next_state<=write; endif; endcase;endif; endprocess; state_clock:process(clk)begin if(clk'eventandclk='1')then present_state<=next_state; endif; endprocess; 對此程序綜合出的電路如圖3所示。現態present_state與次態next_state均由兩個觸發器構成,輸出wr和oe均由 present_state經組合譯碼得到,因此從時鐘的上升沿到狀態機輸出的延遲為通過邏輯陣列的時鐘-輸出時延TCO2,而不是較短的時鐘-輸出時延 TCO,且輸出信號wr,oe直接來自組合邏輯電路,因而可能有毛刺發生。 2.2 輸出由并行輸出寄存器譯碼得到 在第一種方法中,主要由于輸出組合邏輯引入了延時,從而加大了時鐘-輸出時延。為了縮短狀態機輸出到達管腳的延時,可以在鎖存狀態位之前,先進行輸出的組合邏輯譯碼并將其鎖存到專用寄存器中,時鐘上升沿到來時,專用寄存器中直接輸出wr和oe而沒有了組合邏輯引入的延時,從而使狀態機輸出的延遲為TCO。實現該方案的方框圖如圖4。采用這種設計方法的VHDL源程序如下: signalpresent_state:std_logic_vector(1 downto 0); signalnext_state:std_logic_vector(1 downto 0); signalwr_d,oe_d:std_logic; begin process(clk,ready,read_write) begin if(clk'event and clk='1')then case present_stateis when idle=> if ready='1'thennext_state<=decision; else next_state<=idle; endif ; when decision=> if(read_write='1') then next_state<=read; else next_state<=write; endif; when read=> if(ready='1')then next_state<=idle; else next_state<=read; endif; when others=> if(ready='1')then next_state<=idle; else next_state<=write; endif; endcase; endif; endprocess; withnext_stateselect oe_d<='0' whenidle|decision|write,'1'when others; withnext_stateselect wr_d<='0'whenidle|decision|read,'1'when others; state_clock:process(clk) begin if(clk'eventandclk='1')then present_state<=next_state; oe<=oe_d; wr<=wr_d; endif; endprocess; 在此程序中,用到了兩個新的信號oe_d和wr_d,對次態next_state進行鎖存,不象第一種方案中將現態present_state進行譯碼從而得到在下一個時鐘周期oe和wr的取值。對此程序綜合出的電路如圖5所示。oe_d和wr_d作為鎖存器D1和D2的輸入。因此D1、D2的輸出為上一個次態(即現態)的值。clk的上升沿到來時,D1、D2即將oe_d和wr_d鎖存,從而得輸出oe和wr。因此從時鐘的上升沿到狀態機輸出的延遲為時鐘-輸出時延TCO而不是通過邏輯陣列的時鐘-輸出時延TCO2。又由于時鐘信號將輸出加載到附加的D觸發器中,因而消除了輸出信號的毛刺。然而,這種方法存在兩個缺點:(1)由于用到了輸出寄存器,它比第一種設計需要多用兩個寄存器;(2)雖然它的時鐘-輸出時延從TCO2減小到TCO,但從狀態機的狀態位到達oe和wr需要經過兩級組合邏輯,這就影響了系統時鐘的最高頻率。 2.3 輸出直接從狀態位得到 為了能夠把時鐘-輸出時延限制在TCO內,也可以將狀態位本身作為輸出信號。對于狀態位不是很多的狀態機而言,這種方法也許較前兩種更為優越。某種情況下,可能會出現兩種不同狀態有相同的狀態位,此時只需增加一位狀態位加以區別即可。如此程序中,idle、decision、read、write四種狀態可分別編碼為000,001,100,010。采用這種方法所對應的程序如下: signalpresent_state:std_logic_vector(2downto0); state:process(clk,ready,read_write); begin if(clk'eventandclk='1')then case present_stateis when "000"=>ifready='1' then present_state<="001"; else present_state<="000"; endif; when "001"=>if(read_write='1') then present_state<="100"; else present_state<="001"; endif; when "100"=>if(ready='1')then present_state<="000"; elsepresent_state<="100"; endif; when "010"=>if(ready='1') then present_state<="000"; else present_state<="010"; endif; when others=>present_state<="---"; endcase; endif; endprocess; oe<=present_state(2); wr<=present_state(1); 對此程序綜合出的電路如圖6所示。從圖中可知,輸出信號未通過額外的邏輯對現態進行譯碼,而是直接來自狀態寄存器,因而輸出信號上沒有毛刺,并且它所用的宏單元少于通過并行輸出寄存器輸出的方式。 3 結論 從以上分析可知,普通MOORE型狀態機時延最長,速度最慢,可應用于對速度要求不高的場合。同時,由于它的輸出信號中有毛刺,更加限制了它的應用范圍。后兩種方案在相同的條件下,具有相同的時延,即速度是相同的,但第二 種方案所占用面積要比第三種大得多,且對時鐘頻率有一定限制。如果可能的話,選擇“輸出直接從狀態位得到”類型狀態機是一個理想的方案,因為其速度最快,面積最小,設計這種狀態機時,必須在VHDL源碼中對狀態的編碼加以明確的規定,使狀態和輸出信號的取值一致。所以只有在狀態機的規模較小時,才能很好地實現這種類型的設計。 |