2015-06-26 09:04:19 +00:00
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
2017-05-17 08:44:52 +00:00
|
|
|
// Copyright 2014 - 2017 (c) Analog Devices, Inc. All rights reserved.
|
2015-10-09 10:43:14 +00:00
|
|
|
//
|
2017-05-31 15:15:24 +00:00
|
|
|
// In this HDL repository, there are many different and unique modules, consisting
|
|
|
|
// of various HDL (Verilog or VHDL) components. The individual modules are
|
|
|
|
// developed independently, and may be accompanied by separate and unique license
|
|
|
|
// terms.
|
|
|
|
//
|
|
|
|
// The user should read each of these license terms, and understand the
|
2018-03-14 14:45:47 +00:00
|
|
|
// freedoms and responsibilities that he or she has by using this source/core.
|
2017-05-31 15:15:24 +00:00
|
|
|
//
|
|
|
|
// This core is distributed in the hope that it will be useful, but WITHOUT ANY
|
2017-05-29 06:55:41 +00:00
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE.
|
2015-10-09 10:43:14 +00:00
|
|
|
//
|
2017-05-29 06:55:41 +00:00
|
|
|
// Redistribution and use of source or resulting binaries, with or without modification
|
|
|
|
// of this file, are permitted under one of the following two license terms:
|
2015-10-09 10:43:14 +00:00
|
|
|
//
|
2017-05-17 08:44:52 +00:00
|
|
|
// 1. The GNU General Public License version 2 as published by the
|
2017-05-31 15:15:24 +00:00
|
|
|
// Free Software Foundation, which can be found in the top level directory
|
|
|
|
// of this repository (LICENSE_GPL2), and also online at:
|
|
|
|
// <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
|
2017-05-17 08:44:52 +00:00
|
|
|
//
|
|
|
|
// OR
|
|
|
|
//
|
2017-05-31 15:15:24 +00:00
|
|
|
// 2. An ADI specific BSD license, which can be found in the top level directory
|
|
|
|
// of this repository (LICENSE_ADIBSD), and also on-line at:
|
2017-05-29 06:55:41 +00:00
|
|
|
// https://github.com/analogdevicesinc/hdl/blob/master/LICENSE_ADIBSD
|
|
|
|
// This will allow to generate bit files and not release the source code,
|
|
|
|
// as long as it attaches to an ADI device.
|
2015-06-26 09:04:19 +00:00
|
|
|
//
|
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|
|
|
|
|
|
|
|
`timescale 1ns/100ps
|
|
|
|
|
2018-05-30 15:24:24 +00:00
|
|
|
module ad_dds_2 #(
|
2015-06-26 09:04:19 +00:00
|
|
|
|
2018-04-03 12:38:17 +00:00
|
|
|
// Range = 8-24
|
|
|
|
parameter DDS_DW = 16,
|
2018-05-31 14:31:30 +00:00
|
|
|
// Range = 8-24
|
|
|
|
parameter PHASE_DW = 16,
|
2018-04-03 12:38:17 +00:00
|
|
|
// Set 1 for CORDIC or 2 for Polynomial
|
2018-02-07 11:48:03 +00:00
|
|
|
parameter DDS_TYPE = 1,
|
2018-04-03 12:38:17 +00:00
|
|
|
// Range = 8-24
|
2018-02-28 17:09:45 +00:00
|
|
|
parameter CORDIC_DW = 16,
|
2018-04-03 12:38:17 +00:00
|
|
|
// Range = 8-24 ( make sure CORDIC_PHASE_DW < CORDIC_DW)
|
2018-02-28 17:09:45 +00:00
|
|
|
parameter CORDIC_PHASE_DW = 16) (
|
2018-02-15 15:14:55 +00:00
|
|
|
|
2015-06-26 09:04:19 +00:00
|
|
|
// interface
|
|
|
|
|
2018-05-31 14:31:30 +00:00
|
|
|
input clk,
|
|
|
|
input dds_format,
|
|
|
|
input [PHASE_DW-1:0] dds_phase_0,
|
|
|
|
input [ 15:0] dds_scale_0,
|
|
|
|
input [PHASE_DW-1:0] dds_phase_1,
|
|
|
|
input [ 15:0] dds_scale_1,
|
|
|
|
output [ DDS_DW-1:0] dds_data);
|
2018-04-03 12:38:17 +00:00
|
|
|
|
|
|
|
// Local parameters
|
|
|
|
|
|
|
|
localparam CORDIC = 1;
|
|
|
|
localparam POLYNOMIAL = 2;
|
|
|
|
|
|
|
|
// The width for Polynomial DDS is fixed (16)
|
|
|
|
localparam DDS_D_DW = (DDS_TYPE == CORDIC) ? CORDIC_DW : 16;
|
|
|
|
localparam DDS_P_DW = (DDS_TYPE == CORDIC) ? CORDIC_PHASE_DW : 16;
|
|
|
|
// concatenation or truncation width
|
|
|
|
localparam C_T_WIDTH = (DDS_D_DW > DDS_DW) ? (DDS_D_DW - DDS_DW) : (DDS_DW - DDS_D_DW);
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
// internal registers
|
|
|
|
|
2018-04-03 12:38:17 +00:00
|
|
|
reg [ DDS_DW-1:0] dds_data_width = 0;
|
|
|
|
reg [DDS_D_DW-1:0] dds_data_rownd = 0;
|
|
|
|
reg [DDS_D_DW-1:0] dds_data_int = 0;
|
|
|
|
reg [ 15:0] dds_scale_0_d = 0;
|
|
|
|
reg [ 15:0] dds_scale_1_d = 0;
|
|
|
|
reg [ DDS_DW-1:0] dds_data_out = 0;
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
// internal signals
|
|
|
|
|
2018-05-31 14:31:30 +00:00
|
|
|
wire [DDS_D_DW-1:0] dds_data_0_s;
|
|
|
|
wire [DDS_D_DW-1:0] dds_data_1_s;
|
|
|
|
wire [DDS_P_DW-1:0] dds_phase_0_s;
|
|
|
|
wire [DDS_P_DW-1:0] dds_phase_1_s;
|
2015-06-26 09:04:19 +00:00
|
|
|
|
2018-02-07 11:48:03 +00:00
|
|
|
generate
|
2018-06-27 14:06:38 +00:00
|
|
|
// dds channel output
|
|
|
|
assign dds_data = dds_data_out;
|
2018-04-03 12:38:17 +00:00
|
|
|
|
2018-06-27 14:06:38 +00:00
|
|
|
// output data format
|
|
|
|
always @(posedge clk) begin
|
|
|
|
dds_data_out[DDS_DW-1] <= dds_data_width[DDS_DW-1] ^ dds_format;
|
|
|
|
dds_data_out[DDS_DW-2: 0] <= dds_data_width[DDS_DW-2: 0];
|
|
|
|
end
|
2018-04-03 12:38:17 +00:00
|
|
|
|
2018-06-27 14:06:38 +00:00
|
|
|
// set desired data width
|
|
|
|
always @(posedge clk) begin
|
|
|
|
if (DDS_DW <= DDS_D_DW) begin // truncation
|
|
|
|
// fair rownding
|
|
|
|
dds_data_rownd <= dds_data_int + {(C_T_WIDTH){dds_data_int[DDS_D_DW-1]}};
|
|
|
|
dds_data_width <= dds_data_rownd[DDS_D_DW-1:DDS_D_DW-DDS_DW];
|
|
|
|
end else begin // concatenation
|
|
|
|
dds_data_width <= dds_data_int << C_T_WIDTH;
|
2018-04-03 12:38:17 +00:00
|
|
|
end
|
2018-06-27 14:06:38 +00:00
|
|
|
end
|
2018-02-07 11:48:03 +00:00
|
|
|
|
2018-06-27 14:06:38 +00:00
|
|
|
// dual tone
|
|
|
|
always @(posedge clk) begin
|
|
|
|
dds_data_int <= dds_data_0_s + dds_data_1_s;
|
2018-02-07 11:48:03 +00:00
|
|
|
end
|
2018-06-27 14:06:38 +00:00
|
|
|
|
|
|
|
always @(posedge clk) begin
|
|
|
|
dds_scale_0_d <= dds_scale_0;
|
|
|
|
dds_scale_1_d <= dds_scale_1;
|
|
|
|
end
|
|
|
|
|
|
|
|
// phase
|
|
|
|
if (DDS_P_DW > PHASE_DW) begin
|
|
|
|
assign dds_phase_0_s = {dds_phase_0,{DDS_P_DW-PHASE_DW{1'b0}}};
|
|
|
|
assign dds_phase_1_s = {dds_phase_1,{DDS_P_DW-PHASE_DW{1'b0}}};
|
|
|
|
end else begin
|
|
|
|
assign dds_phase_0_s = dds_phase_0[(PHASE_DW-1):PHASE_DW-DDS_P_DW];
|
|
|
|
assign dds_phase_1_s = dds_phase_1[(PHASE_DW-1):PHASE_DW-DDS_P_DW];
|
|
|
|
end
|
|
|
|
|
|
|
|
// dds-1
|
|
|
|
|
|
|
|
ad_dds_1 #(
|
|
|
|
.DDS_TYPE(DDS_TYPE),
|
|
|
|
.DDS_D_DW(DDS_D_DW),
|
|
|
|
.DDS_P_DW(DDS_P_DW))
|
|
|
|
i_dds_1_0 (
|
|
|
|
.clk (clk),
|
|
|
|
.angle (dds_phase_0_s),
|
|
|
|
.scale (dds_scale_0_d),
|
|
|
|
.dds_data (dds_data_0_s));
|
|
|
|
|
|
|
|
// dds-2
|
|
|
|
|
|
|
|
ad_dds_1 #(
|
|
|
|
.DDS_TYPE(DDS_TYPE),
|
|
|
|
.DDS_D_DW(DDS_D_DW),
|
|
|
|
.DDS_P_DW(DDS_P_DW))
|
|
|
|
i_dds_1_1 (
|
|
|
|
.clk (clk),
|
|
|
|
.angle (dds_phase_1_s),
|
|
|
|
.scale (dds_scale_1_d),
|
|
|
|
.dds_data (dds_data_1_s));
|
2018-02-07 11:48:03 +00:00
|
|
|
endgenerate
|
2015-06-26 09:04:19 +00:00
|
|
|
|
|
|
|
endmodule
|
|
|
|
|
|
|
|
// ***************************************************************************
|
|
|
|
// ***************************************************************************
|