FPGA实现基于LUT(查找表)的DDS的设计(含matlab和verilog源码)-FPGA常见问题社区-FPGA CPLD-ChipDebug

FPGA实现基于LUT(查找表)的DDS的设计(含matlab和verilog源码)

基于LUT的DDS的设计
DDS(Direct Digital Synthesis)直接数字频率合成技术由USA J.Tierncy首先提出。它是一种以数字信号处理理论为基础,从相位概念出发直接合成所需波形的一种新的全数字技术的频率合成方法。DDS主要出现在数字混频系统中。在数字混频中,通过DDS产生正交的本地振荡信号即正、余弦信号与输入信号相乘实现频谱搬移,如通信系统的调制、解调。目前FPGA实现DDS有三种途径:基于IIR滤波器的实现方法、基于查找表LUT的实现方法以及基于CORDIC算法的实现方法。其中采用LUT的方法较为通用且比较容易实现。

1 基于LUT的DDS理论

一个典型的基于LUT的DDS系统由相位累加器和波形存储器两部分构成,如图1所示。图中相位累加器的位宽为nbit,步进值为μ,LUT的深度N为2n,宽度为Lbit。LUT中依相位顺序存储一个周期的波形数据。

图1 基于LUT的DDS架构.png
图1 基于LUT的DDS架构

2 matlab 仿真

图2 相位累加器位宽为4bit时LUT地址与存储数据的对应关系.png
图2 相位累加器位宽为4bit时LUT地址与存储数据的对应关系
如图2所示,我们要制作地址位宽为10bit数据位宽为32bit的LUT查找表。Matlab源码如下:

clear all
close all
clc

FS = 44100;%采样率
fc = 1000;
N  = 1024;%1024点一个正玄周期

t =0:2*pi/(N-1):2*pi;

sin_dds = sin(t);

figure,
hold on
plot(t,sin_dds,'*');
legend('sin');
grid;
hold off

图3 matlab 1024点1个周期的正弦波.png
图3 matlab 1024点1个周期的正玄波

3 FPGA仿真

整个仿真结构如图1所示,由相位累加控制器和sin波形存储器组成。仿真生成采样率为44.1KHZ @1KHZ正玄波和余弦波(相位相差90度)。

tb_dds源码:

仿真结果:

生成Sample rate 44.1KHZ@1KHZ的正玄和余弦波相位相差90°。
图4 modelsim 仿真结果.png
图4 modelsim 仿真结果

4 Matlab FFT分析:

图5 FFT分析结果.png

图5 FFT分析结果
由图5可知产生的正玄波频率为1KHZ。基于LUT的DDS设计完成,此节将是后期基于FPGA数字信号处理的基础和关键。

dds_rom.v


