Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

verilog code correction???

Status
Not open for further replies.

sotomie

Newbie level 6
Joined
Apr 5, 2013
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,376
can anyone please tell me if there is any logical error is this always block,its for fibonacci series ,i'm getting my results right but i was just curious if i've done something which isn't correct like using two 'if's?

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
always@(posedge clock)
  begin
      if(n==0)
      current=1;
      else
      begin
      temp=current;
      current=current+previous;
      previous=temp;
      end
      if(current<previous)
      begin
            previous=0;
            n=0;
            current=1;
      end
    n=n+1;
   end   
endmodule

 
Last edited by a moderator:

No logical error, but bad style. Synchronous always blocks should use non-blocking statements for variable assignments.
 
Code:
always@(posedge clock)
  begin
      if(n==0)
      current<=1;
      else
      begin
      temp=current;
      current=current+previous;
      previous=temp;
      end
      if(current<previous)
      begin
            previous<=0;
            n<=0;
            current<=1;
      end
    n<=n+1;
   end   
endmodule
better?
 

No, now you have mixed blocking and non-blocking statements for the same variables, which isn't allowed.
 

can you modify it ? I'm new to verilog.And if i am changing all the blocking assignments to non-blocking results are not right because of this part i think
Code:
temp=current;
      current=current+previous;
      previous=temp;
.Thankyou
 

Yes, the code must be differently arranged when using non-blocking statements.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top