2021年7月3日 星期六

HDLBits/Building Larger Circuits/The complete FSM(Exams/review2015 fsm)

HDLBits/Building Larger Circuits/The complete FSM(Exams/review2015 fsm)

This is the fourth component in a series of five exercises that builds a complex counter out of several smaller circuits. See the final exercise for the overall design.

You may wish to do FSM: Enable shift register and FSM: Sequence recognizer first.

We want to create a timer that:

  1. is started when a particular pattern (1101) is detected,
  2. shifts in 4 more bits to determine the duration to delay,
  3. waits for the counters to finish counting, and
  4. notifies the user and waits for the user to acknowledge the timer.

In this problem, implement just the finite-state machine that controls the timer. The data path (counters and some comparators) are not included here.

The serial data is available on the data input pin. When the pattern 1101 is received, the state machine must then assert output shift_ena for exactly 4 clock cycles.

After that, the state machine asserts its counting output to indicate it is waiting for the counters, and waits until input done_counting is high.

At that point, the state machine must assert done to notify the user the timer has timed out, and waits until input ack is 1 before being reset to look for the next occurrence of the start sequence (1101).

The state machine should reset into a state where it begins searching for the input sequence 1101.

Here is an example of the expected inputs and outputs. The 'x' states may be slightly confusing to read. They indicate that the FSM should not care about that particular input signal in that cycle. For example, once a 1101 pattern is detected, the FSM no longer looks at the data input until it resumes searching after everything else is done.

創建一個計時器,當檢測到序列1101時啟動,接著等待4位,然後計數器完成計數,最後等待用戶確認計數器。大家也看出來了,這道題其實就是前面幾道題目的組合。 


module top_module (
    input clk,
    input reset,      // Synchronous reset
    input data,
    output shift_ena,
    output counting,
    input done_counting,
    output done,
    input ack );

     parameter S0=0,S1=1,S2=2,S3=3;//序列檢測1101的狀態

    parameter S4=4,S5=5,S6=6,S7=7;//S4、S5、S6、S7保持shift_ena為1!

    parameter S8=8;//counting拉高,等待done_counting拉高,然後在下一狀態S9拉低counting

    parameter S9=9;//等待ack拉高時,傳出done信號,並進入S0狀態!


    reg [3:0] state,next;
    always@(posedge clk)
        if(reset)
            state <=S0;    
        else
            state <= next;
    always@(*)
        case(state)
            S0:next=data?S1:S0;
            S1:next=data?S2:S0;
            S2:next=data?S2:S3;
            S3:next=data?S4:S0;
            
            S4:next=S5;
            S5:next=S6;
            S6:next=S7;
            S7:next=S8;
            
            S8:next=done_counting?S9:S8;
            S9:next=ack?S0:S9;
            default:next=S0;
        endcase
    assign shift_ena= (state==S4||state==S5||state==S6||state==S7 ?1:0);
    assign counting=(state==S8?1:0);
    assign done= (state==S9?1:0);
endmodule


沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...