T
Tobias Weingartner
Guest
Hello all,
I've been messing around with some verilog code, trying to implement
a digital controlled oscilator (overglorified counter). I thought
that I had the basics of verilog down, but it seems that I have some
to learn yet.
Anyways, below is some verilog code (I hope) that I wrote, but it does
not seem to want to do what I want it to do. Funny how that goes. It
should respect a reset (and seems to) pulse, as well as a "load" pulse
to load a value, and then start counting up to that value wrapping to
zero when you hit that value. Each time you hit the loaded value, the
output "q" should change, giving you sort of a DCO 50% waveform. For
some reason, div stays "x", and never loads...
Thougths? Pointers to the problem? All suggestions welcome.
module dco(clk,reset,load,data,q);
parameter DBW = 1;
input clk; // System clock
input reset; // Reset
input load; // Load data value
input [DBW-1:0] data; // Data (count) value
output q; // Output waveform
reg [DBW-1:0] count;
reg [DBW-1:0] div;
reg q;
always @(posedge clk)
if(reset) begin
count <= 0;
q <= 0;
end
else if(load) begin
div <= data;
end
else begin
if(count == div) begin
count <= 0;
q <= ~q;
end
else begin
count <= count + 1;
end
end
endmodule
module test;
parameter WIDTH = 14;
reg reset;
reg clk;
reg dco_load;
reg [WIDTH-1:0] dco_data;
wire dco_out;
dco #(WIDTH) dco0(clk,reset,dco_load,dco_data,dco_out);
// Start our clock
initial begin
#0 clk = 0;
forever #5 clk = ~clk;
end
// Send reset pulse, run simulation...
initial begin
reset = 1'bx;
#25 reset = 0;
#25 reset = 1;
#50 dco_load = 0; // Load a value into the DCO
#50 dco_data = 13;
#55 dco_load = 1;
#65 dco_load = 0;
#1000 $finish(2);
end
// Results display code
initial
begin
#0 $write ("\n");
#0 $display ("Results display");
end
always begin @(clk)
begin
$timeformat(-9, 0, "ns", 5);
$display ("%T", $time,,"%b",clk,,
"%b",reset,,
"%b",dco_load,,
"%d",dco_data,,
"%b",dco_out,,
"%d",dco0.div,,
"%d",dco0.count,,
"%b",dco0.q,,
);
end
end
endmodule
Oh, I'm using cver, nothing fancy...
--
[100~Plax]sb16i0A2172656B63616820636420726568746F6E61207473754A[dZ1!=b]salax
I've been messing around with some verilog code, trying to implement
a digital controlled oscilator (overglorified counter). I thought
that I had the basics of verilog down, but it seems that I have some
to learn yet.
Anyways, below is some verilog code (I hope) that I wrote, but it does
not seem to want to do what I want it to do. Funny how that goes. It
should respect a reset (and seems to) pulse, as well as a "load" pulse
to load a value, and then start counting up to that value wrapping to
zero when you hit that value. Each time you hit the loaded value, the
output "q" should change, giving you sort of a DCO 50% waveform. For
some reason, div stays "x", and never loads...
Thougths? Pointers to the problem? All suggestions welcome.
module dco(clk,reset,load,data,q);
parameter DBW = 1;
input clk; // System clock
input reset; // Reset
input load; // Load data value
input [DBW-1:0] data; // Data (count) value
output q; // Output waveform
reg [DBW-1:0] count;
reg [DBW-1:0] div;
reg q;
always @(posedge clk)
if(reset) begin
count <= 0;
q <= 0;
end
else if(load) begin
div <= data;
end
else begin
if(count == div) begin
count <= 0;
q <= ~q;
end
else begin
count <= count + 1;
end
end
endmodule
module test;
parameter WIDTH = 14;
reg reset;
reg clk;
reg dco_load;
reg [WIDTH-1:0] dco_data;
wire dco_out;
dco #(WIDTH) dco0(clk,reset,dco_load,dco_data,dco_out);
// Start our clock
initial begin
#0 clk = 0;
forever #5 clk = ~clk;
end
// Send reset pulse, run simulation...
initial begin
reset = 1'bx;
#25 reset = 0;
#25 reset = 1;
#50 dco_load = 0; // Load a value into the DCO
#50 dco_data = 13;
#55 dco_load = 1;
#65 dco_load = 0;
#1000 $finish(2);
end
// Results display code
initial
begin
#0 $write ("\n");
#0 $display ("Results display");
end
always begin @(clk)
begin
$timeformat(-9, 0, "ns", 5);
$display ("%T", $time,,"%b",clk,,
"%b",reset,,
"%b",dco_load,,
"%d",dco_data,,
"%b",dco_out,,
"%d",dco0.div,,
"%d",dco0.count,,
"%b",dco0.q,,
);
end
end
endmodule
Oh, I'm using cver, nothing fancy...
--
[100~Plax]sb16i0A2172656B63616820636420726568746F6E61207473754A[dZ1!=b]salax