home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / verilog / 479 < prev    next >
Encoding:
Text File  |  1992-12-20  |  3.0 KB  |  94 lines

  1. Newsgroups: comp.lang.verilog
  2. Path: sparky!uunet!spsgate!mogate!newsgate!newsgate!abair
  3. From: abair@parsons.sps.mot.com (Alan Bair)
  4. Subject: Re: execution of always blocks
  5. In-Reply-To: manley@optilink.COM's message of 17 Dec 92 07:15:51 GMT
  6. Message-ID: <ABAIR.92Dec18020726@parsons.sps.mot.com>
  7. Sender: usenet@newsgate.sps.mot.com
  8. Nntp-Posting-Host: 223.12.249.122
  9. Organization: AMCU, Motorola Inc., Austin, Texas.
  10. References: <13665@optilink.COM>
  11. Date: Fri, 18 Dec 1992 09:07:26 GMT
  12. Lines: 80
  13.  
  14. In article <13665@optilink.COM> manley@optilink.COM (Terry Manley) writes:
  15.  
  16.    Ok, I've got a 'newbie' question.
  17.  
  18.    What's the story with this language?
  19.  
  20. Since I just took a class on Verilog, I'll try to answer your question.
  21. It's a good test to see if I learned anything :) I am sure I will be
  22. corrected if I am wrong.
  23.  
  24.    More specifically why doesn't the following work:
  25.  
  26.    reg a,b,c;
  27.  
  28.    always @(posedge Clk) c = b;
  29.    always @(posedge Clk) b = a;
  30.  
  31. The assignments occur on the posedge of the Clk, but there is nothing in
  32. this structure that says which should occur first. In theory they should
  33. occur at the same time, but this setup does not guarantee this. If you
  34. want that you should use the fork ... join construct.
  35.  
  36.    When the following does:
  37.  
  38.    always @(posedge Clk)
  39.      begin
  40.        c = b;
  41.        b = a;
  42.      end
  43.  
  44. In this case, the action will start on the posedge of Clk. Then, because
  45. you used a begin ... end block, versus the fork ... join, the assignments
  46. will take place sequentially. 
  47.  
  48.     c gets the value of b
  49.     b gets the value of a
  50.  
  51. This all takes place in zero time. To have these occur in parallel, you
  52. could use:
  53.  
  54.     always @(posedge Clk)
  55.       fork
  56.         c = b;
  57.         b = a;
  58.       join
  59.  
  60. However, this has the same problem as the two always blocks, there is no
  61. control over which will take place first. I can't remember the exact syntax,
  62. but there is a way to specify that the values of b & a are first saved and
  63. then the assignments take place. This allows them to occur in any order, but
  64. get the results you are after.
  65.  
  66.    In the first case for some reason verilog may perform the "b = a"
  67.    assignment first, thereby throwing away the expected value that c was
  68.    going to get.  We've even seen cases where in a given simulation
  69.    sometimes it works correctly, sometimes it doesn't.
  70.  
  71.    Ideally one would want the data transfer at the posedge of the clock
  72.    to behave like digital logic, that is it would, in this case behave
  73.    like a shift register.  Instead we get what looks like a shift
  74.    register with a bad hold time problem. 
  75.  
  76.    So what is the story with multiple always blocks?
  77.    Is this something to worry about between modules?
  78.    How about between modules in different files?
  79.  
  80. If the actions occur within separate modules, you need to have event controls
  81. to ensure the actions take place in the order you want if that matters.
  82.  
  83.  
  84.    --
  85.    dave
  86.    manley@optilink.com
  87.  
  88. --
  89. Alan Bair                     AMCU DSCS
  90. Motorola, Inc.                    (Design Software &
  91. Mail Stop OE-320             Computer Services)
  92. 6501 William Cannon Dr. West    
  93. Austin, TX  78735-8598          abair@parsons.sps.mot.com
  94.