+ Post New Thread
Results 1 to 8 of 8
  1. #1
    Newbie level 3
    Points: 29, Level: 1

    Join Date
    Oct 2014
    Posts
    3
    Helped
    1 / 1
    Points
    29
    Level
    1

    Getting each output twice from LFSR

    Hi.
    I am trying to make a 32'bit LFSR with a given initial state. I am posting the code and stimulus below.

    Code Verilog - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    
    /*------------------------------------------*/
    module lfsr (clock, reset, out);
      
      input clock, reset;
      output [31:0] out;
      
      reg [31:0] temp;
      wire newbit;
      
      xor (newbit,temp[0],temp[10],temp[30],temp[31]);
      
      initial
      temp = 32'hffffffff;
      
      always @(posedge clock)
      begin
        temp <= {newbit,temp[31:1]};
      end
      
      assign out = temp;
         
    endmodule
     
    /*------------------------------------*/
     
     
    //Stimulus
     
    module lfsrstimulus;
      reg CLOCK, RESET;
      wire [31:0] OUT;
      
      lfsr l1 (CLOCK, RESET, OUT);
      
      initial
      $monitor($time, "Clock = %b, Output = %b\n", CLOCK,OUT);
      
      initial
      begin
      CLOCK = 1'b1;  
      forever #10 CLOCK = ~CLOCK;
      end
      
      initial
      #100 $finish;
      
    endmodule
     
    /*--------------------------------------------*/
    The problem I am having is that when I run the stimulus, each output comes twice. Is this because of timing delays?

    Thanks in advance for any help. :)
    Last edited by FvM; 15th October 2014 at 15:57. Reason: Added syntags tags

    •   Alt15th October 2014, 15:19

      advertising

        
       

  2. #2
    Advanced Member level 5
    Points: 14,946, Level: 29
    mrflibble's Avatar
    Join Date
    Apr 2010
    Posts
    2,724
    Helped
    686 / 682
    Points
    14,946
    Level
    29

    Re: Getting each output twice from LFSR

    No. It is because you choose to confuse yourself. The simulation looks okay. The lfsr gets a new value at every positive going edge of clock. The monitor statement in this case prints the contents of the lfsr registers both when clock is low, and when clock is high. Which is why you perceive it as "double".


    1 members found this post helpful.

    •   Alt15th October 2014, 16:17

      advertising

        
       

  3. #3
    Super Moderator
    Points: 24,082, Level: 37
    ads-ee's Avatar
    Join Date
    Sep 2013
    Location
    USA
    Posts
    5,358
    Helped
    1354 / 1354
    Points
    24,082
    Level
    37

    Re: Getting each output twice from LFSR

    use something like:
    Code Verilog - [expand]
    1
    
    @(posedge CLOCK) $display("%t, Output = %b\n", $time, OUT);
    then you'll only see one output each clock



    •   Alt15th October 2014, 17:04

      advertising

        
       

  4. #4
    Advanced Member level 5
    Points: 14,946, Level: 29
    mrflibble's Avatar
    Join Date
    Apr 2010
    Posts
    2,724
    Helped
    686 / 682
    Points
    14,946
    Level
    29

    Re: Getting each output twice from LFSR

    Another missed learning opportunity of reading the $monitor man page. :( But yes, that is probably the kind of output he's expecting. :)



  5. #5
    Super Moderator
    Points: 24,082, Level: 37
    ads-ee's Avatar
    Join Date
    Sep 2013
    Location
    USA
    Posts
    5,358
    Helped
    1354 / 1354
    Points
    24,082
    Level
    37

    Re: Getting each output twice from LFSR

    Utshash should still read the $monitor man page.



  6. #6
    Advanced Member level 5
    Points: 14,946, Level: 29
    mrflibble's Avatar
    Join Date
    Apr 2010
    Posts
    2,724
    Helped
    686 / 682
    Points
    14,946
    Level
    29

    Re: Getting each output twice from LFSR

    Homo sapiens + path of least resistance equals exactly.

    But I agree. He would do well to read the $monitor documentation. It has a key sentence in it that explains why it shows things the way it does.



  7. #7
    Newbie level 3
    Points: 29, Level: 1

    Join Date
    Oct 2014
    Posts
    3
    Helped
    1 / 1
    Points
    29
    Level
    1

    Re: Getting each output twice from LFSR

    Thank you all. I see my mistake now and as suggested by all of you, I'll read the $monitor documentation. Thanks again. :)

    - - - Updated - - -

    Thank you all for replying and pointing out my stupidity. As suggested by most of you, I'll try to read the $monitor documentation as soon as possible. Thanks again. :)


    1 members found this post helpful.

    •   Alt15th October 2014, 19:28

      advertising

        
       

  8. #8
    Advanced Member level 5
    Points: 14,946, Level: 29
    mrflibble's Avatar
    Join Date
    Apr 2010
    Posts
    2,724
    Helped
    686 / 682
    Points
    14,946
    Level
    29

    Re: Getting each output twice from LFSR

    People that read documentation get free internet cookies!



+ Post New Thread
Please login
--[[ ]]--