`timescale 1ns / 1ps

module dds_rom(
       input                    clk,
       input [9:0]              addr,//0-1023 1T
       output signed [31:0]     sin,
       output signed [31:0]     cos
       );

wire signed [31:0] dds_rom[0:1023];
wire [9:0] cos_addr;
assign cos_addr = addr+10'd256;
assign sin = dds_rom[addr];
assign cos = dds_rom[cos_addr];

assign dds_rom[0]=0;
assign dds_rom[1]=13189608;
assign dds_rom[2]=26378718;
assign dds_rom[3]=39566833;
assign dds_rom[4]=52753456;
assign dds_rom[5]=65938088;
assign dds_rom[6]=79120233;
assign dds_rom[7]=92299394;
assign dds_rom[8]=105475073;
assign dds_rom[9]=118646772;
assign dds_rom[10]=131813997;
assign dds_rom[11]=144976248;
assign dds_rom[12]=158133031;
assign dds_rom[13]=171283849;
assign dds_rom[14]=184428205;
assign dds_rom[15]=197565604;
assign dds_rom[16]=210695550;
assign dds_rom[17]=223817548;
assign dds_rom[18]=236931103;
assign dds_rom[19]=250035720;
assign dds_rom[20]=263130905;
assign dds_rom[21]=276216164;
assign dds_rom[22]=289291003;
assign dds_rom[23]=302354930;
assign dds_rom[24]=315407450;
assign dds_rom[25]=328448072;
assign dds_rom[26]=341476305;
assign dds_rom[27]=354491656;
assign dds_rom[28]=367493634;
assign dds_rom[29]=380481749;
assign dds_rom[30]=393455512;
assign dds_rom[31]=406414432;
assign dds_rom[32]=419358020;
assign dds_rom[33]=432285790;
assign dds_rom[34]=445197252;
assign dds_rom[35]=458091920;
assign dds_rom[36]=470969307;
assign dds_rom[37]=483828928;
assign dds_rom[38]=496670297;
assign dds_rom[39]=509492931;
assign dds_rom[40]=522296345;
assign dds_rom[41]=535080056;
assign dds_rom[42]=547843582;
assign dds_rom[43]=560586442;
assign dds_rom[44]=573308155;
assign dds_rom[45]=586008241;
assign dds_rom[46]=598686221;
assign dds_rom[47]=611341617;
assign dds_rom[48]=623973951;
assign dds_rom[49]=636582747;
assign dds_rom[50]=649167528;
assign dds_rom[51]=661727822;
assign dds_rom[52]=674263153;
assign dds_rom[53]=686773048;
assign dds_rom[54]=699257037;
assign dds_rom[55]=711714647;
assign dds_rom[56]=724145409;
assign dds_rom[57]=736548855;
assign dds_rom[58]=748924515;
assign dds_rom[59]=761271924;
assign dds_rom[60]=773590615;
assign dds_rom[61]=785880124;
assign dds_rom[62]=798139987;
assign dds_rom[63]=810369741;
assign dds_rom[64]=822568927;
assign dds_rom[65]=834737082;
assign dds_rom[66]=846873748;
assign dds_rom[67]=858978468;
assign dds_rom[68]=871050785;
assign dds_rom[69]=883090242;
assign dds_rom[70]=895096387;
assign dds_rom[71]=907068766;
assign dds_rom[72]=919006928;
assign dds_rom[73]=930910422;
assign dds_rom[74]=942778799;
assign dds_rom[75]=954611611;
assign dds_rom[76]=966408413;
assign dds_rom[77]=978168759;
assign dds_rom[78]=989892205;
assign dds_rom[79]=1001578310;
assign dds_rom[80]=1013226631;
assign dds_rom[81]=1024836731;
assign dds_rom[82]=1036408171;
assign dds_rom[83]=1047940514;
assign dds_rom[84]=1059433326;
assign dds_rom[85]=1070886173;
assign dds_rom[86]=1082298622;
assign dds_rom[87]=1093670244;
assign dds_rom[88]=1105000610;
assign dds_rom[89]=1116289291;
assign dds_rom[90]=1127535862;
assign dds_rom[91]=1138739900;
assign dds_rom[92]=1149900980;
assign dds_rom[93]=1161018683;
assign dds_rom[94]=1172092589;
assign dds_rom[95]=1183122279;
assign dds_rom[96]=1194107339;
assign dds_rom[97]=1205047353;
assign dds_rom[98]=1215941909;
assign dds_rom[99]=1226790596;
assign dds_rom[100]=1237593005;
assign dds_rom[101]=1248348728;
assign dds_rom[102]=1259057359;
assign dds_rom[103]=1269718495;
assign dds_rom[104]=1280331733;
assign dds_rom[105]=1290896673;
assign dds_rom[106]=1301412917;
assign dds_rom[107]=1311880067;
assign dds_rom[108]=1322297729;
assign dds_rom[109]=1332665510;
assign dds_rom[110]=1342983019;
assign dds_rom[111]=1353249866;
assign dds_rom[112]=1363465664;
assign dds_rom[113]=1373630029;
assign dds_rom[114]=1383742575;
assign dds_rom[115]=1393802923;
assign dds_rom[116]=1403810692;
assign dds_rom[117]=1413765506;
assign dds_rom[118]=1423666987;
assign dds_rom[119]=1433514764;
assign dds_rom[120]=1443308464;
assign dds_rom[121]=1453047717;
assign dds_rom[122]=1462732158;
assign dds_rom[123]=1472361420;
assign dds_rom[124]=1481935139;
assign dds_rom[125]=1491452956;
assign dds_rom[126]=1500914510;
assign dds_rom[127]=1510319445;
assign dds_rom[128]=1519667407;
assign dds_rom[129]=1528958041;
assign dds_rom[130]=1538190999;
assign dds_rom[131]=1547365932;
assign dds_rom[132]=1556482493;
assign dds_rom[133]=1565540339;
assign dds_rom[134]=1574539127;
assign dds_rom[135]=1583478520;
assign dds_rom[136]=1592358178;
assign dds_rom[137]=1601177768;
assign dds_rom[138]=1609936957;
assign dds_rom[139]=1618635414;
assign dds_rom[140]=1627272811;
assign dds_rom[141]=1635848822;
assign dds_rom[142]=1644363124;
assign dds_rom[143]=1652815396;
assign dds_rom[144]=1661205318;
assign dds_rom[145]=1669532574;
assign dds_rom[146]=1677796851;
assign dds_rom[147]=1685997836;
assign dds_rom[148]=1694135220;
assign dds_rom[149]=1702208696;
assign dds_rom[150]=1710217959;
assign dds_rom[151]=1718162708;
assign dds_rom[152]=1726042642;
assign dds_rom[153]=1733857465;
assign dds_rom[154]=1741606881;
assign dds_rom[155]=1749290598;
assign dds_rom[156]=1756908327;
assign dds_rom[157]=1764459780;
assign dds_rom[158]=1771944672;
assign dds_rom[159]=1779362721;
assign dds_rom[160]=1786713647;
assign dds_rom[161]=1793997172;
assign dds_rom[162]=1801213022;
assign dds_rom[163]=1808360925;
assign dds_rom[164]=1815440611;
assign dds_rom[165]=1822451813;
assign dds_rom[166]=1829394267;
assign dds_rom[167]=1836267710;
assign dds_rom[168]=1843071884;
assign dds_rom[169]=1849806531;
assign dds_rom[170]=1856471398;
assign dds_rom[171]=1863066233;
assign dds_rom[172]=1869590787;
assign dds_rom[173]=1876044815;
assign dds_rom[174]=1882428072;
assign dds_rom[175]=1888740319;
assign dds_rom[176]=1894981316;
assign dds_rom[177]=1901150829;
assign dds_rom[178]=1907248625;
assign dds_rom[179]=1913274473;
assign dds_rom[180]=1919228147;
assign dds_rom[181]=1925109422;
assign dds_rom[182]=1930918075;
assign dds_rom[183]=1936653889;
assign dds_rom[184]=1942316645;
assign dds_rom[185]=1947906132;
assign dds_rom[186]=1953422138;
assign dds_rom[187]=1958864454;
assign dds_rom[188]=1964232876;
assign dds_rom[189]=1969527202;
assign dds_rom[190]=1974747230;
assign dds_rom[191]=1979892765;
assign dds_rom[192]=1984963613;
assign dds_rom[193]=1989959581;
assign dds_rom[194]=1994880482;
assign dds_rom[195]=1999726130;
assign dds_rom[196]=2004496343;
assign dds_rom[197]=2009190939;
assign dds_rom[198]=2013809743;
assign dds_rom[199]=2018352579;
assign dds_rom[200]=2022819277;
assign dds_rom[201]=2027209668;
assign dds_rom[202]=2031523587;
assign dds_rom[203]=2035760870;
assign dds_rom[204]=2039921358;
assign dds_rom[205]=2044004894;
assign dds_rom[206]=2048011324;
assign dds_rom[207]=2051940496;
assign dds_rom[208]=2055792263;
assign dds_rom[209]=2059566479;
assign dds_rom[210]=2063263002;
assign dds_rom[211]=2066881693;
assign dds_rom[212]=2070422414;
assign dds_rom[213]=2073885032;
assign dds_rom[214]=2077269417;
assign dds_rom[215]=2080575442;
assign dds_rom[216]=2083802980;
assign dds_rom[217]=2086951911;
assign dds_rom[218]=2090022116;
assign dds_rom[219]=2093013479;
assign dds_rom[220]=2095925886;
assign dds_rom[221]=2098759229;
assign dds_rom[222]=2101513401;
assign dds_rom[223]=2104188297;
assign dds_rom[224]=2106783816;
assign dds_rom[225]=2109299861;
assign dds_rom[226]=2111736337;
assign dds_rom[227]=2114093151;
assign dds_rom[228]=2116370216;
assign dds_rom[229]=2118567444;
assign dds_rom[230]=2120684754;
assign dds_rom[231]=2122722064;
assign dds_rom[232]=2124679300;
assign dds_rom[233]=2126556385;
assign dds_rom[234]=2128353251;
assign dds_rom[235]=2130069828;
assign dds_rom[236]=2131706053;
assign dds_rom[237]=2133261863;
assign dds_rom[238]=2134737200;
assign dds_rom[239]=2136132008;
assign dds_rom[240]=2137446235;
assign dds_rom[241]=2138679831;
assign dds_rom[242]=2139832749;
assign dds_rom[243]=2140904945;
assign dds_rom[244]=2141896381;
assign dds_rom[245]=2142807017;
assign dds_rom[246]=2143636821;
assign dds_rom[247]=2144385759;
assign dds_rom[248]=2145053805;
assign dds_rom[249]=2145640933;
assign dds_rom[250]=2146147121;
assign dds_rom[251]=2146572349;
assign dds_rom[252]=2146916602;
assign dds_rom[253]=2147179867;
assign dds_rom[254]=2147362133;
assign dds_rom[255]=2147463395;
assign dds_rom[256]=2147483647;
assign dds_rom[257]=2147422890;
assign dds_rom[258]=2147281125;
assign dds_rom[259]=2147058358;
assign dds_rom[260]=2146754598;
assign dds_rom[261]=2146369856;
assign dds_rom[262]=2145904146;
assign dds_rom[263]=2145357485;
assign dds_rom[264]=2144729895;
assign dds_rom[265]=2144021400;
assign dds_rom[266]=2143232025;
assign dds_rom[267]=2142361801;
assign dds_rom[268]=2141410761;
assign dds_rom[269]=2140378940;
assign dds_rom[270]=2139266377;
assign dds_rom[271]=2138073115;
assign dds_rom[272]=2136799197;
assign dds_rom[273]=2135444674;
assign dds_rom[274]=2134009594;
assign dds_rom[275]=2132494014;
assign dds_rom[276]=2130897989;
assign dds_rom[277]=2129221580;
assign dds_rom[278]=2127464850;
assign dds_rom[279]=2125627866;
assign dds_rom[280]=2123710696;
assign dds_rom[281]=2121713414;
assign dds_rom[282]=2119636094;
assign dds_rom[283]=2117478815;
assign dds_rom[284]=2115241658;
assign dds_rom[285]=2112924707;
assign dds_rom[286]=2110528051;
assign dds_rom[287]=2108051779;
assign dds_rom[288]=2105495985;
assign dds_rom[289]=2102860765;
assign dds_rom[290]=2100146218;
assign dds_rom[291]=2097352448;
assign dds_rom[292]=2094479559;
assign dds_rom[293]=2091527660;
assign dds_rom[294]=2088496862;
assign dds_rom[295]=2085387279;
assign dds_rom[296]=2082199029;
assign dds_rom[297]=2078932233;
assign dds_rom[298]=2075587012;
assign dds_rom[299]=2072163494;
assign dds_rom[300]=2068661808;
assign dds_rom[301]=2065082085;
assign dds_rom[302]=2061424461;
assign dds_rom[303]=2057689074;
assign dds_rom[304]=2053876065;
assign dds_rom[305]=2049985576;
assign dds_rom[306]=2046017757;
assign dds_rom[307]=2041972755;
assign dds_rom[308]=2037850723;
assign dds_rom[309]=2033651818;
assign dds_rom[310]=2029376197;
assign dds_rom[311]=2025024022;
assign dds_rom[312]=2020595456;
assign dds_rom[313]=2016090668;
assign dds_rom[314]=2011509826;
assign dds_rom[315]=2006853104;
assign dds_rom[316]=2002120677;
assign dds_rom[317]=1997312724;
assign dds_rom[318]=1992429427;
assign dds_rom[319]=1987470969;
assign dds_rom[320]=1982437537;
assign dds_rom[321]=1977329322;
assign dds_rom[322]=1972146515;
assign dds_rom[323]=1966889314;
assign dds_rom[324]=1961557915;
assign dds_rom[325]=1956152520;
assign dds_rom[326]=1950673333;
assign dds_rom[327]=1945120561;
assign dds_rom[328]=1939494412;
assign dds_rom[329]=1933795100;
assign dds_rom[330]=1928022840;
assign dds_rom[331]=1922177848;
assign dds_rom[332]=1916260346;
assign dds_rom[333]=1910270557;
assign dds_rom[334]=1904208706;
assign dds_rom[335]=1898075023;
assign dds_rom[336]=1891869739;
assign dds_rom[337]=1885593087;
assign dds_rom[338]=1879245305;
assign dds_rom[339]=1872826632;
assign dds_rom[340]=1866337311;
assign dds_rom[341]=1859777585;
assign dds_rom[342]=1853147703;
assign dds_rom[343]=1846447914;
assign dds_rom[344]=1839678472;
assign dds_rom[345]=1832839631;
assign dds_rom[346]=1825931650;
assign dds_rom[347]=1818954790;
assign dds_rom[348]=1811909312;
assign dds_rom[349]=1804795484;
assign dds_rom[350]=1797613574;
assign dds_rom[351]=1790363852;
assign dds_rom[352]=1783046591;
assign dds_rom[353]=1775662069;
assign dds_rom[354]=1768210564;
assign dds_rom[355]=1760692356;
assign dds_rom[356]=1753107729;
assign dds_rom[357]=1745456970;
assign dds_rom[358]=1737740367;
assign dds_rom[359]=1729958211;
assign dds_rom[360]=1722110795;
assign dds_rom[361]=1714198417;
assign dds_rom[362]=1706221373;
assign dds_rom[363]=1698179965;
assign dds_rom[364]=1690074497;
assign dds_rom[365]=1681905274;
assign dds_rom[366]=1673672605;
assign dds_rom[367]=1665376799;
assign dds_rom[368]=1657018170;
assign dds_rom[369]=1648597034;
assign dds_rom[370]=1640113707;
assign dds_rom[371]=1631568510;
assign dds_rom[372]=1622961765;
assign dds_rom[373]=1614293798;
assign dds_rom[374]=1605564934;
assign dds_rom[375]=1596775503;
assign dds_rom[376]=1587925837;
assign dds_rom[377]=1579016269;
assign dds_rom[378]=1570047136;
assign dds_rom[379]=1561018777;
assign dds_rom[380]=1551931530;
assign dds_rom[381]=1542785740;
assign dds_rom[382]=1533581752;
assign dds_rom[383]=1524319912;
assign dds_rom[384]=1515000570;
assign dds_rom[385]=1505624077;
assign dds_rom[386]=1496190788;
assign dds_rom[387]=1486701058;
assign dds_rom[388]=1477155245;
assign dds_rom[389]=1467553709;
assign dds_rom[390]=1457896812;
assign dds_rom[391]=1448184919;
assign dds_rom[392]=1438418396;
assign dds_rom[393]=1428597612;
assign dds_rom[394]=1418722936;
assign dds_rom[395]=1408794742;
assign dds_rom[396]=1398813404;
assign dds_rom[397]=1388779298;
assign dds_rom[398]=1378692803;
assign dds_rom[399]=1368554300;
assign dds_rom[400]=1358364170;
assign dds_rom[401]=1348122799;
assign dds_rom[402]=1337830573;
assign dds_rom[403]=1327487879;
assign dds_rom[404]=1317095109;
assign dds_rom[405]=1306652653;
assign dds_rom[406]=1296160907;
assign dds_rom[407]=1285620265;
assign dds_rom[408]=1275031126;
assign dds_rom[409]=1264393889;
assign dds_rom[410]=1253708955;
assign dds_rom[411]=1242976727;
assign dds_rom[412]=1232197611;
assign dds_rom[413]=1221372012;
assign dds_rom[414]=1210500339;
assign dds_rom[415]=1199583002;
assign dds_rom[416]=1188620414;
assign dds_rom[417]=1177612987;
assign dds_rom[418]=1166561137;
assign dds_rom[419]=1155465280;
assign dds_rom[420]=1144325836;
assign dds_rom[421]=1133143224;
assign dds_rom[422]=1121917867;
assign dds_rom[423]=1110650187;
assign dds_rom[424]=1099340611;
assign dds_rom[425]=1087989564;
assign dds_rom[426]=1076597474;
assign dds_rom[427]=1065164772;
assign dds_rom[428]=1053691889;
assign dds_rom[429]=1042179257;
assign dds_rom[430]=1030627311;
assign dds_rom[431]=1019036486;
assign dds_rom[432]=1007407221;
assign dds_rom[433]=995739953;
assign dds_rom[434]=984035122;
assign dds_rom[435]=972293171;
assign dds_rom[436]=960514541;
assign dds_rom[437]=948699679;
assign dds_rom[438]=936849028;
assign dds_rom[439]=924963036;
assign dds_rom[440]=913042152;
assign dds_rom[441]=901086826;
assign dds_rom[442]=889097507;
assign dds_rom[443]=877074649;
assign dds_rom[444]=865018705;
assign dds_rom[445]=852930130;
assign dds_rom[446]=840809380;
assign dds_rom[447]=828656912;
assign dds_rom[448]=816473184;
assign dds_rom[449]=804258656;
assign dds_rom[450]=792013790;
assign dds_rom[451]=779739046;
assign dds_rom[452]=767434888;
assign dds_rom[453]=755101780;
assign dds_rom[454]=742740187;
assign dds_rom[455]=730350576;
assign dds_rom[456]=717933414;
assign dds_rom[457]=705489169;
assign dds_rom[458]=693018310;
assign dds_rom[459]=680521309;
assign dds_rom[460]=667998637;
assign dds_rom[461]=655450766;
assign dds_rom[462]=642878169;
assign dds_rom[463]=630281321;
assign dds_rom[464]=617660696;
assign dds_rom[465]=605016772;
assign dds_rom[466]=592350024;
assign dds_rom[467]=579660932;
assign dds_rom[468]=566949972;
assign dds_rom[469]=554217626;
assign dds_rom[470]=541464372;
assign dds_rom[471]=528690693;
assign dds_rom[472]=515897070;
assign dds_rom[473]=503083986;
assign dds_rom[474]=490251924;
assign dds_rom[475]=477401369;
assign dds_rom[476]=464532804;
assign dds_rom[477]=451646715;
assign dds_rom[478]=438743590;
assign dds_rom[479]=425823913;
assign dds_rom[480]=412888173;
assign dds_rom[481]=399936857;
assign dds_rom[482]=386970455;
assign dds_rom[483]=373989455;
assign dds_rom[484]=360994347;
assign dds_rom[485]=347985621;
assign dds_rom[486]=334963768;
assign dds_rom[487]=321929279;
assign dds_rom[488]=308882646;
assign dds_rom[489]=295824361;
assign dds_rom[490]=282754917;
assign dds_rom[491]=269674806;
assign dds_rom[492]=256584522;
assign dds_rom[493]=243484559;
assign dds_rom[494]=230375412;
assign dds_rom[495]=217257573;
assign dds_rom[496]=204131539;
assign dds_rom[497]=190997805;
assign dds_rom[498]=177856865;
assign dds_rom[499]=164709216;
assign dds_rom[500]=151555354;
assign dds_rom[501]=138395775;
assign dds_rom[502]=125230975;
assign dds_rom[503]=112061451;
assign dds_rom[504]=98887700;
assign dds_rom[505]=85710218;
assign dds_rom[506]=72529503;
assign dds_rom[507]=59346052;
assign dds_rom[508]=46160362;
assign dds_rom[509]=32972931;
assign dds_rom[510]=19784256;
assign dds_rom[511]=6594835;
assign dds_rom[512]=-6594835;
assign dds_rom[513]=-19784256;
assign dds_rom[514]=-32972931;
assign dds_rom[515]=-46160362;
assign dds_rom[516]=-59346052;
assign dds_rom[517]=-72529503;
assign dds_rom[518]=-85710218;
assign dds_rom[519]=-98887700;
assign dds_rom[520]=-112061451;
assign dds_rom[521]=-125230975;
assign dds_rom[522]=-138395775;
assign dds_rom[523]=-151555354;
assign dds_rom[524]=-164709216;
assign dds_rom[525]=-177856865;
assign dds_rom[526]=-190997805;
assign dds_rom[527]=-204131539;
assign dds_rom[528]=-217257573;
assign dds_rom[529]=-230375412;
assign dds_rom[530]=-243484559;
assign dds_rom[531]=-256584522;
assign dds_rom[532]=-269674806;
assign dds_rom[533]=-282754917;
assign dds_rom[534]=-295824361;
assign dds_rom[535]=-308882646;
assign dds_rom[536]=-321929279;
assign dds_rom[537]=-334963768;
assign dds_rom[538]=-347985621;
assign dds_rom[539]=-360994347;
assign dds_rom[540]=-373989455;
assign dds_rom[541]=-386970455;
assign dds_rom[542]=-399936857;
assign dds_rom[543]=-412888173;
assign dds_rom[544]=-425823913;
assign dds_rom[545]=-438743590;
assign dds_rom[546]=-451646715;
assign dds_rom[547]=-464532804;
assign dds_rom[548]=-477401369;
assign dds_rom[549]=-490251924;
assign dds_rom[550]=-503083986;
assign dds_rom[551]=-515897070;
assign dds_rom[552]=-528690693;
assign dds_rom[553]=-541464372;
assign dds_rom[554]=-554217626;
assign dds_rom[555]=-566949972;
assign dds_rom[556]=-579660932;
assign dds_rom[557]=-592350024;
assign dds_rom[558]=-605016772;
assign dds_rom[559]=-617660696;
assign dds_rom[560]=-630281321;
assign dds_rom[561]=-642878169;
assign dds_rom[562]=-655450766;
assign dds_rom[563]=-667998637;
assign dds_rom[564]=-680521309;
assign dds_rom[565]=-693018310;
assign dds_rom[566]=-705489169;
assign dds_rom[567]=-717933414;
assign dds_rom[568]=-730350576;
assign dds_rom[569]=-742740187;
assign dds_rom[570]=-755101780;
assign dds_rom[571]=-767434888;
assign dds_rom[572]=-779739046;
assign dds_rom[573]=-792013790;
assign dds_rom[574]=-804258656;
assign dds_rom[575]=-816473184;
assign dds_rom[576]=-828656912;
assign dds_rom[577]=-840809380;
assign dds_rom[578]=-852930130;
assign dds_rom[579]=-865018705;
assign dds_rom[580]=-877074649;
assign dds_rom[581]=-889097507;
assign dds_rom[582]=-901086826;
assign dds_rom[583]=-913042152;
assign dds_rom[584]=-924963036;
assign dds_rom[585]=-936849028;
assign dds_rom[586]=-948699679;
assign dds_rom[587]=-960514541;
assign dds_rom[588]=-972293171;
assign dds_rom[589]=-984035122;
assign dds_rom[590]=-995739953;
assign dds_rom[591]=-1007407221;
assign dds_rom[592]=-1019036486;
assign dds_rom[593]=-1030627311;
assign dds_rom[594]=-1042179257;
assign dds_rom[595]=-1053691889;
assign dds_rom[596]=-1065164772;
assign dds_rom[597]=-1076597474;
assign dds_rom[598]=-1087989564;
assign dds_rom[599]=-1099340611;
assign dds_rom[600]=-1110650187;
assign dds_rom[601]=-1121917867;
assign dds_rom[602]=-1133143224;
assign dds_rom[603]=-1144325836;
assign dds_rom[604]=-1155465280;
assign dds_rom[605]=-1166561137;
assign dds_rom[606]=-1177612987;
assign dds_rom[607]=-1188620414;
assign dds_rom[608]=-1199583002;
assign dds_rom[609]=-1210500339;
assign dds_rom[610]=-1221372012;
assign dds_rom[611]=-1232197611;
assign dds_rom[612]=-1242976727;
assign dds_rom[613]=-1253708955;
assign dds_rom[614]=-1264393889;
assign dds_rom[615]=-1275031126;
assign dds_rom[616]=-1285620265;
assign dds_rom[617]=-1296160907;
assign dds_rom[618]=-1306652653;
assign dds_rom[619]=-1317095109;
assign dds_rom[620]=-1327487879;
assign dds_rom[621]=-1337830573;
assign dds_rom[622]=-1348122799;
assign dds_rom[623]=-1358364170;
assign dds_rom[624]=-1368554300;
assign dds_rom[625]=-1378692803;
assign dds_rom[626]=-1388779298;
assign dds_rom[627]=-1398813404;
assign dds_rom[628]=-1408794742;
assign dds_rom[629]=-1418722936;
assign dds_rom[630]=-1428597612;
assign dds_rom[631]=-1438418396;
assign dds_rom[632]=-1448184919;
assign dds_rom[633]=-1457896812;
assign dds_rom[634]=-1467553709;
assign dds_rom[635]=-1477155245;
assign dds_rom[636]=-1486701058;
assign dds_rom[637]=-1496190788;
assign dds_rom[638]=-1505624077;
assign dds_rom[639]=-1515000570;
assign dds_rom[640]=-1524319912;
assign dds_rom[641]=-1533581752;
assign dds_rom[642]=-1542785740;
assign dds_rom[643]=-1551931530;
assign dds_rom[644]=-1561018777;
assign dds_rom[645]=-1570047136;
assign dds_rom[646]=-1579016269;
assign dds_rom[647]=-1587925837;
assign dds_rom[648]=-1596775503;
assign dds_rom[649]=-1605564934;
assign dds_rom[650]=-1614293798;
assign dds_rom[651]=-1622961765;
assign dds_rom[652]=-1631568510;
assign dds_rom[653]=-1640113707;
assign dds_rom[654]=-1648597034;
assign dds_rom[655]=-1657018170;
assign dds_rom[656]=-1665376799;
assign dds_rom[657]=-1673672605;
assign dds_rom[658]=-1681905274;
assign dds_rom[659]=-1690074497;
assign dds_rom[660]=-1698179965;
assign dds_rom[661]=-1706221373;
assign dds_rom[662]=-1714198417;
assign dds_rom[663]=-1722110795;
assign dds_rom[664]=-1729958211;
assign dds_rom[665]=-1737740367;
assign dds_rom[666]=-1745456970;
assign dds_rom[667]=-1753107729;
assign dds_rom[668]=-1760692356;
assign dds_rom[669]=-1768210564;
assign dds_rom[670]=-1775662069;
assign dds_rom[671]=-1783046591;
assign dds_rom[672]=-1790363852;
assign dds_rom[673]=-1797613574;
assign dds_rom[674]=-1804795484;
assign dds_rom[675]=-1811909312;
assign dds_rom[676]=-1818954790;
assign dds_rom[677]=-1825931650;
assign dds_rom[678]=-1832839631;
assign dds_rom[679]=-1839678472;
assign dds_rom[680]=-1846447914;
assign dds_rom[681]=-1853147703;
assign dds_rom[682]=-1859777585;
assign dds_rom[683]=-1866337311;
assign dds_rom[684]=-1872826632;
assign dds_rom[685]=-1879245305;
assign dds_rom[686]=-1885593087;
assign dds_rom[687]=-1891869739;
assign dds_rom[688]=-1898075023;
assign dds_rom[689]=-1904208706;
assign dds_rom[690]=-1910270557;
assign dds_rom[691]=-1916260346;
assign dds_rom[692]=-1922177848;
assign dds_rom[693]=-1928022840;
assign dds_rom[694]=-1933795100;
assign dds_rom[695]=-1939494412;
assign dds_rom[696]=-1945120561;
assign dds_rom[697]=-1950673333;
assign dds_rom[698]=-1956152520;
assign dds_rom[699]=-1961557915;
assign dds_rom[700]=-1966889314;
assign dds_rom[701]=-1972146515;
assign dds_rom[702]=-1977329322;
assign dds_rom[703]=-1982437537;
assign dds_rom[704]=-1987470969;
assign dds_rom[705]=-1992429427;
assign dds_rom[706]=-1997312724;
assign dds_rom[707]=-2002120677;
assign dds_rom[708]=-2006853104;
assign dds_rom[709]=-2011509826;
assign dds_rom[710]=-2016090668;
assign dds_rom[711]=-2020595456;
assign dds_rom[712]=-2025024022;
assign dds_rom[713]=-2029376197;
assign dds_rom[714]=-2033651818;
assign dds_rom[715]=-2037850723;
assign dds_rom[716]=-2041972755;
assign dds_rom[717]=-2046017757;
assign dds_rom[718]=-2049985576;
assign dds_rom[719]=-2053876065;
assign dds_rom[720]=-2057689074;
assign dds_rom[721]=-2061424461;
assign dds_rom[722]=-2065082085;
assign dds_rom[723]=-2068661808;
assign dds_rom[724]=-2072163494;
assign dds_rom[725]=-2075587012;
assign dds_rom[726]=-2078932233;
assign dds_rom[727]=-2082199029;
assign dds_rom[728]=-2085387279;
assign dds_rom[729]=-2088496862;
assign dds_rom[730]=-2091527660;
assign dds_rom[731]=-2094479559;
assign dds_rom[732]=-2097352448;
assign dds_rom[733]=-2100146218;
assign dds_rom[734]=-2102860765;
assign dds_rom[735]=-2105495985;
assign dds_rom[736]=-2108051779;
assign dds_rom[737]=-2110528051;
assign dds_rom[738]=-2112924707;
assign dds_rom[739]=-2115241658;
assign dds_rom[740]=-2117478815;
assign dds_rom[741]=-2119636094;
assign dds_rom[742]=-2121713414;
assign dds_rom[743]=-2123710696;
assign dds_rom[744]=-2125627866;
assign dds_rom[745]=-2127464850;
assign dds_rom[746]=-2129221580;
assign dds_rom[747]=-2130897989;
assign dds_rom[748]=-2132494014;
assign dds_rom[749]=-2134009594;
assign dds_rom[750]=-2135444674;
assign dds_rom[751]=-2136799197;
assign dds_rom[752]=-2138073115;
assign dds_rom[753]=-2139266377;
assign dds_rom[754]=-2140378940;
assign dds_rom[755]=-2141410761;
assign dds_rom[756]=-2142361801;
assign dds_rom[757]=-2143232025;
assign dds_rom[758]=-2144021400;
assign dds_rom[759]=-2144729895;
assign dds_rom[760]=-2145357485;
assign dds_rom[761]=-2145904146;
assign dds_rom[762]=-2146369856;
assign dds_rom[763]=-2146754598;
assign dds_rom[764]=-2147058358;
assign dds_rom[765]=-2147281125;
assign dds_rom[766]=-2147422890;
assign dds_rom[767]=-2147483647;
assign dds_rom[768]=-2147463395;
assign dds_rom[769]=-2147362133;
assign dds_rom[770]=-2147179867;
assign dds_rom[771]=-2146916602;
assign dds_rom[772]=-2146572349;
assign dds_rom[773]=-2146147121;
assign dds_rom[774]=-2145640933;
assign dds_rom[775]=-2145053805;
assign dds_rom[776]=-2144385759;
assign dds_rom[777]=-2143636821;
assign dds_rom[778]=-2142807017;
assign dds_rom[779]=-2141896381;
assign dds_rom[780]=-2140904945;
assign dds_rom[781]=-2139832749;
assign dds_rom[782]=-2138679831;
assign dds_rom[783]=-2137446235;
assign dds_rom[784]=-2136132008;
assign dds_rom[785]=-2134737200;
assign dds_rom[786]=-2133261863;
assign dds_rom[787]=-2131706053;
assign dds_rom[788]=-2130069828;
assign dds_rom[789]=-2128353251;
assign dds_rom[790]=-2126556385;
assign dds_rom[791]=-2124679300;
assign dds_rom[792]=-2122722064;
assign dds_rom[793]=-2120684754;
assign dds_rom[794]=-2118567444;
assign dds_rom[795]=-2116370216;
assign dds_rom[796]=-2114093151;
assign dds_rom[797]=-2111736337;
assign dds_rom[798]=-2109299861;
assign dds_rom[799]=-2106783816;
assign dds_rom[800]=-2104188297;
assign dds_rom[801]=-2101513401;
assign dds_rom[802]=-2098759229;
assign dds_rom[803]=-2095925886;
assign dds_rom[804]=-2093013479;
assign dds_rom[805]=-2090022116;
assign dds_rom[806]=-2086951911;
assign dds_rom[807]=-2083802980;
assign dds_rom[808]=-2080575442;
assign dds_rom[809]=-2077269417;
assign dds_rom[810]=-2073885032;
assign dds_rom[811]=-2070422414;
assign dds_rom[812]=-2066881693;
assign dds_rom[813]=-2063263002;
assign dds_rom[814]=-2059566479;
assign dds_rom[815]=-2055792263;
assign dds_rom[816]=-2051940496;
assign dds_rom[817]=-2048011324;
assign dds_rom[818]=-2044004894;
assign dds_rom[819]=-2039921358;
assign dds_rom[820]=-2035760870;
assign dds_rom[821]=-2031523587;
assign dds_rom[822]=-2027209668;
assign dds_rom[823]=-2022819277;
assign dds_rom[824]=-2018352579;
assign dds_rom[825]=-2013809743;
assign dds_rom[826]=-2009190939;
assign dds_rom[827]=-2004496343;
assign dds_rom[828]=-1999726130;
assign dds_rom[829]=-1994880482;
assign dds_rom[830]=-1989959581;
assign dds_rom[831]=-1984963613;
assign dds_rom[832]=-1979892765;
assign dds_rom[833]=-1974747230;
assign dds_rom[834]=-1969527202;
assign dds_rom[835]=-1964232876;
assign dds_rom[836]=-1958864454;
assign dds_rom[837]=-1953422138;
assign dds_rom[838]=-1947906132;
assign dds_rom[839]=-1942316645;
assign dds_rom[840]=-1936653889;
assign dds_rom[841]=-1930918075;
assign dds_rom[842]=-1925109422;
assign dds_rom[843]=-1919228147;
assign dds_rom[844]=-1913274473;
assign dds_rom[845]=-1907248625;
assign dds_rom[846]=-1901150829;
assign dds_rom[847]=-1894981316;
assign dds_rom[848]=-1888740319;
assign dds_rom[849]=-1882428072;
assign dds_rom[850]=-1876044815;
assign dds_rom[851]=-1869590787;
assign dds_rom[852]=-1863066233;
assign dds_rom[853]=-1856471398;
assign dds_rom[854]=-1849806531;
assign dds_rom[855]=-1843071884;
assign dds_rom[856]=-1836267710;
assign dds_rom[857]=-1829394267;
assign dds_rom[858]=-1822451813;
assign dds_rom[859]=-1815440611;
assign dds_rom[860]=-1808360925;
assign dds_rom[861]=-1801213022;
assign dds_rom[862]=-1793997172;
assign dds_rom[863]=-1786713647;
assign dds_rom[864]=-1779362721;
assign dds_rom[865]=-1771944672;
assign dds_rom[866]=-1764459780;
assign dds_rom[867]=-1756908327;
assign dds_rom[868]=-1749290598;
assign dds_rom[869]=-1741606881;
assign dds_rom[870]=-1733857465;
assign dds_rom[871]=-1726042642;
assign dds_rom[872]=-1718162708;
assign dds_rom[873]=-1710217959;
assign dds_rom[874]=-1702208696;
assign dds_rom[875]=-1694135220;
assign dds_rom[876]=-1685997836;
assign dds_rom[877]=-1677796851;
assign dds_rom[878]=-1669532574;
assign dds_rom[879]=-1661205318;
assign dds_rom[880]=-1652815396;
assign dds_rom[881]=-1644363124;
assign dds_rom[882]=-1635848822;
assign dds_rom[883]=-1627272811;
assign dds_rom[884]=-1618635414;
assign dds_rom[885]=-1609936957;
assign dds_rom[886]=-1601177768;
assign dds_rom[887]=-1592358178;
assign dds_rom[888]=-1583478520;
assign dds_rom[889]=-1574539127;
assign dds_rom[890]=-1565540339;
assign dds_rom[891]=-1556482493;
assign dds_rom[892]=-1547365932;
assign dds_rom[893]=-1538190999;
assign dds_rom[894]=-1528958041;
assign dds_rom[895]=-1519667407;
assign dds_rom[896]=-1510319445;
assign dds_rom[897]=-1500914510;
assign dds_rom[898]=-1491452956;
assign dds_rom[899]=-1481935139;
assign dds_rom[900]=-1472361420;
assign dds_rom[901]=-1462732158;
assign dds_rom[902]=-1453047717;
assign dds_rom[903]=-1443308464;
assign dds_rom[904]=-1433514764;
assign dds_rom[905]=-1423666987;
assign dds_rom[906]=-1413765506;
assign dds_rom[907]=-1403810692;
assign dds_rom[908]=-1393802923;
assign dds_rom[909]=-1383742575;
assign dds_rom[910]=-1373630029;
assign dds_rom[911]=-1363465664;
assign dds_rom[912]=-1353249866;
assign dds_rom[913]=-1342983019;
assign dds_rom[914]=-1332665510;
assign dds_rom[915]=-1322297729;
assign dds_rom[916]=-1311880067;
assign dds_rom[917]=-1301412917;
assign dds_rom[918]=-1290896673;
assign dds_rom[919]=-1280331733;
assign dds_rom[920]=-1269718495;
assign dds_rom[921]=-1259057359;
assign dds_rom[922]=-1248348728;
assign dds_rom[923]=-1237593005;
assign dds_rom[924]=-1226790596;
assign dds_rom[925]=-1215941909;
assign dds_rom[926]=-1205047353;
assign dds_rom[927]=-1194107339;
assign dds_rom[928]=-1183122279;
assign dds_rom[929]=-1172092589;
assign dds_rom[930]=-1161018683;
assign dds_rom[931]=-1149900980;
assign dds_rom[932]=-1138739900;
assign dds_rom[933]=-1127535862;
assign dds_rom[934]=-1116289291;
assign dds_rom[935]=-1105000610;
assign dds_rom[936]=-1093670244;
assign dds_rom[937]=-1082298622;
assign dds_rom[938]=-1070886173;
assign dds_rom[939]=-1059433326;
assign dds_rom[940]=-1047940514;
assign dds_rom[941]=-1036408171;
assign dds_rom[942]=-1024836731;
assign dds_rom[943]=-1013226631;
assign dds_rom[944]=-1001578310;
assign dds_rom[945]=-989892205;
assign dds_rom[946]=-978168759;
assign dds_rom[947]=-966408413;
assign dds_rom[948]=-954611611;
assign dds_rom[949]=-942778799;
assign dds_rom[950]=-930910422;
assign dds_rom[951]=-919006928;
assign dds_rom[952]=-907068766;
assign dds_rom[953]=-895096387;
assign dds_rom[954]=-883090242;
assign dds_rom[955]=-871050785;
assign dds_rom[956]=-858978468;
assign dds_rom[957]=-846873748;
assign dds_rom[958]=-834737082;
assign dds_rom[959]=-822568927;
assign dds_rom[960]=-810369741;
assign dds_rom[961]=-798139987;
assign dds_rom[962]=-785880124;
assign dds_rom[963]=-773590615;
assign dds_rom[964]=-761271924;
assign dds_rom[965]=-748924515;
assign dds_rom[966]=-736548855;
assign dds_rom[967]=-724145409;
assign dds_rom[968]=-711714647;
assign dds_rom[969]=-699257037;
assign dds_rom[970]=-686773048;
assign dds_rom[971]=-674263153;
assign dds_rom[972]=-661727822;
assign dds_rom[973]=-649167528;
assign dds_rom[974]=-636582747;
assign dds_rom[975]=-623973951;
assign dds_rom[976]=-611341617;
assign dds_rom[977]=-598686221;
assign dds_rom[978]=-586008241;
assign dds_rom[979]=-573308155;
assign dds_rom[980]=-560586442;
assign dds_rom[981]=-547843582;
assign dds_rom[982]=-535080056;
assign dds_rom[983]=-522296345;
assign dds_rom[984]=-509492931;
assign dds_rom[985]=-496670297;
assign dds_rom[986]=-483828928;
assign dds_rom[987]=-470969307;
assign dds_rom[988]=-458091920;
assign dds_rom[989]=-445197252;
assign dds_rom[990]=-432285790;
assign dds_rom[991]=-419358020;
assign dds_rom[992]=-406414432;
assign dds_rom[993]=-393455512;
assign dds_rom[994]=-380481749;
assign dds_rom[995]=-367493634;
assign dds_rom[996]=-354491656;
assign dds_rom[997]=-341476305;
assign dds_rom[998]=-328448072;
assign dds_rom[999]=-315407450;
assign dds_rom[1000]=-302354930;
assign dds_rom[1001]=-289291003;
assign dds_rom[1002]=-276216164;
assign dds_rom[1003]=-263130905;
assign dds_rom[1004]=-250035720;
assign dds_rom[1005]=-236931103;
assign dds_rom[1006]=-223817548;
assign dds_rom[1007]=-210695550;
assign dds_rom[1008]=-197565604;
assign dds_rom[1009]=-184428205;
assign dds_rom[1010]=-171283849;
assign dds_rom[1011]=-158133031;
assign dds_rom[1012]=-144976248;
assign dds_rom[1013]=-131813997;
assign dds_rom[1014]=-118646772;
assign dds_rom[1015]=-105475073;
assign dds_rom[1016]=-92299394;
assign dds_rom[1017]=-79120233;
assign dds_rom[1018]=-65938088;
assign dds_rom[1019]=-52753456;
assign dds_rom[1020]=-39566833;
assign dds_rom[1021]=-26378718;
assign dds_rom[1022]=-13189608;
assign dds_rom[1023]=0;


endmodule

testbench_dds.v

`timescale 1ns / 1ps
`define NULL 0
module tb_dds();

parameter KHZ1 =44;
parameter KHZ2 =22;
parameter KHZ4 =11;
reg clk; 
initial begin 
  clk = 0; 
  #313333 clk = 0; 
  forever #11.072 clk = ~clk; 
end//45.1584MHZ

reg reset_n; 
initial begin 
  reset_n = 1; 
  #10000 reset_n = 0; 
  #100000 reset_n = 1; 
end 

reg [9:0] addr;
reg [9:0] cnt;
reg [31:0] k;
integer fb;

wire signed [31:0]     sin;
wire signed [31:0]     cos;

//Phase accumulation controller
always @(posedge clk or negedge reset_n) begin
  if(!reset_n) begin
      addr <= 0;
      cnt  <= 0;
    end
  else if(cnt == KHZ1-1) begin
    cnt <= 0;
    addr <= addr +10'd1;
  end
  else begin
    cnt <= cnt + 1;
    addr <= addr;
  end
end

//reg [8:0] i;//88.2khz
reg [9:0] i;//44.1khz Sample rate
reg signed [31:0] sin_slow;
reg signed [31:0] cos_slow;

always @(posedge clk or negedge reset_n) begin
  if(!reset_n) begin
    i <= 0;
    sin_slow <= 0;
    cos_slow <= 0;
    k <=0;
    fb = $fopen("sin.dat","w");
    if(fb == `NULL) begin
      $display("Can not open R.txt or G.txt or B.txt");
      $finish;
    end 
  end
  else begin
    i <= i+1;
    if(i == 0) begin
      sin_slow <= sin;
      cos_slow <= cos;
      k <= k +1;
      $display("time=[%d],%d",$realtime,sin);
      $fwrite(fb,"%d\n",sin);
      if(k == 4096) begin 
        $fclose(fb);
        $stop;
    end
    end
  end 
end 



dds_rom U_dds_rom( 
       .clk(clk),
       .addr(addr),//0-1023 1T
       .sin(sin),
       .cos(cos)
       );
endmodule

sin.dat下载

请登录后发表评论