基于DDS的数字移相信号发生器 .doc
电子与电气工程系课程设计、专题(综合)实验报告课题名称_ 基于DDS的数字移相信号发生器 专 业_ 电子信息工程_ _ _ 班 级_1_ _ _ 学 号_ _ 姓 名_ _ _ 成 绩_ _ 指导教师_ _ _ 2010 年 12 月20-24日基于DDS的数字移相信号发生器一、课程设计目的1、进一步熟悉Quartus 的软件使用方法;2、熟悉利用VHDL设计数字系统并学习LPM ROM的使用方法;3、学习FPGA硬件资源的使用和控制方法;4、 掌握DDS基本原理,学习利用此原理进行信号发生器的设计二、设计任务1、 完成8位输出数据宽度的频率可调的移相正弦信号发生器。2、 完成8位输出数据宽度的移相三角波、方波信号发生器。3、波形发生器实现幅度可调。(注:任务1为基本要求,任务2、3为提高要求)三、数字DDS的逻辑电路图(顶层文件原理图)逻辑电路图四、工作原理及模块分析:直接数字频率合成器(DDS)是通信系统中常用到的部件,利用DDS可以制成很有用的信号源。与模拟式的频率锁相环PLL相比,它有许多优点,突出为(1)频率的切换迅速;(2)频率稳定度高。一个直接数字频率合成器由相位累加器、波形ROM、D/A转换器和低通滤波器构成。DDS的原理框图如下所示: 图 1 直接数字频率合成器原理图其中K为频率控制字, fc为时钟频率,N为相位累加器的字长,D为ROM数据位及D/A转换器的字长。相位累加器在时钟 fc的控制下以步长K作为累加,输出N位二进制码作为波形ROM的地址,对波形ROM进行寻址,波形ROM输出的幅码S(n)经D/A转换器变成梯形波S(t),再经低通滤波器平滑后就可以得到合成的信号波形了。合成的信号波形形状取决于波形ROM中存放的幅码,因此用DDS可以产生任意波形。本设计中直接利用D/A转换器得到输出波形,省略了低通滤波器这一环节。1、 频率预置与调节电路不变量K被称为相位增量,也叫频率控制字。DDS方程为:f0= fc K/2n,f0为输出频率,fc为时钟频率。当K=1时,DDS输出最低频率(也既频率分辩率)为fc /2nDDS的最大输出频率由 Nyguist 采样定理决定,即fc /2,也就是说K的最大值为2n-1.因此,只要N足够大,DDS可以得到很细的频率间隔。要改变DDS的输出频率,只要改变频率控制字K即可。2、 累加器相位累加器的原理图如下图 图 2 相位累加器原理图相位累加器由N为加法器与N位寄存器级联构成。每来一个时钟脉冲fc,加法器将频率控制字与寄存器输出的累加相位数据相加,再把相加后的结果送至寄存器的数据输入端,寄存器将加法器在上一个时钟作用后所产生的下数据反馈到加法器的输入端;以使加法器在下一个时钟作用下继续频率控制字进行相加。这样,相位累加器在时钟的作用下,进行相位累加,当相位累加器累加满量时,就产生一次溢出,完成一个周期性的动作,这个周期应为 uk= 2n / GCD(2N ;k),其中GCD表示最大公约数。3、波形存储器用相位累加器输出的数据作为波形存储器的取样地址进行波形的相位幅值转换,即可在给定的时间上确定输出的波形的抽样幅值。N位的寻址ROM相当于把00- 3600 的正弦信号离散成具有2n 样值的序列,若波形ROM有D位数据位,则2n个样值的幅值以D位二进制数值固化在ROM 中,按照地址的不同可以输出相宜相位的正弦信号的幅值。相位-幅值变换原理图如下所示。 图 3 相位-幅度变换原理图4、D/A转换器D/A转换器的作用是把已经合成的正弦波的数字量转换成模拟量,正弦幅度量化序列S(n)经D/A转换后变成了包络为正弦波的阶梯波S(t),S(t)的周期为T=uk*Tc.。需要注意的是,频率合成器对D/A转换器的分辨率有一定的要求,D/A转换器的分辨率越高,合成的正弦波S(t)台阶数就越多,输出 波形的精度也就越高。五、结果波形:三角波方波六、相关程序:注:1、 编写的顶层程序总是出现问题,最终选择运用原理图进行顶层的构建(原理图见“三、数字DDS的逻辑电路图(顶层文件原理图)”);2、 其他部分的程序分为加法器、寄存器、正弦信号发生器、方波信号发生器、三角波信号发生器、波形选择模块、调幅模块;3、 本例中,具体模块分析详见“四、工作原理及模块分析”。加法器:LIBRARY IEEE;USE _LOGIC_;USE _LOGIC_;ENTITY SUM IS PORT(K : IN STD_LOGIC_VECTOR( 2 DOWNTO 0); CLK : IN STD_LOGIC; RST : IN STD_LOGIC; WR : OUT STD_LOGIC; CS : OUT STD_LOGIC; OPT : OUT STD_LOGIC_VECTOR(7 DOWNTO 0);END ENTITY SUM;ARCHITECTURE BEHAV OF SUM IS SIGNAL TEM : STD_LOGIC_VECTOR(10 DOWNTO 0); BEGIN PROCESS(CLK ,RST) BEGIN IF RST = '1' THEN TEM<= "" ELSIF CLK'EVENT AND CLK='1' THEN TEM <= TEM + K; END IF; END PROCESS; OPT <= TEM(10 DOWNTO 3) ;WR <= '0' CS <= '0' END ARCHITECTURE BEHAV;寄存器:LIBRARY IEEE;USE _LOGIC_;ENTITY REG ISPORT (D:IN STD_LOGIC_VECTOR(7 DOWNTO 0);CLK:IN STD_LOGIC;Q:OUT STD_LOGIC_VECTOR(7 DOWNTO 0);END ENTITY REG;ARCHITECTURE BEHAV OF REG ISBEGIN PROCESS (CLK) BEGINIF CLK'EVENT AND CLK='1' THEN Q<=D; END IF; END PROCESS;END ARCHITECTURE BEHAV;正弦波发生器:LIBRARY ieee;USE _logic_;LIBRARY altera_mf;USE altera_mf.all;ENTITY sin_rom ISPORT(address: IN STD_LOGIC_VECTOR (7 DOWNTO 0);clock: IN STD_LOGIC ;q: OUT STD_LOGIC_VECTOR (7 DOWNTO 0);END sin_rom;ARCHITECTURE SYN OF sin_rom ISSIGNAL sub_wire0: STD_LOGIC_VECTOR (7 DOWNTO 0);COMPONENT altsyncramGENERIC (address_aclr_a: STRING;init_file: STRING;intended_device_family: STRING;lpm_hint: STRING;lpm_type: STRING;numwords_a: NATURAL;operation_mode: STRING;outdata_aclr_a: STRING;outdata_reg_a: STRING;widthad_a: NATURAL;width_a: NATURAL;width_byteena_a: NATURAL);PORT (clock0: IN STD_LOGIC ;address_a: IN STD_LOGIC_VECTOR (7 DOWNTO 0);q_a: OUT STD_LOGIC_VECTOR (7 DOWNTO 0);END COMPONENT;BEGINq <= sub_wire0(7 DOWNTO 0);altsyncram_component : altsyncramGENERIC MAP (address_aclr_a => "NONE",init_file => "sin_",intended_device_family => "Cyclone",lpm_hint => "ENABLE_RUNTIME_MOD=YES, INSTANCE_NAME=sin",lpm_type => "altsyncram",numwords_a => 256,operation_mode => "ROM",outdata_aclr_a => "NONE",outdata_reg_a => "CLOCK0",widthad_a => 8,width_a => 8,width_byteena_a => 1)PORT MAP (clock0 => clock,address_a => address,q_a => sub_wire0);END SYN;方波信号发生器:LIBRARY ieee;USE _logic_;LIBRARY altera_mf;USE altera_mf.all;ENTITY sqr_rom ISPORT(address: IN STD_LOGIC_VECTOR (7 DOWNTO 0);clock: IN STD_LOGIC ;q: OUT STD_LOGIC_VECTOR (7 DOWNTO 0);END sqr_rom;ARCHITECTURE SYN OF sqr_rom ISSIGNAL sub_wire0: STD_LOGIC_VECTOR (7 DOWNTO 0);COMPONENT altsyncramGENERIC (address_aclr_a: STRING;init_file: STRING;intended_device_family: STRING;lpm_hint: STRING;lpm_type: STRING;numwords_a: NATURAL;operation_mode: STRING;outdata_aclr_a: STRING;outdata_reg_a: STRING;widthad_a: NATURAL;width_a: NATURAL;width_byteena_a: NATURAL);PORT (clock0: IN STD_LOGIC ;address_a: IN STD_LOGIC_VECTOR (7 DOWNTO 0);q_a: OUT STD_LOGIC_VECTOR (7 DOWNTO 0);END COMPONENT;BEGINq <= sub_wire0(7 DOWNTO 0);altsyncram_component : altsyncramGENERIC MAP (address_aclr_a => "NONE",init_file => "sqr_rom .mif",intended_device_family => "Cyclone",lpm_hint => "ENABLE_RUNTIME_MOD=NO",lpm_type => "altsyncram",numwords_a => 256,operation_mode => "ROM",outdata_aclr_a => "NONE",outdata_reg_a => "CLOCK0",widthad_a => 8,width_a => 8,width_byteena_a => 1)PORT MAP (clock0 => clock,address_a => address,q_a => sub_wire0);END SYN;三角波信号发生器:LIBRARY ieee;USE _logic_;LIBRARY altera_mf;USE altera_mf.all;ENTITY tri_rom ISPORT(address: IN STD_LOGIC_VECTOR (7 DOWNTO 0);clock: IN STD_LOGIC ;q: OUT STD_LOGIC_VECTOR (7 DOWNTO 0);END tri_rom;ARCHITECTURE SYN OF tri_rom ISSIGNAL sub_wire0: STD_LOGIC_VECTOR (7 DOWNTO 0);COMPONENT altsyncramGENERIC (address_aclr_a: STRING;init_file: STRING;intended_device_family: STRING;lpm_hint: STRING;lpm_type: STRING;numwords_a: NATURAL;operation_mode: STRING;outdata_aclr_a: STRING;outdata_reg_a: STRING;widthad_a: NATURAL;width_a: NATURAL;width_byteena_a: NATURAL);PORT (clock0: IN STD_LOGIC ;address_a: IN STD_LOGIC_VECTOR (7 DOWNTO 0);q_a: OUT STD_LOGIC_VECTOR (7 DOWNTO 0);END COMPONENT;BEGINq <= sub_wire0(7 DOWNTO 0);altsyncram_component : altsyncramGENERIC MAP (address_aclr_a => "NONE",init_file => "tri_",intended_device_family => "Cyclone",lpm_hint => "ENABLE_RUNTIME_MOD=NO",lpm_type => "altsyncram",numwords_a => 256,operation_mode => "ROM",outdata_aclr_a => "NONE",outdata_reg_a => "CLOCK0",widthad_a => 8,width_a => 8,width_byteena_a => 1)PORT MAP (clock0 => clock,address_a => address,q_a => sub_wire0); END SYN;波形选择器:LIBRARY IEEE;USE _LOGIC_;ENTITY CHOOSE ISPORT( SCW:IN STD_LOGIC_VECTOR(1 DOWNTO 0); D1: IN STD_LOGIC_VECTOR(7 DOWNTO 0); D2: IN STD_LOGIC_VECTOR(7 DOWNTO 0); D3: IN STD_LOGIC_VECTOR(7 DOWNTO 0); Q: OUT STD_LOGIC_VECTOR(7 DOWNTO 0);END CHOOSE;ARCHITECTURE BEHAV OF CHOOSE ISBEGINPROCESS(SCW)BEGINCASE SCW ISWHEN "00"=>Q<=D1;WHEN "01"=>Q<=D2;WHEN "10"=>Q<=D3;WHEN OTHERS=>NULL;END CASE;END PROCESS;END BEHAV;调幅模块:LIBRARY IEEE;USE _LOGIC_;USE _LOGIC_;ENTITY AM IS PORT(SCA : IN STD_LOGIC_VECTOR(1 DOWNTO 0); K : IN STD_LOGIC_VECTOR(7 DOWNTO 0); Q : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); END AM;ARCHITECTURE BEHAV OF AM ISBEGIN PROCESS(SCA) BEGIN CASE SCA IS WHEN "00" => Q <= K; WHEN "01" => Q <= '0' & K(7 DOWNTO 1); WHEN "10" => Q <= "00" & K(7 DOWNTO 2); WHEN "11" => Q <= "000" & K(7 DOWNTO 3); END CASE; END PROCESS;END BEHAV;七、实验心得:(设计中遇到的问题,问题出现的原因及解决问题的方法)