北理工VHDL实验报告.docx

上传人:b****6 文档编号:7795439 上传时间:2023-01-26 格式:DOCX 页数:23 大小:473.28KB
下载 相关 举报
北理工VHDL实验报告.docx_第1页
第1页 / 共23页
北理工VHDL实验报告.docx_第2页
第2页 / 共23页
北理工VHDL实验报告.docx_第3页
第3页 / 共23页
北理工VHDL实验报告.docx_第4页
第4页 / 共23页
北理工VHDL实验报告.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

北理工VHDL实验报告.docx

《北理工VHDL实验报告.docx》由会员分享,可在线阅读,更多相关《北理工VHDL实验报告.docx(23页珍藏版)》请在冰豆网上搜索。

北理工VHDL实验报告.docx

北理工VHDL实验报告

本科实验报告

实验名称:

VHDL语言及集成电路设计实验

课程名称:

VHDL语言及集成电路设计

实验时间:

12、13周周二上午

14、15周周六下午

任课教师:

任仕伟

实验地点:

4#427

实验教师:

任仕伟

实验类型:

□原理验证

■综合设计

□自主创新

学生姓名:

学号/班级:

组号:

学院:

信息与电子学院

同组搭档:

专业:

微电子

成绩:

实验一:

带有异步复位端的D触发器

一、实验目的

(1)熟悉linux操作环境和modelsim软件环境

(2)理解时序逻辑和组合逻辑电路的区别

(3)理解并行语句和顺序语句

(4)用VHDL语言编写一个带有异步复位端的D触发器及其测试文件

二、实验原理

(1)组合逻辑和时序逻辑

组合逻辑电路当前输出的值仅取决于当前的输入,不需要触发器等具有存储能力

的逻辑单元,仅仅使用组合逻辑门;

时序逻辑电路的当前输出不仅取决于当前的输入,还与以前的输入有关,这类电

路中包括寄存器等元件,也包括组合逻辑电路,寄存器通过一个反馈环和组合逻辑模块相连,触发器便是属于时序逻辑电路;

(2)并行和顺序代码

从本质上讲,VHDL代码是并发执行的。

只有PROCESS,FUNCTION或PROCEDURE内的代码才是顺序执行的。

当它们作为一个整体时,与其他模块之间又是并发执行的。

以下是3个并发描述语句(stat1,stat2和stat3)的代码,会产生同样的电路结构。

stat1stat3stat1

stat2=stat2=stat3=其他排列顺序

stat3stat1stat2

(3)并行语句——进程(PROCESS)

1)语法结构:

[进程名:

]PROCESS(敏感信号列表)

[变量说明语句]

BEGIN

(顺序执行的代码)

ENDPROCESS[进程名];

2)PROCESS的特点

多进程之间是并行执行的;

进程结构内部的所有语句都是顺序执行的;

进程中可访问结构体或实体中所定义的信号;

进程的启动是由敏感信号列表所标明的信号来触发,也可以用WAIT语句等待一个触发条件的成立。

各进程之间的通信是由信号来传递的。

(4)带有异步复位端的D触发器

三、实验代码

LIBRARYIEEE;

USEIEEE.STD_LOGIC_1164.ALL;

ENTITYdffIS

PORT(d,clk,rst:

INSTD_LOGIC;

q:

OUTSTD_LOGIC);

ENDdff;定义entitydff

ARCHITECTUREbehaviorOFdffISBEGIN

PROCESS(rst,clk)

BEGIN

IF(rst='1')THEN

q<='0';如果复位信号有效,q为0

