以50MHZ时钟为例,进行1秒钟延时,并输出延时使能信号。

首先计算需要多少次计时,MHZ=10的六次方HZ。T=20ns

一秒钟需要计时次数为5的七次方即5000_0000。

然后计算需要几位的寄存器,需要二进制计算器。需要26位寄存器。

//---------方法一(我的写法)-----------------------------------------------
//--------------4999_9999+1=5000_0000----------------------------
reg [:] cnt_1s; //需要26位寄存器来放置4999_9999
always @ (posedge clk or negedge rst_n)
begin
if(!rst_n)
cnt_1s <= 'd0;
else if(cnt_1s < 'd4999_9999) //需要减一
cnt_1s <= cnt_1s + 'b1;
else
cnt_1s <= cnt_1s;
end
wire cnt_done1s = (cnt_1s == 'd4999_9999);
//---------需要加上使能信号的方法----------------------------------
reg [:] cnt_1s; //需要26位寄存器来放置4999_9999
always @ (posedge clk or negedge rst_n)
begin
if(!rst_n)
cnt_1s <= 'd0;
else if (delay_en) //外界使能信号输入,启动计时
begin
if(cnt_1s < 'd4999_9999)
cnt_1s <= cnt_1s + 'b1;
else
cnt_1s <= cnt_1s;
end
end
wire cnt_done1s = (cnt_1s == 'd4999_9999); //---------方法二------------------------------------------------
wire cnt_done1s;
reg [:] cnt_1s;
always @ (posedge clk or negedge rst_n)
begin
if(!rst_n)
cnt_1s <= 'd0;
else if(cnt_1s < 'd4999_9999)
cnt_1s <= cnt_1s + 'b1;
else
cnt_1s <= cnt_1s;
end
assign cnt_done1s = (cnt_1s == 'd4999_9999);
//------------方法三--------------------------------------
Parameter t_one = 4999_9999; //需要减一
reg[:] delay_cnt;
always @(posedge clk or negedge rst_n)
if(!rst_n)
delay_cnt <= 'd0;
if(delay_cnt == t_one)
delay_cnt <= 'd0;
else
delay_cnt <= delay_cnt +'b1;
wire delay_done = (delay_cnt == t_one)

最新文章

  1. vim--macro
  2. DTO概念
  3. sql server 2005 32位+64位、企业版+标准版、CD+DVD 下载地址大全 .
  4. 使用多种方式实现遍历HashMap
  5. Kafka架构设计:分布式发布订阅消息系统
  6. lighttpd的超时参数详解
  7. cookie机制
  8. new对象数组时的内存布局
  9. (转)sizeof
  10. 一份关于webpack2和模块打包的新手指南
  11. elasticsearch映射
  12. 深度学习实战-强化学习-九宫格 当前奖励值 = max(及时奖励 + 下一个位置的奖励值 * 奖励衰减)
  13. what&#39;s the python之异常处理
  14. You Don&#39;t Know JS: this &amp; Object Prototypes( 第5章 Prototypes)
  15. odroid xu4
  16. [LeetCode] 286. Walls and Gates_Medium tag: BFS
  17. onchange()事件的应用
  18. Android Studio 常用快捷键大全
  19. NI License Activator 用法
  20. 心脏滴血HeartBleed漏洞研究及其POC

热门文章

  1. String.format()
  2. ECShop安装问题
  3. CentOS 常用命令合集
  4. 配置Python虚拟环境
  5. UVALive 6255:Kingdoms(状压DFS)
  6. 百度云下载神器 速盘SpeedPan v1.9.7
  7. C# 中异常抛出捕获机制--throw / try,catch,finally
  8. dbo是默认用户也是架构
  9. vs2005 打不开resoure view?
  10. 使用DQL查询数据库