当前位置: 首页 > news >正文

时序逻辑电路——序列检测器

文章目录

  • 一、序列检测
  • 二、牛客真题
    • 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
http://www.xdnf.cn/news/17533.html

相关文章:

  • 【Contiki】Contiki process概述
  • 基于slimBOXtv 9.16 V2-晶晨S905L3A/ S905L3AB-Mod ATV-Android9.0-线刷通刷固件包
  • 铁氧体和纳米晶:车载定制电感的材料选择
  • 什么是Python单例模式
  • 解决方德桌面操作系统V5.0-G23没ll命令的问题
  • 以太网交换机介绍
  • Docker compose使用、容器迁移
  • 3个实用的脚本
  • Linux系统编程---多进程
  • Python3.14都有什么重要新特性
  • 聚合直播-Simple Live-v1.7.7-全网直播平台能在一个软件上看完
  • java+postgresql+swagger-多表关联insert操作(九)
  • C++ 常用的智能指针
  • 使用Docker搭建开源Email服务器
  • 高防IP如何针对DDoS攻击特点起防护作用
  • 小刚说C语言刷题——1033 判断奇偶数
  • 《GPT-4.1深度解析:AI进化新标杆,如何重塑行业未来?》
  • Spring数据访问全解析:ORM整合与JDBC高效实践
  • 【Mysql】mysql数据库占用空间查询
  • 基础编程题目集 6-2 多项式求值
  • VUE简介
  • 蓝桥杯12. 日期问题
  • 全面解析IPv6:从理论到实践(以H3C配置为例)
  • 搜索插入位置--LeetCode
  • Linux中find和grep的区别
  • 常见但是有挑战的效果组件鸿蒙版
  • 视频分析设备平台EasyCVR化解高速服务区管理难题,打造全方位智能安防监控方案
  • 第 5 期(进阶版):训练第一个 DDPM 模型(使用 CIFAR-10 数据集)
  • 服务器上有conda环境 退出conda环境 再安装uv包管理器这样子就不会有冲突吗
  • MQ基础篇