Verilog学习笔记——05——0-9循环秒计数器

一、

image-20211119162832961

 image-20211119162832961


利用系统计算器将系统时钟分频,对秒脉冲进行计数。

image-20211119163730565 

cont 是秒脉冲分频计数器,需要对 24M 来计数,至少需要 25 位。

spulse 是秒脉冲尖,cont 为 0 时为1,1 秒有 24M 个脉冲,但只有 1 个脉冲时 spulse=1。

sum 是秒计数器,看到 spulse 为 1 时计数。

仿真代码

//2023-5-17
//0-9循环的秒计数器
`timescale 1ns/10ps
module scounter(
clk,
res,
sum
);
input clk;
input res;
output[3:0] sum;
parameter frequency_clk=24;// 设置时钟的参数
reg[24:0] cont;
reg[3:0] sum;
reg spulse;
always@(posedge clk or negedge res) begin
	if(~res)begin
		cont = 0;
		sum = 0;
		spulse = 0;
	end
	else begin
		if(cont==frequency_clk*1000-1)begin
			cont = 0;
		end
		else begin
			cont = cont+1;
		end
		if(cont==0)begin
			spulse = 1;
		end
		else begin
			spulse = 0;
		end
		if(spulse)begin
			if(sum==9)begin
				sum = 0;
			end
			else begin
				sum = sum+1;
			end
		end
	end
end
endmodule
//testbench of scounter
module scounter_tb ;
reg clk;
reg res;
wire[3:0] sum;
scounter scounter(
.clk(clk),
.res(res),
.sum(sum)
);

initial begin
	clk <= 0;
	res <= 0;
	#15 res <= 1;
	#2000 $stop;
end
always #5 clk = ~clk;
endmodule
		

仿真波形

PS:24MHz过长,直接点run-all无法显示波形,降低频率  改为24000即可展现波形

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值