当前位置: 首页 > article >正文

【FSM-3: 串行序列】

FSM-3:串行序列

  • 1 Serial receiver

FSM使用总结:

  • 所有涉及输出的driver原则上用cur_sta;若是使用nxt_sta的相当于是提前一拍知道结果,所以对于输出必须要使用clocked reg,这样才能和cur_sta对应起来;
  • 描述声明状态按照cur_sta的为准,这样输出才能按照cur_sta的为准;

1 Serial receiver






module top_module(
    input clk,
    input in,
    input reset,    // Synchronous reset
    output done
); 

    parameter S0 = 5'b0_0000;	//Start
    parameter S1 = 5'b0_0001;	//Data
    parameter S2 = 5'b0_0010;	//Stop
    parameter S3 = 5'b0_0100;	//OK
    parameter S4 = 5'b0_1000;	//Error
    parameter S5 = 5'b1_0000;	//wait_finish
    
    reg[5 -1:0] cur_sta;
    reg[5 -1:0] nxt_sta;
    
    //==State transition
    always @(*) begin
          case(cur_sta)
                S0: nxt_sta = (in==1'b0) ? S1: S0;
                S1: nxt_sta = (cnt==7) ? S2 : S1;
                S2: nxt_sta = (in==1'b1) ? S3 : S4;
                S3: nxt_sta = (in==1'b1) ? S0 : S1;
                S4: nxt_sta = (in==1'b1) ? S0 : S5;
                S5: nxt_sta = (in==1'b1) ? S0 : S5;
        		default : nxt_sta = S0;
        endcase
    end
    
    //==State Flop-Flop
    always @(posedge clk) begin
        if(reset) begin
            cur_sta <= S0;
        end else begin
           cur_sta <= nxt_sta; 
        end
    end
    
    //==State Output
    reg[8 -1:0] cnt;
    
    always @(posedge clk) begin
        if(reset) begin
            cnt <= 0;
        end else begin
            case(cur_sta) 
                S0: cnt <= 0;
                S1: cnt <= cnt + 1;
                S2: cnt <= 0;
                default: cnt <= 0;
            endcase
        end
    end
    
    assign done = (cur_sta==S3); 
        
endmodule

题目:




module top_module(
    input clk,
    input in,
    input reset,    // Synchronous reset
    output [7:0] out_byte,
    output done
); //

    // Use FSM from Fsm_serial
    parameter S0 = 5'b0_0000;	//Start
    parameter S1 = 5'b0_0001;	//Data
    parameter S2 = 5'b0_0010;	//Stop
    parameter S3 = 5'b0_0100;	//OK
    parameter S4 = 5'b0_1000;	//Error
    parameter S5 = 5'b1_0000;	//wait_finish
    
    reg[5 -1:0] cur_sta;
    reg[5 -1:0] nxt_sta;
    
    //==State transition
    always @(*) begin
          case(cur_sta)
                S0: nxt_sta = (in==1'b0) ? S1: S0;
                S1: nxt_sta = (cnt==7) ? S2 : S1;
                S2: nxt_sta = (in==1'b1) ? S3 : S4;
                S3: nxt_sta = (in==1'b1) ? S0 : S1;
                S4: nxt_sta = (in==1'b1) ? S0 : S5;
                S5: nxt_sta = (in==1'b1) ? S0 : S5;
        		default : nxt_sta = S0;
        endcase
    end
    
    //==State Flop-Flop
    always @(posedge clk) begin
        if(reset) begin
            cur_sta <= S0;
        end else begin
           cur_sta <= nxt_sta; 
        end
    end
    
    //==State Output
    reg[8 -1:0] cnt;
    
    always @(posedge clk) begin
        if(reset) begin
            cnt <= 0;
        end else begin
            case(cur_sta) 
                S0: cnt <= 0;
                S1: cnt <= cnt + 1;
                S2: cnt <= 0;
                default: cnt <= 0;
            endcase
        end
    end
    
    assign done = (cur_sta==S3); 
    // New: Datapath to latch input bits.
    reg[8 -1:0] data;
    
    always @(posedge clk) begin
        if(reset) begin
            data <= 0;
        end else begin
            case(cur_sta)
                S1: data[cnt] <= in;
                S2: data <= data;
                default: data <= data;
            endcase
        end
    end
    
    assign out_byte = (done==1) ? data : 0;

endmodule

http://www.kler.cn/a/576016.html

相关文章:

  • NVIC原理和使用
  • 【免费】2000.1-2021.9上市公司仲裁数据
  • Java数据结构第十八期:探索优先级队列的魅力(二)
  • 论文阅读:基于超图高阶表示的WSI生存预测
  • 前端分页技术的深度解析与实践优化
  • 通过着装人体剪影预测关键点,以获取人体的二维尺寸数据。复现过程包括获取或生成3D人体数据集、生成轮廓图像、训练模型等步骤
  • 测试直播postman+Jenkins所学
  • 网络原理之HTTPS(如果想知道网络原理中有关HTTPS的知识,那么只看这一篇就足够了!)
  • 仕考网:事业单位结构化面试技巧
  • 深入理解Tomcat的Request复用机制及其风险
  • 天津大学02-深度解读DeepSeek:部署、使用、安全【文末附下载链接】
  • Rocky linux 安装 docker
  • 请谈谈 HTTP 中的缓存控制,如何使用 Cache-Control 和 ETag 进行缓存管理?
  • 嵌入式仿真实验教学平台替换Proteus,嵌入式教学创新的新选择
  • Facebook 与信息传播:塑造新闻和媒体的新生态
  • 混元图生视频-腾讯混元开源的图生视频模型
  • Crawl4AI: 赋能AI用户的开源智能网页爬虫与数据提取
  • 电商项目-秒杀系统(四)秒杀异步下单防止重复秒杀
  • Firefox缩小标签页高度以及自定义调整
  • 游戏引擎学习第138天