Difference in clock generation

H

hssig

Guest
Hi,

I have the following clock generators:

always
begin
#(`PERIOD/2) clk = 1'b0;
#(`PERIOD/4) clk = 1'b1;
#(`PERIOD/4) clk = 1'b1;
end

always
begin
#(`PERIOD/2) clk2 = 1'b0;
#(`PERIOD/2) clk2 = 1'b1;
end

Can someone explain to me why the first solution does generate a clock
with 1:3 duty cycle ratio and not as I would expect 1:1 ?

Cheers, hssig
 
hssig a écrit :
Hi,

I have the following clock generators:

always
begin
#(`PERIOD/2) clk = 1'b0;
#(`PERIOD/4) clk = 1'b1;
#(`PERIOD/4) clk = 1'b1;
end

always
begin
#(`PERIOD/2) clk2 = 1'b0;
#(`PERIOD/2) clk2 = 1'b1;
end

Can someone explain to me why the first solution does generate a clock
with 1:3 duty cycle ratio and not as I would expect 1:1 ?
That's because that's what you wrote ;)

Between clk = 0 and clk = 1 (for the first time) you set a delay of `PERIOD/4.
In the #time clk = 1'bx structure, the "time" represents the delay before clk is
set to x and not the time where clk is set to x.
 
On 7/1/2011 12:26 AM, hssig wrote:
Hi,

I have the following clock generators:

always
begin
#(`PERIOD/2) clk = 1'b0;
#(`PERIOD/4) clk = 1'b1;
#(`PERIOD/4) clk = 1'b1;
end

always
begin
#(`PERIOD/2) clk2 = 1'b0;
#(`PERIOD/2) clk2 = 1'b1;
end

Can someone explain to me why the first solution does generate a clock
with 1:3 duty cycle ratio and not as I would expect 1:1 ?

Vince already answered this but here are some other comments.

Think of these statements as wait the specified amount of time and then
execute the assignment. With this in mind it should be obvious why the
two pieces of code differ.

Another subtlety is that depending on how PERIOD is defined you may end
up with integer division which may not generate the exact delay you
expect. If you convert this to a real expression (e.g. use 2.0 instead
of 2 or define PERIOD as a real value) you still may have issues
depending on how the timescale is defined. You need enough time
precision to represent the fractional delay.

Cary
 
Thank you for your explanations. Now it is clear.

Cheers, hssig
 

Welcome to EDABoard.com

Sponsor

Back
Top