VHDL第3次作业题目 数字频率计.docx
- 文档编号:3812260
- 上传时间:2022-11-25
- 格式:DOCX
- 页数:19
- 大小:204.62KB
VHDL第3次作业题目 数字频率计.docx
《VHDL第3次作业题目 数字频率计.docx》由会员分享,可在线阅读,更多相关《VHDL第3次作业题目 数字频率计.docx(19页珍藏版)》请在冰豆网上搜索。
VHDL第3次作业题目数字频率计
西安电子科技大学
VHDL数字系统设计与测试作业
题目数字频率计
学院电子工程学院
专业电子与通信工程
学号
学生姓名
授课教师钟桦
撰写日期:
2015年6月9日
数字频率计
题目要求:
1.用VHDL完成12位十进制数字频率计的设计及仿真。
2.频率测量范围:
1Hz∼10KHz,分成两个频段,即1∼999Hz,1KHz∼10KHz,用三位数码管显示测量频率,用LED显示表示单位,如亮绿灯表示Hz,亮红灯表示KHz。
3.具有自动校验和测量两种功能,即能用标准时钟校验、测量精度。
4.具有超量程报警功能,在超出目前量程档的测量范围时,发出灯光和音响信号。
问题分析:
测量频率的基本原理是在单位时间内检测信号的脉冲个数,计数器对CP1信号进行计数,在1秒定时结束后,将计数器结果送锁存器锁存,同时将计数器清零,为下一次采样测量做好准备。
根据题目要求,将系统分为以下几个模块:
1、测量/校验选择模块(selett)
2、测频控制信号发生器(二分频)(fenpin)
3、与电路模块(andd)
4、计数器模块(counter)
5、送存选择、报警模块(tostore)
6、锁存模块(lockstore)
7、扫描显示模块(scann)
通过以上分析,给出各模块程序代码,并对各个模块进行分别叙述说明。
1、测量/校验选择模块(selett)
输入信号:
选择信号selet
被测信号meas
测试信号test
输出信号:
cp1
当selet=0时,为测量状态,cp1=meas;当selet=1时,为校验状态,cp1=test。
校验与测量共用一个电路,只是被测信号cp1不同而已。
--测量/校验选择
libraryieee;
useieee.std_logic_1164.all;
entityselettis
port(selet,test,meas:
instd_logic;
cp1:
outstd_logic);
endselett;
architecturebehvofselettis
--typestatetypeis(meas,test);
--signalpresent_state,next_state:
statetype:
=meas;
begin
process(selet)
begin
caseseletis
when'1'=>cp1<=test;
when'0'=>cp1<=meas;
whenothers=>cp1<=null;
endcase;
endprocess;
endbehv;
仿真验证其正确性
从上图可以看出,当selet=0时,cp1输出信号为meas,当selet=1时,输出
信号为test,符合设计要求。
2、测频控制信号发生器(二分频)(fenpin)
输入信号:
1HZ时钟信号(clk)
输出信号:
1秒定时信号(周期为2秒)(clk_out)
此模块实际上就是一个二分频的计数器,代码如下:
--分频
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityfenpinis
port(clk:
instd_logic;
clk1:
outstd_logic);
endfenpin;
architecturebehavoffenpinis
begin
process(clk)
variablecount:
integer:
=1;
begin
if(clk'eventandclk='1')then
ifcount=1then
count:
=0;clk1<='1';
else
count:
=count+1;clk1<='0';
endif;
endif;
endprocess;
endbehav;
仿真验证其正确性
由仿真结果可以看出,二分频电路正确,符合设计要求。
3、与电路模块(andd)
输入信号:
二分频时钟(clk2),测量/校验选择模块输出信号(cp2)
输出信号:
与信号(cp)
代码如下:
--与电路
libraryieee;
useieee.std_logic_1164.all;
entityanddis
port(clk2,cp2:
instd_logic;
cp:
outstd_logic);
endandd;
architecturebehvofanddis
begin
cp<=clk2andcp2;
endbehv;
仿真验证其正确性
由仿真结果可以看出,与电路正确,符合设计要求。
4、计数器模块(counter)
由题目要求,计数的范围应该是0000-9999,因此,计数器模块的内部应由四个十进制计数器q4,q3,q2,q1组成。
另外,由于系统设置了溢出信号c。
输入信号:
计数时钟(cp)。
片选信号(rd)
输出信号:
计数输出信号千位:
q4,百位:
q3,十位:
q2,个位:
q1
溢出信号:
c
代码如下
--计数
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitycounteris
port(rd,cp:
instd_logic;
c:
outstd_logic;
q4,q3,q2,q1:
outstd_logic_vector(3downto0));
endcounter;
architecturebehvofcounteris
signalc1,c2,c3,c4:
std_logic;
begin
cnt1:
process(rd,cp)
variablecn1:
std_logic_vector(3downto0);
begin
ifrd='1'then
ifcp'eventandcp='1'then
ifcn1="1001"then
cn1:
="0000";c1<='1';
else
cn1:
=cn1+1;c1<='0';
endif;
endif;
endif;
q1<=cn1;
endprocesscnt1;
cnt2:
process(c1,rd)
variablecn2:
std_logic_vector(3downto0);
begin
ifrd='1'then
ifc1'eventandc1='1'then
ifcn2="1001"then
cn2:
="0000";c2<='1';
else
cn2:
=cn2+1;c2<='0';
endif;
endif;
--else
--cn2:
="0000";--c2<='0';
endif;
q2<=cn2;
endprocesscnt2;
cnt3:
process(c2,rd)
variablecn3:
std_logic_vector(3downto0);
begin
ifrd='1'then
ifc2'eventandc2='1'then
ifcn3="1001"then
cn3:
="0000";c3<='1';
else
cn3:
=cn3+1;c3<='0';
endif;
endif;
endif;
q3<=cn3;
endprocesscnt3;
cnt4:
process(c3,rd)
variablecn4:
std_logic_vector(3downto0);
begin
ifrd='1'then
ifc3'eventandc3='1'then
ifcn4="1001"then
cn4:
="0000";c<='1';
else
cn4:
=cn4+1;c<='0';
endif;
endif;
endif;
q4<=cn4;
endprocesscnt4;
endbehv;
仿真验证其正确性
从仿真结果可以看出,rd=1时计数,rd=0时不计数。
设定rd的周期为1us,cp的周期为10ns,则在rd=1的时间内应该计数50次,从图中可以看出仿真结果符合预期。
5、送存选择、报警模块(tostore)
输入信号:
量程档控制开关(k)
四位十进制信号(qb4,qb3,qb2,qb1)
溢出信号输入(cc)
输出信号:
三位十进制信号(dd3,dd2,dd1)
报警信号(alert)
当k=0时,选择1-999Hz量程,输出信号为qb3,qb2,qb1,如果qb4>0,报警.
当k=1时,选择1K-10KHz量程,输出信号为qb4,qb3,qb2,如果c>0,报警。
代码如下:
--存送选择、报警电路
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitytostoreis
port(qb4,qb3,qb2,qb1:
instd_logic_vector(3downto0);
cc,k:
instd_logic;
dd3,dd2,dd1:
outstd_logic_vector(3downto0);
alert:
outstd_logic);
endtostore;
architecturebehvoftostoreis
begin
process(qb4,qb3,qb2,qb1,cc,k)
begin
ifk='0'then
dd3<=qb3;
dd2<=qb2;
dd1<=qb1;
ifqb4>"0000"orcc>'0'then
alert<='1';
else
alert<='0';
endif;
elsifk='1'then
dd3<=qb4;dd2<=qb3;dd1<=qb2;
ifcc>'0'then
alert<='1';
else
alert<='0';
endif;
else
alert<='0';
endif;
endprocess;
endbehv;
仿真验证其正确性
仿真中设定qb4=4,qb2=2,qb3=3,qb1=1,从仿真结果图中可以看出,当k=0时,dd3=qb3,dd2=qb2,dd1=qb1,应为qb4>0,所以报警信号alert=1;当k=1时,dd3=qb4,dd2=qb3,dd1=qb2,当cc=0时,报警信号alert=0,当cc>0时,报警,alert=1。
因此,仿真结果符合要求。
6、锁存模块(lockstore)
输入端口:
片选信号(ld)
量程选择开关(k)
输入数据(d3,d2,d1)
输出端口:
输出数据(data3,data2,data1)
绿灯(led_green)---表示单位hz
红灯(led_red)---表示单位Khz
代码如下
--锁存电路
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entitylockstoreis
port(ld,k:
instd_logic;
d3,d2,d1:
instd_logic_vector(3downto0);
data3,data2,data1:
outstd_logic_vector(3downto0);
led_green,led_red:
outstd_logic);
endlockstore;
architecturebehvoflockstoreis
begin
process(d3,d2,d1,ld,k)
begin
if(ld='1')then
data3<=d3;
data2<=d2;
data1<=d1;
ifk='0'then
led_green<='1';--led_green-->hz
led_red<='0';--led_red--Khz
else
led_green<='0';--led_green-->hz
led_red<='1';--led_red--Khz
endif;
endif;
endprocess;
endbehv;
仿真验证其正确性
片选信号ld=1时,data3=d3,data2=d2,data1=d1,当k=0时绿灯亮,选择的单位为hz;当k=1时,红灯亮,选择的单位为Khz。
所以,由上图可以,仿真结果符合要求。
7、扫描显示模块(scann)
此模块要完成三件事情:
(1)通过扫描时钟产生数码管扫描信号。
(2)显示小数点
(3)七段译码
由于显示的数码管要加上小数点,因此,要在译码产生的7位数之后加上一位point,point的值由k和扫描信号有关,当k=1,扫描信号=110时,point=1,其他情况都为0。
输入端口:
扫描时钟(clkk)
单位选择开关(k)
输入数据(d_3,d_2,d_1)
输出端口:
扫描信号(selout)
数码管(led)
小数点(point)
代码如下:
--扫描显示电路
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityscannis
port(clkk,k:
instd_logic;
d_3,d_2,d_1:
instd_logic_vector(3downto0);
--qq:
outstd_logic_vector(3downto0);
selout:
outstd_logic_vector(2downto0);
led:
outstd_logic_vector(6downto0);
point:
outstd_logic);
endscann;
architecturebehvofscannis
signalqq:
std_logic_vector(3downto0);
signalsel:
std_logic_vector(1downto0);
signalselout2:
std_logic_vector(2downto0);
--signalpoint1:
std_logic;
begin
p1:
process(clkk,d_3,d_2,d_1)
variablescannum:
std_logic_vector(1downto0);
variableqq1:
std_logic_vector(3downto0);
begin
ifclkk'eventandclkk='1'then
ifscannum="10"then
scannum:
="00";
else
scannum:
=scannum+1;
endif;
endif;
casescannumis
when"00"=>qq1:
=d_1;
when"01"=>qq1:
=d_2;
when"10"=>qq1:
=d_3;
whenothers=>qq1:
=null;
endcase;
sel<=scannum;
qq<=qq1;
endprocessp1;
p2:
process(sel)
variableselout1:
std_logic_vector(2downto0);
--variablescannum:
std_logic_vector(1downto0);
begin
--ifclkk'eventandclkk='1'then
--ifscannum="10"then
--scannum:
="00";
--else
--scannum:
=scannum+1;
--endif;
--endif;
caseselis
when"00"=>selout1:
="001";
when"01"=>selout1:
="010";
when"10"=>selout1:
="100";
whenothers=>selout1:
=null;
endcase;
selout2<=selout1;
endprocessp2;
selout<=selout2;
p3:
process(selout2,k)
begin
if(k='1'andselout2="100")then
point<='1';
else
point<='0';
endif;
endprocessp3;
p4:
process(qq)
begin
caseqqis
when"0000"=>led<="0111111"&point;
when"0001"=>led<="0000110"&point;
when"0010"=>led<="1011011"&point;
when"0011"=>led<="1001111"&point;
when"0100"=>led<="1100110"&point;
when"0101"=>led<="1101101"&point;
when"0110"=>led<="1111101"&point;
when"0111"=>led<="0000111"&point;
when"1000"=>led<="1111111"&point;
when"1001"=>led<="1101111"&point;
whenothers=>led<="0000000"&point;
endcase;
endprocessp4;
endbehv;
仿真验证其正确性
仿真设定输入d_1=4,d_2=5,d_3=6,从仿真结果可以看出扫描和译码正确;从图中可以看出只有当selout=100,k=1同时成立时,小数点才显示。
因此,仿真结果符合要求。
8、顶层模块
顶层模块代码
--topcircuitdescription
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityfreqcounteris
port(clk,clkk,meas,test,selet,k:
instd_logic;
led:
outstd_logic_vector(7downto0);
selout:
outstd_logic_vector(2downto0);
alert,led_green,led_red,point:
outstd_logic);
--clk1,cp1:
outstd_logic;
--dd3,dd2,dd1:
outstd_logic_vector(3downto0);
--data3,data2,data1:
outstd_logic_vector(3downto0);
--q4,q3,q2,q1:
outstd_logic_vector(3downto0));
endfreqcounter;
architecturebehvoffreqcounteris
signals1,s2,s3,s4:
std_logic;
signalsq1,sq2,sq3,sq4:
std_logic_vector(3downto0);
signalsd1,sd2,sd3:
std_logic_vector(3downto0);
signalsdd1,sdd2,sdd3:
std_logic_vector(3downto0);
signalsled:
std_logic_vector(3downto0);
componentfenpinis
port(clk:
instd_logic;
clk1:
outstd_logic);
endcomponentfenpin;
componentselettis
port(selet,test,meas:
instd_logic;
cp1:
outstd_logic);
endcomponentselett;
componentanddis
port(clk2,cp2:
instd_logic;
cp:
outstd_logic);
endcomponentandd;
componentcounteris
port(rd,cp:
instd_logic;
c:
outstd_logic;
q4,q3,q2,q1:
outstd_logic_vector(3downto0));
endcomponentcounter;
componenttostoreis
port(qb4,qb3,qb2,qb1:
instd_logic_vector(3downto0);
cc,k:
instd_logic;
dd3,dd2,dd1:
outstd_logic_vector(3downto0);
alert:
outstd_logic);
endcomponenttostore;
componentlockstoreis
port(ld,k:
instd_logic;
d3,d2,d1:
instd_logic_vector(3downto0);
data3,data2,data1:
outstd_logic_vector(3downto0);
led_green,led_red:
outstd_logic);
endcomponentlockstore;
componentscannis
port(clkk,k:
instd_logic;
d_3,d_2,d_1:
instd_logic_vector(3downto0);
selout:
outstd_logic_vector(2downto0);
led:
outstd_logic_vector(7downto0));
endcomponentscann;
beg
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VHDL第3次作业题目 数字频率计 VHDL 作业 题目