• 序列检测101


    设计一个101序列检测器。要画出状态转移图,写verilog,并仿真测试。

     使用Moore状态机进行序列检测,状态转移图如下:


    module seq_101(
                    clk,
                    rst_n,
                    data_in,
                    data_out
                    );
        input clk;
        input rst_n;
        input data_in;
        output reg data_out;
        
        localparam IDLE=4'b0001,s1=4'b0010,s2=4'b0100,s3=4'b1000;
        //state change
        reg [3:0]current_state;
        reg [3:0]next_state;
        always@(posedge clk or negedge rst_n)
            if(!rst_n)
                current_state<=IDLE;
            else
                current_state<=next_state;
        //next_state generate
        always@(*)begin
                case(current_state)
                    IDLE:begin
                        if(data_in==1)
                            next_state=s1;
                        else
                            next_state=IDLE;
                    end
                    s1:begin
                        if(data_in==0)
                            next_state=s2;
                        else
                            next_state=s1;
                    end
                    s2:begin
                        if(data_in==1)
                            next_state=s3;
                        else
                            next_state=IDLE;
                    end
                    s3:begin
                        if(data_in==1)
                            next_state=s1;
                        else
                            next_state=IDLE;
                    end
                    default:next_state=IDLE;
                    
                endcase
        end
        //
        always@(posedge clk or negedge rst_n)
        begin
            if(!rst_n)
                data_out<=0;
            else if(current_state==s3)
                data_out<=1;
            else
                data_out<=0;
        end
    endmodule 
    `timescale 1ns/1ns
    module tb;
        reg clk;
        reg rst_n;
        reg data_in;
        wire data_out;
        reg [19:0]data_init;
        integer i;
        seq_101 seq_101(
                    .clk(clk),
                    .rst_n(rst_n),
                    .data_in(data_in),
                    .data_out(data_out)
                    );
        initial clk=0;
        always #10 clk=~clk;
        
        initial begin
            rst_n=0;
            data_init=20'b1010_0101_0111_0010_1010;
            #200;
            rst_n=1;
            for (i=0;i<20;i=i+1)
                #20 data_in=data_init[i];
        end
    endmodule
    View Code

    YKJIAO
  • 相关阅读:
    Tensorflow2.0学习(3)---基础
    Tensorflow2.0学习(2)---线性回归和分类
    Tensorflow2.0学习(1)---简介
    人工智能、机器学习、深度学习区别
    window10安装tensorflow2
    conda创建虚拟环境报错
    ubuntu18的firefox安装flash插件
    Shell学习(1)---脚本入门
    检测服务器端口是否被封(墙)
    git 查看远程仓库地址
  • 原文地址:https://www.cnblogs.com/ajiaoa/p/12761282.html
Copyright © 2020-2023  润新知