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

相关推荐
Ruannn(努力版)3 小时前
Academic writing
笔记
_Narcissus_3 小时前
链表算法题和静态链表
数据结构·c++·笔记·算法·链表·ai·力扣
unicrom_深圳市由你创科技3 小时前
国产FPGA的芯片选型应该考虑哪些因素?
fpga开发
九硕智慧建筑一体化厂家4 小时前
大型建筑集群智慧管控升级!IBMS系统实现多系统一体化融合管理
运维·人工智能·笔记·智慧城市
深蓝海拓4 小时前
基于QtPy (PySide6) 的PLC-HMI工程实战记录(五)为当前动作画面的信号连接变量
网络·笔记·python·学习·pyqt
明德扬4 小时前
高速采集选 Direct RF 还是外置 ADC/FMC?从采样率、JESD204B 和开发周期对比
fpga开发·fpga
摇滚侠4 小时前
《SpringBoot 3:入门与应用实战》第 6 章 Spring Boot 最佳实践 阅读笔记 10
java·spring boot·笔记
明德扬4 小时前
机器人为什么需要“感知—控制—计算”一体化?FPGA 多传感器底板设计要点
fpga开发·机器人·fpga
疯狂打码的少年4 小时前
【数据结构】八大排序算法对比总结(时间/空间/稳定性)
数据结构·笔记·算法