[HDLBits] Fsm hdlc

Synchronous HDLC framing involves decoding a continuous bit stream of data to look for bit patterns that indicate the beginning and end of frames (packets). Seeing exactly 6 consecutive 1s (i.e., 01111110) is a "flag" that indicate frame boundaries. To avoid the data stream from accidentally containing "flags", the sender inserts a zero after every 5 consecutive 1s which the receiver must detect and discard. We also need to signal an error if there are 7 or more consecutive 1s.

Create a finite state machine to recognize these three sequences:

  • 0111110: Signal a bit needs to be discarded (disc).
  • 01111110: Flag the beginning/end of a frame (flag).
  • 01111111...: Error (7 or more 1s) (err).

When the FSM is reset, it should be in a state that behaves as though the previous input were 0.

Here are some example sequences that illustrate the desired operation.

复制代码
module top_module(
    input clk,
    input reset,    // Synchronous reset
    input in,
    output disc,
    output flag,
    output err);
	//0-5识别为1,5为0跳discard,为1跳6.6为1跳error,为0跳flag
    reg [3:0]state,next;
    parameter discard=7,flagg=8,error=9;
    always@(*)begin
        case(state)
            0:next<=in?1:0;
            1:next<=in?2:0;
            2:next<=in?3:0;
            3:next<=in?4:0;
            4:next<=in?5:0;
            5:next<=in?6:discard;
            6:next<=in?error:flagg;
            discard:next<=in?1:0;
            flagg:next<=in?1:0;
            error:next<=in?error:0;
        endcase
    end
    always@(posedge clk) begin
        if(reset)
            state<=0;
        else
            state<=next;
    end
    assign disc=state==discard;
    assign flag=state==flagg;
    assign err=state==error;
endmodule
相关推荐
第二层皮-合肥14 小时前
基于FPGA的雷达信号处理设计工具包分享
fpga开发·信号处理
美好的事情总会发生15 小时前
FPGA的LVDS接口电压
嵌入式硬件·fpga开发·硬件工程·智能硬件
卡奥斯开源社区官方20 小时前
量子计算“平价革命”深度解析:AMD破局FPGA方案+中国千比特云服务,技术拐点已至?
fpga开发·量子计算
贝塔实验室1 天前
译码器的结构
驱动开发·算法·网络安全·fpga开发·硬件工程·信息与通信·信号处理
bnsarocket2 天前
Verilog和FPGA的自学笔记9——呼吸灯
笔记·fpga开发·verilog·自学·硬件编程
国科安芯2 天前
基于AS32A601型MCU芯片的屏幕驱动IC方案的技术研究
服务器·人工智能·单片机·嵌入式硬件·fpga开发
cmc10282 天前
145.vivado采信号时ILA用一个probe要比用多个节约资源
fpga开发
白又白、2 天前
数据cdc (clock domain cross)
fpga开发
FakeOccupational2 天前
fpga系列 HDL : Microchip FPGA开发软件 Libero 中导出和导入引脚约束配置
fpga开发
贝塔实验室3 天前
LDPC 码的构造方法
算法·fpga开发·硬件工程·动态规划·信息与通信·信号处理·基带工程