第4章 VHDL设计提高_第1页
第4章 VHDL设计提高_第2页
第4章 VHDL设计提高_第3页
第4章 VHDL设计提高_第4页
第4章 VHDL设计提高_第5页
已阅读5页,还剩45页未读 继续免费阅读

下载本文档

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

文档简介

4.2常用逻辑电路的VHDL实现4.1VHDL设计逻辑电路的基本思想和方法第4章VHDL设计提高4.1

VHDL设计逻辑电路的基本思想和方法4.1.1逻辑函数表达式方法4.1.2真值表方法4.1.3电路连接描述方法4.1.4不完整条件语句方法4.1.5层次化设计方法利用VHDL中的逻辑运算就可以实现任何组合逻辑电路的设计。4.1.1逻辑函数表达式方法在数字逻辑电路设计中,利用真值表来表达组合电路是非常常用的手段,其特点是直观、明了,将真值表用VHDL描述出来也是硬件语言常用的方法之一。4.1.2真值表方法所谓电路连接描述方法,就是将给定的电路原理图用portmap语句来实现。在电路中,某些元件不是基本元件,无法用逻辑函数表达式来表示,也就是说,无法用逻辑运算来实现。4.1.3电路连接描述方法图4.1电路连接描述法的图例libraryieee;useieee.std_logic_1164.all;entitydff1isport(clk:instd_logic;d:instd_logic;q:outstd_lgoic);end;architecturebhvofdff1issignalq1:std_logic;beginprocess(clk,q1)beginifclk'eventandclk='1'thenq1<=d;endif;endprocess;q<=q1;endbhv;4.1.4不完整条件语句方法图4.2QuartsII综合后的RTL电路图层次化设计方法是自顶向下设计方法的最好体现。自顶向下的设计方法将系统分解为各个模块的集合后,可以对设计的每个独立模块分别设计,最后将不同的模块集成为最终的系统,并对其进行综合测试和评价。4.1.5层次化设计方法图4.312位全加器电路原理图1.子模块设计libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityadder4bisport(clr,cin:instd_logic;a,b:instd_logic_vector(3downto0);s:outstd_logic_vector(3downto0);cout:outstd_logic);endadder4b;architectureartofadder4bissignalsint:std_logic_vector(4downto0);signalaa,bb:std_logic_vector(4downto0);beginprocess(clr)beginifclr='1'thensint<="00000";elseaa<='0'&a;bb<='0'&b;sint<=aa+bb+cin;endif;s<=sint(3downto0);cout<=sint(4);endprocess;endart;a2.顶层模块设计libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entityadder12bisport(clr,cin:instd_logic;a,b:instd_logic_vector(11downto0);s:outstd_logic_vector(11downto0);cout:outstd_logic);endadder12b;architectureartofadder12biscomponentadder4bisport(clr,cin:instd_logic;a,b:instd_logic_vector(3downto0);s:outstd_logic_vector(3downto0);cout:outstd_logic);endcomponent;signalcarry_out0,carry_out1:std_logic; beginu1:adder4bportmap(clr=>clr,cin=>cin,a=>a(3downto0),b=>b(3downto0),s=>s(3downto0),cout=>carry_out0);u2:adder4bportmap(clr=>clr,cin=>carry_out,a=>a(7downto4),b=>b(7downto4),s=>s(7downto4),cout=>carry_out1);u3:adder4bportmap(clr=>clr,cin=>carry_out,a=>a(11downto8),b=>b(11downto8),s=>s(11downto8),cout=>cout);endart;4.2常用逻辑电路的VHDL实现4.2.1基本组合逻辑电路设计4.2.2基本时序逻辑电路设计4.2.3状态机的设计4.2.1基本组合逻辑电路设计1.基本逻辑门图4.4基本逻辑门2.三态门图4.58位三态控制门电路3.数据选择器

4.3线-8线译码器图4.63线-8译码器端口图下面用VHDL语言分别以两种方法描述3线-8线译码器,其源程序如下。方法一:用case语句描述,利用真值表辅助,很容易编写程序。libraryieee;useieee.std_logic_1164.all;entitydecoder3_8isport(a,b,c,g1,g2a,g2b:instd_logic;y:outstd_logic_vector(7downto0));end;architectureaofdecoder3_8issignaldz:std_logic_vector(2downto0);begindz<=c&b&a;process(dz,g1,g2a,g2b)beginif(g1='1'andg2a='0'andg2b='0')thencasedziswhen"000"=>y<="11111110";when"001"=>y<="11111101";when"010"=>y<="11111011";when"011"=>y<="11110111";when"100"=>y<="11101111";when"101"=>y<="11011111";when"110"=>y<="10111111";when"111"=>y<="01111111";whenothers=>y<="××××××××";endcase;elsey<="11111111";endif;endprocess;end;方法二:利用移位操作符SLL和程序包std_logic_unsigned中的数据类型转换函数conv_integer可以十分简洁地完成3线-8线译码器的设计。(略去实体部分)architectureaofdecoder3_8isbeginoutput<="00000001"SLLCONV_INTEGER(input);end;方法三:也是利用移位操作符SLL,只不过是每次进程的启动只改变一个端口的输出。architecturebehaveofdecoder3_8isbeginprocess(input)beginoutput<=(others=>'0');output(conv_integer(input))<='1';endprocess;endbehave;5.优先编码器表4.2 8-3优先编码器的真值表输入输出din0din1din2din3din4din5din6din7output0output1output2×××××××0000××××××01100×××××011010××××0111011×××01111100××011111101×011111111001111111111libraryieee;useieee.std_logic_1164.allentitycoderisport(din:instd_logic_vector(0to7);output:outstd_logic_vector(0to2));end;architecturebehaveofcoderissignalsint:std_logic_vevtor(4downto0);beginprocess(din)beginif(din(7)='0')thenoutput<="000";elsif(din(6)='0')thenoutput<="100";elsif(din(5)='0')thenoutput<="010";elsif(din(4)='0')thenoutput<="110";elsif(din(3)='0')thenoutput<="001";elsif(din(2)='0')thenoutput<="101";elsif(din(1)='0')thenoutput<="011";elseoutput<="111";endif;endprocess;endbehav;6.七段码译码器七段码的输出去驱动七段码显示器,才能显示正常的数字。图4.7共阴极数码管显示器电路示意图libraryieee;useieee.std_logic_1164.allentitydecl7sisport(a:instd_logic_vector(3downto0);led7s:outstd_logic_vector(6downto0));end;architecturebehaveofdecl7sisbegin图4.7共阴极数码管显示器电路示意图

