FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-18-2005, 01:18 PM
Paul Uiterlinden
Guest
 
Posts: n/a
Default Continous assign statement in clock: is it safe?

I have a general question: is it safe to have a continuous assign
statement in a clock line, or does this introduce a race condition?

A certain simulation (which has an assignment in a clock line) passes in
ModelSim, but fails in ncsim (only when delay_mode is set to unit, as I
found out later).

Below is some code that I created to reproduce the error. Whatever I try
though, q1, q2 and q3 correctly clock in the data from before the rising
clock edge, so I'm not quite sure whether the assign im the clock is a
prolem or not.

Paul.



module assign_in_clk;
reg clk;
wire clk_1;
wire clk_2;
reg d1;
reg q1;
reg q2;
reg q3;

// Clock generator
//
initial
begin
clk = 1'b0;
repeat (10) #50 clk = !clk;
end

// Flipflops on normal clock
//
always @(posedge clk)
begin
q1 <= d1;
q3 <= q2;
end

// Flipflop on renamed clock (via assign statement)
//
always @(posedge clk_2)
begin
q2 <= q1;
end

// Data generator
//
initial
begin
d1 = 1'b0;
wait(clk == 1'b0);
repeat (5) #100 d1 = !d1;
end

// Assignments in clock
//
assign clk_2 = clk_1;
assign clk_1 = clk;
endmodule
Reply With Quote
  #2 (permalink)  
Old 01-18-2005, 11:19 PM
[email protected]
Guest
 
Posts: n/a
Default Re: Continous assign statement in clock: is it safe?


Paul Uiterlinden wrote:
> I have a general question: is it safe to have a continuous assign
> statement in a clock line, or does this introduce a race condition?


It can certainly introduce a race condition. Actually, to be correct,
the design contains a race condition, and putting a continuous assign
in a clock path may cause it to be exposed, i.e. produce a different
result by changing the order that changes occur. In general, putting
a continuous assignment in a clock path may delay the output to a later
point in the same time slice.

> A certain simulation (which has an assignment in a clock line) passes

in
> ModelSim, but fails in ncsim (only when delay_mode is set to unit, as

I
> found out later).


Different results in different simulators indicates either a bug in one
of them, or a race condition in your design.

> Below is some code that I created to reproduce the error. Whatever I

try
> though, q1, q2 and q3 correctly clock in the data from before the

rising
> clock edge, so I'm not quite sure whether the assign im the clock is

a
> prolem or not.


Since your sample code uses nonblocking assignments, which introduce a
delay into the data path that is guaranteed to be greater than any
number
of zero-delay continuous assignments in series, it should not have any
races between clock and data.

Presumably your actual design is different from this sample code in
some way.

Reply With Quote
  #3 (permalink)  
Old 01-19-2005, 10:44 AM
[email protected]
Guest
 
Posts: n/a
Default Re: Continous assign statement in clock: is it safe?

I dont see why there should be any race condition with this code. it
should work perfectly as though there was only a single clock 'clk'
since you are using non-blocking statements in the procedural blocks.
-Neo

Reply With Quote
  #4 (permalink)  
Old 01-19-2005, 02:09 PM
Paul Uiterlinden
Guest
 
Posts: n/a
Default Re: Continous assign statement in clock: is it safe?

sharp & Neo,

Thanks for your replies. Indeed, I now understand there must be a
difference between my little example and the real design (a netlist from
Synplify) and/or my testbench. Apparently there is some path via
blocking statements from the clock to some output. I will dig into this.

Paul.
Reply With Quote
  #5 (permalink)  
Old 01-19-2005, 09:11 PM
[email protected]
Guest
 
Posts: n/a
Default Re: Continous assign statement in clock: is it safe?

Paul Uiterlinden wrote:
> sharp & Neo,
>
> Thanks for your replies. Indeed, I now understand there must be a
> difference between my little example and the real design (a netlist

from
> Synplify) and/or my testbench. Apparently there is some path via
> blocking statements from the clock to some output. I will dig into

this.
>
> Paul.


Is it possible that the unit delay mode is introducing a delay
in the assign statements (which would delay clk_2 two "units" after
clk)?

Reply With Quote
  #6 (permalink)  
Old 01-20-2005, 07:54 AM
Paul Uiterlinden
Guest
 
Posts: n/a
Default Re: Continous assign statement in clock: is it safe?

[email protected] wrote:
>
> Is it possible that the unit delay mode is introducing a delay
> in the assign statements (which would delay clk_2 two "units" after
> clk)?


Good suggestion, but I don't think so. Because then my little example
code would behave incorrectly when I set delay_mode to unit. I already
checked that: it does not. That's also why I put two assign statements
in the clock, to make sure it will fail if the assign statements are
affected by delay_mode.

Paul.
Reply With Quote
  #7 (permalink)  
Old 01-20-2005, 07:54 PM
[email protected]
Guest
 
Posts: n/a
Default Re: Continous assign statement in clock: is it safe?


[email protected] wrote:
>
> Is it possible that the unit delay mode is introducing a delay
> in the assign statements (which would delay clk_2 two "units" after
> clk)?


I believe that the "correct" behavior for unit delay mode (as
defined by the behavior of Verilog-XL) is that zero delays
remain zero. Only non-zero delays become unit delays. And
I believe that NC implements it correctly.

So while it was a good suggestion, I don't think that is what
is happening.

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
xst: assign Jan Bruns Verilog 6 10-11-2004 08:47 PM
assign statement in netlist rajan Verilog 4 09-01-2004 01:13 PM
Re: Working of continous assignment statement Steven Sharp Verilog 0 04-01-2004 01:39 AM
assign statement behaviour in diff simulators adarsh arora Verilog 1 10-21-2003 01:24 AM
How to assign an array to a vector? Peng Yu Verilog 2 08-06-2003 08:50 PM


All times are GMT +1. The time now is 02:50 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved