Hello
Now I did some tests with the following code and measuring output frequency with an oscillosope.
fOsc = 24 MHz
// Verilog module for variable clock generation of logic
// fOut = fclk * ClockGeneratorAccInc/2^32
module DDS(clk, ClkEnable);
input clk;
output ClkEnable;
parameter ClockGeneratorAccWidth = 32; // plus overflow bit
reg ClockGeneratorAcc;
always @(posedge clk)
begin
ClockGeneratorAcc <= ClockGeneratorAcc + 178956971;
// if (ClockGeneratorAcc == 1) ClockGeneratorAcc <= 0;
end
// Use the highest bit of the counter (MSB) to enable clock
assign ClkEnable = ClockGeneratorAcc;
endmodule
// test logic
module TestDDS(clk, fOut);
input clk;
output fOut;
wire cEn;
reg ClkOut;
DDS ClockGenerator(.clk(clk),.ClkEnable(cEn));
always @(posedge clk)
begin
if (cEn) ClkOut = ~ClkOut;
end
assign PWM = ClkOut;
endmodul
Results:
Using this design without reset on overflow:
There is a periodical signal on the output but the output signal
has area of 12 Mhz clock output and an area with output level 0.
The freuquency of the total signal follows the formula
fOut = 24 Mhz * Increment / 2^32
Using this design with reset on overflow:
There is a periodical signal, the high-low changes are evenly distributed.
I think it works a standard frequency divider.
On higer frequencies e.g. a set value of 18 Mhz I think the output is always 12 MHz
So the logic is not working as expected.
Does anybody have an idea?