EDAboard.com | EDAboard.eu | EDAboard.de | EDAboard.co.uk | RTV forum PL | NewsGroups PL

Difference in clock generation

Ask a question - edaboard.com

elektroda.net NewsGroups Forum Index - Verilog Language - Difference in clock generation

hssig
Guest

Fri Jul 01, 2011 9:26 am   



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

Vince
Guest

Fri Jul 01, 2011 9:26 am   



hssig a écrit :
Quote:
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.

Cary R.
Guest

Fri Jul 01, 2011 8:51 pm   



On 7/1/2011 12:26 AM, hssig wrote:
Quote:
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

hssig
Guest

Sat Jul 02, 2011 2:22 pm   



Thank you for your explanations. Now it is clear.

Cheers, hssig

elektroda.net NewsGroups Forum Index - Verilog Language - Difference in clock generation

Ask a question - edaboard.com

Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
RTV map EDAboard.com map News map EDAboard.eu map EDAboard.de map EDAboard.co.uk map Opony