EDA技术及应用第5章4_第1页
EDA技术及应用第5章4_第2页
EDA技术及应用第5章4_第3页
EDA技术及应用第5章4_第4页
EDA技术及应用第5章4_第5页
已阅读5页,还剩51页未读 继续免费阅读

下载本文档

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

文档简介

1、15.5 VDHL程序设计实例程序设计实例5.5.1 常用组合电路的设计常用组合电路的设计 组合逻辑是电路设计的基础组合逻辑是电路设计的基础, ,组合逻辑的描述可通过并行信组合逻辑的描述可通过并行信号赋值语句或纯组合逻辑行为的进程语句来实现。号赋值语句或纯组合逻辑行为的进程语句来实现。并行赋值语句:并行赋值语句: 1 1、简单信号赋值语句、简单信号赋值语句 2 2、条件信号赋值语句、条件信号赋值语句 3 3、选择信号赋值语句、选择信号赋值语句进程语句:进程语句: 为了保证一个进程语句能生成组合逻辑,在进程语句里所有为了保证一个进程语句能生成组合逻辑,在进程语句里所有被读入的信号都必须包含在该进

2、程语句的敏感表中。被读入的信号都必须包含在该进程语句的敏感表中。25.5.1.1 门电路门电路1、与门、与门方法方法1 1:直接信号赋值:直接信号赋值library ieee;use ieee.std_logic_1164.all;entity and_2 is port (a : in std_logic; b : in std_logic; y : out std_logic );end and_2;architecture behave of and_2 is begin y=a and b;end behave;3方法方法2:进程内信号赋值:进程内信号赋值 注意要将注意要将a和和b都加

3、入敏感信号表。都加入敏感信号表。 architecture behav of and_2 is begin process( a, b ) begin y = a and b; end process; end behav;4方法方法3:进程:进程if条件赋值条件赋值 经过分析发现,只有经过分析发现,只有a和和b都为都为1的时候的时候y才会输才会输出出1。所以描述如下:。所以描述如下: architecture behav of and_2 is begin process( a, b ) begin if ( a = 1 and b = 1 ) then y = 1; else y=0; e

4、nd if; end process; end behav;5方法方法4:进程:进程if条件赋值条件赋值 经过分析发现,经过分析发现,a = 1时,时,y会跟踪会跟踪b的变化,即的变化,即 y= b。 architecture behav of and_2 is begin process( a, b ) begin if a = 1 then y = b; else y=0; end if; end process; end behav;62.与非门与非门library ieee;use ieee.std_logic_1164.all;entity nand_2 is port ( a :

5、in std_logic; b : in std_logic; y : out std_logic);end nand_2;architecture behave of nand_2 is begin y qqqqqqqqq=000; end case; end process p1;end rtl; 8architecture rtl of coder isbegin with d selectqddddddddd0);end case;else d0);end if;end process;end behave;11用用with_ select语句:语句:architecture beha

6、ve of decoder1 issignal sel:std_logic_vector(5 downto 0); begin sel(5)=g1;sel(4)=g2a;sel(3)=g2b;sel(2 downto 0)=data_in; with sel select d=00000001 when 100000, 00000010 when 100001, 00000100 when 100010, 00001000 when 100011, 00010000 when 100100, 00100000 when 100101, 01000000 when 100110, 1000000

7、0 when 100111, “00000000 when others; end behave;125.5.1.3 数据选择器数据选择器sy00a01b10c11d表表5.5.3 5.5.3 真值表真值表 library ieee;use ieee.std_logic_1164.all;entity mux is port( a, b, c, d : in std_logic_vector(3 downto 0); s : in std_logic_vector(1 downto 0); y : out std_logic_vector(3 downto 0);end mux;archite

8、cture archmux of mux is begin mux4_1: process (a, b, c, d,s) begin if s = 00 then y = a; elsif s = 01 then y = b; elsif s = 10 then y = c; else y babX XX XX X1 10 00 0abab) then bt=1;eq=0;st=0; elsif (ab) then bt=0;eq=0;st=1; elsif (a=b) then if (i2=1) then bt=0;eq=1;st=0; elsif (i1=1) then bt=1;eq=

9、0;st=0; elsif (i3=1) then bt=0;eq=0;st=1; else bt= 1;eq=1;st=1; end if; else bt=1;eq=1;st=1; end if; end process p1;end behave; library ieee;use ieee.std_logic_1164.all;entity cc14585 is port ( a : in std_logic_vector(3 downto 0); b : in std_logic_vector(3 downto 0); i1,i2,i3 : in std_logic; bt,st,e

10、q :out std_logic);end cc14585;a0a1a2a3b0b1b2b3i1i2i3BtStEQCC14585图图5.5.10 5.5.10 四位数据比较器四位数据比较器155.5.1.5 5.5.1.5 加法器加法器library IEEE;use IEEE.std_logic_1164.all;entity adder4 is port (a : in std_logic_vector(3 downto 0); b : in std_logic_vector(3 downto 0); cin : in std_logic; sum : out std_logic_vec

11、tor(3 downto 0); cout : out std_logic);end adder4;设计一个设计一个4 4位的加法器位的加法器16architecture structural of adder4 is component adder port (a,b,cin : in std_logic; sum, cout : out std_logic); end component; signal carry : std_logic_vector(0 to 4); begin carry(0) = cin; cout a(i),b = b(i),cin = carry(i), sum

