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两道题目的结合体。

相关推荐
江屿风5 分钟前
C++OJ题经验总结(竞赛)4
开发语言·c++·笔记·算法·dp·双指针
小陈phd12 分钟前
多模态大模型学习笔记(四十三)—— 视觉定位(Visual Grounding):语言描述在图像中的精准锚定
笔记·学习·目标跟踪
searchforAI17 分钟前
怎么把视频里的PPT提取出来?视频转图文笔记完整方案
人工智能·笔记·gpt·ai·音视频·语音识别·ppt
東雪木11 小时前
多线程与并发编程 专属复习笔记
java·开发语言·笔记·java面试
Oll Correct11 小时前
实验二十九:TCP的运输连接管理
网络·笔记
飞翔中文网13 小时前
Java学习笔记之抽象类与接口(设计思想)
java·笔记·学习
智者知已应修善业13 小时前
【proteus设计文氏正弦波信号发生器】2023-5-9
驱动开发·经验分享·笔记·硬件架构·proteus·硬件工程
凉、介15 小时前
深入理解 ARMv8-A|处理器模式与寄存器
笔记·学习·嵌入式·arm
whyTeaFo15 小时前
MIT 6.1810: Lec 5: calling conventions and stack frames RISC-V
笔记
zlinear数据采集卡16 小时前
电源纹波杀手:LDO线性稳压电路的“降噪哲学”——基于ZLinear数据采集卡的深度解析
单片机·嵌入式硬件·fpga开发·硬件架构