VHDL与数字系统EDA设计.doc

上传人:哈尼dd 文档编号:3258622 上传时间:2019-08-06 格式:DOC 页数:20 大小:319.53KB
返回 下载 相关 举报
VHDL与数字系统EDA设计.doc_第1页
第1页 / 共20页
VHDL与数字系统EDA设计.doc_第2页
第2页 / 共20页
VHDL与数字系统EDA设计.doc_第3页
第3页 / 共20页
VHDL与数字系统EDA设计.doc_第4页
第4页 / 共20页
VHDL与数字系统EDA设计.doc_第5页
第5页 / 共20页
点击查看更多>>
资源描述

《VHDL与数字系统EDA设计.doc》由会员分享,可在线阅读,更多相关《VHDL与数字系统EDA设计.doc(20页珍藏版)》请在三一文库上搜索。

1、VHDL与数字系统EDA设计姓名: 李 勃 学号: 0800030014 班级: 代培生班 2009年6月20日目录实验一1实验二5实验三8实验四10实验五14作业18VHDL与数字系统EDA设计李勃 0800030014实验一1. 用IF语句设计一个四十六译码器;2. 用CASE语句设计一个四十六译码器;3. 用GENERATE语句构造一个串行的十六进制计数器。实验目的:学会使用相关EDA软件进行VHDL代码的输入、仿真,会用VHDL实现一些简单的组合逻辑和时序逻辑。1. 用IF语句设计一个四十六译码器实验方案:接口信号的定义如下:port(A : in STD_LOGIC;B : in S

2、TD_LOGIC;C : in STD_LOGIC;D : in STD_LOGIC;Y : out STD_LOGIC_VECTOR(15 downto 0);end decoder;关键部分代码:process(A,B,C,D) variable comb: STD_LOGIC_VECTOR(3 downto 0); begincomb:=A&B&C&D;if comb=0000 then Y=0000000000000001;elsif comb=0001 then Y=0000000000000010;elsif comb=0010 then Y=0000000000000100;el

3、sif comb=0011 then Y=0000000000001000;elsif comb=0100 then Y=0000000000010000;elsif comb=0101 then Y=0000000000100000; elsif comb=0110 then Y=0000000001000000;elsif comb=0111 then Y=0000000010000000; elsif comb=1000 then Y=0000000100000000;elsif comb=1001 then Y=0000001000000000; elsif comb=1010 the

4、n Y=0000010000000000;elsif comb=1011 then Y=0000100000000000;elsif comb=1100 then Y=0001000000000000;elsif comb=1101 then Y=0010000000000000;elsif comb=1110 then Y=0100000000000000;elsif comb=1111 then Y=1000000000000000; else Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y YY=XXXXXXXXXXXXXXXX ;end case ;end proces

5、s;仿真验证:仿真软件: Active HDL 7.13. 用GENERATE语句构造一个串行的十六进制计数器实验方案:接口信号的定义如下:entity counter is port( clk : in STD_LOGIC; clr : in STD_LOGIC; q : out STD_LOGIC_VECTOR(3 downto 0) );end counter;关键部分代码:architecture rtl of counter iscomponent dff port( d : in STD_LOGIC; clr : in STD_LOGIC; clk : in STD_LOGIC;

6、q : out STD_LOGIC; qb : out STD_LOGIC );end component ; signal q_in: std_logic_vector (4 downto 0) ;begin q_in(0) q_in(i+1),clk=q_in(i),clr=clr,q=q(i),qb=q_in(i+1);end generate;end rtl;仿真验证:仿真软件: Active HDL 7.1实验二设计一个两位二进制的加法器实验目的: 学会设计简单的组合逻辑,并进行功能仿真。实验方案:先用基本逻辑门设计一个半加器,再用两个半加器组合成全加器,再用全加器设计成二进制加法器

7、。接口定义如下:entity twobit_adder is port( cin : in STD_LOGIC; a : in STD_LOGIC_VECTOR(1 downto 0); b : in STD_LOGIC_VECTOR(1 downto 0); co : out STD_LOGIC; s : out STD_LOGIC_VECTOR(1 downto 0) );end twobit_adder;关键部分代码:半加器部分:architecture half_adder of half_adder issignal c,d:std_logic ;begin c=a or b;d=a

8、 nand b;co= not d;s=c and d;end half_adder;全加器部分代码:u0: half_adder port map (a,b,u0_s,u0_co); u1: half_adder port map (u0_s,cin,s,u1_co); coa(0),b=b(0),cin=cin,s=s(0),co=u0_co); u1: full_adder port map (a=a(1),b=b(1),cin=u0_co,s=s(1),co=co);仿真软件: Active HDL 7.12. 设计一个两位的BCD计数器实验目的:学会设计简单的时序逻辑,并进行仿真。实

