一、波形变换需求

二、思路

(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

四、行为仿真

FPGA Verilog实现一个脉冲波形变换相关推荐

  1. 离散小波变换的FPGA/Verilog实现

    小波变换(二) 离散小波变换的FPGA/Verilog实现 to 51研究不顺的假期 文章目录 小波变换(二) 尺度函数族 小波函数定义 尺度函数定义 尺度函数分辨率沿拓 多分辨分析(MRA)方程 尺 ...

  2. 一周掌握FPGA Verilog HDL语法 day 4

    今天给大侠带来的是一周掌握FPGA Verilog HDL 语法,今天开启第四天. 一周掌握FPGA Verilog HDL语法 day 3 被平台综合了,如果想要看详细介绍的话,可以到公众号内部&q ...

  3. Flash之SM25QH128M、JFM25F32A读写操作FPGA Verilog实现

    JFM25F32A Flash写操作流程如图1所示,对于Flash类型的存储器,向已经存在数据的单元写入数据时,直接写入是无法写入的,在写入之前必须先执行擦除命令,再进行写入即可:如果待写入的单元为新 ...

  4. FPGA verilog 临近插值任意比例视频缩小代码(多像素并行,能支持8K60)

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qq_46621272/article/ ...

  5. ethercat 主站 FPGA verilog 代码 EtherCAT 总线 demo 板介绍 ethercat 主站 FPGA verilog 代码

    ethercat 主站 FPGA verilog 代码 ECAT运动控制器ARM软件设计 一.ARM向FPGA发送目标位置 1.对应的操作地址 define CUR_POS_SERVO 1 defin ...

  6. FPGA verilog HDL实现中值滤波

    FPGA verilog HDL实现中值滤波 今天给大侠简单带来FPGA verilog HDL实现中值滤波,话不多说,上货. 一.实现步骤: 1.查看了中值滤波实现相关的网站和paper: 2.按照 ...

  7. Pandas把dataframe的索引、复合索引变换为数据列:包含单索引到单列(重命名)、复合索引到多数据列、复合索引的其中一个水平变换为数据列、

    Pandas把dataframe的索引.复合索引变换为数据列:包含单索引到单列(重命名).复合索引到多数据列.复合索引的其中一个水平变换为数据列 目录

  8. 合同变换为什么是一个行变换再跟一个相应的列变换?

    01 为什么合同变换总是一对一对的? 定义 两个 n n n阶方阵 A A A和 B B B满足关系: B = C T A C B=C^TAC B=CTAC,其中 C C C是可逆矩阵,则称 A A ...

  9. FPGA Verilog AD7606驱动代码,包含SPI模式读取和并行模式读取两种

    FPGA Verilog AD7606驱动代码,包含SPI模式读取和并行模式读取两种,代码注释详细 编号:7428665912784264白衫如初oh

最新文章

  1. linux下网卡状态,linux-网络状态
  2. 【Android】ADT中使用NDK编译已有的C++实现的库文件
  3. MATLAB中如何跳过有些缺省值,MATLAB:使用插值替换缺失值(NaN)
  4. 用JAVAMAIL发送邮件的一个简单例子
  5. html5 canvas实现图片玻璃碎片特效
  6. livechart 只显示 y 值_【科研工具51】谷歌,谷歌学术,Scihub有效网址检索软件——Y学术...
  7. python中numpy的用法_Python中numpy多维数组的用法
  8. HtmlUnitDriver 网页内容动态抓取
  9. 基本数据类型-集合(set)_上周内容回顾(字符串_数字_列表_元组_字典_集合)
  10. 实践两个servlet小项目
  11. java map sort_Map 按值排序 (Map sort by value) – Java | 学步园
  12. java类加载器用途_对于java类加载器的认识(2)
  13. python数据结构之递归
  14. 【大厂笔试心得,你还不知道笔试的思路吗?】-- ACM模式篇、笔试题型介绍以及相关准备
  15. 一维非齐次热传导方程的紧致差分格式(附Matlab代码)
  16. Three.js 3D 动画场景搭建
  17. 【unity 保卫星城】--- 开发笔记02(陀螺仪移动)
  18. 彩色图直方图均衡化matlab
  19. Android让屏幕保持常亮,不熄屏的三种方法
  20. 数学知识——欧拉函数

热门文章

  1. 【翻译】eXpressAppFramework QuickStart 业务模型设计(十)——在代码中实现数据验证...
  2. python 战舰_简单Python战舰
  3. python isalnum函数_探究Python中isalnum()方法的使用
  4. C++ 控制结构和函数(二) —— 函数I(Functions I)
  5. Python urllib、urllib2、urllib3
  6. python,时间加减,时间计算,时间格式化,时间提取汇总
  7. printf的两个需要注意的问题:无符号整数和64位整数
  8. 关闭eslint检验;vue-cli3搭建的vue项目关闭eslint;脚手架3关闭eslint;
  9. 为什么[]==0;JavaScript里什么情况下a==!a为true呢?
  10. [vue] vue项目有使用过npm run build --report吗?