牛客进阶题目3:不重叠序列检测
还是移位寄存器,加一个计数器来限制周期
题目要求状态机,懒得画了,移位寄存器可根据时序图直接写
`timescale 1ns/1ns
module sequence_detect(
input clk,
input rst_n,
input data,
output reg match,
output reg not_match
);
reg [5:0] seq_shift ;
reg [2:0] seq_count ;
always @(posedge clk or negedge rst_n) begin
if(!rst_n)
seq_count <= 'd0 ;
else if(seq_count == 3'd5)
seq_count <= 'd0 ;
else
seq_count <= seq_count + 1 ;
end
always @(posedge clk or negedge rst_n) begin
if(!rst_n)
seq_shift <= 'd0 ;
else if(seq_count == 3'd5)
seq_shift <= {5'b0,data} ;
else
seq_shift <= {seq_shift[4:0],data};
end
always @(posedge clk or negedge rst_n) begin
if(!rst_n) begin
match=1'b0;
not_match = 1'b0;
end
else if(seq_count == 3'd5 && {seq_shift[4:0],data}==6'b011100) begin
match <= 1'b1 ;
not_match <= 1'b0 ;
end
else if(seq_count == 3'd5 && {seq_shift[4:0],data}!=6'b011100) begin
match <= 1'b0 ;
not_match <= 1'b1 ;
end
else begin
match <= 1'b0 ;
not_match <= 1'b0 ;
end
end
endmodule
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】