第4章 數(shù)字邏輯單元設計20130909_第1頁
第4章 數(shù)字邏輯單元設計20130909_第2頁
第4章 數(shù)字邏輯單元設計20130909_第3頁
第4章 數(shù)字邏輯單元設計20130909_第4頁
第4章 數(shù)字邏輯單元設計20130909_第5頁
已閱讀5頁,還剩114頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、數(shù)字邏輯單元設計何賓2011.09數(shù)字邏輯單元設計-本章概要 在復雜數(shù)字系統(tǒng)中,其結構總可以用若干基本邏輯單元的組合進行描述。 基本邏輯單元一般分為組合邏輯電路和時序電路兩大類。在此基礎上,可以更進一步進行組合. 本章所介紹的存儲器、運算單元和有限自動狀態(tài)機就是由基本邏輯單元組合而成的。 本章首先介紹基本的組合邏輯電路和時序電路設計,然后介紹在數(shù)字系統(tǒng)設計中普遍使用的存儲器電路、運算單元和有限自動狀態(tài)機。 數(shù)字邏輯單元設計-基本邏輯門電路設計 對基本邏輯門的操作主要有:與、與非、或、或非、異或、異或非和非操作。通過使用VHDL語言中描述基本邏輯門電路操作的關鍵字:and(與),nand(與非)

2、,or(或),nor(或非),xor(異或),xnor(異或非),not(非)來實現(xiàn)對基本邏輯門的操作。一堆復雜的邏輯門操作總可以化簡為集中基本邏輯門操作的組合。 數(shù)字邏輯單元設計-基本邏輯門電路設計基本門電路的設計 Library ieee; Use ieee.std_logic_1164.all; Entity gate is Port(a, b,c : in std_logic; d : out std_logic); end gate; architecture rtl of gate isbegin d=(not a) and b) or c;end rtl; 數(shù)字邏輯單元設計-編碼

3、器和譯碼器設計 在數(shù)字系統(tǒng)中,常常會將某一信息用特定的代碼進行描述,這稱為編碼過程。編碼過程可以通過編碼器電路實現(xiàn)。 同時,將某一特定的代碼翻譯成原始的信息,這稱為譯碼過程。譯碼過程可以通過譯碼器電路實現(xiàn)。 數(shù)字邏輯單元設計-編碼器設計 將某一信息用一組按一定規(guī)律排列的二進制代碼描述稱為編碼。典型的有8421碼、BCD碼等。在使用VHDL語言設計編碼器時,通過使用CASE和IF語句實現(xiàn)對編碼器的描述。 數(shù)字邏輯單元設計-編碼器設計8/3線編碼器的VHDL描述 library ieee; use ieee.std_logic_1164.all; entity priority_encoder_1

