您的位置:首页 > 房产 > 家装 > 信息类网站_网站开发工程师培训机构_网络广告策划方案范文_公司网页网站建设

信息类网站_网站开发工程师培训机构_网络广告策划方案范文_公司网页网站建设

2025/8/27 10:09:31 来源:https://blog.csdn.net/weixin_51116586/article/details/147337287  浏览:    关键词:信息类网站_网站开发工程师培训机构_网络广告策划方案范文_公司网页网站建设
信息类网站_网站开发工程师培训机构_网络广告策划方案范文_公司网页网站建设

文章目录

  • 一、序列检测
  • 二、牛客真题
    • 1. 输入序列连续的序列检测(输入连续、重叠、不含无关项、串行输入)
    • 写法一:移位寄存器
    • 写法二:Moore状态机
    • 写法三:Mealy状态机


一、序列检测

  序列检测器指的就是将一个指定的序列(以‘10010’为例)从数字码流中识别出来,是一个经典的数字电路实例,也是数字IC和FPGA笔试面试中常考的知识点。写法总共可分为三种:
写法:

  • 移位寄存器
  • Moore状态机
  • Mealy状态机

  常考的题目类型有以下特点,可能取其一类型进行拷打,也可能多个类型进行结合。比如说输入非连续且并行输入,最终需要提取出某个非重叠序列。
题目类型:

  • 输入连续/非连续,非连续输入会有使能信号valid
  • 重叠/非重叠序列检测
  • 含无关项/不含无关项,比如说检测输入信号a是否满足011XXX110序列(长度为9位数据,前三位是011,后三位是110,中间三位不做要求)
  • 串行输入/并行输入,比如说并行输入2bit数据

二、牛客真题

1. 输入序列连续的序列检测(输入连续、重叠、不含无关项、串行输入)

  以牛客上比较简单的题目VL25 输入序列连续的序列检测,介绍三种写法。
在这里插入图片描述

写法一:移位寄存器

module sequence_detect(input clk,input rst_n,input a,output reg match);reg [7:0] shift_reg;always @(posedge clk or negedge rst_n)beginif(~rst_n)beginshift_reg <= 'd0;endelse beginshift_reg <= {shift_reg[6:0], a};endendalways @(posedge clk or negedge rst_n)beginif(~rst_n)beginmatch <= 1'b0;endelse if(shift_reg==8'b0111_0001)beginmatch <= 1'b1;endelse beginmatch <= 1'b0;endend
endmodule

写法二:Moore状态机

module sequence_detect(input clk,input rst_n,input a,output reg match);localparam idle  = 'd0;localparam s0    = 'd1;localparam s1    = 'd2;localparam s2    = 'd3;localparam s3    = 'd4;localparam s4    = 'd5;localparam s5    = 'd6;localparam s6    = 'd7;localparam detect= 'd8;reg [3:0] curr_state;reg [3:0] next_state;always @(posedge clk or negedge rst_n)beginif(~rst_n)curr_state <= idle;else curr_state <= next_state;endalways @(*)begincase(curr_state)idle    : next_state = (a==1'b0)?s0     :idle   ;s0      : next_state = (a==1'b1)?s1     :s0     ;s1      : next_state = (a==1'b1)?s2     :s0     ;s2      : next_state = (a==1'b1)?s3     :s0     ;s3      : next_state = (a==1'b0)?s4     :idle   ;s4      : next_state = (a==1'b0)?s5     :s1     ;s5      : next_state = (a==1'b0)?s6     :s1     ;s6      : next_state = (a==1'b1)?detect :s0     ;detect  : next_state = (a==1'b1)?s3     :s0     ;default : next_state = idle;endcaseendalways @(posedge clk or negedge rst_n)beginif(~rst_n)match <= 1'b0;else if(curr_state==detect)match <= 1'b1;elsematch <= 1'b0;endendmodule

写法三:Mealy状态机

  注意:牛客上仿真需要用的是Moore状态机,因此Mealy状态机仿真结果的match会提前一个周期到来.

module sequence_detect(input clk,input rst_n,input a,output reg match);localparam idle  = 'd0;localparam s0    = 'd1;localparam s1    = 'd2;localparam s2    = 'd3;localparam s3    = 'd4;localparam s4    = 'd5;localparam s5    = 'd6;localparam s6    = 'd7;reg [2:0] curr_state;reg [2:0] next_state;always @(posedge clk or negedge rst_n)beginif(~rst_n)curr_state <= idle;else curr_state <= next_state;endalways @(*)begincase(curr_state)idle    : next_state = (a==1'b0)?s0     :idle   ;s0      : next_state = (a==1'b1)?s1     :s0     ;s1      : next_state = (a==1'b1)?s2     :s0     ;s2      : next_state = (a==1'b1)?s3     :s0     ;s3      : next_state = (a==1'b0)?s4     :idle   ;s4      : next_state = (a==1'b0)?s5     :s1     ;s5      : next_state = (a==1'b0)?s6     :s1     ;s6      : next_state = (a==1'b1)?s1     :s0     ;default : next_state = idle;endcaseendalways @(posedge clk or negedge rst_n)beginif(~rst_n)match <= 1'b0;else if(curr_state==s6 && a==1'b1)match <= 1'b1;elsematch <= 1'b0;endendmodule

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com