VL27 不重叠序列检测

ops/2024/10/17 20:23:16/

这里最大的问题是:
always @(*) always @(posedge clk or negedge rst_n)的区别
always @(*) 在当前时钟内会变化
always @(posedge clk or negedge rst_n)由时钟驱动,所以会在下一个时钟才发生变化

代码

module sequence_detect(input clk,input rst_n,input data,output reg match,output reg not_match);parameter zero=0,one=1,two=2,three=3,four=4,five=5,six=6,fail=7;reg [2:0] current_stage,next_stage;reg [2:0] cnt;always @(posedge clk or negedge rst_n) beginif(~rst_n)begincnt <= 3'b0 ;endelse begin cnt <= (cnt == 3'd6) ? 3'b1: cnt+ 3'b1 ;endendalways @(posedge clk or negedge rst_n) beginif(~rst_n)begincurrent_stage <= zero;endelse begincurrent_stage <= next_stage;endendalways @(*) beginif(~rst_n)beginnext_stage <= zero;endelse begincase(current_stage)zero  : next_stage = data==1'b0 ? one  : fail;one   : next_stage = data==1'b1 ? two  : fail;two   : next_stage = data==1'b1 ? three: fail;three : next_stage = data==1'b1 ? four : fail;four  : next_stage = data==1'b0 ? five : fail;five  : next_stage = data==1'b0 ? six  : fail;six   : next_stage = data==1'b0 ? one  : fail;fail : next_stage = (cnt == 6 && data == 1'b0) ? one : fail ;default : next_stage = zero;     endcaseendendalways @(*) beginif(~rst_n)beginmatch <= 1'b0 ;not_match <= 1'b0;endelse beginmatch <= (cnt == 6 && current_stage == six) ;not_match <= (cnt == 6 && current_stage == fail);endendendmodule

testbench

  
module testbench_sequence_detect;  reg clk, rst_n, data;  wire match, not_match;  // Instantiate the Unit Under Test (UUT)  sequence_detect uut (  .clk(clk),   .rst_n(rst_n),   .data(data),   .match(match),   .not_match(not_match)  );  // Clock generation  initial begin  clk = 1;  forever #(5) clk = ~clk;  // Generate a 10ns period clock signal  end  // Test stimulus  initial begin   rst_n = 0;  
//        data = 0;  #10;  // Reset the module  rst_n = 1;data = 0;  #10;  // Send a sequence that does not match the expected pattern  
//        data = 1'b0; #10;  data = 1'b1; #10;  data = 1'b1; #10;  data = 1'b1; #10;  data = 1'b0; #10;  data = 1'b0; #10;  data = 1'b0; #10; // Check if not_match is asserted  if (not_match) begin  $display("Sequence did not match at time %t", $time);  end else begin  $display("Test failed: not_match was not asserted when expected");  
//            $finish;  end  //        // Reset the state  
//        #10;  
//        rst_n = 0;  
//        #10;  
//        rst_n = 1;  // Send the correct sequence  data = 1'b0; #10;  data = 1'b1; #10;  data = 1'b1; #10;  data = 1'b1; #10;  data = 1'b0; #10;  data = 1'b0; #10;  data = 1'b0; #10;  // Check if match is asserted  if (match) begin  $display("Sequence matched at time %t", $time);  end else begin  $display("Test failed: match was not asserted when expected");  
//            $finish;  end  // Finish the simulation  $finish;  end  endmodule

http://www.ppmy.cn/ops/48066.html

相关文章

【2024算力大会分会 | SPIE独立出版 | 往届均已完成EI检索】2024云计算、性能计算与深度学习国际学术会议(CCPCDL 2024)

【2024算力大会分会 | SPIE出版】 2024云计算、性能计算与深度学习国际学术会议(CCPCDL 2024) 2024 International conference on Cloud Computing, Performance Computing and Deep Learning *CCPCDL往届均已完成EI检索&#xff0c;最快会后4个半月完成&#xff01; 一、…

武汉凯迪正大—绝缘强度的测试设备 工频高压耐压交流试验仪 工频耐压试验机

武汉凯迪正大电气有限公司生产KDJS-8A全自动工频耐压试验系统&#xff08;10kVA全自动操作台&#xff09;&#xff0c;是根据国家行业试验标准而设计的试验设备&#xff0c;其安全可靠、功能强、使用方便、维护简单。主要用于对各种电器产品、电气元件、绝缘材料等进行规定电压…

【设计模式】结构型设计模式之 组合模式

介绍 这里的组合模式&#xff0c;与之前的设计模式中的"组合关系"完全是两码事&#xff0c;这里的组合模式主要用来处理结构为树形的数据。 组合模式&#xff08;Composite Pattern&#xff09;是一种结构型设计模式&#xff0c;它允许你将对象组合成树状结构来表示…

C# —— 类型转换

类型转换就是不同变量数据类型之间进行互相转换 隐式转换 : 默认是C#中安全的进行数据转换的方式 一般不会造成数据丢失 相同数据类型之间的隐式转换 有符号 long -> int ->short ->sbyte long l 1; int i 2; short s 3; sbyte sb 4; // 大范围可以装小范围的 l…

如何愉快地实施数仓模型,对比下厨做饭

一般我们建设数仓&#xff0c;有一个链路&#xff1a; 比如这样的 数据从原始层到DWD、DWS层、然后ADS层。 嘿&#xff0c;未来的大数据专家们&#xff01;当我们开始实施数据模型时&#xff0c;不妨参考《大数据之路》这本宝藏书。 让我们一起简化流程&#xff0c;注重细节…

HBuilder中能否使用机器学习

HBuilder中能否使用机器学习? HBuilder是一款由腾讯公司开发的前端开发工具,主要用于快速构建和管理HTML5应用。HBuilder本身是一个专注于Web开发的集成开发环境(IDE),它提供了代码编辑、预览、调试等功能,并且集成了Espresso等移动应用测试框架。HBuilder的核心功能是针…

算法day24

第一题 1047. 删除字符串中的所有相邻重复项 解法&#xff1a;利用数组来模拟一下栈 对于上述字符串转换为字符数组&#xff0c;通过模拟栈的操作来解决这道题&#xff0c;当栈为空时下一位字符直接进行入栈操作&#xff0c;当当前数组中要入栈的字符和栈顶的字符相同时&#x…

实验七、创建小型实验拓扑《计算机网络》

早检到底是谁发明出来的。 一、实验目的 完成本实验后&#xff0c;您将能够&#xff1a; • 设计逻辑网络。 • 配置物理实验拓扑。 • 配置 LAN 逻辑拓扑。 • 验证 LAN 连通性。 二、实验任务 在本实验中&#xff0c;将要求您连接网络设备并配置主机实现基本的网络…