Line 1... |
Line 1... |
|
|
`include "defines.v"
|
`include "defines.v"
|
|
|
module even(clk, out, P, reset, not_zero, enable);
|
module even(clk, out, N, reset, not_zero, enable);
|
|
|
input clk;
|
input clk; // fast input clock
|
output out;
|
output out; // slower divided clock
|
input [`SIZE-1:0] P;
|
input [`SIZE-1:0] N; // divide by factor 'N'
|
input reset;
|
input reset; // asynchronous reset
|
input not_zero;
|
input not_zero; // if !not_zero divide by 1
|
input enable;
|
input enable; // enable the even divider
|
|
|
reg [`SIZE-1:0] counter;
|
reg [`SIZE-1:0] counter;
|
reg out_counter;
|
reg out_counter;
|
wire [`SIZE-1:0] div_2;
|
wire [`SIZE-1:0] div_2;
|
|
|
|
|
|
// if N=0 just output the clock, otherwise, divide it.
|
assign out = (clk & !not_zero) | (out_counter & not_zero);
|
assign out = (clk & !not_zero) | (out_counter & not_zero);
|
assign div_2 = {1'b0, P[`SIZE-1:1]};
|
assign div_2 = {1'b0, N[`SIZE-1:1]};
|
|
|
|
// simple flip-flop even divider
|
always @(posedge reset or posedge clk)
|
always @(posedge reset or posedge clk)
|
begin
|
begin
|
if(reset)
|
if(reset) // asynch. reset
|
begin
|
begin
|
counter <= 1;
|
counter <= 1;
|
out_counter <= 1;
|
out_counter <= 1;
|
end
|
end
|
else if(enable)
|
else if(enable) // only use switching power if enabled
|
begin
|
|
if(counter == 1)
|
|
begin
|
begin
|
|
if(counter == 1) // divide after counter has reached bottom
|
|
begin // of interval 'N' which will be value '1'
|
counter <= div_2;
|
counter <= div_2;
|
out_counter <= ~out_counter;
|
out_counter <= ~out_counter;
|
end
|
end
|
else
|
else
|
begin
|
begin // decrement the counter and wait
|
counter <= counter-1;
|
counter <= counter-1; // to start next trasition.
|
end
|
end
|
end
|
end
|
end
|
end
|
|
|
endmodule //even
|
endmodule //even
|