脉冲信号发生器摘要:本实验是采用fpga方式基于Alter Cyclone2 EP2C5T144C8的简易脉冲信号发生器,可以实现输出一路周期1us到10ms,脉冲宽度:0.1us到周期-0.1us,时间分辨率为0.1us的脉冲信号,并且还能输出一路正弦信号(与脉冲信号同时输出)。
输出模式可分为连续触发和单次手动可预置数(0~9)触发,具有周期、脉宽、触发数等显示功能。
采用fpga计数实现的电路简化了电路结构并提高了射击精度,降低了电路功耗和资源成本。
关键词:FPGA;脉冲信号发生器;矩形脉冲;正弦信号;1 方案设计与比较脉冲信号产生方案:方案一、采用专用DDS芯片的技术方案:目前已有多种专用DDS集成芯片可用,采用专用芯片可大大简化系统硬件制作难度,部数字信号抖动小,输出信号指标高;但专用芯片控制方式比较固定,最大的缺点是进行脉宽控制,测量困难,无法进行外同步,不满足设计要求。
方案二、单片机法。
利用单片机实现矩形脉冲,可以较方案以更简化外围硬件,节约成本,并且也可以实现灵活控制、能产生任意波形的信号发生器。
但是单片机的部时钟一般是小于25Mhz,速度上无法满足设计要求,通过单片机产生脉冲至少需要三条指令,所需时间大于所要求的精度要求,故不可取。
方案二:FPGA法。
利用了可编程逻辑器件的灵活性且资源丰富的特点,通过Quartus 软件的设计编写,实现脉冲信号的产生及数控,并下载到试验箱中,这种方案电路简单、响应速度快、精度高、稳定性好故采用此种方案。
2 理论分析与计算脉冲信号产生原理:输入量周期和脉宽,结合时钟频率,转换成两个计数器的容量,用来对周期和高电平的计时,输出即可产生脉冲信号。
脉冲信号的精度保证:时间分辨率0.1us,周期精度:+0.1%+0.05us,宽度精度:+0.1%+0.05us,为满足精度要求,所以所选时钟频率至少1/0.05us=20MHZ,由于试验箱上大于10MHZ只有50MHZ,故选时钟信号50MHZ,此时精度1/50MHZ=0.02us<0.05us,满足精度要求。
正弦信号产生原理:正弦信号的产生由DDS原理实现,频率由频率控制字M和时钟周期Fc决定,M=Fout*2^N/Fc,Fout=1/T,N即为相位累加器的位数,化简锝M=2^N/(5*T),即说明可以通过输入量周期控制正弦的频率,与脉冲达到同周期。
3程序设计3.1 系统框图如图3-1所示。
图3-1 系统框图按键输入模块:通过不同的按键切换周期和脉宽、高低位输入数据。
(vhdl语言见附录1)图3-2 按键输入模块显示模块:采用查询ROM表的方法,二进制数值通过一个ROM表显示为十进制数值,在数码管上显示。
(Vhdl及rom表见附录2)图3-3 显示模块高低电平计数模块:计数器接时钟脉冲50MHZ,即每次计数0.02us,5次计数为0.1us,即为实验要求的时间精度0.1us,通过置入周期和脉宽放大5倍(周期和脉宽均以0.1us为单位)便可产生高低脉冲信号。
(Mk模块vhdl见附录三)图3-4 脉冲信号产生模块正弦信号产生模块:由DDS原理产生,频率控制字M=Fout*2^N/Fc,Fout=1/T,N即为相位累加器的位数,化简得M=2^N/(5*T),再通过相位累加器查找正弦ROM表,便可产生正弦信号,正弦信号的周期即为T,与脉冲信号同周期。
(reg29、dm1、正弦rom见附录四)图3-5正弦信号产生模块整体电路连接:(见附录五)4 作品测试4.1 测试仪器TDS1002型60MHZ1 0GS/s双通道数字存储示波器,系统试验箱。
4.2 测试方案控制时钟:50MHz按键操作:Key1:十分位、百位计数使能;Key2:个位、千位计数使能;key3:十位、万位计数使能;key4:高三位低三位切换;key5:脉宽、周期切换;key6:脉宽周期输入脉冲;Key7:猝发脉冲计数按键;key8:系统清零键;key3与key2同时按下切换至单猝发方式;key3、2、1同时按下但猝发脉冲发射。
测试方法:按键输入脉宽和周期,经过示波器观察测量正弦和脉冲周期以及脉宽,记录数据制4.3表格,切换猝发方式后继续用示波器进行单猝发计数测试。
4.3 测试结果输入周期输入脉宽显示脉宽脉宽误差显示周期周期误差上升时间正弦周期幅度猝发模式状态下输入数据N,示波器显示输出N个脉冲和正弦信号;波形图见附录6 4.4 结果分析系统在输出脉冲脉宽、周期和正弦波以及猝发脉冲等指标达到题目的基本和发挥部分要求,各项指标测量精度高,整体性能达到题目发挥部分要求。
5 总结本系统以fpga作为系统的核心控制器件,以系统试验箱为平台,具有1us-10ms的方波脉冲发生和正弦脉冲发生功能,同时具有1-9固定数量脉冲单猝发功能,具有精度较高速度快的特点,所有指标均达到或部分超过赛题要求。
附录附件1:按键输入模块library ieee;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_1164.all;entity xianshi isport(cp,change,clr,hl,aj1,aj2,aj3:in std_logic;zq,mk:out std_logic_vector(16 downto 0));end xianshi;architecture one of xianshi issignal m:std_logic_vector(16 downto 0);signal n:std_logic_vector(16 downto 0);beginprocess(cp,change,clr,hl,aj1,aj2,aj3)beginif clr='1'thenm<="00000000000000000"; n<="00000000000000000";elsif cp'event and cp='1' thenif change='0'and hl='0'thenif aj1='1'then m<=m+1;end if;if aj2='1'then m<=m+10;end if;if aj3='1'then m<=m+100;end if;end if;if change='0'and hl='1'thenif aj1='1'then m<=m+1000;end if;if aj2='1'then m<=m+10000;end if;if aj3='1'then m<=m+100000;end if;end if;if change='1'and hl='0'thenif aj1='1'then n<=n+1;end if;if aj2='1'then n<=n+10;end if;if aj3='1'then n<=n+100;end if;end if;if change='1'and hl='1'thenif aj1='1'then n<=n+1000;end if;if aj2='1'then n<=n+10000;end if;if aj3='1'then n<=n+100000;end if;end if;end if;zq<=m;mk<=n;end process;end one;附件2:library ieee;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_1164.all;entity chg isport(change:in std_logic;zq,mk:in std_logic_vector(16 downto 0);xs:out std_logic_vector(16 downto 0));end chg;architecture one of chg isbeginprocess(change)beginif change='0'thenxs<=zq;elsexs<=mk;end if;end process;end one;library ieee;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_1164.all;entity hhll isport(hl:in std_logic;h:in std_logic_vector(16 downto 0);l:in std_logic_vector(9 downto 0);xxss:out std_logic_vector(9 downto 0)); end hhll;architecture one of hhll isbeginprocess(hl)beginif hl='0'thenxxss<=l;elsexxss<=h(9 downto 0);end if;end process;end one;显示rom表附件3:mklibrary ieee;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_1164.all;entity mk isport(clk:in std_logic;t,k:std_logic_vector(19 downto 0); f:out std_logic);end mk;architecture one of mk issignal m:std_logic_vector(19 downto 0); beginprocess(clk,t,m)beginif clk'event and clk='1'thenm<=m+1;if m>=t thenm<="00000000000000000001";f<='0'; elsif m<=k thenf<='1';else f<='0';end if;end if;end process;end one;附件4:Reg29library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity reg29 isport(d:in std_logic_vector(31 downto 0);clk:in std_logic;q:out std_logic_vector(31 downto 0));end reg29;architecture one of reg29 isbeginprocess(clk,d)beginif clk'event and clk='1' thenq<=d;end if;end process;end one;dm1library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity dm1 isport(q:in std_logic_vector(9 downto 0);si:in std_logic_vector(16 downto 0);f:out std_logic_vector(9 downto 0));end dm1;architecture one of dm1 isbeginprocess(si,q)beginif si="00000000000000000" then f<="0000000000"; else f<=q;end if;end process;end one;正弦rom附件五:。