ELSIF(clk'EVENTANDclk='1')THENq<=d;上升沿触发且,q<=d

ENDIF;

ENDPROCESS;结束进程

endARCHITECTUREbehavior;

测试文件:

libraryIEEE;

useieee.std_logic_1164.all;

entitydff_tbis

enddff_tb;

architecturetb_behaviorofdff_tbiscomponentdff

port(

d,rst,clk:

instd_logic;

q:

outstd_logic);

endcomponent;

constantclk_period:

time:

=50ns;

signald,clk,q,rst:

std_logic;

begin

dut:

dffportmap(d=>d,clk=>clk,rst=>rst,q=>q);clk_gen:

process

begin

clk<='0';

waitforclk_period/2;clk<='1';

waitforclk_period/2;endprocess;

d_gen:

process

begin

waitfor100ns;

d<='1';

waitfor100ns;

d<='0';

endprocess;

rst_gen:

process

begin

rst<='1';

waitfor150ns;

rst<='0';

waitfor500ns;

rst<='1';

waitfor150ns;wait;

endprocess;

endtb_behavior;

四、实验结果

五、实验心得

第一次使用此软件,略有陌生,耗费时间稍久,因为之前用过的quartusii9.0不必使用tb文件,所以第一次实验刚开始并没有明白tb文件的用途,上网查找资料之后才明白过来,不过好在程序简单,顺利完成实验。

 

实验二步进电机控制器

一、实验目的

(1)理解两种状态机的区别

(2)熟悉两种编程风格

(3)编写BCD计数器和步进电机

二、实验原理

(1)米里型状态机和摩尔型状态机

米里(Mealy)型状态机:

状态机的输出信号不仅与电路的当前状态有关,还与当前的输入有关

摩尔(Moore)型状态机:

状态机的当前输出仅仅由当前状态决定。

(2)有限状态机设计流程:

1)理解问题背景。

2)逻辑抽象,得出状态转移图。

3状态简化。

4)状态分配。

5)用VHDL来描述有限状态机。

(3)BCD计数器

原理图

(4)步进电机控制器

三、实验代码

(1)BCD计数器

libraryieee;

useieee.std_logic_1164.all;

entitycounteris

port(clk,rst:

instd_logic;

count:

outstd_logic_vector(3downto0));

endcounter;定义entitycounter

architecturestate_machineofcounteris

typestateis

(zero,one,two,three,four,five,six,seven,eight,nine);自定义type类型的量,用来表示程序中要用到的不同状态

signalpr_state,nx_state:

state;定义信号pr_state,nx_state,均为state类型的量

begin

process(rst,clk)

begin

if(rst='1')then

pr_state<=nx_state;如果复位信号有效,保持现态

endif;

endprocess;

process(pr_state)

begin

casepr_stateis

whenzero=>count<="0000";

nx_state<=one;

whenone=>count<="0001";

nx_state<=two;

whentwo=>count<="0010";

nx_state<=three;

whenthree=>count<="0011";

nx_state<=four;

whenfour=>count<="0100";

nx_state<=five;

whenfive=>count<="0101";

nx_state<=six;

whensix=>count<="0110";

nx_state<=seven;

whenseven=>count<="0111";

nx_state<=eight;

wheneight=>count<="1000";

nx_state<=nine;

whennine=>count<="1001";

nx_state<=zero;

endcase;使用case语句,列举所有状态,同时指出所有现态的次态指向

endprocess;

endstate_machine;

(2)步进电机控制器

libraryieee;

useieee.std_logic_1164.all;

entitystepmotoris

port(clk,rst,x:

instd_logic;

output:

outstd_logic_vector(3downto0));

endstepmotor;定义entitystepmoter

architecturestate_machineofstepmotoris

typestateis

(s0,s1,s2,s3);自定义type类型

signalpr_state,nx_state:

state;定义信号量

begin

process(clk,rst)

begin

if(rst='1')then

pr_state<=s0;