12、 = sum(i),cout = carry(i+1); end generate;end structural; 使用已有的使用已有的1 1位全加器设计位全加器设计1718 使用行为描述方式使用行为描述方式architecture behav of adder4 is signal aa,bb,s:std_logic_vector(4 downto 0);beginaa=0&a;bb=0&b;s=aa+bb+cin;sum=s(3 downto 0);cout=s(4);end behav;library IEEE;use IEEE.std_logic_1164.all;us

13、e IEEE.std_logic_unsigned.all;.195.5.2 常用时序电路的设计常用时序电路的设计 触发器、寄存器、移位寄存器、计数器等触发器、寄存器、移位寄存器、计数器等 常用的时序电路包括:常用的时序电路包括: 任何时序电路都是以时钟为驱动信号,时序电路只是在时任何时序电路都是以时钟为驱动信号,时序电路只是在时钟信号的边沿来到时才会发生状态的改变。钟信号的边沿来到时才会发生状态的改变。 时序逻辑的实现通常使用时序逻辑的实现通常使用 process 语句来实现。语句来实现。 下面是时序电路中需要考虑的几个问题:下面是时序电路中需要考虑的几个问题:201. 时钟信号的描述时钟信

14、号的描述process (clock_signal) begin if (clock_edge_condition) then signal_out = signal_in; end if;end process; u 当时钟信号作为进程的敏感信号时,在敏感信号表中只能出现一当时钟信号作为进程的敏感信号时,在敏感信号表中只能出现一 个时钟信号;但是,复位信号等可以出现在敏感信号表中。个时钟信号;但是,复位信号等可以出现在敏感信号表中。 u 在在if 语句中注明时钟是上升沿还是下降沿。语句中注明时钟是上升沿还是下降沿。表述方式表述方式1:if clk=1 and clklast_value=0

