基本邏輯電路設(shè)計(jì)_第1頁
基本邏輯電路設(shè)計(jì)_第2頁
基本邏輯電路設(shè)計(jì)_第3頁
基本邏輯電路設(shè)計(jì)_第4頁
基本邏輯電路設(shè)計(jì)_第5頁
已閱讀5頁,還剩48頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、YANGTZE NORMAL UNIVERSITY基本邏輯電路設(shè)計(jì)v組合邏輯電路v時(shí)序電路設(shè)計(jì)v存儲(chǔ)器YANGTZE NORMAL UNIVERSITY組合邏輯電路設(shè)計(jì)v簡單門電路v編、譯碼器與選擇器v加法器、求補(bǔ)器v三態(tài)門及總線緩沖器YANGTZE NORMAL UNIVERSITY簡單門電路library IEEE;use IEEE.STD_LOGIC_1164.all;entity nand2 is port( a : in STD_LOGIC; b : in STD_LOGIC; y : out STD_LOGIC );end nand2;architecture nand2 of n

2、and2 isbeginyyyyyy=Z; end case;end process;end nand2;YANGTZE NORMAL UNIVERSITY或非門yyyyyy=Z; end case;YANGTZE NORMAL UNIVERSITY反相器y=not a;ayif a=1 then y=0;elsey=1;end if;YANGTZE NORMAL UNIVERSITY異或門yyyyyy=Z; end case;YANGTZE NORMAL UNIVERSITY編碼器IF (d(0) 0)THEN q = “11”; ELSIF (d(1)=0) THEN q = “10”;

3、ELSIF(d(2)=0) THEN q=“01”; ELSE q qqqq=“ZZZZZZZZ”;End case;ElseQ=“ZZZZZZZZ”;End if;YANGTZE NORMAL UNIVERSITY選擇器if sel=00 theny=a;elsif sel=01 theny=b;elsif sel=10 theny=c;elsey=d;end if;aby1cdy0Sel1.0YANGTZE NORMAL UNIVERSITY半加器二進(jìn)制輸入和輸出 進(jìn)位輸出basco0011010101100001半加器真值表半半加加器器abscoYANGTZE NORMAL UNIVER

4、SITYlibrary IEEE;use IEEE.STD_LOGIC_1164.all;entity half_adder is port( a : in STD_LOGIC; b : in STD_LOGIC; s : out STD_LOGIC; co : out STD_LOGIC );end half_adder;architecture half_adder of half_adder issignal c,d:std_logic;begin c=a or b; d=a nand b; co=not d; s=c and d;end half_adder;YANGTZE NORMA

5、L UNIVERSITY全加器半半加加器器ab+co半半加加器器cinsU0_su1u2U0_coYANGTZE NORMAL UNIVERSITYlibrary IEEE;use IEEE.STD_LOGIC_1164.all;entity full_adder is port( a,b,cin : in STD_LOGIC; co,s : out STD_LOGIC);end full_adder;architecture full_adder of full_adder iscomponent half_adderport( a,b : in STD_LOGIC; s,co : out

6、STD_LOGIC );end component ;signal u0_co,u0_s,u1_co:std_logic;begin u0:half_adder port map(a,b,u0_s,u0_co); u1:half_adder port map(u0_s,b,cin,s,u1_co); co=u0_co or u1_co;end full_adder;YANGTZE NORMAL UNIVERSITY三態(tài)門if en=1 thendout=din;elsedout=Z;end if;YANGTZE NORMAL UNIVERSITY單向總線緩沖器if en=1 thendout=

7、din;elsedout=“ZZZZZZZZ”;end if;YANGTZE NORMAL UNIVERSITY雙向緩沖器緩緩沖沖器器adrben endr功能00a=b01b=a1X三態(tài)雙向總線緩沖器真值表YANGTZE NORMAL UNIVERSITYprocess(a,dr,en)beginif en=0 and dr=1 thenbout=a;elsebout=ZZZZZZZZ;end if;b=bout;end process;process(a,dr,en)beginif en=0 and dr=0 thenaout=b;elseaout=ZZZZZZZZ;end if;a=ao