9、验方案:先设计一个一位带进位的BCD计数器,再以它的进位输出作为十位计数器的时钟输入。接口定义:entity BCD_counter isport(clk : in STD_LOGIC;clr : in STD_LOGIC;q0 : out STD_LOGIC_VECTOR(3 downto 0);q1 : out STD_LOGIC_VECTOR(3 downto 0);end BCD_counter;关键部分代码:architecture rtl of BCD_counter is signal co: std_logic ;signal in_q0,in_q1: STD_LOGIC_VE

10、CTOR(3 downto 0);begin q0= in_q0;q1= in_q1;process(clk,clr)beginif (clr=1) thenin_q0=0000;elsif (clkevent and clk=1) thenif (in_q0=1001) thenin_q0=0000;co=1;else in_q0=in_q0+1; co=0;end if;end if;end process;process(co,clr) begin if (clr=1) thenin_q1=0000;elsif (coevent and co=1) then if (in_q1=1001

11、) thenin_q1=0000;else in_q1=in_q1+1;end if;end if ;end process;end rtl;仿真软件: Active HDL 7.1实验三利用数组形式描述256x8bits的RAM,并利用测试床完成对其读写操作。实验目的:学会简单随机存储器的读写操作,并利用测试台对其进行测试。接口定义:entity ram is generic (k:integer :=8; w:integer :=8) ;port(wr : in STD_LOGIC;rd : in STD_LOGIC;cs : in STD_LOGIC;din : in STD_LOGIC

12、_VECTOR(k-1 downto 0);adr : in STD_LOGIC_VECTOR(w-1 downto 0);dout : out STD_LOGIC_VECTOR(k-1 downto 0);end ram;关键部分代码:adr_in=conv_integer(adr);process (wr)begin if(wrevent and wr=1) then wr_rise=now;if(cs=1)thensram(adr_in)=800 ps) report write sram setup time violation severity WARNING;end process

13、;process(rd,cs,adr_in,wr)begin if(rd=0 and cs=1) thendout=sram(adr_in) after 3 ns;elsedoutZ) after 4 ns;end if;end process;process(din)begindin_change300 ps) report read sram hold time violation severity WARNING;end process;仿真软件: Active HDL 7.1实验四用VHDL语言设计UART。实验目的:学会用VHDL语言设计复杂的电路。实验方案:UART主要有由数据总线

14、接口、控制逻辑、波特率发生器、发送部分和接收部分等组成。本设计主要设计UART中最重要的发送部分和接收部分,其他部分设计不在赘述。功能包括发送缓冲器(tbr)、发送移位寄存器(tsr)、帧产生、奇偶校验、并转串、数据接收缓冲器(rbr)、接收移位寄存器(rsr)、帧产生、奇偶校验、串转并。UART的帧格式下图所示: UART发送器的设计数据的发送是由微处理器控制,微处理器给出wrn信号,发送器根据此信号将并行数据din7.0锁存进发送缓冲器tbr7.0,并通过发送移位寄存器tsr7.0发送串行数据至串行数据输出端sdo。在数据发送过程中用输出信号tbre、tsre作为标志信号,当一帧数据由发送

15、缓冲器tbr7.0送到发送发送移位寄存器tsr7.0时,tbre信号为1,而数据由发送移位寄存器tsr7.0串行发送完毕时,tsre信号为1,通知CPU在下个时钟装入新数据。发送器端口信号如下图所示:部分代码:process (rst,wrn) -接收数据至tbrbeginif rst = 1 thentbr 0) ;elsif wrnevent and wrn = 0 thentbr = din ;end if ;end process ;process (rst,clk16x,clk1x_enable)beginif rst = 1 thenclkdiv = 0000 ;elsif clk

