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

相关推荐
梅见十柒14 分钟前
UNIX网络编程笔记:高级套接字编程20-25
网络·经验分享·笔记·unix
hello_ world.16 小时前
k8s笔记04-常用部署命令
笔记·容器·kubernetes
SatoshiGogo16 小时前
《李沐读论文》系列笔记:论文读写与研究方法【更新中】
笔记
IT199516 小时前
Wireshark笔记-DHCP流程与数据包解析
笔记·测试工具·wireshark
子朔不言16 小时前
[MH22D3开发笔记]2. SPI,QSPI速度究竟能跑多快,双屏系统的理想选择
笔记·mh22d3·新龙微·兆讯·双屏
被遗忘的旋律.16 小时前
Linux驱动开发笔记(七)——并发与竞争(上)——原子操作
linux·驱动开发·笔记
鲸鱼240116 小时前
无监督学习中的经典聚类算法——K-Means笔记
笔记
wan5555cn18 小时前
AI 时代“驯导师”职业发展方向探究
大数据·人工智能·笔记·深度学习
霜绛19 小时前
Unity笔记(六)——Mathf、三角函数、坐标系、向量
笔记·学习·unity·游戏引擎
阑梦清川19 小时前
如何使用notion搭建自己的个人知识库(第二大脑)
笔记