The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Apr 19th, 2024, 12:42pm
Pages: 1
Send Topic Print
Verilog - Race Condition - Please Help !! (Read 1493 times)
dash82
New Member
*
Offline



Posts: 3

Verilog - Race Condition - Please Help !!
Oct 24th, 2007, 12:33am
 
I completely modified my code. I guess i am facing one final glitch. I think my logic is correct for 1/2 rate Convolutional Encoder with generator polynomials (1,1,1) & (1,0,1). However, I see a race condition.

I am using "reset" variable to control the set of statements that gets executed. However, I am seeing that all the assignment statements are getting executed everytime, irrespective of the "reset" variable condition.

I want to make my code synthesizable too. Any help would be greatly appreciated. Please excuse me if this question annoys you. Still learning.

Code:


module conencoder (out1,out2,in1,clock,reset);
   output out1,out2;
   input  in1,clock,reset;
   reg u0,u1,u2,temp_u0,temp_u1,temp_u2;
   reg out1,out2;
   
   initial
   begin
      //if (reset)
      //begin
        assign out1    = 1'b0;
        assign out2    = 1'b0;
        assign u0      = 1'b0;
        assign u1      = 1'b0;
        assign u2      = 1'b0;
        assign temp_u0 = 1'b0;
        assign temp_u1 = 1'b0;
        assign temp_u2 = 1'b0;  
      //end
    end
   
   always @(clock)
   begin
      if (reset)
      begin
         //shifting the input bit through 3 registers.
         assign u2 = temp_u1;
         assign u1 = temp_u0;
         assign u0 = in1 ;
      end
      else if (!reset)
              begin
             //performing xor operation to produce the encoded bits. ERROR:All assignment statements are getting                  
             //executed irrespective of "reset" variable block checking.
              assign out1 = (u2 ^ u1 ^ u0);
              assign out2 = (u2 ^ u0);  
              assign temp_u1 = u1 ;
              assign temp_u0 = u0 ;  
       end
    end
   
endmodule

--------------------------------------------------------------------------------
--------
testbench:
--------------

module testbench ;
reg clock,reset,in1 = 1'b0;


conencoder r1(out1,out2,in1,clock,reset);

initial
begin
 //clock = 1'b1;
 //reset = 1'b1;
end

/*always
  begin
    // #30 clock = ~clock ;
  end */

always
  begin
     #3 reset = 1'b1 ;
     #2 in1 = 1'b1;
     #3 clock = 1'b1 ;
     #3 reset = 1'b0;
     #3 clock = 1'b0;
     //ERROR STARTS. After this all assignment statements seems to be getting executed in main code.
     #3 reset = 1'b1 ;
     #2 in1 = 1'b1;
     #3 clock = 1'b1 ;
     #3 reset = 1'b0;
     #3 clock = 1'b0;
     #3 reset = 1'b1 ;
     #2 in1 = 1'b1;
     #3 clock = 1'b1 ;
     #3 reset = 1'b0;
     #3 clock = 1'b0;
     #3 reset = 1'b1 ;
     #2 in1 = 1'b1;
     #3 clock = 1'b1 ;
     #3 reset = 1'b0;
     #3 clock = 1'b0;
     #3 reset = 1'b1 ;
     #2 in1 = 1'b1;
     #3 clock = 1'b1 ;
     #3 reset = 1'b0;
     #3 clock = 1'b0;
     
 
  end
 
endmodule

-------------------------------------------------------------------------------

The above code is compiled with ModelSim and works fine. I know I am making some stupid mistake due to which  
all 'assignment' statements are getting executed in the main code. Please help and I apologize for a long description.
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.