Rules | Recent posts | topic RSS | Search | Register  | Log in

state machine coding styles

 
Post new topic  Reply to topic    EDAboard.com Forum Index -> ASIC Design Methodologies & Tools (Digital)
Author Message
hover



Joined: 12 Jun 2004
Posts: 23
Location: China


Post06 Jun 2006 6:01   state machine coding styles

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.
Back to top
spauls



Joined: 17 Dec 2002
Posts: 547
Helped: 19


Post06 Jun 2006 12:44   Re: state machine coding styles

Io latency will not be affected much by State machine logic.
Back to top
r63511



Joined: 26 Jul 2006
Posts: 27


Post26 Jul 2006 18:16   state machine coding styles

in the second design, the output might contain a lot of glitches, which is very dangerous if used directly to drive other combinational logic.
Back to top
Post new topic  Reply to topic    EDAboard.com Forum Index -> ASIC Design Methodologies & Tools (Digital)
Page 1 of 1 All times are GMT + 1 Hour


Abuse
Administrator
Moderators
topic RSS 
sitemap