含有无关项的序列检测

含有无关项的序列检测

题目描述
请编写一个序列检测模块,检测输入信号a是否满足011XXX110序列(长度为9位数据,前三位是011,后三位是110,中间三位不做要求),当信号满足该序列,给出指示信号match。

程序的接口信号图如下:
在这里插入图片描述
程序的功能时序图如下:
在这里插入图片描述

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input a,
	output reg match
	);

  
    parameter idle   = 8'b00000001;
    parameter state1 = 8'b00000010;
    parameter state2 = 8'b00000100;
    parameter state3 = 8'b00001000;
    parameter state4 = 8'b00010000;
    parameter state5 = 8'b00100000;
    parameter state6 = 8'b01000000;
    parameter state7 = 8'b10000000;
    
    reg [0:7] c_state,n_state;
    reg [0:1] cnt;
    always@(posedge clk or negedge rst_n)
        begin
            if(!rst_n)
                c_state <= idle;
            else
                c_state <= n_state;
        end
    always@(*)
        begin
            case(c_state)
                idle:begin
                    if(a == 0)
                        n_state = state1;
                    else
                        n_state = idle;
                end
                state1:begin
                    if(a == 1)
                        n_state = state2;
                    else
                        n_state = state1;
                end
                state2:begin
                    if(a == 1)
                        n_state = state3;
                    else
                        n_state = state1;
                end
                state3:begin
                    if(cnt == 2)
                        n_state = state4;
                    else
                        n_state = state3;
                end
                state4:begin
                    if(a == 1)
                        n_state = state5;
                    else
                        n_state = state1;
                end
                state5:begin
                    if(a == 1)
                        n_state = state6;
                    else
                        n_state = state1;
                end
                state6:begin
                    if(a == 0)
                        n_state = state7;
                    else
                        n_state = idle;
                end
                state7:begin
                    if(a == 1)
                        n_state = idle;
                    else
                        n_state = state1;
                end
                default:n_state = idle;
            endcase
        end
    always@(posedge clk or negedge rst_n)
        begin
            if(!rst_n)
                cnt <= 2'b0;
            else if(c_state == state3 && cnt == 2'd3)
                cnt <= 2'b0;
            else if(c_state == state3)
                cnt <= cnt + 1'b1;
            else
                cnt <= 2'b0;
        end
    always@(posedge clk or negedge rst_n)
        begin
            if(!rst_n)
                match <= 1'b0;
            else if(c_state == state7)
                match <= 1'b1;
            else
                match <= 1'b0;
        end
endmodule
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

傻童:CPU

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值