This is an old revision of the document!


Prin asamblarea pașilor de mai sus obținem un schelet de cod minimal pentru un FSM

Prin asamblarea pașilor de mai sus obținem un schelet de cod minimal pentru un FSM

module BasicFsm (
    // ------------------------------------------------------------
    // Ieșiri
    // ------------------------------------------------------------
    output wire o_w_out ,
    // ------------------------------------------------------------
    // Intrări
    // ------------------------------------------------------------
    input wire i_w_clk ,
    input wire i_w_reset ,
    input wire i_w_in ,
    // ------------------------------------------------------------
    );
 
    // --------------------------------------------------------------------
    // Codificarea stărilor
    // --------------------------------------------------------------------
    localparam STATE_Initial = 3'd0 ,
    STATE_1 = 3'd1 ,
    STATE_2 = 3'd2 ,
    STATE_3 = 3'd3 ,
    STATE_4 = 3'd4 ,
    STATE_5_PlaceHolder = 3'd5 ,
    STATE_6_PlaceHolder = 3'd6 ,
    STATE_7_PlaceHolder = 3'd7;
    // --------------------------------------------------------------------
 
 
    // --------------------------------------------------------------------
    // Regiștri pentru memorarea stărilor
    // --------------------------------------------------------------------
    reg [2:0] l_r_currentState ;
    reg [2:0] l_r_nextState ;
    // --------------------------------------------------------------------
 
    // --------------------------------------------------------------------
    // Ieșiri
    // --------------------------------------------------------------------
    // ieșire pe 1 bit
    assign o_w_out = ( l_r_currentState == STATE_4 );
 
 
    // --------------------------------------------------------------------
    // Tranziție sincrona: bloc always@(posedge Clock) 
    // --------------------------------------------------------------------
    always@ ( posedge i_w_clk ) begin
        if ( i_w_reset ) begin
            l_r_currentState <= STATE_Initial ;
        else begin
            l_r_currentState <=  l_r_nextState ;
        end
    end
    // --------------------------------------------------------------------
 
 
    // --------------------------------------------------------------------
    // Tranziție condiționată: bloc always@ ( * ) 
    // --------------------------------------------------------------------
always@ ( * ) begin
         l_r_nextState = l_r_currentState ;
 
        case ( l_r_currentState )
            STATE_Initial : begin
                l_r_nextState = STATE_1 ;
            end
            STATE_1 : begin
                if (!i_w_in)
                    l_r_nextState = STATE_2 ;
            end
            STATE_2 : begin
                if (i_w_in)
                    l_r_nextState = STATE_3 ;
            end
            STATE_3 : begin
                if (i_w_in)
                    l_r_nextState = STATE_4 ;
                else
                    l_r_nextState = STATE_1 ;
            end
            STATE_4 : begin
                if (i_w_in)
                    l_r_nextState = STATE_1 ;
                else
                    l_r_nextState = STATE_2 ;
            end
            // Stări pentru tratarea erorilor
            // Dacă automatul ajunge în aceste stări se va reseta.
            STATE_5_PlaceHolder : begin
                l_r_nextState = STATE_Initial ;
            end
            STATE_6_PlaceHolder : begin
                l_r_nextState = STATE_Initial ;
            end
            STATE_7_PlaceHolder : begin
                l_r_nextState = STATE_Initial ;
            end
        endcase
    end
    // --------------------------------------------------------------------
 
endmodule
soc/laboratoare/04/dfa_skel.1774190200.txt.gz · Last modified: 2026/03/22 16:36 by robert_fabian.tudor
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0