Line 1... |
Line 1... |
|
|
`include "defines.v"
|
`include "defines.v"
|
|
|
module odd(clk, out, P, reset, enable);
|
module odd(clk, out, N, reset, enable);
|
|
|
input clk; // slow clock
|
input clk; // slow clock
|
output out;
|
output out; // fast output clock
|
input [`SIZE-1:0] P;
|
input [`SIZE-1:0] N; // division factor
|
input reset;
|
input reset; // synchronous reset
|
input enable;
|
input enable; // odd enable
|
|
|
reg [`SIZE-1:0] counter;
|
reg [`SIZE-1:0] counter; // these 2 counters are used
|
reg [`SIZE-1:0] counter2;
|
reg [`SIZE-1:0] counter2; // to non-overlapping signals
|
reg out_counter;
|
reg out_counter; // positive edge triggered counter
|
reg out_counter2;
|
reg out_counter2; // negative edge triggered counter
|
reg rst_pulse;
|
reg rst_pulse; // pulse generated when vector N changes
|
reg [`SIZE-1:0] old_P;
|
reg [`SIZE-1:0] old_N; // gets set to old N when N is changed
|
wire not_zero;
|
wire not_zero; // if !not_zero, we devide by 1
|
|
|
assign out = out_counter2 ^ out_counter;
|
assign out = out_counter2 ^ out_counter; // xor to generate 50% duty, half-period
|
|
// waves of final output
|
|
// positive edge counter/divider
|
always @(posedge clk)
|
always @(posedge clk)
|
begin
|
begin
|
if(reset | rst_pulse)
|
if(reset | rst_pulse)
|
begin
|
begin
|
counter <= P;
|
counter <= N;
|
out_counter <= 1;
|
out_counter <= 1;
|
end
|
end
|
else if (enable)
|
else if (enable)
|
begin
|
begin
|
if(counter == 1)
|
if(counter == 1)
|
begin
|
begin
|
counter <= P;
|
counter <= N;
|
out_counter <= ~out_counter;
|
out_counter <= ~out_counter;
|
end
|
end
|
else
|
else
|
begin
|
begin
|
counter <= counter-1;
|
counter <= counter-1;
|
end
|
end
|
end
|
end
|
end
|
end
|
|
|
reg [`SIZE-1:0] initial_begin;
|
reg [`SIZE-1:0] initial_begin; // this is used to offset the negative edge counter
|
wire [`SIZE:0] interm_3;
|
wire [`SIZE:0] interm_3; // from the positive edge counter in order to
|
assign interm_3 = {1'b0,P} + 3;
|
assign interm_3 = {1'b0,N} + 3; // guarante 50% duty cycle.
|
|
|
|
// counter driven by negative edge of clock.
|
always @(negedge clk)
|
always @(negedge clk)
|
begin
|
begin
|
if(reset | rst_pulse)
|
if(reset | rst_pulse) // reset the counter at system reset
|
begin
|
begin // or change of N.
|
counter2 <= P;
|
counter2 <= N;
|
initial_begin <= interm_3[`SIZE:1];
|
initial_begin <= interm_3[`SIZE:1];
|
out_counter2 <= 1;
|
out_counter2 <= 1;
|
end
|
end
|
else if(initial_begin <= 1 && enable)
|
else if(initial_begin <= 1 && enable) // Do normal logic after odd calibration.
|
begin
|
begin // This is the same as the even counter.
|
if(counter2 == 1)
|
if(counter2 == 1)
|
begin
|
begin
|
counter2 <= P;
|
counter2 <= N;
|
out_counter2 <= ~out_counter2;
|
out_counter2 <= ~out_counter2;
|
end
|
end
|
else
|
else
|
begin
|
begin
|
counter2 <= counter2-1;
|
counter2 <= counter2-1;
|
Line 68... |
Line 70... |
begin
|
begin
|
initial_begin <= initial_begin - 1;
|
initial_begin <= initial_begin - 1;
|
end
|
end
|
end
|
end
|
|
|
|
//
|
|
// reset pulse generator:
|
|
// __ __ __ __ _
|
|
// clk: __/ \__/ \__/ \__/ \__/
|
|
// _ __________________________
|
|
// N: _X__________________________
|
|
// _____
|
|
// rst_pulse: __/ \___________________
|
|
//
|
|
// This block generates an internal reset for the odd divider in the
|
|
// form of a single pulse signal when the odd divider is enabled.
|
always @(posedge clk or posedge reset)
|
always @(posedge clk or posedge reset)
|
begin
|
begin
|
if(reset)
|
if(reset)
|
begin
|
begin
|
rst_pulse <= 0;
|
rst_pulse <= 0;
|
end
|
end
|
else if(enable)
|
else if(enable)
|
begin
|
begin
|
if(P != old_P)
|
if(N != old_N) // pulse when reset changes
|
begin
|
begin
|
rst_pulse <= 1;
|
rst_pulse <= 1;
|
end
|
end
|
else
|
else
|
begin
|
begin
|
rst_pulse <= 0;
|
rst_pulse <= 0;
|
end
|
end
|
old_P <= P;
|
|
end
|
|
end
|
end
|
|
old_N <= N; // always save the old N value to guarante reset from
|
|
end // an even-to-odd transition.
|
|
|
endmodule //odd
|
endmodule //odd
|
|
|
No newline at end of file
|
No newline at end of file
|