Verilog数字系统设计——10进制计数器

10进制计数器

一、什么是十进制计数器

计数器不仅能用于对时钟脉冲计数,还可以用于分频,定时,产生节拍脉冲序列以及进行数字运算等,分为同步计数器和异步计数器,在同步计数器中,当时钟脉冲的输入时,触发器的翻转是同时发生的。而在异步计数中,触发器的翻转有先有后,不是同时发生的。
10进制计数器建模
编程实现10进制计数器,具有异步复位功能,十位和个位用8421BCD码表示

二、代码实现

2.1、counter module

module counter10_1(o_count,o_cout,i_clk,i_reset,i_load,i_datin,i_cin);
	output reg [7:0] o_count;
	output reg o_cout;
	input i_clk,i_reset,i_load,i_cin;
	input [7:0] i_datin;

	always @(posedge i_clk or i_reset)//Asynchronous zero setting
		begin
			if(i_reset)	
				begin
				o_count <= 0;//reset
				o_cout <= 0;
				end
			else if(i_load)	
				o_count <= i_datin;//Synchronous setting

			else if(o_count[3:0] >= 4'b1001)//gewei jinwei,shiwei jia yi
				begin
				o_count[7:4] <= o_count[7:4]+4'b0001;//shiwei plus 1
				o_count[3:0] <= 0; //gewei is 0
				end

			else if(o_count[7:4] >= 4'b1001)//shiwei jinwei
				begin
				o_count[7:0] <= 0;	//all is 0
				o_cout <= o_cout+1;	//10bit counter jinwei signal plus 1
				end

			else			//normal count
				o_count[3:0] <= o_count[3:0]+4'b0001;	
		end

endmodule

2.2、test module

module test_counter10;
	//module counter10_1(o_count,o_cout,i_clk,i_reset,i_load,i_datin,i_cin);
	wire [7:0] o_count_t;
	wire o_cout_t;
	reg i_clk_t,i_reset_t,i_load_t,i_cin_t;
	reg [7:0] i_datin_t;

	counter10_1 mycounter(
		.o_count(o_count_t),
		.o_cout(o_cout_t),
		.i_clk(i_clk_t),
		.i_reset(i_reset_t),
		.i_load(i_load_t),
		.i_datin(i_datin_t),
		.i_cin(i_cin_t));
	
	initial					//reset signal is 1--> reset  load signal is 1 --> load signal
	begin
		i_datin_t[7:0]=8'b1001_1111;	// zhishu signal
		i_clk_t=0;		// clock
		i_reset_t = 1;		// reset signal
		i_load_t =1;		// initial zhishu signal
		i_cin_t = 0;	// initial signal
		
		#100 i_reset_t = 0;	// enter jishu type o_count = 8'b1001_1111
		i_datin_t[7:0] = 8'b0000_0000;	// reset initial data
		#80  i_load_t = 0;	// enter counter type		
	end

	//always #200 i_cin_t = ~i_cin_t;			//jinwei signal
	always #20 i_clk_t = ~i_clk_t;			//clock signal
	//always #500 i_reset_t = ~i_reset_t;		//reset signal
endmodule

三、仿真截图

仿真截图

  • 9
    点赞
  • 100
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

masterHu_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值