VHDL实验_新_及答案.ppt

上传人:本田雅阁 文档编号:2108697 上传时间:2019-02-14 格式:PPT 页数:34 大小:172.02KB
返回 下载 相关 举报
VHDL实验_新_及答案.ppt_第1页
第1页 / 共34页
VHDL实验_新_及答案.ppt_第2页
第2页 / 共34页
VHDL实验_新_及答案.ppt_第3页
第3页 / 共34页
亲,该文档总共34页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《VHDL实验_新_及答案.ppt》由会员分享,可在线阅读,更多相关《VHDL实验_新_及答案.ppt(34页珍藏版)》请在三一文库上搜索。

1、实验1 熟悉实验环境,完成下述实验内容: 2输入与门、 2输入或门、 2输入异或门及非门的设计。 D触发器的设计。 带有异步清零、异步置位功能的边沿JK触发器的设计。,1-1代码,非门 LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; ENTITY NOT IS PORT(A:IN STD_LOGIC; Y:OUT STD_LOGIC); END ENTITY NOT; ARCHITECTURE ART OF NOT IS BEGIN Y= NOT A; END ARCHITECTURE ART;,1-1代码,异或门 LIBRARY IEEE; USE IE

2、EE.STD_LOGIC_1164.ALL; ENTITY XOR2 IS PORT(A,B:IN STD_LOGIC; Y:OUT STD_LOGIC); END ENTITY XOR2; ARCHITECTURE ART OF XOR2 IS BEGIN Y=A XOR B; END ARCHITECTURE ART;,1-2代码,D触发器的设计 library ieee; use ieee.std_logic_1164.all; entity d_chufa is port ( clk,d:in std_logic; q:out std_logic); end d_chufa; arch

3、itecture behav of d_chufa is begin process(clk)is begin if(clk event and clk=1)then q=d; end if; end process; end behav;,1-3代码,异步清零、异步置位功能的边沿JK触发器 library ieee; use ieee.std_logic_1164.all; entity jk is port( pset,clr,clk,j,k:in std_logic; q,qb:out std_logic); end entity; architecture behav of jk is

4、 signal q_s,qb_s:std_logic; begin process(pset,clr,clk,j,k) begin if(pset=0)and(clr=1)then q_s=1;qb_s=0; elsif(pset=1)and(clr=0)then q_s=0;qb_s=1; elsif(clk event and clk=1)then if(j=0)and(k=1)then q_s=0;qb_s=1; elsif(j=1)and(k=0)then q_s=1;qb_s=0; elsif(j=1)and(k=1)then q_s=not q_s; qb_s=not qb_s;

5、end if; end if; q=q_s; qb=qb_s; end process; end behav;,实验21,实验内容:完成下述模块的设计,实现真值表中的半加与半减的功能。 提示信息:将加法与减法区分成两个功能模块,使用BLOCK语句将构造体分为两大部分。,输 入 值,半 加 法 器(A+B),半 减 法 器(A-B),A,B,Sum,Car,Difference,Borrow,0,0,0,1,1,0,1,1,0,0,1,0,1,0,0,1,0,1,1,0,0,1,0,0,2-1代码,library ieee; use ieee.std_logic_1164.all; use ie

6、ee.std_logic_unsigned.all; entity half is port ( a,b:in std_logic; sum,car,dif,bor:out std_logic); end half; architecture behav of half is begin g1:block begin sum=a xor b; car=a xor b; end block g1; g2:block begin dif=a xor b; bor=(not a) and b; end block g2; end behav;,实验22,实验内容:设计一个4位加减法器. 要求:a,b

7、:数据输入; sub: 控制端,高电平实现加法功能, 低电平实现减法功能; s:和与差的输出; co:进位与借位的输出。,2-2代码,library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity subadd is port(sub:in std_logic; a,b:in std_logic_vector(3 downto 0); s:out std_logic_vector(3 downto 0); co:out std_logic); end entity subadd; archit

8、ecture behav of subadd is signal temp:std_logic_vector(4 downto 0); begin process(sub,a,b) begin if sub=1 then temp=a+b; else temp=a-b; end if; end process; s=temp(3 downto 0); co=temp(4); end behav;,实验31,实验内容:如下表所示为4位双向通用移位寄存器74LS194的真值表,编写程序描述该逻辑,仿真其功能。,3-1代码,library ieee; use ieee.std_logic_1164.

