V语言 FSM题目

该博客详细介绍了如何使用Verilog语言实现一个有限状态机(FSM)实例,包括不同状态间的转换逻辑和计数器操作。在状态0中,数据被处理;在状态1-3,定时器递增;在状态4,开始计数;状态5进行减法计数,直到计数为0;状态6标记完成,等待ack信号;状态7则重置所有状态并回到初始状态。整个过程展示了FSM在数字逻辑设计中的应用。
摘要由CSDN通过智能技术生成

一个FSM实例


module test4( 
    input clk,
    input reset,      
    input data,
    output reg [3:0] count,
    output reg counting,
    output reg done,
    input ack 
);

reg [4:0] state,next_state;
reg [3:0] temp,timer;

always @(posedge clk) begin
    if(reset)begin
        state<=5'b0;
        next_state<=5'b0;
        count<=4'b0;
        counting<=1'b0;
        done<=1'b0;
        temp=4'b0;
    end 
    else begin
        state=next_state;
    end
    case (state)
        0: begin
            temp={temp[2:0],data};
            if(temp==4'b1101)begin
                next_state=1;
                timer=4'b0;
            end
        end
        1,2,3: begin 
            timer<={timer[2:0],data};
            next_state=state+1;
        end
        4:begin
            timer={timer[2:0],data};
            next_state=state+1;
            count<=timer;
            counting<=1'b1;
        end
        5:begin 
            if(count)begin
                count<=count-1;
            end else begin
                counting<=1'b0;
                next_state=6;
            end
        end
        6:begin
            done<=1'b1;
            if(ack) begin
                next_state<=7; 
            end
        end
        7:begin
            done<=1'b0;
            next_state=0;
        end
    endcase
end	
endmodule

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值