FPGA Verilog实现一个脉冲波形变换

一、波形变换需求

二、思路

(1)脉冲边沿提取,得到波形的上升沿r_rise和下降沿r_fall

(2)将上升沿r_rise延迟一节拍r_r_rise,r_rise更新上一周期的周期和脉宽并清空上一次的脉冲周期计数和脉宽周期计数,r_r_rise启动本次脉冲周期计数和脉宽计数,r_fall结束本次脉宽计数

三、代码

`timescale 1ns / 1ps
module pulse_transfer(ttl_in	,// mcu ttl inputsys_clk	,// 100MHz clk inputreset_n	,// negtive reset inputttl_out,  // fpga ttl output				);/*! -------------------------------------------------------------------------- */
/*!  module port defination */
input							ttl_in	;
input							sys_clk	;
input							reset_n	;
output							ttl_out	;parameter FRE_SYS		 = 30'd100000000;//100MHz/*! -------------------------------------------------------------------------- */
/*!  module macro defination */
parameter MAX_PULSE_WIDTH_COUNT	= 16'd20000; /*! max width  200us = 10ns*20000 */
parameter MAX_PULSE_PERIOD_COUNT = 30'd100000000;           /*! max period  1s */
parameter COUNT_OFFSET = 3'd2;
parameter TIME_1US = 8'd100;							
parameter TIME_300NS = 8'd30;/*! -------------------------------------------------------------------------- */
/*!  get rise and fall edge  */
wire 							w_is_rise_trigger;
wire 							w_is_fall_trigger;
reg							    r_ttl_in_delay;
reg							    r_ttl_in_delay_1;
always	@	(	posedge sys_clk  or negedge reset_n )
beginif(	!reset_n )	beginr_ttl_in_delay   	<=	1'b0	;r_ttl_in_delay_1	<=	1'b0	;endelsebeginr_ttl_in_delay	    <=	ttl_in	;r_ttl_in_delay_1	<=	r_ttl_in_delay	;end
end	//assign	w_is_rise_trigger =  ~r_ttl_in_delay&ttl_in;
//assign	w_is_fall_trigger =  ~ttl_in&r_ttl_in_delay;/*! -------------------------------------------------------------------------- */
/*!  synch rise and fall trigger  */
reg								r_is_rise_trigger;
reg								r_is_fall_trigger;
always	@	(	posedge sys_clk or negedge reset_n)
beginif(	!reset_n )	beginr_is_rise_trigger <= 1'b0;r_is_fall_trigger <= 1'b0;endelse if({r_ttl_in_delay,r_ttl_in_delay_1} == 2b'10)beginr_is_rise_trigger	<= 1'b1;r_is_fall_trigger <= 1'b0;endelse if({r_ttl_in_delay,r_ttl_in_delay_1} == 2b'01)beginr_is_rise_trigger	<= 1'b0;r_is_fall_trigger <= 1'b1;endelse beginr_is_rise_trigger <= 1'b0;r_is_fall_trigger <= 1'b0;end
end/*! -------------------------------------------------------------------------- */
/*!  get start count trigger  */
reg								r_count_start_trigger;
wire							w_count_clear_trigger;
assign w_count_clear_trigger = r_is_rise_trigger;
always	@	(	posedge sys_clk or negedge reset_n )
beginif(	!reset_n )	r_count_start_trigger	<=	1'b0;elser_count_start_trigger	<=	w_count_clear_trigger;
end	/*! -------------------------------------------------------------------------- */
/*!  get period and width count enable flag  */
reg								r_is_pulse_period_count_enable;
reg								r_is_pulse_width_count_enable;
always	@	(	posedge sys_clk or negedge reset_n)
beginif(	!reset_n )	beginr_is_pulse_period_count_enable = 1'b0;r_is_pulse_width_count_enable = 1'b0;endelse	beginif( r_is_rise_trigger )beginr_is_pulse_period_count_enable = 1'b0;r_is_pulse_width_count_enable = 1'b0;endif( r_count_start_trigger )beginr_is_pulse_width_count_enable  = 1'b1;r_is_pulse_period_count_enable = 1'b1;endif( r_is_fall_trigger )r_is_pulse_width_count_enable = 1'b0;end
end	/*! -------------------------------------------------------------------------- */
/*!  pulse width and period count handle */
reg			[30:0]				r_pulse_period_count;
reg			[30:0]				r_pulse_period;
reg			[30:0]				r_pulse_width_count;
reg			[30:0]				r_pulse_width;
always	@	(	posedge sys_clk or negedge reset_n )
beginif(	!reset_n )	beginr_pulse_width_count <= 30'd0;r_pulse_width <= 30'd0;r_pulse_period_count <=	30'd0;r_pulse_period <= 30'd0;endelsebeginif(	r_is_rise_trigger )begin				r_pulse_period_count <= 30'd0;r_pulse_width_count <= 30'd0;endif( r_is_pulse_width_count_enable )r_pulse_width_count <= r_pulse_width_count + 1'b1;elsebeginr_pulse_width <= r_pulse_width_count;endif( r_is_pulse_period_count_enable )r_pulse_period_count <= r_pulse_period_count + 1'b1;elsebeginr_pulse_period <= r_pulse_period_count;endend
end/*! -------------------------------------------------------------------------- */
/*!  output pulse handle */
reg			[30:0]			r_out_cnt;
reg							r_ttl_out;		
always	@	(	posedge sys_clk or negedge reset_n )
beginif(	!reset_n )	beginr_ttl_out <= 1'b0;r_out_cnt <= 1'b0;endelsebegin//if( r_pulse_period > MAX_PULSE_PERIOD_COUNT || r_pulse_width > MAX_PULSE_WIDTH_COUNT)//	begin//		r_ttl_out <= 1'b0;//		r_out_cnt <= 1'b0;//	end//elseif(r_pulse_period == 0 || r_pulse_width == 0)beginr_out_cnt <= 1'b0;endelsebeginif( r_pulse_width <= TIME_1US + 4'd10 )//*note in <1.1us casebeginif( r_out_cnt < TIME_300NS )//0.3usbeginr_ttl_out <= 1'b1;r_out_cnt <= r_out_cnt + 1'b1;endelse if ( r_out_cnt < r_pulse_period )beginr_ttl_out <= 1'b0;r_out_cnt <= r_out_cnt + 1'b1;	endelsebeginr_ttl_out <= 1'b0;	r_out_cnt <= 1'b0;	endendelsebeginif( r_out_cnt < r_pulse_width - TIME_1US)//*note -1usbeginr_ttl_out <= 1'b1;r_out_cnt <= r_out_cnt + 1'b1;endelse if ( r_out_cnt < r_pulse_period )beginr_ttl_out <= 1'b0;r_out_cnt <= r_out_cnt + 1'b1;	endelsebeginr_ttl_out <= 1'b0;	r_out_cnt <= 1'b0;	endendendend
end/*! -------------------------------------------------------------------------- */
/*!  output assign handle */
assign	ttl_out	= r_ttl_out;endmodule

四、行为仿真

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/404836.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

[react] 状态管理器它精髓是什么?

[react] 状态管理器它精髓是什么&#xff1f; 统一的数据管理 个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试题

夺命雷公狗jquery---22-bind为jquery对象绑定多个相关事件

<!DOCTYPE html> <html><head><meta charset"utf-8"><title></title><script src"js/jquery.js"></script><script>//页面载入ready方法$(function(){$(img).bind({mouseover:function(){$(#result…

STM32 DSP库的使用方法

一、工程中如何添加DSP库 在keil5软件中点击 Pack&#xff0c;CMISIS组件选择DSP资源&#xff0c;可以选择Source源码或者Library库导入到项目中&#xff0c;点击OK&#xff0c;可以在项目树中看到该资源已经导入了工程。 二、 如何使用DSP库 DSP库对浮点计算做了优化和增强&…

SharePoint 2010-随机出现的页面性能问题

有个客户, 服务器的配置巨牛, 24核CPU, 64GB内存, 这样的三台机器组成了一个SharePoint 2010的服务器场. 就是这样牛的配置, 出现了性能问题. 看performance log, 发现CPU, 内存都资源非常充裕, 问题发生的时候request/sec的值也非常的低. 问题发生的频率很低, 一天十次以内. …

[react] 在使用react过程中什么时候用HOC?

[react] 在使用react过程中什么时候用HOC&#xff1f; 给组件增加额外的功能 个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试题

C++使用Json作为数据包装格式的通信

From: http://blog.sina.com.cn/s/blog_4ae178ba01014eve.html http://blog.csdn.net/chenziwen/article/details/5785932 Json大家都耳熟能详了吧&#xff1f;现在Json广泛用于各类通信&#xff0c;特别是基于Http协议的通信&#xff0c;一般的服务端动态脚本语言都有库支持…

iOS开发多线程篇—线程的状态

iOS开发多线程篇—线程的状态 一、简单介绍 线程的创建&#xff1a; self.thread[[NSThread alloc]initWithTarget:self selector:selector(test) object:nil]; 说明&#xff1a;创建线程有多种方式&#xff0c;这里不做过多的介绍。 线程的开启&#xff1a; [self.thread star…

Qt 编写应用程序升级的配置文件json 生成工具

通过此工具将需要更新的应用程序和相关目录下的依赖文件配置成json格式的升级文件&#xff0c;客户端版本监控软件通过读取此json文件&#xff0c;对比相应字段&#xff0c;实现自动拉取文件&#xff0c;从而保证客户端应用程序自动更新。 此json文件放在待升级的exe同级目录下…

以太网供电新标准POE+,IEEE802.3at解析

以太网供电新标准POE&#xff0c;IEEE802.3at解析 以太网供电新标准POE&#xff0c;IEEE802.3at一、IEEE 802.3at标准出现的背景为了遵循IEEE 802.3af规范&#xff0c;受电设备(PD)上的PoE功耗被限制为12.95W&#xff0c;这对于传统的IP电话以及网络摄像头而言足以满足需求&am…

C# 6.0 (C# vNext) 的新功能:Expression Bodied Functions and Properties

Expression Bodied Function 它可以用在&#xff1a;methodsuser-defined operatorstype conversionsread-only properties indexers 看下面的样例&#xff1a;public class RgbColor(int r, int g, int b) {public int Red { get; } r;public int Green { get; } g;public i…

[react] 在React中如何避免不必要的render?

[react] 在React中如何避免不必要的render&#xff1f; shouldComponentUpdate、memoization、PureComponent 个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试题

C++的JSON库及使用方法

From: http://blog.csdn.net/moruite/article/details/7310976 VC没有自带的JSON库&#xff0c;所以分享一下如何使用该库http://download.csdn.net/detail/moruite/4104704 1. json.h头文件包含了如下API [cpp] view plaincopy #ifndef CPPTL_JSON_H_INCLUDED # define CP…

流程制造项目中关于销售订单数量与实际产生数量不同时的解决方案

流程制造项目中关于销售订单数量与实际产生数量不同时的解决方案 在流程制造项目中&#xff0c;例如涂料领域&#xff0c;往往实际生产出来的数量与销售订单的数量会产生差异&#xff0c;这种差异是小额值的。 例如客户A下了100KG的涂料&#xff0c;但车间实际生产出来的数量会…

KEIL ARM 6.12 compiler 编译__ASM 错误的解决方法

1、问题 KEIL compiler 设置为 “use default compiler version 5” 可以正确编译以下汇编和C混合代码&#xff0c;更改编译器为V6.12后不识别__ASM关键字&#xff0c;并对汇编语法报错。 替换为 __ASM void MSR_MSP(uint32_t addr) {MSR MSP, r0 BX r14 } 2、解决办法 6.12…

GCD牛逼的中枢调度器

GCD的基本使用: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {// dispatch_sync : 同步&#xff0c;不具备开启线程的能力// dispatch_async : 异步&#xff0c;具备开启线程的能力// 并发队列 &#xff1a;多个任务可以同时执行// 串行队列 &#xff1…

[react] 在React中组件的props改变时更新组件的有哪些方法?

[react] 在React中组件的props改变时更新组件的有哪些方法&#xff1f; 新版用 getDerivedstatefromProps(nextProps){ 业务逻辑} 个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起…

平庸错了吗?

平庸&#xff0c;百度百科里的释义是&#xff1a;平凡、普通、寻常而不突出&#xff0c;没有作为。就像我&#xff0c;一直认为自已是个很平庸的人&#xff0c;平凡&#xff0c;很普通。没有优秀杰出的才能&#xff0c;没有高深莫测的思想&#xff0c;甚至没有多少可以用来奢侈…

QT 多屏参数获取和设置

1、获取屏幕参数 QList<QScreen *> screen_list QGuiApplication::screens();for(int i0;i<screen_list.count();i){qDebug()<<screen_list.at(i)->size(); //屏幕的像素分辨率qDebug()<<screen_list.at(i)->availableGeometry();//屏幕…

JIURL文档-Linux的虚拟内存与分页机制(x86-64位)(一)

作者&#xff1a;JIURL日期&#xff1a;2015年10月30日分页机制Linux&#xff08;x64CPU&#xff09;使用基于分页机制的虚拟内存。每个进程有256TB&#xff08;48位&#xff09;的虚拟地址空间。基于分页机制&#xff0c;这256TB地址空间的一些部分 被映射了物理内存&#xff…

[react] React怎样跳过重新渲染?

[react] React怎样跳过重新渲染&#xff1f; 生命周期 shouldComponentUpdate return false &#xff1f; 个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试题