4、 is port ( sel : in std_logic_vector (7 downto 0); code :out std_logic_vector (2 downto 0); end priority_encoder_1; architecture archi of priority_encoder_1 is begin code = 000 when sel(0) = 1 else 001 when sel(1) = 1 else 010 when sel(2) = 1 else 011 when sel(3) = 1 else 100 when sel(4) = 1 else 10

5、1 when sel(5) = 1 else 110 when sel(6) = 1 else 111 when sel(7) = 1 else ZZZ; end archi; 數(shù)字邏輯單元設計-譯碼器設計 譯碼的過程實際上就是編碼過程的逆過程,即將一組按一定規(guī)律排列的二進制數(shù)還原為原始的信息。下面以最常用的3:8譯碼器為例,給出其VHDL語言描述。 數(shù)字邏輯單元設計-譯碼器設計abcdefgh a b c d a f b e f g h g e c d(a) 外形圖(b) 共陰極(c) 共陽極+VCCabcdefgh3.5.3 顯示譯碼器1、數(shù)碼顯示器、數(shù)碼顯示器b=c=f=g=1,a=d=

6、e=0時時c=d=e=f=g=1,a=b=0時時共陰極共陰極真值表真值表 數(shù)字邏輯單元設計-譯碼器設計十六進制數(shù)的共陽極十六進制數(shù)的共陽極7 7段數(shù)碼顯示段數(shù)碼顯示VHDLVHDL描述描述 library ieee;library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_unsigned.all; entity decoder is entity decoder is port(hex: in std_l

7、ogic_vector(3 downto 0); port(hex: in std_logic_vector(3 downto 0); led : out std_logic_vector(6 downto 0); led : out std_logic_vector(6 downto 0); end decoder; end decoder; architecture rtl of decoder is architecture rtl of decoder is begin begin with hex selectwith hex select LED= 1111001 when 000

8、1, -1 LED= 1111001 when 0001, -1 0100100 when 0010, -2 0100100 when 0010, -2 0110000 when 0011, -3 0110000 when 0011, -3 0011001 when 0100, -4 0011001 when 0100, -4 0010010 when 0101, -5 0010010 when 0101, -5 0000010 when 0110, -6 0000010 when 0110, -6 1111000 when 0111, -7 1111000 when 0111, -7 000

9、0000 when 1000, -8 0000000 when 1000, -8 0010000 when 1001, -9 0010000 when 1001, -9 0001000 when 1010, -A 0001000 when 1010, -A 0000011 when 1011, -b 0000011 when 1011, -b 1000110 when 1100, -C 1000110 when 1100, -C 0100001 when 1101, -d 0100001 when 1101, -d 0000110 when 1110, -E 0000110 when 1110

10、, -E 0001110 when 1111, -F 0001110 when 1111, -F 1000000 when others; -0 1000000 when others; -0 end rtl; end rtl;數(shù)字邏輯單元設計-運算單元數(shù)據(jù)運算單元主要包含加法器、減法器、乘法器和除法器,由這四種運算單元和邏輯運算單元一起,可以完成復雜數(shù)學運算。在VHDL語言中,支持的幾種運算有:加(+)、減(-)、乘(*)、除(/)、取余(MOD)、冪乘(*)。數(shù)字邏輯單元設計-加法器設計 在VHDL描述加法器時,使用+運算符比門級描述更簡單。下面給出帶進位輸入和輸出的無符號的8比特加法器的

11、VHDL描述。數(shù)字邏輯單元設計-加法器設計帶進位輸入和輸出的無符號的8比特加法器的VHDL描述library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity adders_4 isport(A,B,CI : in std_logic_vector(7 downto 0);SUM : out std_logic_vector(7 downto 0);CO : out std_logic);end adders_4;architecture ar

12、chi of adders_4 issignal tmp: std_logic_vector(8 downto 0);begin SUM = tmp(7 downto 0);CO = tmp(8);tmp = conv_std_logic_vector(conv_integer(A) + conv_integer(B) +conv_integer(CI),9);end archi;數(shù)字邏輯單元設計-減法器設計減法是加法的反運算,采用VHDL語言的-符號描述減法器,比用門級描述更簡單。下面給出一個無符號8位帶借位的減法器的VHDL描述。數(shù)字邏輯單元設計-減法器設計【例例4-10】無符號8位帶借位

13、的減法器的VHDL描述library IEEE;use IEEE.STD_LOGIC_1164.ALL;use ieee.std_logic_arith.all;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity adders_8 isport(A,B : in std_logic_vector(7 downto 0);BI : in std_logic;RES : out std_logic_vector(7 downto 0);end adders_8;architecture archi of adders_8 isbeginRES = A - B - BI;e

14、nd archi;數(shù)字邏輯單元設計-乘法器設計用VHDL語言實現(xiàn)乘法器時,乘積和符號應該為2的冪次方。PLD的優(yōu)點就是在內部集成了乘法器的硬核,具體在IP核的設計中詳細討論。數(shù)字邏輯單元設計-乘法器設計下面給出一個8位和4位無符號的乘法器的VHDL描述library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity multipliers_1 isport(A : in std_logic_vector(7 downto 0);B : in std_logic_vector(3 downto 0);R

15、ES : out std_logic_vector(11 downto 0);end multipliers_1;architecture beh of multipliers_1 isbeginRES = A * B;end beh;數(shù)字邏輯單元設計-除法器設計除法器可以用VHDL語言的/符號實現(xiàn),需要注意的是在使用/符號進行除法運算時,除數(shù)必須是常數(shù),而且是2的整數(shù)冪。因為除法器的運行有這樣的限制,實際上除法也可以用移位運算實現(xiàn)。下面給出一個除法器的VHDL描述。數(shù)字邏輯單元設計-除法器設計除法器的VHDL描述。library ieee;use ieee.std_logic_1164.al

16、l;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;Entity divider_1 isport(DI : in unsigned(7 downto 0);DO : out unsigned(7 downto 0);end divider_1;Architecture one of divder_1 isSignal di2,di3:integer;Begin di2=conv_integer(di); di3=di2/2; do=conv_unsigned(di3,8);End one;數(shù)字邏輯單元設計-數(shù)據(jù)選擇器設

17、計設計 在數(shù)字系統(tǒng)設計中,常使用CASE和IF語句描述數(shù)據(jù)選擇器。下面給出這兩種描述方法。 數(shù)字邏輯單元設計-數(shù)據(jù)選擇器設計設計4選1多路選擇器的IF語句描述library ieee;use ieee.std_logic_1164.all;entity multiplexers_1 isport (a, b, c, d : in std_logic;s : in std_logic_vector (1 downto 0);o : out std_logic);end multiplexers_1;architecture archi of multiplexers_1 isbeginproce

18、ss (a, b, c, d, s)beginif (s = 00) then o = a;elsif (s = 01) then o = b;elsif (s = 10) then o = c;elsif (s=“11”) then o = d;else o o o o o o=x;end case;end process;end archi; 數(shù)字邏輯單元設計-數(shù)字比較器 比較器就是對輸入數(shù)據(jù)進行比較,并判斷其大小的邏輯電路。在數(shù)字系統(tǒng)中,比較器是基本的組合邏輯單元之一,比較器主要是使用關系運算符實現(xiàn)的。 數(shù)字邏輯單元設計-數(shù)字比較器8位數(shù)據(jù)比較器的VHDL描述library ieee;u

19、se ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity comparator_1 isport(A,B : in std_logic_vector(7 downto 0);CMP : out std_logic);end comparator_1;architecture archi of comparator_1 isbeginCMP = B else 0;end archi; 數(shù)字邏輯單元設計-總線緩沖器 總線是一組相關信號的集合。在計算機系統(tǒng)常用的總線有數(shù)據(jù)總線、地址總線和控制總線。由于總線上經(jīng)常需要連接很多的設

20、備,因此必須正確的控制總線的輸入和輸出,這樣才不會產(chǎn)生總線訪問的沖突,下面將介紹總線三態(tài)控制和雙向控制的VHDL描述方法。數(shù)字邏輯單元設計-總線緩沖器三態(tài)門的進程描述Library ieee;Use ieee.std_logic_1164.all;Entity tri_gate is Port (en : in std_logic; din : in std_logic_vector(7 downto 0); dout : out std_logic_vector(7 downto 0);end tri_gate;Architecture rtl of tri_gate isbegin pro

21、cess(din,en) begin if(en=1) then dout=din; else dout=ZZZZZZZZ; end if; end process;end rtl;數(shù)字邏輯單元設計-總線緩沖器三態(tài)門的WHEN-ELSE進程描述Library ieee;Use ieee.std_logic_1164.all;Entity tri_gate is Port (en : in std_logic; din : in std_logic_vector(7 downto 0); dout : out std_logic_vector(7 downto 0);end tri_gate;A

22、rchitecture rtl of tri_gate isbegindout= din when en =1 else ZZZZZZZZ;end rtl; 數(shù)字邏輯單元設計-時序邏輯電路設計時序邏輯電路的輸出狀態(tài)不僅與輸入變量的狀態(tài)有關,而且還與系統(tǒng)原先的狀態(tài)有關。時序電路最重要的特點是存在著記憶單元部分,時序電路主要包括: 1) 基本觸發(fā)器 2) 計數(shù)器 3) 移位寄存器 4) 脈沖寬度調制等。數(shù)字邏輯單元設計-觸發(fā)器設計觸發(fā)器是時序邏輯電路的最基本單元,觸發(fā)器具有“記憶”能力。根據(jù)沿觸發(fā)、復位和置位方式的不同觸發(fā)器可以有多種實現(xiàn)方式。在PLD中經(jīng)常使用的觸發(fā)器有D觸發(fā)器、JK觸發(fā)器和T觸

23、發(fā)器等。 數(shù)字邏輯單元設計-D觸發(fā)器設計【例例4-20】帶時鐘使能和異步復位/置位的D觸發(fā)器的VHDL描述D觸發(fā)器是數(shù)字電路中應用最多的一種時序電路。表4.1給出了帶時鐘使能和異步復位/置位的D觸發(fā)器的真值表。 數(shù)字邏輯單元設計-D觸發(fā)器設計Library ieee;Useieee.std_logic_1164.all;Entity fdd is Port(clk,d,clr,pre,ce : in std_logic; q : out std_logic);end fdd;architecture rtl of dff is signal q_tmp : std_logic; begin q

24、=q_tmp; process(clk,clr,pre,c) begin if(clr=1) then q_tmp=0; elsif(pre=1) then q_tmp=1; elsif rising_edge(clk) then if(ce=1) then q_tmp=d; else q_tmp=q_tmp; end if; end if; end process;end rtl; 數(shù)字邏輯單元設計-JK觸發(fā)器設計JK觸發(fā)器要比D觸發(fā)器復雜一些。 輸入輸入輸出輸出RSCEJKCQ1XXXX001XXX1000XXX無變化無變化00100X無變化無變化00101000111翻轉翻轉001101

25、數(shù)字邏輯單元設計-JK觸發(fā)器設計帶時鐘使能和異步復位/置位的JK觸發(fā)器的VHDL描述Library ieee;Use ieee.std_logic_1164.all;Entity fdd is Port(s,r,j,k,ce,c: in std_logic; q : out std_logic);end fdd;architecture rtl of dff is signal q_tmp : std_logic;begin q=q_tmp; process(s,r,c) begin if(r=1) then q_tmp=0; elsif(s=1) then q_tmp=1; elsif ri

26、sing_edge(clk) then if(ce=0) then q_tmp=q_tmp; else if(j=0 and k=1) then q_tmp=0; elsif(j=1 and k=0) then q_tmp=1; elsif(j=1 and k=1) then q_tmp=not q_tmp; end if; end if; end process; end rtl; 數(shù)字邏輯單元設計-鎖存器設計鎖存器和觸發(fā)器不同之處,就在于觸發(fā)方式的不同,觸發(fā)器是靠敏感信號的邊沿出發(fā),而鎖存器是靠敏感信號的電平觸發(fā)。下面給出鎖存器的VHDL描述。 數(shù)字邏輯單元設計-鎖存器設計Library

27、ieee;Use ieee.std_logic_1164.all;Entity latch isPort(gate,data,set : in std_logic; Q : out std_logic);End latch;Architecture rtl of latch isBegin process(gate,data,set) Begin if(set=0) then Q=1; elsif(gate=1) then Q=data; end if; end process;end rtl; 數(shù)字邏輯單元設計-計數(shù)器設計 根據(jù)計數(shù)器的觸發(fā)方式不同,計數(shù)器可以分為:同步計數(shù)器和異步計數(shù)器兩種

28、。當賦予計數(shù)器更多的功能時,計數(shù)器的功能就非常復雜了。需要注意的是,計數(shù)器是常用的定時器的核心部分,當計數(shù)器輸出控制信號時,計數(shù)器也就變成了定時器了。所以只要掌握了計數(shù)器的設計方法,就可以很容易的設計定時器。本書中主要介紹同步計數(shù)器的設計。 同步計數(shù)器指在時鐘脈沖(計數(shù)脈沖)的控制下,計數(shù)器做加法或減法的運算。 數(shù)字邏輯單元設計-通用計數(shù)器設計 一個8進制(從0到7)的計數(shù)器是一個3位二進制的計數(shù)器。下圖給出了3位八進制計數(shù)器的狀態(tài)圖。數(shù)字邏輯單元設計-通用計數(shù)器設計3位計數(shù)器的VHDL語言行為級描述library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IE

29、EE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity count3bit is Port ( clr : in STD_LOGIC; clk : in STD_LOGIC; qs : out STD_LOGIC_VECTOR (2 downto 0);end count3bit;數(shù)字邏輯單元設計-帶模計數(shù)器設計 下面以模5計數(shù)器為例,介紹帶模計數(shù)器的設計方法。模5計數(shù)器就是反復的從0到4計數(shù)。即,有5個狀態(tài)和輸出為000-100,然后返回0。數(shù)字邏輯單元設計-帶模計數(shù)器設計5進制計數(shù)器的VHDL語言行為級描述library

30、IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity mod5cnt is Port ( clr : in STD_LOGIC; clk : in STD_LOGIC; qs : out STD_LOGIC_VECTOR (2 downto 0);end mod5cnt;architecture Behavioral of mod5cnt isSignal q:std_logic_vector(2 downto 0);begin process(c

31、lk,clr) begin if(clr=1) then q=000; elsif(rising_edge(clk) then if(q=100) then q=000; else q=q + 1; end if; end if;qs=q; end process;end Behavioral;數(shù)字邏輯單元設計-移位寄存器設計 一個N位移位寄存器包含N個觸發(fā)器。如下圖,在每一個時鐘脈沖時,數(shù)據(jù)從一個觸發(fā)器移動到另一個觸發(fā)器。如圖所示,串行數(shù)據(jù)data_in從移位寄存器的左邊輸入進來,在每個時鐘到來時,q3移動到q2,q2移動到q1,q1移動到q0。 數(shù)字邏輯單元設計-移位寄存器設計數(shù)字邏輯單元

32、設計-移位寄存器設計在VHDL語言中,對移位寄存器的描述有三種方式: )并置操作符 shreg = shreg (6 downto 0) & SI; 2)FOR-LOOP語句 for i in 0 to 6 loop shreg(i+1) = shreg(i); end loop; shreg(0) = SI; 3)預定義的移位操作符SLL或SRL等 數(shù)字邏輯單元設計-移位寄存器設計1、預定義的移位操作符(1)算術左移的VHDL描述/ sla (2)邏輯左移的VHDL描述 / sll (3)算術右移的VHDL描述/ sra (4)邏輯右移的VHDL描述 / srl 數(shù)字邏輯單元設計-移

33、位寄存器設計 2、通過VHDL的類型操作,元件例化、信號連接等不同實現(xiàn)方法實現(xiàn)移位操作運算. 下面通過函數(shù)調用,元件例化、信號連接等不同實現(xiàn)方法實現(xiàn)一個16位的串行輸入、串行輸出的移位寄存器。 數(shù)字邏輯單元設計-移位寄存器設計【例例4-28】類型操作實現(xiàn)16位移位寄存器的VHDL描述library ieee;use ieee.std_logic_1164.all;entity shift_registers_1 isport(C, SI : in std_logic; fo:out std_logic_vector(15 downto 0); SO : out std_logic);end s

34、hift_registers_1; 數(shù)字邏輯單元設計-移位寄存器設計【例例4-29】并置操作實現(xiàn)16位串入/并出移位寄存器的VHDL描述library ieee;use ieee.std_logic_1164.all;entity shift_registers_5 isport(C, SI : in std_logic;PO : out std_logic_vector(15 downto 0);end shift_registers_5;數(shù)字邏輯單元設計-消抖電路設計 當按鍵時,不可避免的引起按鍵的抖動,需要大約ms級的時間才能穩(wěn)定下來。也就是說,輸入到FPGA的按鍵信號并不是直接從0變到

35、1,而是在ms級時間內在0和1進行交替變化。 由于時鐘信號變化的比按鍵抖動更快,因為會把錯誤的信號鎖存在寄存器中,這在時序電路是非常嚴重的問題。因此,需要消抖電路來消除按鍵的抖動。如下圖所示,該電路可以完成按鍵的消抖,隨后的設計將驗證這個電路的正確性。數(shù)字邏輯單元設計-消抖電路設計數(shù)字邏輯單元設計-消抖電路設計消抖電路的VHDL語言描述library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity debounce4 is Port ( in

36、p : in STD_LOGIC_VECTOR (3 downto 0); cclk : in STD_LOGIC; clr : in STD_LOGIC; outp : out STD_LOGIC_VECTOR (3 downto 0);end debounce4;architecture Behavioral of debounce4 issignal delay1,delay2,delay3 : std_logic_vector(3 downto 0);begin process(cclk,clr,inp) begin if(clr=1) then delay1=0000; delay2

37、=0000; delay3=0000; elsif(rising_edge(cclk) then delay1=inp; delay2=delay1; delay3=delay2; end if; end process; outp=delay1 and delay2 and delay3; end Behavioral;數(shù)字邏輯單元設計FSM原理從上面的數(shù)學模型可以看出,如果在數(shù)字系統(tǒng)中實現(xiàn)有限狀態(tài)機,則應該包含三部分:狀態(tài)寄存器;下狀態(tài)轉移邏輯;輸出邏輯。描述有限狀態(tài)機的關鍵是狀態(tài)機的狀態(tài)集合以及這些狀態(tài)之間的轉移關系。描述這種轉換關系除了數(shù)學模型外,還可以用狀態(tài)轉移圖或狀態(tài)轉移表來實現(xiàn)。

38、狀態(tài)轉移圖由三部分組成:表示不同狀態(tài)的狀態(tài)點、連接這些狀態(tài)點的有向箭頭以及標注在這些箭頭上的狀態(tài)轉移條件。狀態(tài)轉移表采用表格的方式描述狀態(tài)機。狀態(tài)轉移表由三部分組成:當前狀態(tài)、狀態(tài)轉移事件和下一狀態(tài)。數(shù)字邏輯單元設計FSM設計優(yōu)點采用有限狀態(tài)機描述有以下方面的優(yōu)點:、可以采用不同的編碼風格,在描述狀態(tài)機時,設計者常采用的編碼有二進制、格雷碼、one hot編碼,用戶可以根據(jù)自己的需要在綜合時確定,而不需要修改源文件或修改源文件中的編碼格式以及狀態(tài)機的描述。 、可以實現(xiàn)狀態(tài)的最小化,(如果one hot編碼,控制信號數(shù)量龐大)。 、設計靈活,將控制單元與數(shù)據(jù)單元分離開。 數(shù)字邏輯單元設計狀態(tài)編碼

39、 設計者可以在使用狀態(tài)機之前應該定義狀態(tài)變量的枚舉類型,定義可以在狀態(tài)機描述的源文件中,也可以在專門的程序包中。 【例例】狀態(tài)變量的定義 TYPE main_con_state IS (state1,state2); 【例例】狀態(tài)變量的定義 signal current_state :main_con_state; signal next_state: main_con_state; 數(shù)字邏輯單元設計狀態(tài)編碼 FSM的狀態(tài)可以采用的狀態(tài)編碼規(guī)則有很多,在Xilinx的狀態(tài)編碼“One_Hot”;“Gray”;”Compact”;”Johnson”;“Sequential”;“Speed1”;“

40、User”的編碼方式;下面對這些狀態(tài)編碼的性能進行簡單的介紹。數(shù)字邏輯單元設計狀態(tài)編碼十進制數(shù)十進制數(shù)二進制碼二進制碼Gray碼碼Johnson碼碼One-hot嗎嗎000000000000110010010010102010011011100301101011110004100110510111161101017111100數(shù)字邏輯單元設計狀態(tài)編碼1、One_Hot狀態(tài)編碼ONE HOT的編碼方案對每一個狀態(tài)采用一個觸發(fā)器,即4個狀態(tài)的狀態(tài)機需4個觸發(fā)器。同一時間僅1個狀態(tài)位處于有效電平(如邏輯“l(fā)”)。在使用One_Hot狀態(tài)編碼時,觸發(fā)器使用較多,但邏輯簡單,速度快。 數(shù)字邏輯單元設計狀

41、態(tài)編碼 2、Gray狀態(tài)編碼Gray碼編碼每次僅一個狀態(tài)位的值發(fā)生變化。在使用Gray狀態(tài)編碼時,觸發(fā)器使用較少,速度較慢,不會產(chǎn)生兩位同時翻轉的情況。采用格雷碼進行狀態(tài)編碼時,采用T觸發(fā)器是最好的實現(xiàn)方式。 數(shù)字邏輯單元設計狀態(tài)編碼 3、Compact狀態(tài)編碼 Compact狀態(tài)編碼能夠使所使用的狀態(tài)變量位和觸發(fā)器的數(shù)目變得最少。該編碼技術基于超立方體浸潤技術。當進行面積優(yōu)化的時候可以采用Compact狀態(tài)編碼 數(shù)字邏輯單元設計狀態(tài)編碼4、Johnson狀態(tài)編碼 Johnson狀態(tài)編碼能夠使狀態(tài)機保持一個很長的路徑,而不會產(chǎn)生分支。 5、Sequential狀態(tài)編碼 Sequential狀態(tài)

42、編碼采用一個可標示的長路徑,并采用了連續(xù)的基2編碼描述這些路徑。下一個狀態(tài)等式被最小化。 6、Speed1狀態(tài)編碼 Speed1狀態(tài)編碼用于速度的優(yōu)化。狀態(tài)寄存器中所用的狀態(tài)的位數(shù)取決于特定的有限自動狀態(tài)及FSM,但一般情況下它要比FSM的狀態(tài)要多。數(shù)字邏輯單元設計FSM的分類 狀態(tài)機分類很多,主要分為Moore狀態(tài)機、Mealy狀態(tài)機和擴展有限狀態(tài)機。下面就Moore狀態(tài)機、Mealy狀態(tài)機的原理和應用進行詳細的介紹。FSM的分類-MOORE狀態(tài)機 Moore型狀態(tài)機與Mealy型狀態(tài)機的區(qū)別在與,Moore型狀態(tài)機的輸出僅與狀態(tài)機的狀態(tài)有關,與狀態(tài)機的輸入無關。 FSM的分類-MOORE狀

43、態(tài)機 下面以序列檢測器為例,說明Moore狀態(tài)機的設計。該序列檢測器將檢測序列“1101”,當檢測到該序列時,狀態(tài)機的輸出z為1。下圖給出了基于Moore狀態(tài)機的序列檢測器的運行原理。FSM的分類-MOORE狀態(tài)機 下面對這個狀態(tài)機進行詳細說明: 1)初始狀態(tài)為S0,如果輸入為1則狀態(tài)遷移到S1;否則等待接收序列的頭部。 2)在狀態(tài)S1,如果輸入為0,則必須返回狀態(tài)S0;否則遷移狀態(tài)到S2(表示接收到連續(xù)的1); 3)在狀態(tài)S2,如果輸入為1,則停留在狀態(tài)S2;否則遷移狀態(tài)到S3(表示接收到序列110); 4)在狀態(tài)S3,如果輸入為0,則必須返回到狀態(tài)S0;否則遷移到狀態(tài)S4(表示接收到序列1

44、101); 5)在狀態(tài)S4,狀態(tài)機輸出為1。如果輸入為0,則必須返回到狀態(tài)S0;否則遷移狀態(tài)到狀態(tài)S2(表示接收到序列11)。FSM的分類-MOORE狀態(tài)機Moore型序列檢測器的VHDL語言描述library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity seqdeta isport( clk : in std_logic;clr : in std_logic;din : in std_logic;dout : out std_logic

45、 );end seqdeta;architecture Behavioral of seqdeta istype state is(s0,s1,s2,s3,s4); -狀態(tài)聲明signal present_state,next_state : state; beginprocess(clr,clk)begin if(clr=1) then -狀態(tài)寄存器 present_state=s0; elsif rising_edge(clk) then present_stateif(din=1) then when s0=if(din=1) then next_state=s1; next_state

46、=s1; else else next_state=s0; next_stateif(din=1) then when s1=if(din=1) then next_state=s2; next_state=s2; else else next_state=s0; next_stateif(din=0) then when s2=if(din=0) then next_state=s3; next_state=s3; else else next_State=s2; next_State=s2; end if; end if;FSM的分類-MOORE狀態(tài)機process(present_sta

47、te) -輸出邏輯和當前輸入無關begin if(present_state=s4) then dout=1; else dout=0; end if;end process;end Behavioral;FSM的分類-MEALY型狀態(tài)機 如下圖所示,Mealy型狀態(tài)機的輸出由狀態(tài)機的輸入和狀態(tài)機的狀態(tài)共同決定;FSM的分類-MEALY型狀態(tài)機 下面以序列檢測器為例,說明Mealy狀態(tài)機的設計。該序列檢測器將檢測序列“1101”,當檢測到該序列時,狀態(tài)機的輸出z為1.下圖給出了基于Mealy狀態(tài)機的序列檢測器的運行原理。FSM的分類-MEALY型狀態(tài)機 Moore狀態(tài)機檢測序列時,使用了5個狀

48、態(tài),當為狀態(tài)S4時,輸出為1。 也可以使用Mealy狀態(tài)機檢測序列。當為狀態(tài)S3時,且輸入為1時,輸出z為1。狀態(tài)遷移的條件表示為當前輸入/當前輸出。比如當為狀態(tài)S3時(接收到序列110),輸入為1,輸出將變?yōu)?。下一個時鐘沿有效時,狀態(tài)變化到S1,輸出z變?yōu)?。 為了讓z成為寄存的輸出(也就是說狀態(tài)變化為S1時,輸出仍然被保持1),為輸出添加寄存器。即Mealy狀態(tài)機的輸出和D觸發(fā)器連接,這樣下一個時鐘有效時,狀態(tài)仍然變化到S1,但輸出被鎖存為1(被保持)。FSM的分類-MEALY型狀態(tài)機library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.ST

