VHDL第一次实验报告.docx
《VHDL第一次实验报告.docx》由会员分享,可在线阅读,更多相关《VHDL第一次实验报告.docx(70页珍藏版)》请在冰豆网上搜索。
![VHDL第一次实验报告.docx](https://file1.bdocx.com/fileroot1/2023-1/28/839540a5-4b86-4af7-bdc9-fb7d9ea918b5/839540a5-4b86-4af7-bdc9-fb7d9ea918b51.gif)
VHDL第一次实验报告
深圳大学实验报告
课程名称:
EDA技术
实验项目名称:
基本电路行为的描述
学院:
信息工程学院
专业:
电子信息工程
指导教师:
报告人:
学号:
班级:
2
实验时间:
实验报告提交时间:
2014年5月9日
教务部制
实验内容:
1多路选择器(习题2.1)
2ROM(习题3.4)
3简易加法器(习题3.5)
4通用译码器(习题4.4)
5第五章习题5.1、5.5、5.6、5.7、5.8
实验要求:
1.依次完成各电路功能的VHDL代码编写
2.完成相应电路仿真,并对仿真结果截图,截图中要求尽可能多的体现不同输入信号对应的输入结果
3.完成实验报告,并按时提交至Blackboard,实验报告见实验报告模板,要求按模板各项内容完成。
4.特别提示:
实验报告按模板内容逐项填写,要求有完整的VHDL代码、仿真测试文件(VHDLtestbench)、仿真结果截图、仿真结果分析、实验结论(或对实验的总结、心得体会)等内容。
实验过程及内容:
2.1多路选择器
多路选择器的顶层电路如图P2.1所示。
根据真值表,如果输入sel=“01”或者sel=“10”,那么输出将等于对应的某一输入(c=a或c=b).然而如果输入sel=“00”或者sel=“11”,那么输出将分别为‘0’和‘Z’(高阻)。
(a)填写表格,完成下面的代码。
(b)是对你的解答给出相关的注释。
(c)将代码编译后进行仿真,验证其正确性。
实验完整VHDL代码:
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
entitymuxis
Port(a:
inSTD_LOGIC_VECTOR(7DOWNTO0);
b:
inSTD_LOGIC_VECTOR(7DOWNTO0);
sel:
inSTD_LOGIC_VECTOR(1DOWNTO0);
c:
outSTD_LOGIC_VECTOR(7DOWNTO0));
endmux;
architectureexampleofmuxis
begin
PROCESS(a,b,sel)
begin
IF(sel="00")THEN
c<="00000000";
ELSIF(sel="01")THEN
c<=a;
ELSIF(sel="10")THEN
c<=b;
ELSE
c<=(OTHERS=>'U');
ENDIF;
ENDPROCESS;
endEXAMPLE;
仿真测试文件代码:
LIBRARYieee;
USEieee.std_logic_1164.ALL;
ENTITYTest_MuxIS
ENDTest_Mux;
ARCHITECTUREbehaviorOFTest_MuxIS
COMPONENTmux
PORT(
a:
INstd_logic_vector(7downto0);
b:
INstd_logic_vector(7downto0);
sel:
INstd_logic_vector(1downto0);
c:
OUTstd_logic_vector(7downto0)
);
ENDCOMPONENT;
--Inputs
signala:
std_logic_vector(7downto0):
=(others=>'0');
signalb:
std_logic_vector(7downto0):
=(others=>'0');
signalsel:
std_logic_vector(1downto0):
=(others=>'0');
--Outputs
signalc:
std_logic_vector(7downto0);
--Noclocksdetectedinportlist.Replacebelowwith
--appropriateportname
BEGIN
--InstantiatetheUnitUnderTest(UUT)
uut:
muxPORTMAP(
a=>a,
b=>b,
sel=>sel,
c=>c
);
--Stimulusprocess
stim_proc:
process
begin
--holdresetstatefor100ns.
a<="10101010";
b<="11110000";
sel<="00";
waitfor100ns;
sel<="01";
waitfor100ns;
sel<="10";
waitfor100ns;
sel<="11";
waitfor100ns;
--insertstimulushere
wait;
endprocess;
END;
仿真结果:
如图,当输入信号sel为“00”时,输出信号c为“00000000”;当输入信号sel为“01”时,输出信号c等于a即为“10101010”;当输入信号sel为“10”时,输出信号c等于b即为“11110000”;当输入信号sel为其他情况时,输出信号c等于自己设定的值,在此处即为“U”。
习题3.4ROM
试用1*1维常数来实现只读存储器ROM(read-onlymemory),假设一个ROM由许多深度为8,位宽为4的块组成。
提示:
首先建立一个名为rom的数组,然后定义一个rom类型的信号来实现ROM,用常数值填充到ROM块中:
CONSTANTmy_rom:
rom:
=(values);。
实验完整VHDL代码:
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
entityROMis
Port(addr:
inintegerrange0to7;
data:
outSTD_LOGIC_vector(3downto0));
endROM;
architectureBehavioralofROMis
TYPEROMISARRAY(0TO7)OFSTD_LOGIC_VECTOR(3DOWNTO0);
CONSTANTmy_rom:
ROM:
=("0000",
"0001",
"0010",
"0011",
"0100",
"0101",
"0110",
"0111");
begin
data<=my_rom(addr);
endBehavioral;
仿真测试文件代码:
LIBRARYieee;
USEieee.std_logic_1164.ALL;
ENTITYrom1IS
ENDrom1;
ARCHITECTUREbehaviorOFrom1IS
--ComponentDeclarationfortheUnitUnderTest(UUT)
COMPONENTROM
PORT(
addr:
INintegerrange0to7;
data:
OUTstd_logic_vector(3downto0)
);
ENDCOMPONENT;
--Inputs
signaladdr:
integerrange0to7;
--Outputs
signaldata:
std_logic_vector(3downto0);
--Noclocksdetectedinportlist.Replacebelowwith
--appropriateportname
BEGIN
--InstantiatetheUnitUnderTest(UUT)
uut:
ROMPORTMAP(
addr=>addr,
data=>data
);
--Stimulusprocess
stim_proc:
process
begin
--holdresetstatefor100ns.
addr<=0;
waitfor100ns;
addr<=2;
waitfor100ns;
addr<=3;
waitfor100ns;
addr<=5;
waitfor100ns;
addr<=7;
waitfor100ns;
addr<=1;
waitfor100ns;
wait;
endprocess;
END;
仿真结果:
如图。
当输入信号addr为“0”时,输出信号data为“0000”;当输入信号addr为“2”时,输出信号data为“0010”;当输入信号addr为“3”时,输出信号data为“0011”;当输入信号addr为“5”时,输出信号data为“0101”;当输入信号addr为“7”时,输出信号data为“0111”;当输入信号addr为“1”时,输出信号data为“0001”。
习题3.5简易加法器
重新编写一段代码,实现例3.3所示的加法器,要求所有输入/输出信号的类型均为STD_LOGIC_VECTOR(提示:
回顾3.8节所学的内容)。
实验完整VHDL代码:
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
useIEEE.STD_LOGIC_arith.all;
useIEEE.STD_LOGIC_unsigned.all;
entityadder1is
Port(a:
inSTD_LOGIC_VECTOR(3DOWNTO0);
b:
inSTD_LOGIC_VECTOR(3DOWNTO0);
sum:
outSTD_LOGIC_VECTOR(4DOWNTO0));
endadder1;
architectureBehavioralofadder1is
begin
sum<=('0'&a)+('0'&b);
endBehavioral;
仿真测试文件代码:
LIBRARYieee;
USEieee.std_logic_1164.ALL;
ENTITYadder2IS
ENDadder2;
ARCHITECTUREbehaviorOFadder2IS
--ComponentDeclarationfortheUnitUnderTest(UUT)
COMPONENTadder1
PORT(
a:
INstd_logic_vector(3downto0);
b:
INstd_logic_vector(3downto0);
sum:
OUTstd_logic_vector(4downto0)
);
ENDCOMPONENT;
--Inputs
signala:
std_logic_vector(3downto0):
=(others=>'0');
signalb:
std_logic_vector(3downto0):
=(others=>'0');
--Outputs
signalsum:
std_logic_vector(4downto0);
--Noclocksdetectedinportlist.Replacebelowwith
--appropriateportname
BEGIN
--InstantiatetheUnitUnderTest(UUT)
uut:
adder1PORTMAP(
a=>a,
b=>b,
sum=>sum
);
--Stimulusprocess
stim_proc:
process
begin
--holdresetstatefor100ns.
a<="0000";b<="0001";
waitfor100ns;
a<="0010";b<="0011";
waitfor100ns;
a<="0100";b<="0101";
waitfor100ns;
a<="0110";b<="0111";
waitfor100ns;
a<="1000";b<="1001";
waitfor100ns;
a<="1010";b<="1011";
waitfor100ns;
a<="1100";b<="1101";
waitfor100ns;
a<="1110";b<="1111";
waitfor100ns;
wait;
endprocess;
END;
仿真结果:
如图。
当输入信号a为“0000”,b为“0001”时,输出信号sum为“00001”;当输入信号a为“0010”,b为“0011”时,输出信号sum为“00101”;当输入信号a为“0100”,b为“0101”时,输出信号sum为“01001”;当输入信号a为“0110”,b为“0111”时,输出信号sum为“01101”;当输入信号a为“1000”,b为“1001”时,输出信号sum为“10001”;当输入信号a为“1010”,b为“1011”时,输出信号sum为“10101”;当输入信号a为“1100”,b为“1101”时,输出信号sum为“11001”;当输入信号a为“1110”,b为“1111”时,输出信号sum为“11101”。
习题4.4通用译码器
下面这个习题和例4.1中的译码器电路有关。
(1)在例4.1给出的电路中,如果矢量的位宽发生变化,那么程序中的信号sel(第7行)和(第8行)的位宽也要相应的改变。
如果想要把例4.1中的设计修改为一个通用译码器。
为此必须在ENTITY中使用GENERIC语句指定sel的位宽(假设n=3),然后用n的函数来替代sel和x的位宽上界。
综合后,对电路进行仿真,验证其正确性。
实验完整VHDL代码:
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
entitydecoder1is
GENERIC(n:
INTEGER:
=3);
Port(ena:
inSTD_LOGIC;
sel:
inSTD_LOGIC_VECTOR(n-1DOWNTO0);
x:
outSTD_LOGIC_VECTOR((2**n)-1DOWNTO0));
enddecoder1;
architectureBehavioralofdecoder1is
begin
PROCESS(ena,sel)
VARIABLEtemp1:
STD_LOGIC_VECTOR(x'HIGHDOWNTO0);
VARIABLEtemp2:
INTEGERRANGE0TOx'HIGH;
BEGIN
temp1:
=(OTHERS=>'1');
temp2:
=0;
IF(ena='1')THEN
FORiINsel'RANGELOOP
IF(sel(i)='1')THEN
temp2:
=2*temp2+1;
ELSE
temp2:
=2*temp2;
ENDIF;
ENDLOOP;
temp1(temp2):
='0';
ENDIF;
x<=temp1;
ENDPROCESS;
ENDBehavioral;
仿真测试文件代码:
LIBRARYieee;
USEieee.std_logic_1164.ALL;
ENTITYdecoder2IS
ENDdecoder2;
ARCHITECTUREbehaviorOFdecoder2IS
COMPONENTdecoder1
Port(ena:
inSTD_LOGIC;
sel:
inSTD_LOGIC_VECTOR(2DOWNTO0);
x:
outSTD_LOGIC_VECTOR(7DOWNTO0));
ENDCOMPONENT;
--Inputs
signalena:
std_logic:
='0';
signalsel:
std_logic_vector(2downto0):
=(others=>'0');
--Outputs
signalx:
std_logic_vector(7downto0);
--Noclocksdetectedinportlist.Replacebelowwith
--appropriateportname
BEGIN
--InstantiatetheUnitUnderTest(UUT)
uut:
decoder1PORTMAP(
ena=>ena,
sel=>sel,
x=>x
);
--Stimulusprocess
stim_proc:
process
begin
--holdresetstatefor100ns.
ena<='1';sel<="010";
waitfor100ns;
ena<='1';sel<="100";
waitfor100ns;
ena<='1';sel<="110";
waitfor100ns;
ena<='1';sel<="100";
waitfor100ns;
ena<='1';sel<="101";
waitfor100ns;
ena<='1';sel<="111";
waitfor100ns;
ena<='1';sel<="101";
waitfor100ns;
--insertstimulushere
wait;
endprocess;
END;
仿真结果:
如图。
让使能端始终为“1”。
当输入信号sel为“010”时,输出信号x为“11111011”;当输入信号sel为“100”时,输出信号x为“11101111”;当输入信号sel为“110”时,输出信号x为“10111111”;当输入信号sel为“100”时,输出信号x为“11101111”;当输入信号sel为“101”时,输出信号x为“11011111”;当输入信号sel为“111”时,输出信号x为“01111111”;当输入信号sel为“101”时,输出信号x为“11011111”。
(2)在例4.1的设计中引入了一个二进制整数到整数的转换函数(第20行第26行)。
如果把sel声明为整数,就不需要使用这个转换函数。
要求读者修改代码,将信号sel声明为整数类型。
当信号sel的位宽用n来指定时,代码才是通用的。
综合代码并进行仿真。
实验完整VHDL代码:
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
entitydecoder3is
GENERIC(n:
INTEGER:
=3);
Port(ena:
inSTD_LOGIC;
sel:
inINTEGERRANGE0TO(2**n)-1;
x:
outSTD_LOGIC_VECTOR((2**n)-1DOWNTO0));
enddecoder3;
architectureBehavioralofdecoder3is
begin
PROCESS(ena,sel)
VARIABLEtemp1:
STD_LOGIC_VECTOR(x'HIGHDOWNTO0);
BEGIN
temp1:
=(OTHERS=>'1');
IF(ena='1')THEN
temp1(sel):
='0';
ENDIF;
x<=temp1;
ENDPROCESS;
ENDBehavioral;
仿真测试文件代码:
LIBRARYieee;
USEieee.std_logic_1164.ALL;
ENTITYdecorder4IS
ENDdecorder4;
ARCHITECTUREbehaviorOFdecorder4IS
--ComponentDeclarationfortheUnitUnderTest(UUT)
COMPONENTdecoder3
PORT(
ena:
INstd_logic;
sel:
INintegerrange0to7;
x:
OUTstd_logic_vector(7downto0)
);
ENDCOMPONENT;
--Inputs
signalena:
std_logic:
='0';
signalsel:
integer:
=0;
--Outputs
signalx:
std_logic_vector(7downto0);
--Noclocksdetectedinportlist.Replacebelowwith
--appropriateportname
BEGIN
--InstantiatetheUnitUnderTest(UUT)
uut:
decoder3PORTMAP(
ena=>ena,
sel=>sel,
x=>x
);
--Stimulusprocess
stim_proc:
process
begin
--holdresetstatefor100ns.