01 DDS

一、工作原理

DDS(Direct Digital Synthesis)直接数字合成,常当成是信号发生器。通过matlab生成 2n 个点的正弦波查找表,波形数据保存在txt文本中。

二、matlab产生波形数据

这里是生成1024点正弦波数据,那么在区间(0,2π)内,每隔 2π/(1024-1)取一个值。

01 DDS
clear all
close all
clc

N  = 1024;%1024点一个正弦周期
Q  = 32;  %量化32bit

t =0:2*pi/(N-1):2*pi;
sin_dds = sin(t);
Maxb = max(abs(sin_dds));
Qb=round((sin_dds/Maxb)*(2^(Q-1)-1));

fidQb= fopen('wave.txt','w');
fprintf(fidQb,'wire signed [31:0] dds_rom[0:%d];\n',N-1); 
for i=1:length(Qb)
    fprintf(fidQb,'assign dds_rom[%d]=%d;\n',i-1,Qb(i)); 
end
fclose(fidQb);

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

figure,
hold on
plot(t,Qb,'*');
legend('sin');
grid;
hold off
View Code

01 DDS

 

 还有一个正弦波波形的数据:

01 DDS

三、综合代码

01 DDS
module dds_rom(
input sys_clk,
input [9:0]sin_addr,//地址数就是有多少个点,这里是1024
output signed[31:0]sin,//正弦波波形数据格式是32位
output signed[31:0]cos
);

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

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

endmodule 
View Code

四、仿真代码及仿真结果

这里设时钟是22.144,那么根据奈奎斯特理论,这里的采样频率需要44。

`timescale 1ns/1ps
module tb_dds();

parameter kHz=44;//根据奈奎斯特理论 只有采样频率高于原始信号最高频率的两倍时 才能把正弦波波形对应的数据还原成为原来波形

reg sys_clk;
reg [9:0]sin_addr;
wire signed[31:0]sin;
wire signed[31:0]cos;

initial begin
sys_clk=0;
#313333 sys_clk=0;
end
always #11.072 sys_clk=~sys_clk;

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

//相位积累控制器
reg [9:0]cnt;
always @(posedge sys_clk or negedge sys_rst_n) begin
  if(!sys_rst_n) begin
      sin_addr <= 0;
      cnt  <= 0;
    end
  else if(cnt == kHz-1) begin
    cnt <= 0;
    sin_addr <= sin_addr +10'd1;
  end
  else begin
    cnt <= cnt + 1;
    sin_addr <= sin_addr;
  end
end


dds_rom u_dds_rom(
.sys_clk (sys_clk),
.sin_addr (sin_addr),
.sin (sin),
.cos (cos)
);
endmodule 

 

01 DDS

 

上一篇:单片机及其工作原理粗略介绍


下一篇:冒泡排序实现