8、ut;end process;YANGTZE NORMAL UNIVERSITY時(shí)序電路的設(shè)計(jì)v時(shí)鐘信號(hào)和復(fù)位信號(hào)v觸發(fā)器v寄存器v計(jì)數(shù)器YANGTZE NORMAL UNIVERSITY時(shí)鐘信號(hào)v上升沿 clkevent and clk = 1 rising_edge(clk)v下降沿 clkevent and clk = 0 falling_edge(clk)YANGTZE NORMAL UNIVERSITY普通d觸發(fā)器if clkevent and clk=1 thenq=d;end if;YANGTZE NORMAL UNIVERSITY非同步D觸發(fā)器process(clk,rst)b

9、eginif rst=1 thenq=0;elsif clkevent and clk=1 thenq=d;end if;end process;YANGTZE NORMAL UNIVERSITY非同步復(fù)位/置位觸發(fā)器process(clk,rst,pset)beginif rst=1 thenq=0;elsif pset=0 thenq=1;elsif clkevent and clk=1 thenq=d;end if;end process;YANGTZE NORMAL UNIVERSITY同步復(fù)位的d觸發(fā)器process(clk,rst,pset)beginif clkevent and

10、 clk=1 thenif rst=1 thenq=0;else q=d;end if;end if;end process;YANGTZE NORMAL UNIVERSITY寄存器dclkqdclkqdclkqdclkqdffx(0)dffx(1)dffx(2)dffx(3)aclkbYANGTZE NORMAL UNIVERSITYarchitecture shift of shift isbegincomponent dffport (d,clk: in std_logic;q: out std_logic);end component ;signal z:std_logic_vecto

11、r(0 to 4);beginz(0)=a;g1:for i in 0 to 3 generate dffx:dff port map (z(i),clk,z(i+1);end generate;b=z(4);end shift;YANGTZE NORMAL UNIVERSITY同步計(jì)數(shù)器 所謂同步計(jì)數(shù)器,就是在時(shí)鐘脈沖的控制下,構(gòu)成計(jì)數(shù)器的各觸發(fā)器狀態(tài)同時(shí)發(fā)生變化的那一類計(jì)數(shù)器可逆計(jì)數(shù)器process(clk,rst)beginif rst=1 thencount0); elsif clkevent and clk=1 then if updn=1 then count=count+1; e

