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

相关推荐
博览鸿蒙2 小时前
FPGA前端设计适合哪些人学?该怎么学?
fpga开发
孞㐑¥2 小时前
C++vector类
开发语言·c++·经验分享·笔记
柒十三.4 小时前
江科大51单片机笔记【12】DS18B20温度传感&温度报警器(下)
笔记·嵌入式硬件·51单片机
!!!5254 小时前
Spring Cloud Gateway 笔记
笔记·spring cloud·gateway
柒十三.5 小时前
江科大51单片机笔记【13】LCD1602
笔记·嵌入式硬件·51单片机
Long_poem5 小时前
【自学笔记】Rust语言基础知识点总览-持续更新
开发语言·笔记·rust
lally.6 小时前
SSTI注入笔记
笔记·ssti
北京阿尔泰科技厂家7 小时前
2路模拟量同步输出卡、任意波形发生器卡—PCIe9100数据采集卡
fpga开发·工业自动化·数据采集卡·任意波形发生器·模拟量输出卡
szxinmai主板定制专家9 小时前
基于ARM+FPGA的高端伺服驱动与运动控制解决方案
大数据·arm开发·人工智能·fpga开发·架构
蓑衣客VS索尼克14 小时前
单片机中的基础外设GPIO的知识和应用—(6)
笔记·stm32·单片机·嵌入式硬件