I'm playing with verilog, to which I'm new, and an Anlogic AL3-10 device. Using the Tang Dynasty IDE release 5.0.3 and run into strange behavior of which I'm not sure if it is my verilog or the IDE.
Trying to make a DDS with two 14 bit DAC's. For first testing I made a sawtooth generator and when running on a fixed counter increment it works for both channels, as long as there is a power of 2 relation between the two channels. When I set step values that have a non power of 2 relation it either kills the first channel or the frequency is incorrect.
The code I wrote for this:
//---------------------------------------------------------------------------
//Main module for connections with the outside world
module FA201_Lichee_nano
(
//Input signals
input wire i_xtal, //50 MHz clock
//Output signals
output wire o_dac1_clk,
output wire o_dac1_wrt,
output wire o_dac2_clk,
output wire o_dac2_wrt,
output wire [13:0] o_dac1_d,
output wire [13:0] o_dac2_d
);
//---------------------------------------------------------------------------
//Internal wire
wire core_clock;
wire [31:0] channel1_signal_step;
wire [31:0] channel2_signal_step;
//---------------------------------------------------------------------------
//Connection with the sub modules
pll_clock pll
(
.refclk (i_xtal),
.reset (1'b0),
.clk0_out (core_clock)
);
awg dac1
(
.i_main_clock (core_clock),
.i_signal_step (32'h400000),
.o_dac_clk (o_dac1_clk),
.o_dac_wrt (o_dac1_wrt),
.o_dac_d (o_dac1_d)
);
awg dac2
(
.i_main_clock (core_clock),
.i_signal_step (32'h1723549),
.o_dac_clk (o_dac2_clk),
.o_dac_wrt (o_dac2_wrt),
.o_dac_d (o_dac2_d)
);
endmodule
//---------------------------------------------------------------------------
//----------------------------------------------------------------------------------
//Module for generating the DAC signals
module awg
(
//Input
input i_main_clock,
input [31:0] i_signal_step,
//Output
output [13:0] o_dac_d,
output o_dac_clk,
output o_dac_wrt
);
//--------------------------------------------------------------------------------
//Registers
reg clock;
reg write;
reg [35:0] signal_phase;
//--------------------------------------------------------------------------------
//Logic
always@(posedge i_main_clock)
begin
clock <= ~clock;
end
always@(posedge i_main_clock)
begin
write <= ~write;
end
always@(negedge i_main_clock)
begin
if(write == 1'b1)
signal_phase <= signal_phase + i_signal_step;
else
signal_phase <= signal_phase;
end
//--------------------------------------------------------------------------------
//Connect
assign o_dac_d = signal_phase[35:22];
assign o_dac_clk = clock;
assign o_dac_wrt = write;
endmodule
//----------------------------------------------------------------------------------
When I set the same value for both step values it works with both outputting the same frequency. As long as there is a power of 2 relation between the two it works correctly. I just tried it with decimal 4194304 for channel 1 and decimal 12582912 for channel 2. A factor 3 between the two. The result is 30.4KHz on channel 1 and 22.8KHz on channel 2. The 22.8KHz is correct. The frequency on channel 1 should have been 7.6KHz
So why is this happening?