题解 | #不重叠序列检测#

alt

移位寄存器+计数器实现

`timescale 1ns/1ns
module sequence_detect(
	input clk,
	input rst_n,
	input data,
	output reg match,
	output reg not_match
	);
    
    reg [2:0] cnt_seq;
    reg [5:0] reg_data;
    
    always@(posedge clk or negedge rst_n) begin: count_sequence
        if(~rst_n)
            cnt_seq <= 3'b0;
        else if(cnt_seq == 3'd5)
            cnt_seq <= 3'b0;
        else
            cnt_seq <= cnt_seq + 1;
    end
        
    always@(posedge clk or negedge rst_n) begin: register_data
        if(~rst_n)
            reg_data <= 6'b0;
        else
            reg_data <= {reg_data[4:0], data};
    end
    
    always@(posedge clk or negedge rst_n) begin:judge_match
        if(~rst_n) begin
            match <= 0;
            not_match <= 0;
        end
        else if(cnt_seq == 3'd5) begin
            if({reg_data[4:0], data} == 6'b011100) begin
                match <= 1;
                not_match <= 0;
            end
            else begin
                match <= 0;
                not_match <= 1;
            end
        end
        else begin
            match <= 0;
            not_match <= 0;
        end
    end
    
endmodule
《Verilog/VHDL必刷习题集》 文章被收录于专栏

Verilog/VHDL必刷习题集,包含基础知识、组合逻辑设计、时序逻辑设计、状态机设计、RAM及FIFO设计等等。

全部评论

相关推荐

07-25 13:42
门头沟学院 Java
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-24 13:32
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务