12、lse count=count-1; end if; end if;end process;YANGTZE NORMAL UNIVERSITY異步計(jì)數(shù)器v異步計(jì)數(shù)器又稱行波計(jì)數(shù)器,它的下一位計(jì)數(shù)器的輸出作為上一位計(jì)數(shù)器的始終信號(hào)。clkcount3dclkqdclkqdclkqdclkqcount0count1count2dclkqqnqnqnqnYANGTZE NORMAL UNIVERSITYlibrary IEEE;use IEEE.STD_LOGIC_1164.all;entity rplcont is port( clk : in STD_LOGIC; count : out STD

13、_LOGIC_VECTOR(7 downto 0); end rplcont;architecture rplcont of rplcont issignal count_in_bar:std_logic_vector(7 downto 0);component dffport (clk,d:in std_logic; q,qb:out std_logic);end component ;begin count_in_bar(0)count_in_bar(i), d=count_in_bar(i+1), q=count(i),qb=count_in_bar(i+1); end generate

14、;end rplcont;YANGTZE NORMAL UNIVERSITY存儲(chǔ)器v建議使用宏功能模塊YANGTZE NORMAL UNIVERSITY狀態(tài)機(jī)的VHDL設(shè)計(jì)狀態(tài)譯碼器狀態(tài)寄存器輸出譯碼器輸入反饋狀態(tài)組合邏輯輸出狀態(tài)機(jī)的結(jié)構(gòu)示意圖擴(kuò)展內(nèi)容擴(kuò)展內(nèi)容YANGTZE NORMAL UNIVERSITY狀態(tài)機(jī)的基本操作v狀態(tài)機(jī)內(nèi)部狀態(tài)轉(zhuǎn)換。狀態(tài)機(jī)的下一個(gè)狀態(tài)由譯碼器根據(jù)當(dāng)前狀態(tài)和輸入條件決定。v產(chǎn)生輸出信號(hào)序列。輸出信號(hào)由輸出譯碼器根據(jù)當(dāng)前狀態(tài)和輸入條件決定。YANGTZE NORMAL UNIVERSITY狀態(tài)機(jī)的分類v一般狀態(tài)機(jī)vMOORE狀態(tài)機(jī)vMEALY狀態(tài)機(jī)YANGTZE NO

15、RMAL UNIVERSITY一般狀態(tài)機(jī)的設(shè)計(jì)v為了能獲得可綜合的,高效的vhdl狀態(tài)描述,建議使用枚舉數(shù)據(jù)類型來定義狀態(tài)機(jī)的狀態(tài),并使用多進(jìn)程方式來描述狀態(tài)機(jī)的內(nèi)部邏輯。 一般情況下,一個(gè)進(jìn)程描述時(shí)序邏輯,包括狀態(tài)寄存器的工作和寄存器狀態(tài)的輸出。另一個(gè)進(jìn)程描述組合邏輯,包括進(jìn)程間狀態(tài)值的傳遞邏輯以及狀態(tài)以及狀態(tài)轉(zhuǎn)換值的輸出。必要時(shí)還可以引入第三個(gè)進(jìn)程完成其他的邏輯功能。YANGTZE NORMAL UNIVERSITY一般狀態(tài)機(jī)實(shí)例library IEEE;use IEEE.STD_LOGIC_1164.all;entity s_machine is port( clk : in STD_L

16、OGIC; rst : in STD_LOGIC; state_input : in STD_LOGIC_VECTOR(1 downto 0); comb_output : out STD_LOGIC_VECTOR(1 downto 0) );end s_machine;architecture s_machine of s_machine istype states is (st0,st1,st2,st3);signal cur_state,next_state : states;YANGTZE NORMAL UNIVERSITYbeginprocess(clk,rst)begin if r

17、st=1 then cur_state=st0; elsif clkevent and clk=1 then cur_statecomb_output=00; if state_input=00 then next_state=st0; else next_statecomb_output=01; if state_input=00 thenYANGTZE NORMAL UNIVERSITY next_state=st1; else next_statecomb_output=10; if state_input=11 then next_state=st2; else next_statec

18、omb_output=11; if state_input=11 then next_state=st3; else next_state=st0; end if; end case; end process;end s_machine;YANGTZE NORMAL UNIVERSITY111序列檢測(cè)器v例:111序列檢測(cè)器的功能是連續(xù)輸入三個(gè)或三個(gè)以上的1時(shí),電路輸出為1,其余情況下輸出為0。1/00/01/01/11/10/00/00/0s0s1s2s3s0:初始狀態(tài),電路還未收到一個(gè)有效1 s1:收到一個(gè)1后的狀態(tài)S2:連續(xù)收到兩個(gè)1后的狀態(tài) s3:連續(xù)收到三個(gè)1個(gè)后的狀態(tài) YANGTZ

19、E NORMAL UNIVERSITY111序列檢測(cè)器程序library IEEE;use IEEE.STD_LOGIC_1164.all;entity s_machine is port( clk : in STD_LOGIC; rst : in STD_LOGIC; din : in STD_LOGIC; comb_output : out STD_LOGIC );end s_machine;architecture s_machine of s_machine istype states is (st0,st1,st2,st3);signal cur_state,next_state :

20、 states;YANGTZE NORMAL UNIVERSITYbeginprocess(clk,rst)begin if rst=1 then cur_state=st0; elsif clkevent and clk=1 then cur_statecomb_output=0; if din=1 then next_state=st1; else next_statecomb_output=0; if din=1 thenYANGTZE NORMAL UNIVERSITY next_state=st2; else next_state if din=1 then next_state=s

21、t3; comb_output=1; else next_state=st0; comb_output if state_input=1 then next_state=st3; comb_output=1; else next_state=st0; comb_output=0; end if; end case; end process;end s_machine;YANGTZE NORMAL UNIVERSITY思考題l設(shè)計(jì)任務(wù):設(shè)計(jì)一個(gè)自動(dòng)售貨機(jī)控制程序,它的投幣口每次可以投入1元、2元、5元,且規(guī)定投入1元或2元后不得再投入5元。當(dāng)投入總值等于或超過設(shè)定值(4元),售貨機(jī)就自動(dòng)送出貨物

22、并找回多余的錢。v基本要求:按照上面要求,編寫程序,實(shí)現(xiàn)售單一商品的功能。(10分)v擴(kuò)展要求:在基本要求的基礎(chǔ)上,完善電路,實(shí)現(xiàn)售多個(gè)商品的功能(設(shè)定值應(yīng)該相應(yīng)增加)。(5分)撰寫完整的設(shè)計(jì)報(bào)告于13周上課時(shí)上交。報(bào)告內(nèi)容要求:詳細(xì)的設(shè)計(jì)方案,設(shè)計(jì)程序(關(guān)鍵部分應(yīng)該有注釋),仿真波形,設(shè)計(jì)中存在的問題及改進(jìn)措施。報(bào)告形式:打印稿YANGTZE NORMAL UNIVERSITY提示信號(hào)輸入: din=00 未投幣 din=01 投入1元 din=10 投入2元 din=11 投入5元狀態(tài):s0 初始狀態(tài),還沒有收到投幣; s1 收到1元; s2 收到2元; s3 收到3元;輸出:commod

23、ity 控制送出商品,1為送出; give_change控制找錢,分析題目要求,找錢只有兩種情況(不找或找1元錢)。YANGTZE NORMAL UNIVERSITYMoore狀態(tài)機(jī)狀態(tài)機(jī)vMoore狀態(tài)機(jī)狀態(tài)機(jī)的輸出輸出只與有限狀態(tài)自動(dòng)機(jī)的當(dāng)前狀態(tài)有關(guān),與輸入信號(hào)的當(dāng)前值無關(guān)。 Moore有限狀態(tài)機(jī)在時(shí)鐘CLOCK脈沖的有效邊沿后的有限個(gè)門延后,輸出達(dá)到穩(wěn)定值。即使在一個(gè)時(shí)鐘周期內(nèi)輸入信號(hào)發(fā)生變化,輸出也會(huì)在一個(gè)完整的時(shí)鐘周期內(nèi)保持穩(wěn)定值而不變。輸入對(duì)輸出的影響要到下一個(gè)時(shí)鐘周期才能反映出來。 Moore有限狀態(tài)機(jī)最重要的特點(diǎn)就是將輸入與輸出信號(hào)隔離開來。YANGTZE NORMAL UNI

24、VERSITYMealy狀態(tài)機(jī)狀態(tài)機(jī)vMealy狀態(tài)機(jī)狀態(tài)機(jī)與Moore有限狀態(tài)機(jī)不同,Mealy有限狀態(tài)機(jī)的輸出不單與當(dāng)前狀態(tài)有關(guān),而且與輸入信號(hào)的當(dāng)前值有關(guān)。 Mealy有限狀態(tài)機(jī)的輸出直接受輸入信號(hào)的當(dāng)前值影響,而輸入信號(hào)可能在一個(gè)時(shí)鐘周期內(nèi)任意時(shí)刻變化,這使得Mealy有限狀態(tài)機(jī)對(duì)輸入的響應(yīng)發(fā)生在當(dāng)前時(shí)鐘周期,比Moore有限狀態(tài)機(jī)對(duì)輸入信號(hào)的響應(yīng)要早一個(gè)周期。因此,輸入信號(hào)的噪聲可能影響在輸出的信號(hào)。YANGTZE NORMAL UNIVERSITY狀態(tài)機(jī)實(shí)例ADC0809EOCDIN7.0ALEOESTARTADDA控制器控制器RDWRRAM_DIN7.0ADDRESS12.0CS

25、6264OESTARTALECSRDWRRAM_DIN7.0ADDRESS12.0ADDACLKRSTDIN7.0EOCYANGTZE NORMAL UNIVERSITY控制器程序library IEEE;use IEEE.STD_LOGIC_1164.all;use ieee.std_logic_unsigned.all;entity adtosram is port( clk : in STD_LOGIC; -工作時(shí)鐘工作時(shí)鐘 rst : in STD_LOGIC; -復(fù)位復(fù)位 eoc : in STD_LOGIC; -轉(zhuǎn)換結(jié)束標(biāo)志轉(zhuǎn)換結(jié)束標(biāo)志 din : in STD_LOGIC_VEC

26、TOR(7 downto 0); oe : out STD_LOGIC; start : out STD_LOGIC; ale : out STD_LOGIC;-地址鎖存允許地址鎖存允許 cs : out STD_LOGIC; rd : out STD_LOGIC; wr : out STD_LOGIC; adda : out STD_LOGIC; -AD地址線最低位地址線最低位 ram_din : out STD_LOGIC_VECTOR(7 downto 0); address : out STD_LOGIC_VECTOR(12 downto 0) );end adtosram;YANGT

27、ZE NORMAL UNIVERSITYarchitecture adtosram of adtosram istype ad_states is (st0,st1,st2,st3,st4,st5,st6,st7);type writ_states is (start_write,write1,write2,write3,write_end);signal ram_current_state,ram_next_state:writ_states;signal adc_current_state,adc_next_state:ad_states;signal adc_end:std_logic;

28、 signal lock: std_logic; -轉(zhuǎn)換后數(shù)據(jù)輸出鎖存信號(hào)轉(zhuǎn)換后數(shù)據(jù)輸出鎖存信號(hào)signal enable:std_logic; -ad轉(zhuǎn)換允許信號(hào),高電平有效轉(zhuǎn)換允許信號(hào),高電平有效signal addres_plus:std_logic;-sram地址加地址加1時(shí)鐘信號(hào)時(shí)鐘信號(hào)signal adc_data:std_logic_vector(7 downto 0);signal addres_cnt:std_logic_vector(12 downto 0);beginadda=1; -選擇通道選擇通道1rd=1; - 禁止寫禁止寫sramadc:process(adc_c

29、urrent_state,eoc,enable) ad轉(zhuǎn)換組合電路進(jìn)轉(zhuǎn)換組合電路進(jìn)程程beginif rst=1 then adc_next_stateale=0;start=0; oe=0;lock=0; adc_end=0; -ad轉(zhuǎn)換初始化轉(zhuǎn)換初始化if enable=1 then adc_next_state=st1;-允許轉(zhuǎn)換,轉(zhuǎn)下一狀態(tài)允許轉(zhuǎn)換,轉(zhuǎn)下一狀態(tài)else adc_next_stateale=1;start=0; oe=0;lock=0; adc_end=0;adc_next_stateale=1;start=1; oe=0;lock=0; adc_end=0;adc_ne

30、xt_stateale=1;start=1; oe=0;lock=0; adc_end=0; -延遲一個(gè)脈沖周期延遲一個(gè)脈沖周期if eoc=1 then adc_next_state=st4; else adc_next_stateale=0;start=0; oe=0;lock=0; adc_end=0;if eoc=1 then adc_next_state=st5;-轉(zhuǎn)化結(jié)束,轉(zhuǎn)下一狀態(tài)轉(zhuǎn)化結(jié)束,轉(zhuǎn)下一狀態(tài)YANGTZE NORMAL UNIVERSITYelse adc_next_stateale=0;start=0; oe=1;lock=1; adc_end=1; -開啟數(shù)據(jù)輸出使

31、能信號(hào)開啟數(shù)據(jù)輸出使能信號(hào)oeadc_next_stateale=0;start=0; oe=1;lock=1; adc_end=1;adc_next_stateale=0;start=0; oe=1;lock=1; adc_end=1; adc_next_stateadc_next_state=st0;end case; end if;end process adc;YANGTZE NORMAL UNIVERSITYad_state:process(clk) -ad轉(zhuǎn)換時(shí)序進(jìn)程轉(zhuǎn)換時(shí)序進(jìn)程beginif clkevent and clk=1 thenadc_current_state=adc_next_state;end if;end process ad_state;data_lock:process(lock)beginif lock=1 and lockevent thenadc_data=din;end i

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論