DDS生成正弦波spa
`timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 2018/09/28 13:43:40 // Design Name: // Module Name: DDS // Project Name: // Target Devices: // Tool Versions: // Description: // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// module DDS( input mclk, input rst_n, input [31:0]fword, //frequency control input [11:0]pword, //phase control output [9:0]da_data ); reg [31:0]r_fword; reg [11:0]r_pword; reg [31:0]fcnt = 0; wire [11:0]addr_rom; //信號存儲到寄存器中 always @(posedge mclk) begin r_fword <= fword; r_pword <= pword; end
//累加器,r_fword值的大小決定了fcnt值增長的快慢,調節頻率便是調節r_fword的值 always @(posedge mclk or negedge rst_n) begin if(!rst_n) fcnt <= 32'd0; else fcnt <= fcnt + r_fword; end
//fcnt高十位做爲ROM的地址,r_pword爲偏移相位值,本仿真中r_pword設置爲0,即不作偏移 assign addr_rom = fcnt[31:20] + r_pword;
//給ROM時鐘和地址,ROM即吐出數據 sin_rom sin_rom ( .clka(mclk), // input wire clka .addra(addr_rom), // input wire [11 : 0] addra .douta(da_data) // output wire [9 : 0] douta ); endmodule /* add_force {/DDS/mclk} -radix hex {1 0ns} {0 5000ps} -repeat_every 10000ps add_force {/DDS/rst_n} -radix hex {0 0ns} {1 200ns} add_force {/DDS/fword} -radix hex {00004000 0ns} add_force {/DDS/pword} -radix hex {0 0ns} */
仿真結果:code
關於ROM時序分析:blog
經過以上分析,明顯能夠看出當ROM的地址更新後,數據在兩個時鐘週期內不會更新,而是第三個時鐘上升沿到來的時候,ROM輸出數據纔會更新。ip