状态机的学习---常用的HDL模板(二)

一段式

    将关于状态机的所有功能全部写在一起,仅适用一些功能简单且输出为寄存器形式
的状态机,对于复杂的状态机不利于代码的理解描述。
    将状态机的状态跳转、输入、输出等相关功能全部集中到一起。全部位于时序逻辑
中,无法输出组合逻辑。

三段式

    将状态机分为三大部分进行描述,即状态跳转部分、次态生成部分、输出生成部
分。
    状态跳转部分:将次态更新为现态。
    次态生成部分:描述状态转移函数,根据现态和输入计算出次态。
    输出生成部分:根据状态机的现态和输入得出输出

例子
在这里插入图片描述```verilog

module top_module(clk, reset, in, out);
input clk;
input reset;    // Synchronous reset to state B
input in;
output out;//  
reg out;

parameter A = 1'b0;
parameter B = 1'b1;

reg current_state, next_state;

always@(posedge clk)begin
    if(reset)begin
        current_state <= B;
    end
    else begin
        current_state <= next_state;
    end
end

always@(*)begin
    case(current_state)
        B:begin
            if(in == 1'b1)begin
                next_state = B;
            end
            else begin
                next_state = A;
            end
        end
        A:begin
            if(in == 1'b1)begin
                next_state = A;
            end
            else begin
                next_state = B;
            end
        end
    endcase
end

always@(*)begin
    if(current_state == B)begin
        out = 1'b1;
    end
    else begin
        out = 1'b0;
    end
end


endmodule
[练习](https://hdlbits.01xz.net/wiki/Fsm1s)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值