名称:基于FPGA的数字跑表设计Verilog代码ISE仿真
软件:ISE
语言:Verilog
代码功能:
数字跑表
/信号定义:
CLK:CLK为时钟信号;
CLR:为异步复位信号;
PAUSE:为暂停信号;
MSH,MSL:百分秒的高位和低位SH,SL:秒信号的高位和低位
MH,ML:分钟信号的高位和低位。*/
nodule paobiaoput CLKnput CLR,nput PAUSE,
output 3: 0 MSH, MSL, SH,SL,MH,M
∥自己实现逻辑代码endmodule
完成指标:
1)能够实现百分秒的高位和低位计时;
2)能够实现异步清零复位;
3)能够实现暂停;
4)能够实现秒信号的高位和低位,分钟信号的高位和低位计时;
5)附加功能,例如增加到小时信号的计数。
提示
1)CLK为百分秒的驱动信号,上升沿有效。当CLK上升沿跳变时MSL加1,当MSL累加到10时MSH加1。
2)MSH,MSL为百分秒计数的高位和低位,每计满100,产生一个进位信号用于秒信号计数。同理SH,SL,MH,ML的计数也是同样的逻辑。
3)CLR为异步复位信号,指只有在CLK下降沿时所有计数归零。
4)当计时满60分钟时归零重新开始计时。
FPGA代码Verilog/VHDL代码资源下载:www.hdlcode.com
演示视频:
设计文档:
1.工程文件
2.程序文件
3.测试文件
4.程序运行
5.仿真
CLR异步清零,下降沿清零
暂停按键,按下暂停,再按继续计时
暂停按键,按下暂停,再按继续计时
秒表计时
部分代码展示:
`timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 21:10:27 01/10/2019 // Design Name: // Module Name: paobiao // Project Name: // Target Devices: // Tool versions: // Description: // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// module paobiao( input CLK, input CLR,//异步清零,下降沿清零 input PAUSE,//按一次暂停,再按一次继续 output [3:0] MSH,MSL,SH,SL,MH,ML ); reg zanting=0;//暂停信号,为1时暂停,为0时正常计时 always@(posedge PAUSE) //按一次PAUSE,zanting变化一次 zanting<=~zanting; //计时 reg [7:0] hun_second_count_reg=7'd0;//百分之秒,0.01-0.99 reg [7:0] hun_second_count=7'd0; reg second_enable=0;//秒计数 always@(posedge CLK or negedge CLR) begin if(CLR==0) begin hun_second_count_reg<='d0;//清零 end else if(zanting) hun_second_count_reg<=hun_second_count_reg;//暂停 else if(hun_second_count_reg>='d99) begin hun_second_count_reg<='d0; second_enable<='d1;//计数到99产生下一级计数脉冲 end else begin hun_second_count_reg<=hun_second_count_reg+'d1;//百分之秒计时 second_enable<='d0; end end always@(posedge CLK or negedge CLR) if(CLR==0) hun_second_count<='d0;//清零 else hun_second_count<=hun_second_count_reg; reg [7:0] second_count='d0; reg minute_enable=0; always@(posedge CLK or negedge CLR) begin if(CLR==0) begin second_count<='d0; end else if(zanting)//暂停 second_count<=second_count;//暂停 else if(second_enable)//秒计时使能 if(second_count>='d59) begin second_count<='d0; minute_enable<=1; end else begin second_count<=second_count+'d1;//秒计时 minute_enable<=0; end else begin second_count<=second_count; minute_enable<=0; end end reg [7:0] minute_count='d0; always@(posedge CLK or negedge CLR) begin if(CLR==0) begin minute_count<='d0; end else if(zanting)//暂停 minute_count<=minute_count;//暂停 else if(minute_enable)//分计时使能 if(minute_count>='d59) begin minute_count<='d0; end else begin minute_count<=minute_count+'d1;//分计时 end else begin minute_count<=minute_count; end end //MSH,MSL,SH,SL,MH,ML assign MSH=hun_second_count/10;//除以10得到十位 assign MSL=hun_second_count%10;//除以10的余数得到个位
点击链接获取代码文件:http://www.hdlcode.com/index.php?m=home&c=View&a=index&aid=811
448