16、16xevent and clk16x = 1 thenif clk1x_enable = 1 thenclkdiv = clkdiv + 0001 ;end if ;end if ;end process ;clk1x = clkdiv(3) ; -产生clk1x时钟process (rst,clk1x,no_bits_sent,tbr)beginif rst = 1 thensdo = 1 ;tsre = 1 ;tsr = 00000000 ;parity = 1 ;elsif clk1xevent and clk1x = 1 thenif std_logic_vector(no_bits

17、_sent) = 0001 thentsr = tbr ; -发送缓冲器tbr数据进入发送移位寄存器tsrtsre = 0 ; -发送移位寄存器空标志置“0”elsif std_logic_vector(no_bits_sent) = 0010 thensdo = 0011 and std_logic_vector(no_bits_sent) = 1010 thentsr = tsr(6 downto 0) & 0 ; -从低位到高位进行移位输出至串行输出端sdosdo = tsr(7) ;parity = parity xor tsr(7) ; -数据位中的1校验end if ;end if

18、 ;end process ;process (rst,clk1x,clk1x_enable) -产生发送字符长度和发送次序计数器beginif rst = 1 or clk1x_enable = 0 thenno_bits_sent = 0000 ;elsif clk1xevent and clk1x = 1 thenif clk1x_enable = 1 thenno_bits_sent = no_bits_sent + 0001 ;end if ;end if ;end process ;UART接收器的设计串行数据帧和接收时钟是异步的,发送来的数据由逻辑1变为逻辑0可以视为一个数据帧的

19、开始。接收器先要捕捉起始位,确定rxd输入由1到0,逻辑0要8个CLK16时钟周期,才是正常的起始位,然后在每隔16个CLK16时钟周期采样接收数据,移位输入接收移位寄存器rsr,最后输出数据dout。还要输出一个数据接收标志信号标志数据接收完。接收器的端口信号如下图所示:部分代码:process (clk1x,rst)beginif rst = 1 thenrsr = 00000000 ;rbr = 00000000 ;parity = 1 ;framing_error = 0 ;parity_error = 0001 and std_logic_vector(no_bits_rcvd) 1

20、001 then - 数据帧数据由接收串行数据端移位入接收移位寄存器rsr(0) = rxd2 ;rsr(7 downto 1) = rsr(6 downto 0) ;parity = parity xor rsr(0) ;elsif std_logic_vector(no_bits_rcvd) = 1010 thenrbr = rsr ; -接收移位寄存器数据进入接收缓冲器elsif parity = 0 thenparity_error = 1 ;elsif std_logic_vector(no_bits_rcvd) = 1001 and rxd2 = 0 thenframing_err

21、or = 1 ;end if ;end if ;end process ;process (rst,clk1x,clk1x_enable,no_bits_rcvd)beginif rst = 1 or (std_logic_vector(no_bits_rcvd) = 1100 and clk1x_enable = 0) thenno_bits_rcvd = 0000 ;elsif clk1xevent and clk1x = 1 thenif clk1x_enable = 1 thenno_bits_rcvd = no_bits_rcvd + 0001 ;end if ;end if ;en

22、d process ;dout = std_logic_vector(rbr) when rdn = 0 else ZZZZZZZZ ;end ;UART设计总模块将发送器和接收器模块组装起来,就能较容易地实现通用异步收发器总模块。总模块RTL图如下图:程序在MAX+PLUS II环境下的分析波形仿真图:由于条件限制,数据给的太多,从上图是看不出来的,所以,为了说明设计的正确性,只给出了一个数据。通过波形仿真图我们可以清楚的看到UART的工作原理。实验五完成第九章计时电路设计。实验目的:学会设计稍微复杂一点的电路,学会自顶向下的设计方法。实验方案:先进行十进制计数器,六进制计数器,四进制计数器

