delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2012/02/20/00:43:05

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
Date: Mon, 20 Feb 2012 00:42:48 -0500
From: gene glick <geneglick AT optonline DOT net>
Subject: Re: [geda-user] verilog question - blocking/non-blocking
In-reply-to: <201202200517.q1K5HrUD026271@envy.delorie.com>
To: geda-user AT delorie DOT com
Message-id: <4F41DD58.8030607@optonline.net>
MIME-version: 1.0
References: <4F41CB0A DOT 2020902 AT optonline DOT net>
<201202200517 DOT q1K5HrUD026271 AT envy DOT delorie DOT com>
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110323
Thunderbird/3.1.9
Reply-To: geda-user AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: geda-user AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On 02/20/2012 12:17 AM, DJ Delorie wrote:

> always @(posedge clk)
>    begin
>       /* edge happens here */
>       new_count = count + 1;
>       if (new_count == 0)
>         do_something
>       count = new_count;
>    end
>
>
> always @(posedge clk)
>    begin
>       prev_count = count;
>       /* edge happens here */
>       count<= prev_count + 1;   // non-blocking method
>       if (prev_count == 0)
>         do_something
>    end
>
>
> My personal paradigm is to use '=' in an @always combinatoric state
> machine that computes the next state from the current state, and '<='
> in a separate edge-triggered @always that just copies the next state
> to the current state.
>
> For example, see http://www.delorie.com/electronics/sdram/simple1.v
>
> The last two blocks are an "always @(negedge ram_wclock) begin" that
> copies the next state to the current state, followed by a huge "always
> @(...lots of things...)" that computes the next state.
>
> I've found that if I try to mix combinatoric and edge logic in the
> same block, I end up doing something pessimal and the chip won't run
> as fast as it should.
>

I suppose the "=" (blocking) makes the code sequential, like C - if that 
clarifies it some. But I was really wondering how the synthesis tools 
deal with this. I almost always avoid using the "=" form.  It doesn't 
bother me that my states are off (delayed) by 1 clock tick.  So in my 
2nd example, during simulation do_something runs when the counter is 1 
not 0. Not really a big deal. In the first example, do_something runs 
when the counter is 0. Makes looking at the waveforms, and the counter, 
line up nice but what the heck does the synthesis tool build?

Wouldn't your method of 'previous count' and 'count' use twice as many 
registers?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019