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

相关推荐
露临霜1 分钟前
人性的贪婪和妄念
笔记
谙弆悕博士2 分钟前
Lua学习笔记
c语言·开发语言·笔记·学习·lua·创业创新·业界资讯
xqqxqxxq20 分钟前
多线程、进程与JVM 技术笔记
jvm·笔记
万古长歌27 分钟前
CSDN年度技术趋势预测
笔记
Jul1en_35 分钟前
【SpringCloud】Eureka、Nacos 简单概念笔记
笔记·spring cloud·eureka
LuminousCPP39 分钟前
C 语言动态内存管理全解析:从基础函数到柔性数组与内存分区
c语言·经验分享·笔记·学习·柔性数组
汽车仪器仪表相关领域44 分钟前
Kvaser USBcan Pro 2xHS v2:双通道高速 CAN/FD 专业级 USB 接口,汽车与工业总线深度开发与诊断的核心工具
网络·人工智能·功能测试·fpga开发·汽车·可用性测试
d111111111d1 小时前
MQTT+STM32+ESP8266网络程序分层+韦老师
笔记·stm32·单片机·嵌入式硬件·学习·php
得闲喝茶1 小时前
SQL处理数据的常用语法语句
数据库·笔记·sql·数据分析·excel
糖炒栗子03261 小时前
最小二乘优化笔记:从损失函数、正则项到 BA / 图优化
人工智能·笔记·机器学习