23、等底层模块的设计,再运用模块化的设计方法,把它们组装成完整的计时器电路。接口:entity stop_watch isport(sysres : in STD_LOGIC;reset_sw : in STD_LOGIC;start_stop_sw : in STD_LOGIC;clk : in STD_LOGIC;dispen : in STD_LOGIC;enclk : in STD_LOGIC;xinxuanma :out STD_LOGIC;segment : out STD_LOGIC_VECTOR(6 downto 0);common : out STD_LOGIC_VECTOR(5

24、 downto 0);end stop_watch;关键部分代码:顶层模块的代码:architecture rtl of stop_watch is component clkgen port(sysres : in STD_LOGIC;en1 : in STD_LOGIC;clk : in STD_LOGIC;cntclk : out STD_LOGIC;keyclk : out STD_LOGIC);end component; component keyin port(reset_sw : in STD_LOGIC;start_stop_sw : in STD_LOGIC;keyclk

25、: in STD_LOGIC;clk : in STD_LOGIC;res : out STD_LOGIC;stst : out STD_LOGIC);end component;component ctrl port(sysres : in STD_LOGIC;res : in STD_LOGIC;stst : in STD_LOGIC;cntclk : in STD_LOGIC;cnten : out STD_LOGIC);end component ;component cntblk port(sysres : in STD_LOGIC;clk : in STD_LOGIC;cnten

26、: in STD_LOGIC;res : in STD_LOGIC;secl2 : out STD_LOGIC_VECTOR(3 downto 0);secl1 : out STD_LOGIC_VECTOR(3 downto 0);sec : out STD_LOGIC_VECTOR(3 downto 0);sec10 : out STD_LOGIC_VECTOR(2 downto 0);min : out STD_LOGIC_VECTOR(3 downto 0);min10 : out STD_LOGIC_VECTOR(2 downto 0);end component ; componen

27、t disp port(secl2 : in STD_LOGIC_VECTOR(3 downto 0);secl1 : in STD_LOGIC_VECTOR(3 downto 0);sec : in STD_LOGIC_VECTOR(3 downto 0);sec10 : in STD_LOGIC_VECTOR(3 downto 0);min : in STD_LOGIC_VECTOR(3 downto 0);min10 : in STD_LOGIC_VECTOR(3 downto 0); sysres : in STD_LOGIC;clk : in STD_LOGIC;dispen : i

28、n STD_LOGIC;segment : out STD_LOGIC_VECTOR(6 downto 0);common : out STD_LOGIC_VECTOR(5 downto 0);end component ; signal cntclk_s :std_logic :=0;signal keyclk_s:std_logic :=0;signal stst_s:std_logic :=0;signal cnten_s:std_logic :=0;signal res_s :std_logic :=0; signal secl2_s:STD_LOGIC_VECTOR(3 downto

29、 0):=0000;signal secl1_s:STD_LOGIC_VECTOR(3 downto 0):=0000;signal sec_s:STD_LOGIC_VECTOR(3 downto 0):=0000;signal min_s:STD_LOGIC_VECTOR(3 downto 0):=0000;signal sec10_s:STD_LOGIC_VECTOR(3 downto 0):=0000;signal min10_s :STD_LOGIC_VECTOR(3 downto 0):=0000; signal sec10_s1:STD_LOGIC_VECTOR(2 downto

30、0):=000;signal min10_s1:STD_LOGIC_VECTOR(2 downto 0):=000; beginxinxuanma= cntclk_s; sec10_s=0&sec10_s1;min10_s=0&min10_s1;u0: clkgen port map(sysres,enclk,clk,cntclk_s,keyclk_s);u1: keyin port map (reset_sw,start_stop_sw,keyclk_s,clk,res_s,stst_s);u2: ctrl port map (sysres,res_s,stst_s,cntclk_s,cnt

31、en_s); u3: cntblk port map(sysres,cnten_s,clk,res_s,secl2_s,secl1_s,sec_s,sec10_s1,min_s,min10_s1);u4: disp port map (secl2_s,secl1_s,sec_s,sec10_s,min_s,min10_s,sysres,clk,dispen,segment,common);end rtl;仿真验证为了是波形看的更清楚,把计数器的计数脉冲引到到了模块外面,即CLK经过10分频得到的100HZ的信号,通过下面语句引出xinxuanma= cntclk_s; 在这里这个信号被命名为x

32、inxuanma。Start_stop_sw信号复位后,可以看到计数了,百分之一为06,即1,其他各位为3F,即0,下一个计时脉冲到来后,百分之一为5B,即1,其它各位为3F , 即0。分析可知,仿真结果是正确的。作业根据如下声明完成下页作业1、2。SIGNAL a : BIT := 1;SIGNAL b : BIT_VECTOR (3 DOWNTO 0) := 1100;SIGNAL c : BIT_VECTOR (3 DOWNTO 0) := 0010;SIGNAL d : BIT_VECTOR (7 DOWNTO 0);SIGNAL e : INTEGER RANGE 0 TO 255;SIGNAL f : INTEGER RANGE -128 TO 127;作业1x1 x1 = 10010x2 x2 = 00101100x3 x3 =1110x4 x4 = 0x5 x5 = 0000x6 x6 =0011x7 x7 = 0011x8 x8 = 0d 0, OTHERS=1); - d 0dHIGH - 7cLEFT -0dRIGHT -0cRANGE - 3 to 0dLENGTH -8cREVERSE_RANGE - 0 to 318

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

当前位置:首页 > 研究报告 > 信息产业


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