HDLBits【学习记录(难点)】
1.4-bit decimal counter
Build a 4-digit BCD (binary-coded decimal) counter. Each decimal digit is encoded using 4 bits: q[3:0] is the ones digit, q[7:4] is the tens digit, etc. For digits [3:1], also output an enable signal indicating when each of the upper three digits should be incremented.

module top_module (
input clk,
input reset, // Synchronous active-high reset
output [3:1] ena,
output [15:0] q);
assign ena[3:1]={
(q[3:0]==4'd9)&&(q[11:8]==4'd9)&&(q[7:4]==4'd9),(q[7:4]==4'd9)&&(q[3:0]==4'd9),(q[3:0]==4'd9)};
// assign q={q[15:12],q[11:8],q[7:4],q[3:0]};
BCD_Decade_Counter Ge_BCD(
.clk(clk),
.reset(reset),
.enable(1'b1),
.q(q[3:0])
);
BCD_Decade_Counter Shi_BCD(
.clk(clk),
.reset(reset),
.enable(ena[1]),
.q(q[7:4])
);
BCD_Decade_Counter Bai_BCD(
.clk(clk),
.reset(reset),
.enabl

该博客详细介绍了如何使用Verilog设计一个4位二进制编码的十进制计数器(BCD计数器)和一个12小时时钟。4位BCD计数器分别处理个位、十位、百位和千位,每个位都有相应的进位条件。12小时时钟设计中,通过多个计数器模拟秒、分、小时的递增,并处理AM和PM的切换。在时钟达到12:59:59PM时,会自动转换为01:59:59AM。所有计数器都依赖于一个共同的时钟信号,并使用使能信号来控制递增。

1万+

被折叠的 条评论
为什么被折叠?