49、D_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity seqdetb isport( clk : in std_logic;clr : in std_logic;din : in std_logic;dout : out std_logic );end seqdetb;architecture Behavioral of seqdetb istype state is(s0,s1,s2,s3); -定義狀態(tài)signal present_state,next_state : state; beginprocess(clr,clk) -狀

50、態(tài)寄存器begin if(clr=1) then present_state=s0; elsif rising_edge(clk) then present_stateif(din=1) then next_state=s1; else next_stateif(din=1) then next_state=s2; else next_stateif(din=0) then next_state=s3; else next_Stateif(din=1) then next_state=s1; else next_state next_state=s0; end case;end process

51、;FSM的分類-MEALY型狀態(tài)機process(clr,clk) -輸出邏輯和當前輸入有關begin if(clr=1) then dout=0; elsif rising_edge(clk) then if(present_state=s3 and din=1) then dout=1; else dout=0; end if; end if;end process;數(shù)字邏輯單元設計狀態(tài)機描述規(guī)則狀態(tài)機描述方式:三進程;兩進程;單進程; 該狀態(tài)圖包含: 1)四個狀態(tài):s1,s2,s3,s4; 2)5個轉移; 3)1個輸入“x1”; 4)1個輸出“outp”; 數(shù)字邏輯單元設計狀態(tài)機描述規(guī)則

