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.

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.
 

Io latency will not be affected much by State machine logic.
 

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top