《基于FPGA的相位差测量模块的设计》由会员分享,可在线阅读,更多相关《基于FPGA的相位差测量模块的设计(24页珍藏版)》请在金锄头文库上搜索。
1、基于 FPGA 的相位差测量模块的设计相位差测量设计思路相位差测量设计要求基于FPGA设计一个测量两路同频率信号相位差的模块,具体要求如下: 测量信号频率范围: 20Hz 20kHz ,精度:2度,测量波形: 方波。自行设计相位差可控双路输出脉冲源作为被测对象。发挥部分:(1)相位差和频率交替显示或同时显示(2)提高测量精度(3)拓宽频率范围到20Hz200kHz(4)设计出一套相位计前置整形电路方案(采用模拟电路或者模数混合,仅设计和仿真,不制作) ,要求能自适应峰峰值在0.2V至5伏的非方波输入信号,尽量减少两路输入信号幅度不一致引入的误差,带宽不小于20Hz20kHz,输出信号能接入本课
2、题设计的相位差测量模块。相位差测量设计方案根据题目要求,我们组把这个模块的设计分为四个子模块,分别为:信号源的发生、频率计的设计、相位差的测量和四位 LED 相位差显示。信号源的发生产生两路同频、相位差可控的信号;频率计的设计是借用信号源产生的信号,然后根据内部晶振产生闸门宽度为 1 秒的闸门信号,在高电平时开始计数,记得的周期个数,即信号源产生信号的频率;相位差的测量是先通过测量两路信号的上升沿之间内部晶振的周期数,然后由此周期数换算出相位差,再通过 VHDL 语言内部函数转换成十进制数输出到显示模块。RTL 图如下:模块程序LIBRARY IEEE;USE IEEE.STD_LOGIC_1
3、164.ALL;USE IEEE.STD_LOGIC_UNSIGNED.ALL;ENTITY kzys ISPORT ( CLK : IN STD_LOGIC;KG : IN STD_LOGIC;ZS : IN NATURAL;KG_OUT: OUT STD_LOGIC );END entity kzys;ARCHITECTURE one OF kzys ISSIGNAL CNT: NATURAL;BEGIN PROCESS(KG,CLK)BEGINIF KG=0 THEN CNTf_out1f_out1f_out1f_out1f_out1f_out1f_out1f_out1f_out1f_o
4、ut1f_out1f_out1f_out1f_out1f_out1f_out1f_out10 THENCNT8:=CNT8-1;ELSECNT8 :=ZS;FULL 0 THENCNT8:=CNT8-1;ELSECNT8 :=ZS;FULL sw_1,f_out1=a,y_out2=b);u2:kzys port map(zs=b,clk=clk,kg=kg,kg_out=c);u3: plfsqy port map(clk=clk,ZS=a, KG=C,F_OUTY=F_OUTY);u4: plfsq port map(clk=clk,ZS=a,KG=KG,F_OUT=F_OUT);END
5、ARCHITECTURE qq;library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;entity cnt10 isport(clk,en,clr:in std_logic;count10:buffer integer range 0 to 400000000);end cnt10;architecture art of cnt10 isbeginprocess(clk,clr,en)beginif clr=1thencount10 5 then cnt := 0;qwave1,en=en1,clr=c
6、lr1,count10=date);end art;library IEEE;use IEEE.STD_LOGIC_1164.ALL;use IEEE.STD_LOGIC_ARITH.ALL;use IEEE.STD_LOGIC_UNSIGNED.ALL;entity measure_n isPort( clk,clk0,clk1:in std_logic;n_out:out std_logic_vector(15 downto 0);end measure_n;architecture art of measure_n issignal count0,count01,count02,coun
7、t1,count2 : std_logic_vector(15 downto 0);signal x,y,a,clk10,clk11,clk20,clk21: std_logic;beginprocess(clk,clk0,clk1,x,y,count1,count2)beginif clkevent and clk=1thencase a iswhen 0=clk100);end if;if clk10=0thenxclk200);end if;if clk20=0thenxaclkin,clk0=clk0in,clk1=clk1in,n_out=d);u2: freq_measure po
8、rt map(clk0=clkin,wave1=clk0in,q=e);u3: consider1 port map(clk=clkin,n1=d,freq=8192,cout=f);u4: count port map(clk=clkin,c_in=f,qa1=qa1out,qb1=qb1out,qc1=qc1out,qd1=qd1out);end art;四位 LED 相位差显示:LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY BCD7 ISPORT(BCD:IN INTEGER RANGE 0 TO 9;LED:OUT STD_LOGIC_
9、VECTOR(6 DOWNTO 0);END;ARCHITECTURE ART OF BCD7 ISBEGINLED= 0111111WHEN BCD= 0 ELSE0000110WHEN BCD= 1 ELSE1011011WHEN BCD= 2 ELSE1001111WHEN BCD= 3 ELSE1100110WHEN BCD= 4 ELSE1101101WHEN BCD= 5 ELSE1111101WHEN BCD= 6 ELSE0000111WHEN BCD= 7 ELSE 1111111WHEN BCD= 8 ELSE1101111WHEN BCD= 9 ELSE0000000;E
10、ND ART;LIBRARY IEEE;USE IEEE.STD_LOGIC_1164.ALL;ENTITY Vhdl1 ISPORT(LOCK:IN STD_LOGIC;QA,QB,QC,QD:IN INTEGER RANGE 0 TO 9;LEDA,LEDB,LEDC,LEDD:OUT STD_LOGIC_VECTOR(6 DOWNTO 0);END;ARCHITECTURE ART OF Vhdl1 ISSIGNAL QAL,QBL,QCL,QDL:INTEGER RANGE 0 TO 9;COMPONENT BCD7PORT(BCD:IN INTEGER RANGE 0 TO 9;LED:OUT STD_LOGIC_VECTOR(6 DOWNTO 0);END COMPONENT;BEGINPROCESS(LOCK)BEGINIF(LOCKEVENT AND LOCK=1)THEN QAL=QA;QBL=QB;QCL=QC;QDL=QD;END IF;END PROCESS;U1:BCD7 PORT MAP(QAL,LEDA);U2:BCD7 PORT MAP(QBL,LEDB);U3:BCD7 PORT MAP(QCL,LEDC);U4:BCD7 PORT MAP(QDL,LEDD);END ART;