52、1、單進程狀態(tài)機的實現(xiàn)方法 如圖4.7單進程的mealy狀態(tài)機所示,采用單進程狀態(tài)機描述時,狀態(tài)的變化、狀態(tài)寄存器和輸出功能描述用一個進程進行描述。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity fsm_1 isport(clk,reset,x1:in std_logic; outp:out std_logic);end fsm_1;architecture one of fsm_1 istype state_type is

53、(s1,s2,s3,s4);signal state:state_type;begin process (clk,reset)begin if reset=1 then state=s1; outpif x1=1 then state=s2;outp=1; else state=s3;outpstate=s4;outpstate=s4;outpstate=s1;outp=1; end case;end if;end process; end one; 數(shù)字邏輯單元設計狀態(tài)機描述規(guī)則如圖4.8所示,與單進程狀態(tài)機不同的是,采用雙進程狀態(tài)機時,輸出函數(shù)用一個進程描述,而狀態(tài)寄存器和下一狀態(tài)函數(shù)用另

54、一個進程描述。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity fsm_2 is port(clk,reset,x1:in std_logic; outp:out std_logic);end entity;architecture one of fsm_2 istype state_type is (s1,s2,s3,s4);signal state:state_type;beginprocess(clk,reset)begi

55、n if (reset=1) then stateif x1=1 then state =s2; else statestatestatestateoutpoutpoutpoutp=0; end case;end process;end one; 數(shù)字邏輯單元設計狀態(tài)機描述規(guī)則3、三進程狀態(tài)機的實現(xiàn)規(guī)則如圖4.9所示,與雙進程狀態(tài)機不同的是,采用三進程狀態(tài)機時,輸出函數(shù)用一個進程描述,而狀態(tài)寄存器和下一狀態(tài)函數(shù)分別用兩個進程描述。library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity fsm_3 is port(clk,reset,x1:in std_logic; outp:out std_logic);end fsm_3;architecture one of fsm_3 istype state_type is (s1,s2,s3,s4);signal state,next_state:state_type;begin process(clk,reset)begin if (reset=1) then state=s1;elsif rising_ed

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論