15、and clkevent if clkevent and clk= 1 表述方式表述方式2:if(rising_edge(clk)时钟信号作为进程的敏感信号时钟信号作为进程的敏感信号21表述方式表述方式1:if clk=1 and clklast_value=0 and clkevent if clkevent and clk= 1 表述方式表述方式2:if(rising_edge(clk)上升沿的描述方法:上升沿的描述方法:下降沿的描述方法:下降沿的描述方法:表述方式表述方式1:if clk=0 and clklast_value=1 and clkevent if clkevent and

16、 clk= 0 表述方式表述方式2:if(falling_edge(clk)222. 2. 复位信号的描述复位信号的描述 同步复位:同步复位:当复位信号有效且在约定的时钟边沿到来时触发器才被当复位信号有效且在约定的时钟边沿到来时触发器才被复位。在复位。在VHDLVHDL语言描述的时候,同步复位进程的敏感信号只有时钟信号,且语言描述的时候,同步复位进程的敏感信号只有时钟信号,且用用ifif语句来描述必要的复位条件。语句来描述必要的复位条件。 异步复位:异步复位:当复位信号有效时触发器立即被复位。当复位信号有效时触发器立即被复位。process (reset,clk) begin if (rese

17、t 1) then signal_out = reset_value; elsif (clockevent and clock_edge_condition) then end if;end process;-敏感信号中包括敏感信号中包括reset信号信号- 异步复位信号异步复位信号- 时钟边沿检测时钟边沿检测下面是异步复位的一个例子下面是异步复位的一个例子235.5.2.2 触发器设计触发器设计D D触发器触发器 library ieee;use ieee.std_logic_1164.all;entity dff1 is port (clk,d : in std_logic; q : ou

18、t std_logic );end dff1;architecture rtl of dff1 isbegin process (clk) begin if (clkevent and clk=1) then q = d; end if; end process;end rtl; 24异步复位的异步复位的D触发器触发器 library ieee;use ieee.std_logic_1164.all;entity dff2 is port (clk,d,clr : in std_logic; q : out std_logic );end dff2;architecture rtl of df

19、f2 isbegin process (clk,clr) begin if clr=0 then q=0; elsif (clkevent and clk=1) then q = d; end if; end process;end rtl; 25同步复位的同步复位的D触发器触发器 library ieee;use ieee.std_logic_1164.all;entity dff3 is port (clk,d,clr : in std_logic; q : out std_logic );end dff3;architecture rtl of dff3 isbegin process

20、(clk) begin if (clkevent and clk=1) then if clr=1 then q=0; else q = d; end if; end if; end process;end rtl; 265.5.2.3 寄存器设计寄存器设计设计一个设计一个8位的通用寄存器位的通用寄存器D0OECPD7D6D5D4D3D2D1Q0Q7Q6Q5Q4Q3Q2Q11D2DOECP8D7D6D5D4D3D4Q5Q6Q7Q8Q3Q2Q1Q图5.4.14 8位寄存器librarylibrary ieee; ieee;useuse ieee.std_logic_1164. ieee.std_

21、logic_1164.allall; ;entityentity reg reg isis portport (oe : (oe :inin std_logic; std_logic; clk : clk :inin std_logic; std_logic; d : d :in in std_logic_vector(7 std_logic_vector(7 downtodownto 0); 0); q : q :outout std_logic_vector(7 std_logic_vector(7 downtodownto 0); 0);endend reg; reg;27archite

22、cture rtl of reg is signal q_tmp : std_logic_vector(7 downto 0); begin process (clk) begin if (clkevent and clk = 1) then q_tmp = d; end if; end process; process (oe , q_tmp) begin if (oe = 0) then q = q_tmp; else q = ZZZZZZZZ; end if; end process;end rtl; 285.5.2.4 计数器设计计数器设计n 按照计数器中的触发器是否同时翻转分类:按照

23、计数器中的触发器是否同时翻转分类: 同步计数器和异步计数器同步计数器和异步计数器n 按照计数过程中的数字增减分类:按照计数过程中的数字增减分类: 加法计数器、减法计数器、可逆计数器加法计数器、减法计数器、可逆计数器n 按照计数器中进位方式分类:按照计数器中进位方式分类: 二进制、二二进制、二-十进制十进制n 按照计数器的容量:按照计数器的容量: 十进制计数器、十二进制计数器、六十进制等计数器十进制计数器、十二进制计数器、六十进制等计数器通常将计数器可分为以下几类:通常将计数器可分为以下几类:29library ieee; use ieee.std_logic_1164.all;use ieee

24、.std_logic_unsigned.all;entity counter10 isport(en,reset,clk:in std_logic;q:buffer std_logic_vector(3 downto 0);co:out std_logic);end counter10;architecture behav of counter10 isbegin process(clk,reset,en) beginif reset=1 then q=0000;elsif clkevent and clk=1 thenif en=1 thenif q1001 then q=q+1;else

25、q=0000;end if;end if;end if; end process; co=1 when q=1001 else 0;end behav;Std_logicStd_logic和整数相加必须有和整数相加必须有并行语句在结构体中并行语句在结构体中不需要再定义中间信号不需要再定义中间信号具有异步清零端和使能端的同步十进制加法计数器具有异步清零端和使能端的同步十进制加法计数器+ +1 1或或+ +”00010001”3031architecture behav of counter10 isbegin process(clk,reset,en) beginif reset=1 thenq

26、=0000;elsif clkevent and clk=1 thenif en=1 thenif q=1001 then q=0000; else q=q+1;end if;end if;end if; end process; co=1 when q=1001 else 0;end behav;计数部分的另一种写法计数部分的另一种写法32architecture behav of counter10 isbegin process(clk,reset,en) beginif reset=1 then q=0000;elsif clkevent and clk=1 thenif en=1 t

27、henif q=1001 then q=0000; else q=q+1;end if;end if;end if; end process; process(q) begin if q=1001 then co=1; else co=0; end if; end process; -co=1 when q=1001 else 0;end behav;在进程内描述进位在进程内描述进位33具有异步清零、同步置数端和使能端的同步十进制加法计数器具有异步清零、同步置数端和使能端的同步十进制加法计数器library ieee;use ieee.std_logic_1164.all;use ieee.s

28、td_logic_unsigned.all;entity counter10 isport(en,reset,clk,ld:in std_logic;d:in std_logic_vector(3 downto 0);q:buffer std_logic_vector(3 downto 0);co:out std_logic);end ;architecture behav of counter10 isbegin process(clk,en,reset) beginif reset=1 then q=0000; -异步清异步清0 elsif clkevent and clk=1 then

29、if ld=1 then q=d; -同步置数同步置数 elsif en=1 then if q1001 then q=q+1; else q=0000; end if; end if;end if; end process; co=1 when q=1001 else 0;end ;3435具有异步清零、异步置数端和使能端的同步十进制加法计数器具有异步清零、异步置数端和使能端的同步十进制加法计数器library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity counter10 isport(en

30、,reset,clk,ld:in std_logic;d:in std_logic_vector(3 downto 0);q:buffer std_logic_vector(3 downto 0);co:out std_logic);end ;architecture behav of counter10 isbegin process(clk,en,reset,ld,d) beginif reset=1 then q=0000; -异步清异步清0 elsif ld=1 then q=d; -异步置数异步置数 elsif clkevent and clk=1 then if en=1 then

31、 if q1001 then q=q+1; else q=0000; end if; end if;end if; end process; co=1 when q=1001 else 0;end ;3637具有同步清零、同步置数端和使能端的同步十进制加法计数器具有同步清零、同步置数端和使能端的同步十进制加法计数器library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity counter10 isport(en,reset,clk,ld:in std_logic;d:in std_logic_v

32、ector(3 downto 0);q:buffer std_logic_vector(3 downto 0);co:out std_logic);end ;architecture behav of counter10 isbegin process(clk,en) begin if clkevent and clk=1 then if reset=1 then q=“0000”; -同步清同步清0 elsif ld=1 then q=d; -同步置数同步置数 elsif en=1 then if q1001 then q=q+1; else q=0000; end if; end if;

33、end if; end process; co=1 when q=1001 else 0;end ;3839计数结果为整数类型的写法计数结果为整数类型的写法library ieee;use ieee.std_logic_1164.all;-use ieee.std_logic_unsigned.all;entity count10_int is port(clk,en,reset:in std_logic; q:out integer range 0 to 9; co:out std_logic);end count10_int;architecture behav of count10_in

34、t is signal qi:integer range 0 to 9;begin process(clk,reset,en) beginif reset=1 then qi=0;elsif clkevent and clk=1 then if en=1 thenif qi9 then qi=qi+1;else qi=0;end if;end if;end if; end process;q=qi;co=1 when qi=9 else 0;end behav;整数类型相加时不需要整数类型相加时不需要Q Q为为OutOut类型时要定义一个信号类型时要定义一个信号40具有异步清零端和使能端的同步

35、十进制减法计数器具有异步清零端和使能端的同步十进制减法计数器library ieee;use ieee.std_logic_1164.all;entity count10_int is port(clk,en,reset:in std_logic; q:out integer range 0 to 9; co:out std_logic);end count10_int;architecture behav of count10_int is signal qi:integer range 0 to 9;beginprocess(clk,reset,en) begin if reset=1 t

36、hen qi=0; elsif clkevent and clk=1 thenif en=1 then if qi=0 then qi=9; else qi=qi-1; end if;end if; end if; end process; q=qi; co=1 when qi=0 else 0;end behav;4142具有异步清零端和使能端的同步十进制可逆计数器具有异步清零端和使能端的同步十进制可逆计数器library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity counter10_bd

37、isport(en,reset,clk,up_down:in std_logic;q:buffer std_logic_vector(3 downto 0);co:out std_logic);end ;architecture behav of counter10_bd isbegin43process(clk,reset,en)begin if reset=1 then q=0000; elsif clkevent and clk=1 then if en=1 then if up_down = 1 then if q1001 then q=q+1; else q=0000; end if

38、; elsif q=0000 then q=1001; else q=q-1; end if; end if; end if;end process;process(q,up_down)beginif up_down = 1 then if q=1001 then co=1; else co=0; end if;elsif q=0000 then co=1;else co=0;end if;end process;end ;4445同步同步4 4位二进制加法计数器位二进制加法计数器entity cnt4 is port(clk:in bit;q:buffer integer range 15

39、downto 0);end;architecture bhv of cnt4 is begin process(clk) begin if clkevent and clk=1 then q=q+1; end if; end process;end;46具有异步清零端和使能端的同步具有异步清零端和使能端的同步4 4位二进制可逆计数器位二进制可逆计数器library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity counter16_bd is port(en,reset,clk,up_down:in

40、 std_logic;q:buffer std_logic_vector(3 downto 0);end ;architecture behav of counter16_bd isbegin47 process(clk,reset) beginif reset=1 then q=0000; elsif clkevent and clk=1 then if en=1 then if up_down = 1 then q=q+1; else q=q-1; end if; end if;end if;end process;end ;48具有异步清零端和使能端的同步具有异步清零端和使能端的同步BC

41、DBCD码码6060进制加法计数器进制加法计数器用二个进程分别描述个位和十位用二个进程分别描述个位和十位library ieee;use ieee.std_logic_1164.all;entity count60_bcd is port(en,reset:in std_logic;clk: in std_logic;qh,ql:buffer integer range 0 to 9; co:out std_logic);end count60_bcd;49architecture behav of count60_bcd isbegin process(clk,reset,en) beginif reset=1 then ql=0; elsif clkevent and clk=1 thenif en=1 then if ql9 then ql=ql+1;else ql=0; end if;end if;end if; end process;50process(clk,reset,en)begin if reset=1 then qh=0; elsif clkevent an

温馨提示

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

评论

0/150

提交评论