测量频率及占空比的频率计设计Word下载.docx
《测量频率及占空比的频率计设计Word下载.docx》由会员分享,可在线阅读,更多相关《测量频率及占空比的频率计设计Word下载.docx(29页珍藏版)》请在冰点文库上搜索。
但是,在本设计中,频率测量范围较小,量程划分也简单,所以,我选方案1进行设计。
方案一原理图:
方案二原理图:
(3)实验相关电路原理:
(1)设计原理:
a测频率:
数字频率计的核心是电子计数器。
电子计数器可以对脉冲数目进行累加运算,能把任意一段时间内的脉冲总数计算出并由数码管显示出来。
如某个时间间隔t内对周期性信号的累加计数值为N,则信号频率f为f=N/t
。
因此,首先应将被测信号变成周期性的脉冲,脉冲形成电路就是起这个作用,其脉冲的重复频率等于被测信号频率。
脉冲形成后将它加到闸门电路的一个输入端A,闸门电路就是用来控制开和关的一种电路,当具有标准时间的闸门脉冲到达时,闸门便开启,允许由A进入的脉冲通过;
闸门脉冲结束后,闸门便关闭,信号就不能通过。
闸门开启时通过的脉冲送到电子计数器进行计数,由装在面板上的数码管显示出来。
例如,时基信号的作用时间为1秒,闸门电路将打开1秒,若在这段时间内通过闸门电路的脉冲数目为1000个,则被测信号的频率就是1000Hz。
b测占空比:
测占空比有很多种方法,本设计采用多周期测量法其测量原理是:
预置的时间和被测信号同时输入到同步电路,在同步电路输出端得到一个与被测信号同步的闸门信号。
基准信号同时控制两个闸门的开启和关闭。
在相同的闸门开启时间内,两个计数器分别对被测信号的通过的高电平和低电平个数进行计数,对得出的结果做运算,得到的结果即为被测信号的占空比。
(2)超高速A/D、D/A板GW_ADDA说明:
GW_ADDA板含两片10位超高速DAC(转换速率最高150MHz)和一片8位ADC(转换速率最高50MHz),另2片3dB带宽大于260MHz的高速运放组成变换电路。
GW_ADDA板上所有的A/D和D/A全部处于使能状态,除了数据线外,任一器件的控制信号线只有时钟线,这有利于高速控制和直接利用MATLAB/DSPBuilder工具的设计。
GW_ADDA板上工作时钟必须由FPGA的I/O口提供,且DAC和ADC的工作时钟是分开的。
无法直接利用MATLAB和DSPBuilder进行自动流程的设计,优点是时钟频率容易变化,且可通过Cyclone中的PLL的到几乎任何时钟频率。
由此即可测试ADC和DAC的最高转换频率。
两个电位器可分别调协两个D/A输出的幅度(输出幅度峰峰值不可大于5V,否则波形失真);
模拟信号从接插口的2针“AIN”输入,J1和J2分别是模拟信号输出的PA、PB口,也可在两挂钩处输出,分别是两个10位DA5651输出口。
注意,使用A/D,D/A板必须打开GW48-PK2主系统板上的+/-12V电源,用后关闭!
三、电路图及设计文件:
(1)系统电路图:
(2)系统的RTL级描述:
(3)系统的引脚锁定图
(4)程序源代码:
libraryieee;
--输入信号模块
useieee.std_logic_1164.all;
entitycompis
port(signl:
instd_logic_vector(7downto0);
fout:
outstd_logic);
endcomp;
--signl为信号发生器产生的信号
architectureoneofcompis
begin
process(signl)
begin
if(signl>
"
00000000"
)then--判断输入信号不为0
fout<
='
1'
;
--fout为以后电路的门
else--信号
0'
endif;
endprocess;
endone;
--自动切换量程模块
useieee.std_logic_unsigned.all;
useieee.std_logic_arith.all;
entitycornais
port(clr,fin,en,key2,rst:
instd_logic;
ranin:
instd_logic_vector(15downto0);
alm:
outstd_logic;
dis_out:
bufferstd_logic_vector(15downto0));
endcorna;
architectureoneofcornais
signalc0,c1,c2,c3,c4:
std_logic_vector(3downto0);
p1:
process(en,fin)
ifrst='
thenalm<
elsifclr='
then
c0<
="
0000"
c1<
c2<
c3<
c4<
elsiffin'
eventandfin='
ifen='
ifc0<
1001"
then
c0<
=c0+1;
else
c0<
ifc1<
c1<
=c1+1;
else
ifc2<
c2<
=c2+1;
else
c2<
ifc3<
c3<
=c3+1;
ifc4<
0001"
c4<
=c4+1;
else
c4<
1111"
c2<
c1<
--超过量程2KHZ时会报警,并
alm<
--且数码管显示为”FFFF”
endif;
endif;
endif;
endif;
else
c4<
c3<
c2<
c1<
alm<
endif;
endprocessp1;
p2:
process(key2,ranin,c4)
ifkey2='
dis_out<
=ranin;
--若key2有效,则输出为占空比,否
elsifc4/="
then--则为显示频率
=c4&
c3&
c2&
c1;
--c4不为“0000”时,量程最低位为
else--10HZ,记频率范围为0-2KHZ,c4为
=c3&
c1&
c0;
--“0000”时,量程最低位为1HZ,记
--频率范围为0-9999HZ
endprocessp2;
endone;
--记低电平个数木块
entitycount1is
port(enl,clr,clk0:
loout:
bufferintegerrange1to600000);
endcount1;
architectureoneofcount1is
process(enl,clr,clk0)
ifclr='
loout<
=1;
elsif(clk0'
eventandclk0='
)then
ifenl='
then--当输入信号有效时,在clk0
loout<
=loout+1;
--上升沿来临时,记下低电
--平个数
--记高电平个数模块
entitycount2is
port(enh,clr,clk0:
hiout:
endcount2;
architectureoneofcount2is
process(enh,clr,clk0)
then--clk0为实验板自带的12MHZ
hiout<
--信号
ifenh='
hiout<
=hiout+1;
--上升沿时记下高电平的个
--数
--控制模块一
entityctrlis
port(clk2:
rst,load:
en:
bufferstd_logic);
endctrl;
architectureoneofctrlis
process(clk2,en)
begin--clk2为试验箱自带的1HZ信号
ifclk2'
eventandclk2='
en<
=noten;
--以clk2二分频产生相反的en,rst
--信号,用来作为自动切换量程模块
ifclk2='
anden='
rst<
--的使能信号和复位信号
rst<
load<
--对en取反得到load,作为锁存器模块
--的允许锁存信号
--控制模块二
entityctrl1is
port(fin:
enl:
bufferstd_logic;
clr,load:
endctrl1;
architectureoneofctrl1is
signalct:
std_logic;
process(fin,enl,ct)
iffin'
ct<
=(notct);
iffin='
andct='
clr<
--clr为记低电平模块的复位信号
else
ifct='
andfin='
enl<
--enl为记高电平模块的使能信号
load<
--load为计算占空比模块的门控信号
--控制模块三
entityctrl2is
enh:
clr:
endctrl2;
architectureoneofctrl2is
std_logic;
process(fin,enh,ct)
--clr为记高电平模块的复位信号
enh<
--enh为记高电平模块的使能信号
--译码显示模块
entitydispis
port(key2,clk0:
ran:
dataout:
outstd_logic_vector(15downto0));
enddisp;
architectureoneofdispis
process(key2,clk0)
ifclk0'
if(key2='
)then--key2有效时,把计算的占空比
dataout<
=ran&
--输出显示
--锁存器模块
entityreg16is
port(load:
datain:
dataout:
endreg16;
architectureoneofreg16is
process(load)
ifload'
eventandload='
dataout<
=datain;
--锁存要输出的信息
endone;
--计算占空比模块
entityslovis
high,low:
inintegerrange1to600000;
ran:
outstd_logic_vector(7downto0));
endslov;
architectureoneofslovis
signala,b:
integerrange0to9;
signalranh,ranl:
process(high,low)
begin--计算占空比
a<
=(high*10)/(high+low);
b<
=((high*10)rem(high+low))*10/(high+low);
process(a,b)
begin--把计算出来的占空比转换输出
ranh<
=conv_std_logic_vector(a,4);
ranl<
=conv_std_logic_vector(b,4);
ran<
=ranh&
ranl;
--整形模块
entityzhengxingis
port(clk0,a:
q:
endzhengxing;
architectureoneofzhengxingis
process(clk0)
q<
=a;
--对输入信号进行整形
--顶层文件
entitydivis
port(clk0,clk2,key2,rst:
signl:
data:
enddiv;
--各个模块的元件例化声明
architectureoneofdivis
componentcompis
fout:
endcomponent;
componentzhengxingis
q:
componentctrlis
rst,load:
endcomponentctrl;
componentreg16is
datain:
componentctrl1is
enl:
clr,load:
componentctrl2is
enh:
clr:
componentcount1is
outintegerrange1to600000);