009---基于Verilog HDL的单比特信号边沿检测

news/2025/3/11 6:35:22/

文章目录

  • 摘要
  • 一、边沿检测
  • 二、时序逻辑实现
    • 2.1 rtl
    • 2.2 tb
  • 三、组合逻辑实现
    • 3.1 rtl
    • 3.2 tb


摘要

文章为学习记录。采用时序逻辑和组合逻辑实现边沿检测的核心逻辑。组合逻辑实现的上升沿和下降沿的脉冲比时序逻辑实现的上升沿和下降沿的脉冲提前一拍。


一、边沿检测

边沿检测主要作用是能够准确的识别出单比特信号的上升沿或下降沿。
边沿检测原理:利用寄存器对信号前一状态和后一状态进行寄存,若前后两个状态不同,则检测到了边沿。

二、时序逻辑实现

仿真波形如下图所示。
在这里插入图片描述

2.1 rtl

module edge_dect(
input  wire  clk,
input  wire  rst_n,
input  wire  data,output reg   pos_edge,
output reg   neg_edge);reg  data_reg1;
reg  data_reg2;
reg  data_reg3;always @(posedge clk or negedge rst_n)
beginif(!rst_n)begindata_reg1 <= 0;data_reg2 <= 0;data_reg3 <= 0;endelsebegindata_reg1 <= data;data_reg2 <= data_reg1;data_reg3 <= data_reg2;end
endalways @(posedge clk or negedge rst_n)
beginif(rst_n == 1'b0)pos_edge <= 1'b0;else if(data_reg2 && (~data_reg3)) pos_edge <= 1'b1;else pos_edge <= 1'b0;
endalways @(posedge clk or negedge rst_n)
beginif(rst_n == 1'b0)neg_edge <= 1'b0;else if((~data_reg2) && data_reg3) neg_edge <= 1'b1;else neg_edge <= 1'b0;
endendmodule

2.2 tb

module tb_edge_dect();reg  clk;
reg  rst_n;
reg  data;wire   pos_edge;
wire   neg_edge;initial
beginrst_n = 0;data  = 0;#101;rst_n = 1;#200;data  = 1;#500;data  = 0;#200;$stop;
endinitial
beginclk = 1;
end
always #10 clk = ~clk;edge_dect  edge_dect_inst1
(
. clk(clk),
. rst_n(rst_n),
. data(data),. pos_edge(pos_edge),
. neg_edge(neg_edge));endmodule

三、组合逻辑实现

仿真波形如下图所示。
在这里插入图片描述

3.1 rtl

module edge_dect(
input  wire  clk,
input  wire  rst_n,
input  wire  data,output wire   pos_edge,
output wire   neg_edge);reg  data_reg1;
reg  data_reg2;
reg  data_reg3;always @(posedge clk or negedge rst_n)
beginif(!rst_n)begindata_reg1 <= 0;data_reg2 <= 0;data_reg3 <= 0;endelsebegindata_reg1 <= data;data_reg2 <= data_reg1;data_reg3 <= data_reg2;end
endassign pos_edge = data_reg2 && (~data_reg3);
assign neg_edge = ~data_reg2 && data_reg3;
//always @(posedge clk or negedge rst_n)
//begin
//    if(rst_n == 1'b0)
//       pos_edge <= 1'b0;
//    else if(data_reg2 && (~data_reg3)) 
//       pos_edge <= 1'b1;
//   else 
//       pos_edge <= 1'b0;
//end//always @(posedge clk or negedge rst_n)
//begin
//    if(rst_n == 1'b0)
//       neg_edge <= 1'b0;
//    else if((~data_reg2) && data_reg3) 
//       neg_edge <= 1'b1;
//   else 
//       neg_edge <= 1'b0;
//endendmodule

3.2 tb

tb文件与时序逻辑实现的tb文件一样。


http://www.ppmy.cn/news/1578273.html

相关文章

ThreadLocal源码剖析

文章目录 四种引用的概念Entry的类定义弱引用和内存泄漏如果key使用强引用如果key使用弱引用为什么使用弱引用 hash冲突的解决ThreadLocalMap中的set方法演示垃圾回收get触发GCset触发GC ThreadLocal-内存清理探测式清理&#xff08;ExpungeStaleEntry&#xff09;启发式清理&a…

图形编辑器基于Paper.js教程24:图像转gcode的重构,元素翻转,旋转

前段时间在雕刻图片时&#xff0c;旋转图片&#xff0c;翻转图片后&#xff0c;发现生成准确的gcode&#xff0c;虽然尺寸对&#xff0c;但是都是以没有旋转&#xff0c;没有翻转的图片进行生成的。后来思考了一下&#xff0c;发现这真是一个大bug&#xff0c;无论图片如何选择…

FreeRTOS第17篇:FreeRTOS链表实现细节05_MiniListItem_t:FreeRTOS内存优化

文/指尖动听知识库-星愿 文章为付费内容,商业行为,禁止私自转载及抄袭,违者必究!!! 文章专栏:深入FreeRTOS内核:从原理到实战的嵌入式开发指南 1 为什么需要迷你列表项? 在嵌入式系统中,内存资源极其宝贵。FreeRTOS为满足不同场景需求,设计了标准列表项(ListItem_…

C++后端服务器开发技术栈有哪些?有哪些资源或开源库拿来用?

一、 C后台服务器开发是一个涉及多方面技术选择的复杂领域&#xff0c;特别是在高性能、高并发的场景下。以下是C后台服务器开发的一种常见技术路线&#xff0c;涵盖了从基础到高级的技术栈。 1. 基础技术栈 C标准库 C11/C14/C17/C20&#xff1a;使用现代C特性&#xff0c;如…

Linux系统编程--线程同步

目录 一、前言 二、线程饥饿 三、线程同步 四、条件变量 1、cond 2、条件变量的使用 五、条件变量与互斥锁 一、前言 上篇文章我们讲解了线程互斥的概念&#xff0c;为了防止多个线程同时访问一份临界资源而出问题&#xff0c;我们引入了线程互斥&#xff0c;线程互斥其实…

前端知识点---前端里的接口

文章目录 1. 接口&#xff08;Interface&#xff09;作为对象的类型定义&#xff1a;① 接口是对象的模版, 类也是对象的模版 可以定义对象的属性跟类型1. 接口是对象的模板&#xff1a;2. 类是对象的模板 ②类可以被具体实现 可以new一个类, 接口只能用来定义类型 接口没法被具…

SQLiteStudio:一款免费跨平台的SQLite管理工具

SQLiteStudio 是一款专门用于管理和操作 SQLite 数据库的免费工具。它提供直观的图形化界面&#xff0c;简化了数据库的创建、编辑、查询和维护&#xff0c;适合数据库开发者和数据分析师使用。 功能特性 SQLiteStudio 提供的主要功能包括&#xff1a; 免费开源&#xff0c;可…

解决Node Electron下调用Python脚本输出中文乱码的问题

博主原博客地址&#xff1a;https://www.lisok.cn/Front-End/610.html 调用Pyinstaller打包后的可执行文件方式如下: import { promisify } from util import { exec } from child_process import { app } from electronasync handleVerifyZy(id) {const entity await this.f…