• HDLBis-Fsm3s


    See also: State transition logic for this FSM

    The following is the state transition table for a Moore state machine with one input, one output, and four states. Implement this state machine. Include a synchronous reset that resets the FSM to state A. (This is the same problem as Fsm3 but with a synchronous reset.)

    StateNext stateOutput
    in=0in=1
    AAB0
    BCB0
    CAD0
    DCB1

    Module Declaration

    module top_module(
        input clk,
        input in,
        input reset,
        output out); 

    自己写的代码:

    1. module top_module(
    2. input clk,
    3. input in,
    4. input reset,
    5. output out);
    6. //采用同步置位reset
    7. reg[3:0] state;
    8. parameter A = 0, //0001
    9. B = 1, //0010
    10. C = 2, //0100
    11. D = 3; //1000
    12. // State transition logic
    13. always @(posedge clk) begin
    14. if(reset)begin
    15. state <= 4'b0001;
    16. end
    17. else begin
    18. state[A] <= state[A]&(~in)|state[C]&(~in);
    19. state[B] <= state[A]&in | state[B]&in |state[D]∈
    20. state[C] <= state[B]&(~in) | state[D]&(~in);
    21. state[D] <= state[C]∈
    22. end
    23. end
    24. // State flip-flops with synchronous reset
    25. // Output logic
    26. assign out = state[D];
    27. endmodule

    标准的写法是在always @(posedge clk)模块中写

     if(reset)begin

                state <= 4'b0001;

            end

            else begin

               state <= nextstate;

            end

    通过组合逻辑对nextstate的状态进行改变

    下面是标准的代码:

    1. module top_module(
    2. input clk,
    3. input in,
    4. input reset,
    5. output out);
    6. //采用同步置位reset
    7. reg[3:0] state,nextstate;
    8. parameter A = 0, //0001
    9. B = 1, //0010
    10. C = 2, //0100
    11. D = 3; //1000
    12. // State transition logic
    13. always @(*)begin
    14. nextstate[A] <= state[A]&(~in)|state[C]&(~in);
    15. nextstate[B] <= state[A]&in | state[B]&in |state[D]∈
    16. nextstate[C] <= state[B]&(~in) | state[D]&(~in);
    17. nextstate[D] <= state[C]∈
    18. end
    19. // State flip-flops with synchronous reset
    20. always @(posedge clk) begin
    21. if(reset)begin
    22. state <= 4'b0001;
    23. end
    24. else begin
    25. state <= nextstate;
    26. end
    27. end
    28. // Output logic
    29. assign out = state[D];
    30. endmodule

  • 相关阅读:
    06.位置匹配 (Python)
    《未来简史》读书笔记
    【学习笔记】 CF850F Rainbow Balls
    Java正则表达式之账号检验与判断基础
    Spring Data JPA 按多个列排序
    阿里巴巴内部:2022年全技术栈(架构篇+算法篇+大数据)你值得拥有
    java-php-python-ssm亿互游在线平台网站计算机毕业设计
    数据科学与大数据(学习记录)
    开源协议介绍
    Linux安装和使用Android Debug Bridge(ADB)
  • 原文地址:https://blog.csdn.net/Kai666888/article/details/133647882