|
楼主 |
发表于 2020-12-18 15:09:13
|
显示全部楼层
module DDS(
clk,
rst_n,
en_DDS,
Fword,
Pword,
q
);
input clk;
input rst_n;
input en_DDS;
input [31:0]Fword; //频率控制字
input [11:0]Pword; //相位控制字
output [11:0]q;
reg [31:0]r_Fword;
reg [11:0]r_Pword;
reg [31:0]F_acc;
reg [11:0]rom_address;
always@(posedge clk or negedge rst_n)
if(!rst_n)
r_Fword <= 0;
else if(en_DDS)
r_Fword <= Fword;
else
r_Fword <= 0;
always@(posedge clk or negedge rst_n)
if(!rst_n)
r_Pword <= 0;
else if(en_DDS)
r_Pword <= Pword;
else
r_Pword <= 0;
always@(posedge clk or negedge rst_n)
if(!rst_n)
F_acc <= 32'd0;
else if(en_DDS)
F_acc <= F_acc + r_Fword;
else
F_acc <= 32'd0;
always@(posedge clk or negedge rst_n)
if(!rst_n)
rom_address <= 12'd0;
else if(en_DDS)
rom_address <= F_acc[31:20] + r_Pword;
else
rom_address <= 12'd0;
DDS_rom DDS_rom0(
.address(rom_address),
.clock(clk),
.q(q)
);
endmodule
|
|