elsif(clk'eventandclk='1')then

pr_state<=nx_state;

endif;

endprocess;

process(pr_state,x)

begin

if(x='0')then

casepr_stateis

whens0=>output<="0001";

nx_state<=s3;

whens1=>output<="0010";

nx_state<=s0;

whens2=>output<="0100";

nx_state<=s1;

whens3=>output<="1000";

nx_state<=s2;

endcase;

elsif(x='1')then

casepr_stateis

whens0=>output<="0001";nx_state<=s1;

whens1=>output<="0010";nx_state<=s2;

whens2=>output<="0100";nx_state<=s3;

whens3=>output<="1000";nx_state<=s0;endcase;

endif;

endprocess;

endstate_machine;

四、仿真结果

BCD计数器:

步进电机控制器:

五、实验心得

这次所做实验为BCD计数器和步进电机控制,程序比较简单,有可以使用的模板,结果也比较有意思,主要是对状态机的理解运用和VHdl语句中例如case语句、if语句、when语句的区分和正确使用。

 

实验三十六位加法器设计

 

一、实验目的

(1)掌握元件例化的方法

(2)理解for/generate语句的用法

(3)编程完成4位加法器和16位加法器的设计

二、实验原理

(1)元件的例化

元件声明是对VHDL模块(即底层设计,也是完整的VHDL设计)的说明,使之可在其他被调用,元件声明可放在程序包中,也可在某个设计的构造体中声明。

元件例化指元件的调用。

元件声明及元件例化的语法分别如下:

元件声明:

component〈元件实体名〉

prot(〈元件端口信息,同该元件实现时的实体的port部分〉);

endcompnent;

元件例化:

〈例化名〉:

〈实体名,即元件名〉portmap(〈端口列表〉);

(2)生成语句(GENERATE)

GENERATE语句用于循环执行某项操作。

FOR模式的生成语句主要用于相同结构的描述中;

FOR模式语法结构:

FOR/GENERATE:

标号:

FOR变量IN离散区间GENERATE

(并行处理语句);

ENDGENERATE;

(3)16位加法器的设计

三、实验代码

4位加法器:

libraryieee;

useieee.std_logic_1164.all;

entityadder4is

port(a,b:

instd_logic_vector(3downto0);

cin:

instd_logic;

s:

outstd_logic_vector(3downto0);

cout:

outstd_logic);

endadder4;

定义entityadder4,cin为进位输入,cout为进位输出,s为求和结果

architecturebehavofadder4is

signalc:

std_logic_vector(4downto0);

signalp:

std_logic_vector(3downto0);

signalg:

std_logic_vector(3downto0);

begin

G1:

foriin0to3generate

p(i)<=a(i)xorb(i);

g(i)<=a(i)andb(i);

s(i)<=p(i)xorc(i);

endgenerate;

c(0)<=cin;

c

(1)<=(cinandp(0))org(0);

c

(2)<=(cinandp(0)andP

(1))or(g(0)andp

(1))org

(1);

c(3)<=(cinandp(0)andP

(1)andP

(2))or(g(0)andp

(1)andP

(2))or(g

(1)andP

(2))org

(2);

c(4)<=(cinandp(0)andP

(1)andP

(2)andP(3))or(g(0)andp

(1)andP

(2)andP(3))or(g

(1)andP

(2)andP(3))or(g

(2)andP(3))org(3);

cout<=c(4);

endbehav;

使用超前进位加法器设计原理,代入公式,写出语句

16位加法器:

libraryieee;

useieee.std_logic_1164.all;

entityadderis

port(a,b:

instd_logic_vector(15downto0);

s:

outstd_logic_vector(15downto0);

cin:

instd_logic;

cout:

outstd_logic);

endadder;

定义entityadder,为16位加法器

architecturebehavofadderis

componentadder4is

port(a,b:

instd_logic_vector(3downto0);

s:

outstd_logic_vector(3downto0);

cin:

instd_logic;

cout:

outstd_logic);

endcomponent;

进行元件实例化,以四个4位adder作为基本元件设计16位加法器

signalm1,m2,m3:

std_logic;

begin

u1:

adder4portmap(a(3downto0),b(3downto0),s(3downto0),cin,m1);u2:

adder4portmap(a(7downto4),b(7downto4),s(7downto4),m1,m2);u3:

adder4portmap(a(11downto8),b(11downto8),s(11downto8),m2,m3);

u4:

adder4portmap(a(15downto12),b(15downto12),s(15downto12),m3,cout);

元件之间端口连接线

endbehav;

测试程序:

libraryieee;

useieee.std_logic_1164.all;

entityadder_tbis

endentityadder_tb;

architecturebehavofadder_tbis

componentadder

port(a,b:

instd_logic_vector(15downto0);

s:

outstd_logic_vector(15downto0);

cin:

instd_logic;

cout:

outstd_logic);

endcomponent;

signalclk:

std_logic:

='0';

signala,b:

std_logic_vector(15downto0);

signals:

std_logic_vector(15downto0);

signalcin:

std_logic;

signalcout:

std_logic;

begin

w:

adderportmap(a=>a,b=>b,s=>s,cin=>cin,cout=>cout);

process

begin

a<=x"0000";

b<=x"0000";

cin<='1';

waitfor100ns;

a<="0000100000000001";b<="0100000000000111";cin<='0';

waitfor100ns;

a<=x"1111";

b<=x"1111";

cin<='1';

waitfor100ns;

a<="0000100000000001";b<="1110000000000111";cin<='1';

wait;

endprocess;

endbehav;

四、实验原理

五、实验心得

本次实验主要是加法器设计,课堂上曾经讲过两种,即逐级进位加法器和超前进位加法器,在使用第一种思路设计时,程序出现错误,当时未调试成功(后来发现错误是公式代入错误),改为使用课件上给出的超前进位加法器的原程序,编写tb文件之后,程序正常运行。

在程序的知识运用方面,主要是对元件实例化的实际运用,掌握基本使用规则,并能从中体会出其方便好用之处为之后的灵活运用打下基础。

 

实验四选择运算器

 

一、实验目的:

(1)对前几次实验用到的知识进行总结

(2)综合运用理论课上的知识,完成选择运算器的设计

二、实验原理

(1)设计要求:

输出信号:

一个COUT(15:

0),16位

乘法器:

要求用部分积实现

加法器:

8位加法器,高7位补零

完成比较器、乘法器、加法器的设计,不可以直接使用+,x运算符直接实现。

(2)选择器运算器总原理图

(3)乘法器部分采用并行乘法器

(4)加法器:

8位加法器的设计和上一个试验类似,先设计一个4位加法器,进而编译8位加法器。

三、实验代码

Adder4:

libraryieee;

useieee.std_logic_1164.all;

entityadder4is

port(a,b:

instd_logic_vector(3downto0);

sum:

outstd_logic_vector(3downto0);

jin:

outstd_logic;

cin:

instd_logic:

='0');

endadder4;

architectureadder4ofadder4is

signalc:

std_logic_vector(4downto0);

signalp:

std_logic_vector(3downto0);

signalg:

std_logic_vector(3downto0);

begin

G1:

foriin0to3generate

p(i)<=a(i)xorb(i);

g(i)<=a(i)andb(i);

sum(i)<=p(i)xorc(i);

endgenerate;

c(0)<=cin;

c

(1)<=(c(0)andp(0))org(0);

c

(2)<=(c(0)andp(0)andp

(1))or(g(0)andp

(1))org

(1);

c(3)<=(c(0)andp(0)andp

(1)andp

(2))or(g(0)andp

(1)andp

(2))or(g

(1)andp

(2))org

(2);

c(4)<=(c(0)andp(0)andp

(1)andp

(2)andp(3))or(g(0)andp

(1)andp

(2)andp(3))or(g

(1)andp

(2)andp(3))or(g

(2)andp(3))org(3);

jin<=c(4);

endadder4;

为元件实例化的元件定义,与实验三所用代码相同

 

Adder8:

libraryieee;

useieee.std_logic_1164.all;

usework.my_component_adder.all;

entityadder8is

port(a,b:

instd_logic_vector(7downto0);

sum:

outstd_logic_vector(7downto0);

jin:

outstd_logic);

endadder8;

architectureadder8ofadder8is

signalm:

std_logic;

signalcin:

std_logic:

='0';

begin

u1:

adder4portmap(a(3downto0),b(3downto0),sum(3downto0),m,cin);

u2:

adder4portmap(a(7downto4),b(7downto4),sum(7downto4),jin,m);

endadder8;

8位加法器描述

Cheng:

libraryieee;

useieee.std_logic_1164.all;

useieee.std_logic_unsigned.all;

entitychengis

port(a,b:

instd_logic_vector(7downto0);

ch:

outstd_logic_vector(15downto0));

endcheng;

architecturechengofchengis

begin

process(a,b)

variabletemp:

std_logic_vector(15downto0);

variabletemp1:

std_logic_vector(15downto0);

begin

temp:

=(others=>'0');

temp1:

=(others=>'0');

foriin0to7loop

tem

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

当前位置:首页 > 高等教育 > 工学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1