Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

state machine coding styles

Status
Not open for further replies.

hover

Junior Member level 2
Joined
Jun 12, 2004
Messages
22
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
China
Activity points
178
Hi, below there are two types of state machine coding styles.

Code:
1. always@(posedge clk or negedge rst_n)
    ...
       current_state <= next_state;
    ...
    always@(current_state)
    ...
    case(current_state)
    ...
       s1:
            if...
              next_state = s2;
            ...
    ...
    always@(posedge clk or negedge rst_n)
    ...
      else
         a <= 1'b0;
         b <= 1'b0;
         c <= 1'b0;
         case(current_state)
            s1:
                  a<=1'b1;
            s2:
                  b<=1'b1;
            s3:
                  c<=1'b1;
            default:
        ....

2. always@(posedge clk or negedge rst_n)
    ...
       current_state <= next_state;
    ...
    
    always@(current_state)
     ...
     a = 1'b0;
     b = 1'b0;
     c = 1'b0;
     case(current_state)
     ...
       s1:
            if...
              begin
                  next_state = s2;
                  a=1'b1;
              end
       s2:
            if...
              begin
                  next_state = s3
                  b=1'b1;
              end
        s3:
            c=1'b1;
        default:
        .........
It is said that the first one format of the two state machines is a standard and better one. But for the first one, there is one clock period latency with a, b and c signal. For some cases, it will not be good.
 

spauls

Advanced Member level 2
Joined
Dec 17, 2002
Messages
524
Helped
26
Reputation
52
Reaction score
9
Trophy points
1,298
Activity points
3,353
Io latency will not be affected much by State machine logic.
 

r63511

Junior Member level 3
Joined
Jul 26, 2006
Messages
27
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,413
in the second design, the output might contain a lot of glitches, which is very dangerous if used directly to drive other combinational logic.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top