Verilog刷题笔记53

题目:

Fsm serialdata

See also: Serial receiver

Now that you have a finite state machine that can identify when bytes are correctly received in a serial bitstream, add a datapath that will output the correctly-received data byte. out_byte needs to be valid when done is 1, and is don't-care otherwise.

解题:

cpp 复制代码
module top_module(
    input clk,
    input in,
    input reset,    // Synchronous reset
    output [7:0] out_byte,
    output done
); //
    parameter idle=0,start=1,data_receive=2,stop=3,error=4;
    reg [2:0]state,next_state;
    reg [3:0]cnt;
    reg [7:0]out;
    always@(posedge clk)begin
        if(reset)
            state=idle;
        else
            state=next_state;
    end
    always@(*)begin
        case(state)
            idle:next_state=(in==0)?start:idle;
            start:next_state=data_receive;
            data_receive:next_state=(cnt==8)?(in?stop:error):data_receive;
            stop:next_state=in?idle:start;
            error:next_state=in?idle:error;
            default:next_state=idle;
        endcase
    end
    always@(posedge clk)begin
        if(reset)
            cnt=0;
        else begin
            case(next_state)
                start:cnt=0;
                data_receive:cnt=cnt+1;
                default:cnt=cnt;
            endcase
        end
    end
    always@(posedge clk)begin
        if(reset)
            out=0;
        else begin
            case(next_state)
                start:out=0;
                data_receive:out={in,out[7:1]};
            endcase
        end
    end
    assign done=(state==stop)?1:0;
    assign out_byte=out;

    // Use FSM from Fsm_serial

    // New: Datapath to latch input bits.

endmodule

结果正确:

本题在51、52题目的基础上增加了记录数据、计周期数的功能。

即51、52两道题目的结合体。

相关推荐
minglie16 分钟前
嵌入式协程AlarmProtothread
mcu·fpga开发
思成不止于此11 分钟前
【MySQL 零基础入门】事务精讲(三):隔离级别与实战总结
数据库·笔记·学习·mysql
小智RE0-走在路上15 分钟前
Python学习笔记(12) --对象,类的成员方法,构造方法,其他内置方法,封装,继承,多态,类型注解
笔记·python·学习
唐·柯里昂79833 分钟前
[rk3566AI模型部署]泰山派buildroot部署yolov5 使用rknn_model_zoo
c语言·c++·笔记·yolo·rk3566·瑞芯微·泰山派
xUxIAOrUIII1 小时前
【数据库原理】期末复习(初稿)
数据库·笔记
客梦1 小时前
数据结构--排序
数据结构·笔记
Godspeed Zhao1 小时前
自动驾驶中的传感器技术79——Sensor Fusion(2)
人工智能·fpga开发·自动驾驶
先生沉默先1 小时前
c#Socket学习,使用Socket创建一个在线聊天,日志笔记(5)
笔记·学习·c#
峰顶听歌的鲸鱼1 小时前
20.MySql数据库
运维·数据库·笔记·mysql·云计算·学习方法
_Kayo_1 小时前
css 练习笔记1
前端·css·笔记