基本逻辑电路设计_第1页
基本逻辑电路设计_第2页
基本逻辑电路设计_第3页
基本逻辑电路设计_第4页
基本逻辑电路设计_第5页
已阅读5页,还剩48页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、YANGTZE NORMAL UNIVERSITY基本逻辑电路设计v组合逻辑电路v时序电路设计v存储器YANGTZE NORMAL UNIVERSITY组合逻辑电路设计v简单门电路v编、译码器与选择器v加法器、求补器v三态门及总线缓冲器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半加器二进制输入和输出 进位输出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三态门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三态双向总线缓冲器真值表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时序电路的设计v时钟信号和复位信号v触发器v寄存器v计数器YANGTZE NORMAL UNIVERSITY时钟信号v上升沿 clkevent and clk = 1 rising_edge(clk)v下降沿 clkevent and clk = 0 falling_edge(clk)YANGTZE NORMAL UNIVERSITY普通d触发器if clkevent and clk=1 thenq=d;end if;YANGTZE NORMAL UNIVERSITY非同步D触发器process(clk,rst)b

9、eginif rst=1 thenq=0;elsif clkevent and clk=1 thenq=d;end if;end process;YANGTZE NORMAL UNIVERSITY非同步复位/置位触发器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同步复位的d触发器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同步计数器 所谓同步计数器,就是在时钟脉冲的控制下,构成计数器的各触发器状态同时发生变化的那一类计数器可逆计数器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异步计数器v异步计数器又称行波计数器,它的下一位计数器的输出作为上一位计数器的始终信号。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存储器v建议使用宏功能模块YANGTZE NORMAL UNIVERSITY状态机的VHDL设计状态译码器状态寄存器输出译码器输入反馈状态组合逻辑输出状态机的结构示意图扩展内容扩展内容YANGTZE NORMAL UNIVERSITY状态机的基本操作v状态机内部状态转换。状态机的下一个状态由译码器根据当前状态和输入条件决定。v产生输出信号序列。输出信号由输出译码器根据当前状态和输入条件决定。YANGTZE NORMAL UNIVERSITY状态机的分类v一般状态机vMOORE状态机vMEALY状态机YANGTZE NO

15、RMAL UNIVERSITY一般状态机的设计v为了能获得可综合的,高效的vhdl状态描述,建议使用枚举数据类型来定义状态机的状态,并使用多进程方式来描述状态机的内部逻辑。 一般情况下,一个进程描述时序逻辑,包括状态寄存器的工作和寄存器状态的输出。另一个进程描述组合逻辑,包括进程间状态值的传递逻辑以及状态以及状态转换值的输出。必要时还可以引入第三个进程完成其他的逻辑功能。YANGTZE NORMAL UNIVERSITY一般状态机实例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序列检测器v例:111序列检测器的功能是连续输入三个或三个以上的1时,电路输出为1,其余情况下输出为0。1/00/01/01/11/10/00/00/0s0s1s2s3s0:初始状态,电路还未收到一个有效1 s1:收到一个1后的状态S2:连续收到两个1后的状态 s3:连续收到三个1个后的状态 YANGTZ

19、E NORMAL UNIVERSITY111序列检测器程序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设计任务:设计一个自动售货机控制程序,它的投币口每次可以投入1元、2元、5元,且规定投入1元或2元后不得再投入5元。当投入总值等于或超过设定值(4元),售货机就自动送出货物

22、并找回多余的钱。v基本要求:按照上面要求,编写程序,实现售单一商品的功能。(10分)v扩展要求:在基本要求的基础上,完善电路,实现售多个商品的功能(设定值应该相应增加)。(5分)撰写完整的设计报告于13周上课时上交。报告内容要求:详细的设计方案,设计程序(关键部分应该有注释),仿真波形,设计中存在的问题及改进措施。报告形式:打印稿YANGTZE NORMAL UNIVERSITY提示信号输入: din=00 未投币 din=01 投入1元 din=10 投入2元 din=11 投入5元状态:s0 初始状态,还没有收到投币; s1 收到1元; s2 收到2元; s3 收到3元;输出:commod

23、ity 控制送出商品,1为送出; give_change控制找钱,分析题目要求,找钱只有两种情况(不找或找1元钱)。YANGTZE NORMAL UNIVERSITYMoore状态机状态机vMoore状态机状态机的输出输出只与有限状态自动机的当前状态有关,与输入信号的当前值无关。 Moore有限状态机在时钟CLOCK脉冲的有效边沿后的有限个门延后,输出达到稳定值。即使在一个时钟周期内输入信号发生变化,输出也会在一个完整的时钟周期内保持稳定值而不变。输入对输出的影响要到下一个时钟周期才能反映出来。 Moore有限状态机最重要的特点就是将输入与输出信号隔离开来。YANGTZE NORMAL UNI

24、VERSITYMealy状态机状态机vMealy状态机状态机与Moore有限状态机不同,Mealy有限状态机的输出不单与当前状态有关,而且与输入信号的当前值有关。 Mealy有限状态机的输出直接受输入信号的当前值影响,而输入信号可能在一个时钟周期内任意时刻变化,这使得Mealy有限状态机对输入的响应发生在当前时钟周期,比Moore有限状态机对输入信号的响应要早一个周期。因此,输入信号的噪声可能影响在输出的信号。YANGTZE NORMAL UNIVERSITY状态机实例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; -工作时钟工作时钟 rst : in STD_LOGIC; -复位复位 eoc : in STD_LOGIC; -转换结束标志转换结束标志 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; -转换后数据输出锁存信号转换后数据输出锁存信号signal enable:std_logic; -ad转换允许信号,高电平有效转换允许信号,高电平有效signal addres_plus:std_logic;-sram地址加地址加1时钟信号时钟信号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转换组合电路进转换组合电路进程程beginif rst=1 then adc_next_stateale=0;start=0; oe=0;lock=0; adc_end=0; -ad转换初始化转换初始化if enable=1 then adc_next_state=st1;-允许转换,转下一状态允许转换,转下一状态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; -延迟一个脉冲周期延迟一个脉冲周期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;-转化结束,转下一状态转化结束,转下一状态YANGTZE NORMAL UNIVERSITYelse adc_next_stateale=0;start=0; oe=1;lock=1; adc_end=1; -开启数据输出使

31、能信号开启数据输出使能信号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转换时序进程转换时序进程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等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论