您好,欢迎来到99网。
搜索
您的当前位置:首页quartus实现基于Verilog HDL的数字秒表

quartus实现基于Verilog HDL的数字秒表

来源:99网

一、前言

  • 用Verilog HDL设计一个数字跑表,其引脚和功能如下图:

二、实操

module biao(clk,reset,pause,msh,msl,sh,sl,minh,minl);
//其中msh为百分秒的十位,msl为百分秒的个位,sh为秒的十位,sl为秒的个位,minh为分的十位,minl为分的个位
input clk,reset,pause;
output [3:0] msh,msl,sh,sl,minh,minl;
reg [3:0] msh,msl,sh,sl,minh,minl;
reg count1,count2;
always @(posedge clk or posedge reset)
 begin
   if(reset)
	 begin
	{msh,msl}<=0;
	count1<=0;
	 end
	else if(!pause)
	 begin
	if(msl==9)
	  begin
	 msl<=0;
	 if(msh==9)
	   begin
	 msh<=0;
	 count1<=1;
	   end
	 else
	 msh<=msh+1;
	  end
	 else
	  begin 
	  msl<=msl+1;
	  count1<=0;
	  end
	 end
 end
always @(posedge count1 or posedge reset)
begin
if(reset)
	begin
	{sh,sl}<=0;
	count2<=0;
	end
else if(sl==9)
	begin
	sl<=0;
	if(sh==5)
		begin
		sh<=0;
		count2<=1;
		end
	else 
	sh<=sh+1;
	end
	else
	begin
	sl<=sl+1;
	count2<=0;
	end
end
always@(posedge count2 or posedge reset)
	begin
	if(reset)
	 begin
	minh<=0;
	minl<=0;
	 end
	else if(minl==9)
	begin
	 minl<=0;
	 if(minh==5)
	 minh<=0;
	 else
	 minh<=minh+1;
	 end
	 else
	 minl<=minl+1;
	 end
endmodule

编译到0 error。

  1. 新建一个仿真文件vwf
    调出输入输出,

设置仿真波形图

全部修改后,编译运行可以看到波形

可以看到当msl完成0-9的一个循环时msh加一,当msh完成0-9的一个循环时sl加一,当sl完成0-9的一个循环时sh加一,从而实现秒表功能。

三、小结

了解了Verilog语言的编写,希望能在板子上实现此功能。

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 99spj.com 版权所有 湘ICP备2022005869号-5

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务