Fsm serialdp

Fsm serialdp
HDLBIT
在这里插入图片描述

原文对问题得描述也有些问题。
之前写的状态机不怎么规范,重新去看了看状态机的规范。**

时序电路用周期内稳定的next_state做判断,组合逻辑用周期内稳定的current_state做判断。

**
如果你够牛你可以在时序电路中用current_state。

module top_module(
    input clk,
    input in,
    input reset,    // Synchronous reset
    output [7:0] out_byte,
    output done
); //
parameter IDLE=4'd0,START=4'd1,RXD=4'd2,STOP=4'd3,WAIT=4'd4,PARITY=4'd5;
    reg [7:0] out_byte_reg;
    reg [3:0] current_state;
    reg [3:0] next_state;
    wire odd;
    wire re;
    reg [3:0] cnt_byte;
    always @(posedge clk)
        begin
            if(reset)
                current_state<=IDLE;
            else
                current_state<=next_state;
        end
    always @(*) begin
        case(current_state)
        IDLE:next_state=(in==0)?START:IDLE;
        START:next_state=RXD;
        RXD:next_state=(cnt_byte==8)?PARITY:RXD;
        PARITY:next_state=(in==1)?STOP:WAIT;
        STOP:next_state=(in==0)?START:IDLE;
        WAIT:next_state=(in==1)?IDLE:WAIT;
        default:next_state=IDLE;
        endcase
    end
    
    always @(posedge clk) begin
        if(reset)
            cnt_byte<=0;
        else if(next_state==RXD)
            begin
                out_byte_reg[cnt_byte]<=in;
                cnt_byte<=cnt_byte+1;
            end
        else 
            cnt_byte<=0;
    end
    
    parity u1(
        .clk(clk),
        .reset(reset || next_state == IDLE || next_state == START),
        .in(in),
        .odd(odd)
    );
    assign done=((current_state == STOP)&&(~odd));
    assign out_byte=done?out_byte_reg:8'bz;
    /*always @(posedge clk) begin
        if(current_state==STOP&&done==1)
            out_byte<=out_byte_reg;
        else
            out_byte<=8'bz;
            
    end*/
    // Modify FSM and datapath from Fsm_serialdata

    // New: Add parity checking.

endmodule
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值