波形发生器.docx
《波形发生器.docx》由会员分享,可在线阅读,更多相关《波形发生器.docx(46页珍藏版)》请在冰豆网上搜索。
波形发生器
>dds_ise7.1_su.rar>dds6.v,change:
2004-12-04,size:
36686b
窗体顶端
/************************************************************/
//Title:
波形发生器*/
//Date:
2004-11-27
//Copyright:
CUSH四院二队*/
/************************************************************/
moduleDDS(FREQWORD,AX,CLK,DACOUT/*,sine2*/,EN,CLK_OUT,/*OUTCLK2,*/SELECT);
input[7:
0]FREQWORD;//频率控制字
input[1:
0]AX;//数据输入选择
input[2:
0]SELECT;//波形选择
inputCLK,EN;//系统时钟,使能端
output[11:
0]DACOUT;//D/A的数据输入
outputCLK_OUT;//D/A时钟
reg[17:
0]FREQ_REG;//频率控制字寄存器
reg[2:
0]COUNTER;//三分频50MHz-->16.667MHz
reg[11:
0]DACOUT_BUFFER;
//reg[11:
0]SIN_ROM;//波形表
//reg[11:
0]FANGBO_ROM;
//reg[11:
0]SANJIAO_ROM;
//reg[11:
0]JUCI_ROM;
reg[18:
0]PHASE;//相位累加器
reg[9:
0]MOD_PHASE;//查表地址
regOUTCLK;
regCLK_REG_1;
//wireCLK_REG_2;
/************************************************/
//读入频率控制字//
always@(negedgeEN)
begin
case(AX)
2'h0:
FREQ_REG[17:
16]=FREQWORD[1:
0];
2'h1:
FREQ_REG[15:
8]=FREQWORD;
2'h2:
FREQ_REG[7:
0]=FREQWORD;
endcase
end
/************************************************/
//对CLK三分频//
always@(posedgeCLK)
begin
if(COUNTER<2'h2)
begin
COUNTER<=COUNTER+1;
OUTCLK<=0;
end
else
begin
COUNTER<=0;
OUTCLK<=1;
end
end
assignCLK_OUT=OUTCLK;
/************************************************/
//相位累加产生进位,改变查表地址//
always@(posedgeCLK)
begin
if(EN)
begin
PHASE=PHASE+FREQ_REG;
if(PHASE<18'h21e89)
begin
CLK_REG_1<=0;
end
else
begin
PHASE=PHASE-18'h21e89;
CLK_REG_1<=1;
end
end
end
/************************************************/
//相位累加,生成查表地址//
//assignCLK_REG_2=CLK_REG_1;
always@(posedgeCLK_REG_1)
begin
if(MOD_PHASE<10'h167)
MOD_PHASE<=MOD_PHASE+1;
else
MOD_PHASE<=0;
end
assignDACOUT=DACOUT_BUFFER;
/***********************************************/
//波形选择//
always@(posedgeCLK)
case(SELECT)
3'b000:
DACOUT_BUFFER=SIN_ROM(MOD_PHASE);
3'b001:
DACOUT_BUFFER=SANJIAO_ROM(MOD_PHASE);
3'b011:
DACOUT_BUFFER=FANGBO_ROM(MOD_PHASE);
3'b010:
DACOUT_BUFFER=JUCI_ROM(MOD_PHASE);
3'b110:
DACOUT_BUFFER=SIN_ROM(MOD_PHASE*4%360);
3'b100:
DACOUT_BUFFER=JUCI_ROM(359-MOD_PHASE);
3'b101:
DACOUT_BUFFER=SIN_ROM(MOD_PHASE)<<1+SIN_ROM(3*MOD_PHASE)<<2+SIN_ROM(5*MOD_PHASE)/8;
default:
DACOUT_BUFFER=SIN_ROM(MOD_PHASE);
endcase
function[11:
0]FANGBO_ROM;
input[8:
0]fangphase;//always@(MOD_PHASE)
begin
if(fangphase<180)
FANGBO_ROM=12'd0;
else
FANGBO_ROM=12'd4095;
end
endfunction
function[11:
0]SIN_ROM;//always@(MOD_PHASE)
input[8:
0]sinphase;
begin
case(sinphase)
9'h0:
SIN_ROM=12'd2048;
9'h1:
SIN_ROM=12'd2084;
9'h2:
SIN_ROM=12'd2120;
9'h3:
SIN_ROM=12'd2156;
9'h4:
SIN_ROM=12'd2188;
9'h5:
SIN_ROM=12'd2228;
9'h6:
SIN_ROM=12'd2260;
9'h7:
SIN_ROM=12'd2296;
9'h8:
SIN_ROM=12'd2332;
9'h9:
SIN_ROM=12'd2368;
9'ha:
SIN_ROM=12'd2400;
9'hb:
SIN_ROM=12'd2440;
9'hc:
SIN_ROM=12'd2472;
9'hd:
SIN_ROM=12'd2508;
9'he:
SIN_ROM=12'd2544;
9'hf:
SIN_ROM=12'd2576;
9'h10:
SIN_ROM=12'd2612;
9'h11:
SIN_ROM=12'd2648;
9'h12:
SIN_ROM=12'd2680;
9'h13:
SIN_ROM=12'd2716;
9'h14:
SIN_ROM=12'd2748;
9'h15:
SIN_ROM=12'd2780;
9'h16:
SIN_ROM=12'd2816;
9'h17:
SIN_ROM=12'd2848;
9'h18:
SIN_ROM=12'd2880;
9'h19:
SIN_ROM=12'd2912;
9'h1a:
SIN_ROM=12'd2944;
9'h1b:
SIN_ROM=12'd2976;
9'h1c:
SIN_ROM=12'd3008;
9'h1d:
SIN_ROM=12'd3040;
9'h1e:
SIN_ROM=12'd3072;
9'h1f:
SIN_ROM=12'd3104;
9'h20:
SIN_ROM=12'd3132;
9'h21:
SIN_ROM=12'd3164;
9'h22:
SIN_ROM=12'd3192;
9'h23:
SIN_ROM=12'd3224;
9'h24:
SIN_ROM=12'd3252;
9'h25:
SIN_ROM=12'd3280;
9'h26:
SIN_ROM=12'd3308;
9'h27:
SIN_ROM=12'd3336;
9'h28:
SIN_ROM=12'd3364;
9'h29:
SIN_ROM=12'd3392;
9'h2a:
SIN_ROM=12'd3420;
9'h2b:
SIN_ROM=12'd3444;
9'h2c:
SIN_ROM=12'd3472;
9'h2d:
SIN_ROM=12'd3496;
9'h2e:
SIN_ROM=12'd3520;
9'h2f:
SIN_ROM=12'd3544;
9'h30:
SIN_ROM=12'd3568;
9'h31:
SIN_ROM=12'd3592;
9'h32:
SIN_ROM=12'd3616;
9'h33:
SIN_ROM=12'd3640;
9'h34:
SIN_ROM=12'd3660;
9'h35:
SIN_ROM=12'd3684;
9'h36:
SIN_ROM=12'd3704;
9'h37:
SIN_ROM=12'd3724;
9'h38:
SIN_ROM=12'd3744;
9'h39:
SIN_ROM=12'd3764;
9'h3a:
SIN_ROM=12'd3784;
9'h3b:
SIN_ROM=12'd3804;
9'h3c:
SIN_ROM=12'd3820;
9'h3d:
SIN_ROM=12'd3840;
9'h3e:
SIN_ROM=12'd3856;
9'h3f:
SIN_ROM=12'd3872;
9'h40:
SIN_ROM=12'd3888;
9'h41:
SIN_ROM=12'd3904;
9'h42:
SIN_ROM=12'd3920;
9'h43:
SIN_ROM=12'd3936;
9'h44:
SIN_ROM=12'd3948;
9'h45:
SIN_ROM=12'd3960;
9'h46:
SIN_ROM=12'd3972;
9'h47:
SIN_ROM=12'd3984;
9'h48:
SIN_ROM=12'd3996;
9'h49:
SIN_ROM=12'd4008;
9'h4a:
SIN_ROM=12'd4020;
9'h4b:
SIN_ROM=12'd4028;
9'h4c:
SIN_ROM=12'd4036;
9'h4d:
SIN_ROM=12'd4044;
9'h4e:
SIN_ROM=12'd4052;
9'h4f:
SIN_ROM=12'd4060;
9'h50:
SIN_ROM=12'd4068;
9'h51:
SIN_ROM=12'd4072;
9'h52:
SIN_ROM=12'd4076;
9'h53:
SIN_ROM=12'd4080;
9'h54:
SIN_ROM=12'd4084;
9'h55:
SIN_ROM=12'd4088;
9'h56:
SIN_ROM=12'd4091;
9'h57:
SIN_ROM=12'd4093;
9'h58:
SIN_ROM=12'd4095;
9'h59:
SIN_ROM=12'd4095;
9'h5a:
SIN_ROM=12'd4095;
9'h5b:
SIN_ROM=12'd4095;
9'h5c:
SIN_ROM=12'd4095;
9'h5d:
SIN_ROM=12'd4093;
9'h5e:
SIN_ROM=12'd4091;
9'h5f:
SIN_ROM=12'd4088;
9'h60:
SIN_ROM=12'd4084;
9'h61:
SIN_ROM=12'd4080;
9'h62:
SIN_ROM=12'd4076;
9'h63:
SIN_ROM=12'd4072;
9'h64:
SIN_ROM=12'd4068;
9'h65:
SIN_ROM=12'd4060;
9'h66:
SIN_ROM=12'd4052;
9'h67:
SIN_ROM=12'd4044;
9'h68:
SIN_ROM=12'd4036;
9'h69:
SIN_ROM=12'd4028;
9'h6a:
SIN_ROM=12'd4020;
9'h6b:
SIN_ROM=12'd4008;
9'h6c:
SIN_ROM=12'd3996;
9'h6d:
SIN_ROM=12'd3984;
9'h6e:
SIN_ROM=12'd3972;
9'h6f:
SIN_ROM=12'd3960;
9'h70:
SIN_ROM=12'd3948;
9'h71:
SIN_ROM=12'd3936;
9'h72:
SIN_ROM=12'd3920;
9'h73:
SIN_ROM=12'd3904;
9'h74:
SIN_ROM=12'd3888;
9'h75:
SIN_ROM=12'd3872;
9'h76:
SIN_ROM=12'd3856;
9'h77:
SIN_ROM=12'd3840;
9'h78:
SIN_ROM=12'd3820;
9'h79:
SIN_ROM=12'd3804;
9'h7a:
SIN_ROM=12'd3784;
9'h7b:
SIN_ROM=12'd3764;
9'h7c:
SIN_ROM=12'd3744;
9'h7d:
SIN_ROM=12'd3724;
9'h7e:
SIN_ROM=12'd3704;
9'h7f:
SIN_ROM=12'd3684;
9'h80:
SIN_ROM=12'd3660;
9'h81:
SIN_ROM=12'd3640;
9'h82:
SIN_ROM=12'd3616;
9'h83:
SIN_ROM=12'd3592;
9'h84:
SIN_ROM=12'd3568;
9'h85:
SIN_ROM=12'd3544;
9'h86:
SIN_ROM=12'd3520;
9'h87:
SIN_ROM=12'd3496;
9'h88:
SIN_ROM=12'd3472;
9'h89:
SIN_ROM=12'd3444;
9'h8a:
SIN_ROM=12'd3420;
9'h8b:
SIN_ROM=12'd3392;
9'h8c:
SIN_ROM=12'd3364;
9'h8d:
SIN_ROM=12'd3336;
9'h8e:
SIN_ROM=12'd3308;
9'h8f:
SIN_ROM=12'd3280;
9'h90:
SIN_ROM=12'd3252;
9'h91:
SIN_ROM=12'd3224;
9'h92:
SIN_ROM=12'd3192;
9'h93:
SIN_ROM=12'd3164;
9'h94:
SIN_ROM=12'd3132;
9'h95:
SIN_ROM=12'd3104;
9'h96:
SIN_ROM=12'd3072;
9'h97:
SIN_ROM=12'd3040;
9'h98:
SIN_ROM=12'd3008;
9'h99:
SIN_ROM=12'd2976;
9'h9a:
SIN_ROM=12'd2944;
9'h9b:
SIN_ROM=12'd2912;
9'h9c:
SIN_ROM=12'd2880;
9'h9d:
SIN_ROM=12'd2848;
9'h9e:
SIN_ROM=12'd2816;
9'h9f:
SIN_ROM=12'd2780;
9'ha0:
SIN_ROM=12'd2748;
9'ha1:
SIN_ROM=12'd2716;
9'ha2:
SIN_ROM=12'd2680;
9'ha3:
SIN_ROM=12'd2648;
9'ha4:
SIN_ROM=12'd2612;
9'ha5:
SIN_ROM=12'd2576;
9'ha6:
SIN_ROM=12'd2544;
9'ha7:
SIN_ROM=12'd2508;
9'ha8:
SIN_ROM=12'd2472;
9'ha9:
SIN_ROM=12'd2440;
9'haa:
SIN_ROM=12'd2404;
9'hab:
SIN_ROM=12'd2368;
9'hac:
SIN_ROM=12'd2332;
9'had:
SIN_ROM=12'd2296;
9'hae:
SIN_ROM=12'd2260;
9'haf:
SIN_ROM=12'd2228;
9'hb0:
SIN_ROM=12'd2188;
9'hb1:
SIN_ROM=12'd2156;
9'hb2:
SIN_ROM=12'd2120;
9'hb3:
SIN_ROM=12'd2084;
9'hb4:
SIN_ROM=12'd2048;
9'hb5:
SIN_ROM=12'd2012;
9'hb6:
SIN_ROM=12'd1976;
9'hb7:
SIN_ROM=12'd1940;
9'hb8:
SIN_ROM=12'd1904;
9'hb9:
SIN_ROM=12'd1868;
9'hba:
SIN_ROM=12'd1832;
9'hbb:
SIN_ROM=12'd1896;
9'hbc:
SIN_ROM=12'd1760;
9'hbd:
SIN_ROM=12'd1728;
9'hbe:
SIN_ROM=12'd1692;
9'hbf:
SIN_ROM=12'd1656;
9'hc0:
SIN_ROM=12'd1620;
9'hc1:
SIN_ROM=12'd1588;
9'hc2:
SIN_ROM=12'd1552;
9'hc3:
SIN_ROM=12'd1520;
9'hc4:
SIN_ROM=12'd1484;
9'hc5:
SIN_ROM=12'd1448;
9'hc6:
SIN_ROM=12'd1416;
9'hc7:
SIN_ROM=12'd1380;
9'hc8:
SIN_ROM=12'd1348;
9'hc9:
SIN_ROM=12'd1312;
9'hca:
SIN_ROM=12'd1280;
9'hcb:
SIN_ROM=12'd1248;
9'hcc:
SIN_ROM=12'd1216;
9'hcd:
SIN_ROM=12'd1184;
9'hce:
SIN_ROM=12'd1152;
9'hcf:
SIN_ROM=12'd1120;
9'hd0:
SIN_ROM=12'd1088;
9'hd1:
SIN_ROM=12'd1056;
9'hd2:
SIN_ROM=12'd1024;
9'hd3:
SIN_ROM=12'd992;
9'hd4:
SIN_ROM=12'd964;
9'hd5:
SIN_ROM=12'd932;
9'hd6:
SIN_ROM=12'd904;
9'hd7:
SIN_ROM=12'd872;
9'hd8:
SIN_ROM=12'd844;
9'hd9:
SIN_ROM=12'd816;
9'hda:
SIN_ROM=12'd788;
9'hdb:
SIN_ROM=12'd760;
9'hdc:
SIN_ROM=12'd732;
9'hdd:
SIN_ROM=12'd704;
9'hde:
SIN_ROM=12'd676;
9'hdf:
SIN_ROM=12'd652;
9'he0:
SIN_ROM=12'd624;
9'he1:
SIN_ROM=12'd600;
9'he2:
SIN_ROM=12'd576;
9'he3:
SIN_ROM=12'd548;
9'he4:
SIN_ROM=12'd524;
9'he5:
SIN_ROM=12'd504;
9'he6:
SIN_ROM=12'd480;
9'he7:
SIN_ROM=12'd456;
9'he8:
SIN_ROM=12'd432;
9'he9:
SIN_ROM=12'd412;
9'hea:
SIN_ROM=12'd392;
9'heb:
SIN_ROM=12'd372;
9'hec:
SIN_ROM=12'd348;
9'hed:
SIN_ROM=12'd332;
9'hee:
SIN_ROM=12'd312;
9'hef:
SIN_ROM=12'd292;
9'hf0:
SIN_ROM=12'd276;
9'hf1:
SIN_ROM=12'd256;
9'hf2:
SIN_ROM=12'd240;
9'hf3:
SIN_ROM=12'd224;
9'hf4:
SIN_ROM=12'd208;
9'hf5:
SIN_ROM=12'd192;
9'hf6:
SIN_ROM=12'd176;
9'hf7:
SIN_ROM=12'd164;
9'hf8:
SIN_ROM=12'd148;
9'hf9:
SIN_ROM=12'd136;
9'hfa:
SIN_ROM=12'd124;
9'hfb:
SIN_ROM=12'd112;
9'hfc:
SIN_ROM=12'd100;
9'hfd:
SIN_ROM=12'd88;
9'hfe:
SIN_ROM=12'd78;
9'hff:
SIN_ROM=12'd68;
9'h100:
SIN_ROM=12'd60;
9'h101:
SIN_ROM=12'd52;
9'h102:
SIN_ROM=12'd44;
9'h103:
SIN_ROM=12'd36;
9'h104:
SIN_ROM=12'd30;
9'h105:
SIN_ROM=12'd24;
9'h106:
SIN_ROM=12'd20;
9'h107:
SIN_ROM=12'd16;
9'h108:
SIN_ROM=12'd12;
9'h109:
SIN_ROM=12'd8;
9'h10a:
SIN_ROM=12'd6;