process(a)begincaseaiswhen"0000"=>led7s<="0111111";when"0001"=>led7s<="0000110";when"0010"=>led7s<="1011011";when"0011"=>led7s<="1001111";when"0100"=>led7s<="1100110";when"0101"=>led7s<="1101101";when"0110"=>led7s<="1111101";when"0111"=>led7s<="0000111";when"1000"=>led7s<="1111111";when"1001"=>led7s<="1101111";when"1010"=>led7s<="1110111";when"1011"=>led7s<="1111100";when"1100"=>led7s<="0111001";when"1101"=>led7s<="1011110";when"1110"=>led7s<="1111001";when"1111"=>led7s<="1110001";whenothers=>null;endcase;endprocess;end;7.二-十进制BCD译码器BCD译码器在电路设计中也经常用到,尤其在计数、显示、译码电路中。图4.8BCD译码器端口图libraryieee;useieee.std_logic_1164.all;useieee.std_logic_signed.all;entitybcdymqisport(din:inintegerrange15downto0;a,b:outintegerrange9downto0);end;architecturefpq1ofbcdymqisbeginp1:process(din)beginifdin<10thena<=din;b<=0;elsea<=din-10;b<=1;endif;endprocessp1;end;8.多位加(减)法器下面以4位全减器为例来说明,加法器可以用相似的方法实现。libraryieee;useieee.std_logic_1164.all;useieee.std_logic_signed.all;entityjianfaqiisport(a,b:instd_logic_vector(0to3);c0:instd_logic;c1:outstd_logic;d:outstd_logic_vector(0to3));end;architectureaofjianfaqiisbeginprocessbeginifa>b+c0thend<=a-(b+c0);c1<='0';elsec1<='1';d<=("10000")-(b+c0-a);endif;endprocess;end;4.2.2基本时序逻辑电路设计T触发器的动作特点是翻转,我们以上升沿触发的T触发器设计为例进行讲解。1.触发器

libraryieee;useieee.std_logic_1164.all;useieee.std_logic_signed.all;entitytff1isport(t,clk:instd_logic;q:outstd_logic);end;architectureaoftff1issignalq_temp:std_logic;beginp1:process(clk)beginifrising_edge(clk)thenift='1'then--当T=1时T触发器具有2分频的功能

q_temp<=notq_temp;elseq_temp<=q_temp;endif;endif;q<=q_temp;endprocess;q<=q_temp;end;2.计数器计数器是逻辑电路中使用最广泛的电路,在复杂电路的设计中几乎离不开计数器。(1)n位二进制计数器设计一般把计数器的模值M=2n、状态编码为自然二进制数的计数器简称为n位二进制计数器。为了使设计的信号更具有工程实际的意义,下面的例子使用了一般情况下的in、out端口模式。libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entitycnt4IS port(clk :in std_logic;q :out std_logic_vector(3downto0) ); endcnt4;architecturebehaveofcnt4issignalq1:std_logic_vector(3downto0);beginprocess(clk)beginif(clk'eventandclk='1')thenq1<=q1+1;endif;endprocess;q<=q1;endbehave;图4.94位二进制计数器的仿真波形图(2)一般计数器设计libraryieee;useieee.std_logic_1164.all;useieee.std_logic_unsigned.all;entitycnt10is port(clk,rst,en,updown:instd_logic;cq:outstd_logic_vector(3downto0)); endcnt10;architecturebehaveofcnt10isbeginprocess(clk,rst,en,updown)variablecqi:std_logic_vector(3downto0);beginifrst='1'thencqi:=(others=>'0'); --计数器异步复位

elsif(clk'eventandclk='1')then --检测时钟上升沿

ifen='1'then --检测是否允许计数(同步使能)

ifupdown='0'thenifcqi<9thencqi:=cqi+1; --允许计数,检测是否小于9elsecqi:=(others=>'0'); --大于9,计数值清零

endif;elseifcqi>0thencqi:=cqi-1; --检测是否大于0elsecqi:=(others=>'1'); --否则,计数值置1endif;endif;endif;endif;cq<=cqi; --将计数值向端口输出endprocess;endbehave;图4.10一般计数器的仿真波形图3.分频器分频器电路的实质其实还是计数器的设计。

下面介绍两种任意分频的方法。

方法一:利用计数器的进位输出端分频。

要设计n分频的分频器,我们就设计一个N进制计数器,将计数器的进位作为分频器的输出。方法二:数控分频器(通过改变并行置数值分频)。

数控分频器是利用计数值可并行预置的加法计数器设计完成的。方法是将计数器溢出位与预置数加载输入信号相减。图4.11数控分频器的仿真波形图4.移位寄存器方法一:利用信号的传输延迟性。图4.12一般移位寄存器的仿真波形图方法二:带模式控制的移位寄存器。图4.13带模式控制的移位寄存器的仿真波形图4.2.3状态机的设计

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论