1、狀態(tài)機(jī)設(shè)計(jì)
Mealy 機(jī)方框圖
狀態(tài)寄存器輸出當(dāng)前的信號(hào),用來控制下一個(gè)狀態(tài)是什么,和當(dāng)前狀態(tài)下的輸出是什么。
Moore機(jī)方框圖
2、狀態(tài)機(jī)---3種類型
二元的:(CPLD與陣列扇入比較多,寄存器比較少)
S1 = 001, S2 = 010, S3 = 011, S3 = 100,etc。。。
枚舉的:
S1 = 100, S2 = 110, S3 = 101, S4 = 111,etc。。。
One Hot:每1 個(gè)狀態(tài)機(jī)只有1個(gè)寄存器(FPGA觸發(fā)器比較多)
S1 = 00000001, S2 =00000010,S3 = 00000100,etc。。。
3、對(duì)生剩余狀態(tài)的處理
1、在CASE 語句中增加語句,對(duì)每個(gè)非法狀態(tài)明確地給出狀態(tài)輪換的指示;
2、用OTHERS語句來對(duì)未提及的狀態(tài)做統(tǒng)一處理。
Moore 型狀態(tài)機(jī)設(shè)計(jì)
摩爾型的有限狀態(tài)機(jī)的輸出只與當(dāng)前狀態(tài)有關(guān),而與輸入信號(hào)的當(dāng)前值無關(guān),且僅豐時(shí)鐘信號(hào)邊沿到來時(shí)才發(fā)生變化。
要實(shí)現(xiàn)這種結(jié)構(gòu),必須使用暫存信號(hào)(如 temp)來存儲(chǔ)電路的輸出值,當(dāng)今信號(hào)在時(shí)鐘邊沿出現(xiàn)時(shí)才能夠更新輸出。
例:
library ieee;
use ieee.std_logic_1164.all;
entity s_machine2 is
port(
clk, reset : in std_logic;
x : in std_logic;
z : out std_logic
);
architecture behav of s_machine2 is
type m_state is(s0, s1, s2);
signal present_state, next_state : m_state;
signal temp : std_logic;
begin
-----------------------時(shí)序進(jìn)程---------------------------
reg : process(reset, clk)
begin
if reset = ‘1’ then present_state 《= s0;
elsif clk = ‘1’ and clk‘event then
z 《=temp; --只有在時(shí)鐘的上升沿時(shí),輸出才會(huì)發(fā)生變化。是同步輸出。
prsent_state 《=nxet_state;
end if;
end process;
-------------------------組合進(jìn)程-----------------------------
com : process(present_state, x)
begin
case prsent_state is
when s0 =》
if x = ’0‘ then next_state 《= s0;
else next_state 《= s1;
end if;
temp 《= ’0‘;
when s1 =》
if x = ’0‘ then next_state 《= s0;
else next_state 《= s2;
end if;
temp 《= ’0‘;
when s2 =》
if x = ’0‘; then next_state 《= s0; temp 《= ’1‘;
else next_state 《= s2; temp 《= ’0‘;
end if
end case;
end process;
end behv;
Mearly 型的有限狀態(tài)機(jī)設(shè)計(jì)
米立狀態(tài)機(jī)的輸出信號(hào)是當(dāng)前狀態(tài)和輸出信號(hào)的函數(shù),它的輸出在輸入變化后立即發(fā)生變化,
不依賴時(shí)鐘信號(hào)的同步。是異步輸出。
例:
library ieee;
use ieee.std_logic_1164.all;
entity s_machine1 is
port(
clk, reset : in std_logic;
x : in std_logic;
z : out std_logic
);
end s_machine1;
architecture behav of s_machine2 is
type m_state is(s0, s1, s2);
signal present_state, next_state : m_state;
begin
-----------------------時(shí)序進(jìn)程---------------------------
reg : process(reset, clk)
begin
if reset = ’1‘ then present_state 《= s0;
elsif clk = ’1‘ and clk’event then
prsent_state 《=nxet_state;
end if;
end process;
-------------------------組合進(jìn)程-----------------------------
com : process(present_state, x)
begin
case prsent_state is
when s0 =》
if x = ‘0’ then next_state 《= s0;
else next_state 《= s1;
end if;
z 《= ‘0’;
when s1 =》
if x = ‘0’ then next_state 《= s0;
else next_state 《= s2;
end if;
z 《= ‘0’;
when s2 =》
if x = ‘0’; then next_state 《= s0; z 《= ‘1’;
else next_state 《= s2; z《= ‘0’;
end if
end case;
end process;
end behv;
可以看到在該程序中,只要輸入有變化,輸出z就會(huì)有變化,它并不依賴于時(shí)鐘的上升沿。
怎樣確保一個(gè)進(jìn)程是組合進(jìn)程:
1、不出現(xiàn)帶沿的語句,即組合進(jìn)程中決不能出現(xiàn)用時(shí)鐘沿控制的敏感信號(hào);
2、在組合電路的進(jìn)程中,給出輸出端口的缺省值,這樣可以防止鎖存器的生成;
3、在敏感清單中包含所有的輸入量,防止鎖存器的生成。
敏感清單不全的話綜合時(shí)可能出現(xiàn)敬告。
例:下例敏感清單中輸入端口不全,可能出現(xiàn)鎖存器
p0 : process (a)
begin
q 《= a and b;
end process p0;
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
下面是一個(gè)實(shí)例,洗衣機(jī)的工作過程:
TYPE state_type IS(idle, fill, heat_w, wash, drain);
entity wm is
port(
clk, reset, door_closed, full : in std_logic;
heat_demand, done, empty : in std_logic;
water, spin, heat, pump : out std_logic
);
end wm;
architecture behave of wm is
------------------------說明部分--------------------------
--說明部分用枚舉數(shù)據(jù)類型來字義狀態(tài)機(jī)中的狀態(tài);并把狀態(tài)變量(如現(xiàn)態(tài)和次態(tài))定義為信號(hào)。
type state_type is (
idle, fill, heat_w, wash, drain);
signal state : state_type;
begin
process (clk, reset)
begin
if reset = ‘1’ then
state 《= idle;
elsif clk‘event and clk= ’1‘ then
case state is
when idle =》
if door_closed = ’1‘ then
state 《= fill;
else
state 《= idle;
end if
when fill =》
if full =’1‘; then
state 《= neat_w;
else
state 《= fill;
。
。
。
when others =》
state 《= idle;
end case
end if;
end process;
----------------------------------------------
利用兩個(gè)進(jìn)程(純組合邏輯措施一)
--------------時(shí)序進(jìn)程----------------------------
--時(shí)序進(jìn)程是指在時(shí)鐘驅(qū)動(dòng)下負(fù)責(zé)狀態(tài)轉(zhuǎn)換的進(jìn)程,只表示次態(tài)和現(xiàn)態(tài)的關(guān)系
process(clk, reset)
begin
if reset =’1‘ then
state 《= idle;
elsif clk’event and clk = ‘1’ then
state 《= next_state;
end if;
end process;
------------------組合進(jìn)程---------------------
組合進(jìn)程的任務(wù)是根據(jù)輸入信號(hào)和現(xiàn)態(tài)對(duì)輸出端口賦值以及確定狀態(tài)機(jī)的下一個(gè)狀態(tài),由于沒有任何信號(hào)
的賦值是通過其他某個(gè)信號(hào)的跳變來觸發(fā)的,所以不會(huì)產(chǎn)生寄存器。一般用CASE 或IF語句來實(shí)現(xiàn)
process(state, door_closed, full,
heat_demand, done, empty)
begin
case state is
when idle =》
if door_closed =‘1’ then
next_state 《= fill;
else
next_state 《= idle;
end if;
when fill =》
if full = ‘1’ then
next_state 《= heat_w;
else
next_state 《= fill;
。
。
。
end case;
end if;
end process;
process(state)
begin
water_i 《= ‘0’;
spin_i 《= ‘0’;
heat_i 《= ‘0’;
pump_i 《= ‘0’;
case state is
when idle =》
when fill =》
water_i 《= ‘1’;
when heat_w =》
spin_i 《=‘1’;
heat_i 《= ‘1’;
when wash =》
spin_i 《= ‘1’;
when drain =》
spin_i 《= ‘1’;
pump_i 《= ‘i’;
end case;
end process;
--------------寄存輸出---------------------
process (clk)
begin
if rising_edge(clk) then
water 《= water_i;
spin 《= spin_i;
heat 《= heat_i;
pump 《= pump_i;
end if;
end process
-
寄存器
+關(guān)注
關(guān)注
31文章
5397瀏覽量
122674 -
狀態(tài)機(jī)
+關(guān)注
關(guān)注
2文章
493瀏覽量
27961
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
SaberRD狀態(tài)機(jī)建模工具介紹(一)什么是狀態(tài)機(jī)建模

Verilog狀態(tài)機(jī)+設(shè)計(jì)實(shí)例

玩轉(zhuǎn)Spring狀態(tài)機(jī)

有限狀態(tài)機(jī)有什么類型?
狀態(tài)機(jī)是什么?什么是消息觸發(fā)類型的狀態(tài)機(jī)?
狀態(tài)機(jī)舉例
狀態(tài)機(jī)代碼生成工具
什么是狀態(tài)機(jī) 狀態(tài)機(jī)的描述三種方法
FPGA:狀態(tài)機(jī)簡述

什么是狀態(tài)機(jī)?狀態(tài)機(jī)5要素

狀態(tài)模式(狀態(tài)機(jī))

Verilog狀態(tài)機(jī)的類型

評(píng)論