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

相关推荐
Shea的笔记本3 分钟前
MindSpore实战笔记:WaveNet音乐生成复现全记录
笔记
koo36424 分钟前
pytorch深度学习笔记23
pytorch·笔记·深度学习
FakeOccupational1 小时前
【电路笔记 STM32】Cortex-M7 内核上的数据缓存结构图 + MPU内存保护单元 + Cache基本操作 + Cache&DMA 时序图
笔记·stm32·缓存
daxi1501 小时前
Verilog入门实战——第3讲:流程控制语句(if-else / case / 循环结构)
fpga开发·fpga
C羊驼2 小时前
C语言学习笔记(十一):数据在内存中的存储
c语言·经验分享·笔记·学习
承渊政道2 小时前
【优选算法】(实战体验滑动窗口的奇妙之旅)
c语言·c++·笔记·学习·算法·leetcode·visual studio
C羊驼2 小时前
C语言学习笔记(十):操作符
c语言·开发语言·经验分享·笔记·学习
鹭天2 小时前
RAG学习笔记
笔记·学习
存储服务专家StorageExpert3 小时前
NetApp NVME SSD 盘的学习笔记
运维·服务器·笔记·学习·存储维护·emc存储·netapp
无聊大侠hello world3 小时前
黑马大模型 RAG 与 Agent 实战学习笔记
笔记·学习