9、all; entity ls194 is port ( clr,s0,s1,clk,l,r:in std_logic; p:in std_logic_vector(3 downto 0); q:out std_logic_vector(3 downto 0); end ls194; architecture behav of ls194 is signal qs:std_logic_vector(3 downto 0); begin process(clr,s0,s1,clk,l,r)is begin if(clr=0)then qs=“0000“; elsif(clk event and c

10、lk=1)then if(s1=1)and(s0=1)then qs=p; elsif(s1=0)and(s0=1)then if(r=1)then qs(3)=1; qs(2 downto 0)=qs(3 downto 1); elsif(r=0)then qs(3)=0; qs(2 downto 0)=qs(3 downto 1); end if; elsif(s1=1)and(s0=0)then if(l=1)then qs(0)=1; qs(3 downto 1)=qs(2 downto 0); elsif(l=0)then qs(0)=0; qs(3 downto 1)=qs(2 d

11、ownto 0); end if; end if; end if; q=qs; end process; end behav;,实验32,实验内容:38译码器的设计(要求用WITHSELECT语句完成)(图形见下页)。 提示信息: 常见的38 译码器的真值 表如右:,A0 A1 A2,0 0 0,0 0 1,0 1 0,0 1 1,1 0 0,1 0 1,1 1 0,1 1 1,Y0 Y1 Y2 Y3 Y4 Y5 Y6 Y7,1 0 0 0 0 0 0 0,0 1 0 0 0 0 0 0,0 0 1 0 0 0 0 0,0 0 0 1 0 0 0 0,0 0 0 0 1 0 0 0,0 0 0

12、 0 0 1 0 0,0 0 0 0 0 0 1 0,0 0 0 0 0 0 0 1,当EN1时,译码器正常工作;当EN=0时,译码器不动作。,A0,A1,A2,EN,Y0,Y7,3-2代码,library ieee; use ieee.std_logic_1164.all; entity decode3to8 is port(a:in std_logic_vector(2 downto 0); en:in std_logic; y:out std_logic_vector(7 downto 0); end decode3to8; architecture behav of decode3to

13、8 is signal sel:std_logic_vector(3 downto 0); begin sel=a,实验41 功能要求:4位数据输入,可表示0F十六个数值。将其译码为共阴极7段LED的显示码。LED的每段和dout的连接关系见下图。 模块名:LEDDECODER 输入端口:i数据输入(4位) 输出端口:dout译码输出(7位),4-1代码,library ieee; use ieee.std_logic_1164.all; entity leddecoder is port(i:in std_logic_vector(3 downto 0); dout:out std_logi

14、c_vector(0 to 6); end leddecoder; architecture behav of leddecoder is begin process(i) begin case i is when “0000“=doutdoutdoutdoutdoutdoutdoutdoutdoutdoutdoutdoutdoutdoutdoutdoutdout=“0000000“; end case; end process; end behav;,实验42,实验内容:设计完成一个7位的偶同位产生器。 提示信息:同位共分为两种形式: 奇同位:数据位与奇同位的1的个数为奇数。 偶同位:数据位

15、与偶同位的1的个数为偶数。 n位的偶同位产生器的输入信号为n位,输出信号为n+1位,其中前n位为输入信号,最后一位为偶同位位,且保证输出的n+1位信息中1的个数为偶数个。(奇同位产生器工作原理类似),4-2代码,library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity tongwei is port ( a:in std_logic_vector(6 downto 0); c:out std_logic_vector(7 dow

16、nto 0); end entity; architecture behav of tongwei is signal temp:std_logic; begin temp=a(0)xor a(1)xor a(2)xor a(3)xor a(4)xor a(5)xor a(6); c=a ,实验51,实验内容:完成1位全加器的设计。 提示信息:输入为A,B,C,其中A、B为输入数据,C为输入的进位标志位;输出为Sum和Car,其中Sum为本次运算结果位,Car为本次进位标志位。,5-1代码_,library ieee; use ieee.std_logic_1164.all; entity f

17、ulladd is port ( a,b,c:in std_logic; car,s:out std_logic); end entity fulladd; architecture behav of fulladd is begin s=a xor b xor c ; car=(a and b)or(b and c)or(c and a); end behav;,实验52,实验内容:完成4位全加法器的设计。 提示信息:一个4位的全加法器可以由4个1位的全加法器级联而成。,A(0),B(0),S(0),C(1),C(2),C(3),Co,A(1),B(1),S(1),S(2),S(3),A(2

18、),B(2),A(3),B(3),5-2代码_,library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity fulladd4 is port( a,b:in std_logic_vector(3 downto 0); c0:out std_logic; s:out std_logic_vector(3 downto 0); end fulladd4; architecture str of fulladd4 is signal c

19、1,c2,c3:std_logic; signal t:std_logic; component fulladd port(a,b,c:in std_logic; car,sum:out std_logic); end component; begin t=0; u1: fulladd port map(a(0),b(0),t,c1,s(0); u2: fulladd port map(a(1),b(1),c1,c2,s(1); u3: fulladd port map(a(2),b(2),c2,c3,s(2); u4: fulladd port map(a(3),b(3),c3,c0,s(3

20、); end architecture str;,实验61,实验内容:设计一个3bits的可逆计数器。 提示信息:由名称可以知道,它的计数方式可以加(检测到CLK时钟的上升沿,计数器加1),也可以减(检测到CLK时钟的上升沿,计数器减1)。使用一个控制信号DIR决定计数器是作加法或减法的动作。,6-1代码_,updncount_3 is port(clk,clr,updn:in std_logic; qa,qb,qc:out std_logic); end library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigne

21、d.all; entity updncount_3; architecture rtl of updncount_3 is signal count_3:std_logic_vector(2 downto 0); begin qa0); elsif (clkevent and clk=1) then if (updn=1) then count_3=count_3+1; else count_3=count_3-1; end if; end if; end process; end rtl,实验62,实验内容:分频器设计。 要求: (1)设计一个占空比为50%的6分频器; (2)设计一个占空比

22、为1:2的6分频器。 提示信息:占空比为时钟周期中高电平与低电平之比。,6-2代码(_),library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; entity fdiv is generic(N:integer:=6); port( clkin:in std_logic; clkout:out std_logic ); end fdiv; architecture a of fdiv is signal cnt:integer range

23、0 to n/2-1; n=6 signal temp:std_logic; begin process(clkin) begin if(clkinevent and clkin=1)then if(cnt=n/2-1)then cnt=0; temp=not temp; else cnt=cnt+1; end if; end if; end process; clkout=temp; end a;,6-2代码,占空比1:2 (_),LIBRARY IEEE; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee

24、.std_logic_unsigned.all; entity shiyan62 is port ( clkin:in std_logic; rest:in std_logic; clk6fen:out std_logic); end; architecture rtl of shiyan62 is signal counter:std_logic_vector(0 to 2); begin process(clkin,counter,rest) begin if rest=0 then counter=“000“; elsif clkinevent and clkin=1then if co

25、unter5 then counter=counter+1; if counter3 then clk6fen=1; else clk6fen=0; end if; else counter=“000“; end if; end if ; end process; end architecture rtl;,实验71,实验内容:设计完成一10进制加法计数器。该计数器具有同步置数、同步清零的功能。 输入信号为:clk,clr,en,datain 输出信号为:dataout,co 当输入信号clr1时,计数器清零; 当置数信号en=1时,计数器装入输入datain为计数初值重新计数; 其它情况下,

26、计数器进行10进制加法计数,每计数到9时,输出co1,表示进位。,7-1代码(_),library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity count10 is port ( clr,clk,en:in std_logic; datain:in std_logic_vector(3 downto 0); co:out std_logic; dataout:out std_logic_vector(3 downto 0); end count10; architecture behav

27、of count10 is signal tmp:std_logic_vector(3 downto 0); begin process(clk) begin if(clk event and clk=1)then if(clr=1)then tmp=“0000“; elsif(en=1)then tmp=datain; elsif(tmp=“1001“)then tmp=“0000“;co=1; else tmp=tmp+1;co=0; end if; end if; end process; dataout=tmp; end behav;,实验72,实验内容:设计完成100进制加法计数器。

28、要求:采用构造体结构化描述方式由2个10进制计数器级联而成,7-2代码_,顶层文件: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity count100 is port(clk:in std_logic; co:out std_logic; dout1,dout2:out std_logic_vector(3 downto 0); end count100; architecture behave of count100 is component count10 is port(

29、clk:in std_logic; co:out std_logic; dataout:out std_logic_vector(3 downto 0); end component; signal temp:std_logic; begin u1:count10 port map(clk,temp,dout1); u2:count10 port map(temp,co,dout2); end behave;,底层文件: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity coun

30、t10 is port(clk:in std_logic; co:out std_logic; dataout:out std_logic_vector(3 downto 0); end count10; architecture behave of count10 is signal temp:std_logic_vector(3 downto 0); begin dataout=temp; process(clk) begin if(clkevent and clk=1)then if(temp=“1001“)then temp=“0000“; co=1; else temp=temp+1; co=0; end if; end if; end process; end behave;,实验8-1,实验内容:LPM兆功能块的使用。 对LPM兆功能单元的lpm_fifo模块进行合理的参数设置,借助仿真手段分析输入、输出端口的功能,并进行简单的说明。,实验8-2,实验内容: 利用LPM兆功能单元的lpm_fifo模块实现对连续输入的数据的延时。 要求:输入数据宽度为8位,延时时间为5个时钟周期。,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1