D
David Brown
Guest
Chloe,
If you are designing the circuit as an ASIC implementation, you should also
take into account testability issues. In many cases the internal clock needs
to be a divide by of the main clock for for power reduction, but doesn't
need to be a symetrical clock. The following circuit provides the divide-by
function with a 25/75 duty clock, allows easy clock balancing, and easy
implementation of scan since the clock path has a constant delay whether in
scan or functional mode.
It might be worth drawing out the circuit to get a better understanding on
it's operation.
Hope this helps!
David Brown
////////////////////////////////////////////////////////////
// Divide by 2 clock
////////////////////////////////////////////////////////////
module div_by_2(
clk, // system clock input
resetb, // async reset (low true input)
test_enable, // Used for scan testing, turns clock on at 1x
clock rate
clk_div_by_2_out // Divide by 2 clock output
);
// INPUTS
input clk;
input resetb;
input test_enable;
// OUTPUTS
output clk_div_by_2_out;
// PARAMETERS
parameter DELAY = 1; // unit delay used to mimic structural netlist
// delays
// Wires
wire clk_div_by_2_out;
wire clk_enable;
// Registers
reg div_by_ff;
reg clk_en_ff;
//////////////////////////////////////
// CODE
//////////////////////////////////////
// Toggle Flip Flop
always@(posedge clk or negedge resetb)
begin
if(!resetb)
div_by_ff <= #DELAY 1'd0;
else
div_by_ff <= #DELAY ~div_by_ff;
end
// Clock Enable Flip Flop
always@(negedge clk or negedge resetb)
begin
if(!resetb)
clk_en_ff <= #DELAY 1'd0;
else
clk_en_ff <= #DELAY div_by_ff;
end
assign clk_enable = test_enable | clk_en_ff;
assign clk_div_by_2_out = clk_enable & clk;
endmodule
//////////////////////////////////////
// Test Bench
//////////////////////////////////////
module test();
reg clk; // Clock input
reg resetb; // Async Reset Input (Low true)
reg test_enable; // Test Enable Input used for scan testing
wire clk_div_by_2_out; // Clock divide by 2 output 25/75 duty cycle
// Code
always #10 clk = ~clk;
// Initialization
initial
begin
$dumpfile("test.vcd");
$dumpvars(0,test);
$dumpon;
clk = 1'b0;
test_enable = 1'b0;
resetb = 1'b1;
#22 resetb = 1'b0; // reset circuit (offset from clk)
#20 resetb = 1'b1; // release reset
#1000 resetb = 1'b0; // place back in reset
#10 test_enable = 1'b1; // place in test mode
#20 resetb = 1'b1; // release reset
#1000 $finish; // End of test
end
div_by_2 div_by_2(
.clk(clk),
.resetb(resetb),
.test_enable(test_enable),
.clk_div_by_2_out(clk_div_by_2_out)
);
endmodule
"Chloe" <chloe_music2003@yahoo.co.uk> wrote in message
news:1118193616.986756.67250@f14g2000cwb.googlegroups.com...
If you are designing the circuit as an ASIC implementation, you should also
take into account testability issues. In many cases the internal clock needs
to be a divide by of the main clock for for power reduction, but doesn't
need to be a symetrical clock. The following circuit provides the divide-by
function with a 25/75 duty clock, allows easy clock balancing, and easy
implementation of scan since the clock path has a constant delay whether in
scan or functional mode.
It might be worth drawing out the circuit to get a better understanding on
it's operation.
Hope this helps!
David Brown
////////////////////////////////////////////////////////////
// Divide by 2 clock
////////////////////////////////////////////////////////////
module div_by_2(
clk, // system clock input
resetb, // async reset (low true input)
test_enable, // Used for scan testing, turns clock on at 1x
clock rate
clk_div_by_2_out // Divide by 2 clock output
);
// INPUTS
input clk;
input resetb;
input test_enable;
// OUTPUTS
output clk_div_by_2_out;
// PARAMETERS
parameter DELAY = 1; // unit delay used to mimic structural netlist
// delays
// Wires
wire clk_div_by_2_out;
wire clk_enable;
// Registers
reg div_by_ff;
reg clk_en_ff;
//////////////////////////////////////
// CODE
//////////////////////////////////////
// Toggle Flip Flop
always@(posedge clk or negedge resetb)
begin
if(!resetb)
div_by_ff <= #DELAY 1'd0;
else
div_by_ff <= #DELAY ~div_by_ff;
end
// Clock Enable Flip Flop
always@(negedge clk or negedge resetb)
begin
if(!resetb)
clk_en_ff <= #DELAY 1'd0;
else
clk_en_ff <= #DELAY div_by_ff;
end
assign clk_enable = test_enable | clk_en_ff;
assign clk_div_by_2_out = clk_enable & clk;
endmodule
//////////////////////////////////////
// Test Bench
//////////////////////////////////////
module test();
reg clk; // Clock input
reg resetb; // Async Reset Input (Low true)
reg test_enable; // Test Enable Input used for scan testing
wire clk_div_by_2_out; // Clock divide by 2 output 25/75 duty cycle
// Code
always #10 clk = ~clk;
// Initialization
initial
begin
$dumpfile("test.vcd");
$dumpvars(0,test);
$dumpon;
clk = 1'b0;
test_enable = 1'b0;
resetb = 1'b1;
#22 resetb = 1'b0; // reset circuit (offset from clk)
#20 resetb = 1'b1; // release reset
#1000 resetb = 1'b0; // place back in reset
#10 test_enable = 1'b1; // place in test mode
#20 resetb = 1'b1; // release reset
#1000 $finish; // End of test
end
div_by_2 div_by_2(
.clk(clk),
.resetb(resetb),
.test_enable(test_enable),
.clk_div_by_2_out(clk_div_by_2_out)
);
endmodule
"Chloe" <chloe_music2003@yahoo.co.uk> wrote in message
news:1118193616.986756.67250@f14g2000cwb.googlegroups.com...
Hello everyone,
I'm very new to Verilog and hardware design, so any help or advice
given would be appreciated.
I have 2 clocks in my design. First clock is running at 60MHz, and the
other one is generated at a divided frequency of 2 from the first
clock, ie at 30MHz. Because its frequency is only divided by two, I
don't see the need for a counter. But please check and let me know if
I'm thinking wrongly:
-----------------
module FreqDivider(in_clk, out_clk, rst);
input in_clk;
input rst;
output out_clk;
reg out_clk;
always @(posedge in_clk or negedge rst)
begin
if (!rst)
begin
out_clk <= 1'b0;
end
else
out_clk = ~out_clk;
end
endmodule
-------------------------
testbench :
module FreqDiv_tb();
wire out_clk;
reg in_clk;
reg rst;
initial
begin
rst = 0;
in_clk = 0;
forever #10 in_clk = ~in_clk;
end
initial
begin
#1000;
rst = 1;
#1000;
rst = 0;
#1000;
#10000 $finish;
end
FreqDivider freqdiv_inst (in_clk, out_clk, _rst);
endmodule
------------------------------
It's an asynchronous design.
Would the RTL (not the testbench) be synthesizable? What about the race
conditions?
Thanks very much in advance.