[HDLBits] 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.

Note that the serial protocol sends the least significant bit first.

复制代码
module top_module(
    input clk,
    input in,
    input reset,    // Synchronous reset
    output [7:0] out_byte,
    output done
); //
	reg [3:0] state,next;
    //0:还没接到起始位,1:接到起始位,...,9:接到最后一个数据位,10:接到终止位,11:没接到终止位
    always@(*) begin
        case(state)
            0:next<=in?0:1;
            1:next<=2;
            2:next<=3;
            3:next<=4;
            4:next<=5;
            5:next<=6;
            6:next<=7;
            7:next<=8;
            8:next<=9;
            9:next<=in?10:11;
            10:next<=in?0:1;
            //接到终止位后接到0即开始位,那就直接跳到1
            11:next<=in?0:11;
            //判断是否接到终止位。这里是设置了两种终止位状态来判断是否done
        endcase
    end

    always@(posedge clk) begin
        if(reset)
            state<=0;
        else
            state<=next;
    end
    assign done=(state==10);
    // Use FSM from Fsm_serial
    always@(posedge clk) begin
        case(state)
            1:out_byte[0]<=in;
            2:out_byte[1]<=in;
            3:out_byte[2]<=in;
            4:out_byte[3]<=in;
            5:out_byte[4]<=in;
            6:out_byte[5]<=in;
            7:out_byte[6]<=in;
            8:out_byte[7]<=in;            
        endcase
    end
    // New: Datapath to latch input bits.

endmodule
相关推荐
热爱学习地派大星6 小时前
FPGA矩阵算法实现
fpga开发
热爱学习地派大星10 小时前
Xilinx FPGA功耗评估
fpga开发·verilog·vivado·fpga功耗·xpe
搬砖的小码农_Sky15 小时前
XILINX Ultrascale+ Kintex系列FPGA的架构
fpga开发·架构
XvnNing15 小时前
【Verilog硬件语言学习笔记4】FPGA串口通信
笔记·学习·fpga开发
进击的奶龙16 小时前
21verilog函数
verilog·基础语法
千宇宙航16 小时前
闲庭信步使用SV搭建图像测试平台:第二十七课——图像的腐蚀
图像处理·计算机视觉·fpga开发
尤老师FPGA11 天前
使用DDR4控制器实现多通道数据读写(十六)
fpga开发·ddr4
HX科技11 天前
STM32给FPGA的外挂FLASH进行升级
stm32·嵌入式硬件·fpga开发·flash·fpga升级
sz66cm11 天前
FPGA基础 -- Verilog 驱动强度(drive strength)与电荷强度(charge strength)
fpga开发
海涛高软11 天前
FPGA深度和突发长度计算
fpga开发