fn<='0';
else
fn<='1';
endif;
endprocess;
endBehavioral;
3、计时器
编写实验代码如下:
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
useIEEE.STD_LOGIC_ARITH.ALL;
useIEEE.STD_LOGIC_UNSIGNED.ALL;
entityjsqis
Port(clk:
inSTD_LOGIC;
start:
inSTD_LOGIC;
stop:
inSTD_LOGIC;
reset:
inSTD_LOGIC;
digit1:
outSTD_LOGIC_VECTOR(6downto0);
digit2:
outSTD_LOGIC_VECTOR(6downto0);
digit3:
outSTD_LOGIC_VECTOR(6downto0));
endjsq;
architectureBehavioralofjsqis
begin
process(clk,start,stop,reset)
variabletemp1:
integerrange0to10;
variabletemp2:
integerrange0to6;
variabletemp3:
integerrange0to10;
begin
if(reset='1')then
temp1:
=0;
temp2:
=0;
temp3:
=0;
elsif(clk'eventandclk='1'andstart='1'andstop='0')then
temp1:
=temp1+1;
if(temp1=10)then
temp2:
=temp2+1;
temp1:
=0;
if(temp2=6)then
temp3:
=temp3+1;
temp2:
=0;
if(temp3=10)then
temp3:
=0;
endif;
endif;
endif;
endif;
casetemp1is
when0=>digit1<="1111110";
when1=>digit1<="0110000";
when2=>digit1<="1101101";
when3=>digit1<="1111001";
when4=>digit1<="0110011";
when5=>digit1<="1011011";
when6=>digit1<="1011111";
when7=>digit1<="1110000";
when8=>digit1<="1111111";
when9=>digit1<="1111011";
whenothers=>null;
endcase;
casetemp2is
when0=>digit2<="1111110";
when1=>digit2<="0110000";
when2=>digit2<="1101101";
when3=>digit2<="1111001";
when4=>digit2<="0110011";
when5=>digit2<="1011011";
when6=>digit2<="1011111";
whenothers=>null;
endcase;
casetemp3is
when0=>digit3<="1111110";
when1=>digit3<="0110000";
when2=>digit3<="1101101";
when3=>digit3<="1111001";
when4=>digit3<="0110011";
when5=>digit3<="1011011";
when6=>digit3<="1011111";
when7=>digit3<="1110000";
when8=>digit3<="1111111";
when9=>digit3<="1111011";
whenothers=>null;
endcase;
endprocess;
endBehavioral;
4、密度编码器
编写实验代码如下:
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
useIEEE.STD_LOGIC_ARITH.ALL;
useIEEE.STD_LOGIC_UNSIGNED.ALL;
entitymiduis
Port(din:
inSTD_LOGIC_VECTOR(7downto1);
dout:
outSTD_LOGIC_VECTOR(7downto0));
endmidu;
architectureBehavioralofmiduis
begin
process(din)
variabletemp:
integerrange0to7;
begin
temp:
=0;
foriindin'rangeloop
if(din(i)='1')then
temp:
=temp+1;
endif;
endloop;
casetempis
when0=>dout<="00000001";
when1=>dout<="00000010";
when2=>dout<="00000100";
when3=>dout<="00001000";
when4=>dout<="00010000";
when5=>dout<="00100000";
when6=>dout<="01000000";
when7=>dout<="10000000";
endcase;
endprocess;
endBehavioral;
5、数据时延
libraryIEEE;
useIEEE.STD_LOGIC_1164.ALL;
useIEEE.STD_LOGIC_ARITH.ALL;
useIEEE.STD_LOGIC_UNSIGNED.ALL;
entityshujushiyanis
Port(d:
inSTD_LOGIC_VECTOR(3downto0);
clk:
inSTD_LOGIC;
sel:
inintegerrange1to4;
q:
outSTD_LOGIC_VECTOR(3downto0));
endshujushiyan;
architectureBehavioralofshujushiyanis
signalinternal:
std_logic_vector(15downto0):
=(others=>'0');
signalq1:
std_logic_vector(3downto0):
=(others=>'0');
signalq2:
std_logic_vector(3downto0):
=(others=>'0');
signalq3:
std_logic_vector(3downto0):
=(others=>'0');
signalq4:
std_logic_vector(3downto0):
=(others=>'0');
begin
process(d,clk,sel)
begin
if(clk'eventandclk='1')then
q1<=d;
q2<=q1;
q3<=q2;
q4<=q3;
endif;
endprocess;
q<=q1whensel=1else
q2whensel=2else
q3whensel=3else
q4;
endBehavioral;
实验结果及分析:
1、优先级编码器
(1)使用IF语句得到仿真结果如下:
分析:
根据图中信息,使用IF语句输出结果指出了输入矢量从高位开始出现第一个‘1’的位置‘若输入矢量中没有‘1’,则输出‘000’,满足要求。
(2)使用CASE语句得到仿真结果如下:
分析:
根据图中信息,同上,使用CASE语句输出结果指出了输入矢量从高位开始出现第一个‘1’的位置,若输入矢量中没有‘1’,则输出‘000’,满足要求。
2、通用分频器:
得到的2分频结果如下:
分析:
由于在process(clk)里面用的是clk’eventandclk=’0’,所以只能出现偶数分频,上图是二分频的仿真结果。
3、计时器
仿真结果如下:
分析:
在第一个上升沿来临时,start=’1’,stop=’0’,reset=’0’,开始计数,应计时到0:
01;在第三个上升沿来临时,reset=’1’,所以复位,全部置0;第五个上升沿来临时,stop=’1’,所以暂停计时一个周期,之后继续计时;在第七个上升沿来临时,start=’0’,跟stop类似,暂停计时一个周期,之后继续计时。
由于对ISE的功能了解不全面,时钟周期未能设置为1S(当设置为1S时,仿真结果有误)。
若把时钟周期看为1S,则符合要求。
4、密度编码器
分析:
由图观察,当输入矢量din中出现n个’1’时,那么输出矢量dout(n)=’1’,dout(m)=’0’
(m≠n),满足要求。
5、数据时延
分析:
sel=2时,输出信号延后输入信号两个周期,与要求一致。
寄存器分析:
由程序可知,当clk为上升沿时,q1、q2、q3、q4分别同时被赋值,所以理论上应产生4个寄存器,实验编译后实际产生的寄存器如下图:
可知,程序编译产生了4个寄存器,与理论分析符合。
实验心得
1、写程序要戒骄戒躁,不可急于求成。
2、写的程序有时候在仿真的时候可能会与书上的不一样,这时需要好好分析,不能尽信书。
指导教师批阅意见:
成绩评定:
指导教师签字:
年月日
备注:
注:
1、报告内的项目或内容设置,可根据实际情况加以调整和补充。
2、教师批改学生实验报告时间应在学生提交实验报告时间后10日内。