image.png

    1. `timescale 1ns/1ns
    2. module seq_circuit(
    3. input C,
    4. input clk,
    5. input rst_n,
    6. output wire Y
    7. );
    8. reg current_state;
    9. reg next_state;
    10. always @(posedge clk or negedge rst_n) begin
    11. if(!rst_n) begin
    12. current_state <= 2'b00;
    13. next_state <= 2'b00;
    14. end
    15. else begin
    16. current_state <= next_state;
    17. end
    18. end
    19. always @(*) begin
    20. case(current_state)
    21. 2'b00 : next_state = (C == 1'b1)? 2'b01 : 2'b00;
    22. 2'b01 : next_state = (C == 1'b1)? 2'b01 : 2'b11;
    23. 2'b10 : next_state = (C == 1'b1)? 2'b10 : 2'b00;
    24. 2'b11 : next_state = (C == 1'b1)? 2'b11 : 2'b10;
    25. default : next_state = 2'b00;
    26. endcase
    27. end
    28. assign Y = ((current_state == 2'b11) | ((current_state == 2'b10) && (C == 1)))? 1'b1: 1'b0;
    29. endmodule