Count15
构建一个 4 位二进制计数器,该计数器的计数范围为 0 到 15(包括 15),周期为 16。复位输入是同步的,应将计数器复位至0。

改题目两个注意点:
- 同步复位
- 图片可知低电平有效
module top_module (
input clk,
input reset, // Synchronous active-high reset
output [3:0] q
);
always @ (posedge clk )begin
if(reset)begin
q <= 0;
end
else
q <= q+4'b1;
end
endmodule
Count10
构建一个从 0 到 9(含)计数的十进制计数器,周期为 10。复位输入是同步的,应将计数器复位至0。

此题与上题的注意点相同,不同主要在于q为4位,如果不进行清零操作,那么就会一直计数到15,因此要想周期为10,就要计数到9的时候清零。
module top_module (
input clk,
input reset, // Synchronous active-high reset
output [3:0] q
);
always @ (posedge clk )begin
if(reset)begin
q <= 0;
end
else if (q == 4'd9)begin //q >= 4'd9也可
q <= 0;
end
else begin
q <= q+4'b1;
end
end
endmodule
Count 1to10
制作一个十进制计数器,包括 1 到 10。复位输入是同步的,应将计数器复位至1

此题的区别在于计数器的初值从1开始。
module top_module (
input clk,
input reset,
output [3:0] q
);
always @ (posedge clk )begin
if(reset)begin
q <= 4'b1;
end
else if(q >= 4'd10)begin
q <= 4'b1;
end
else
q <= q+4'b1;
end
endmodule
Countslow
构建一个从 0 到 9 计数的十进制计数器,周期为 10。复位输入是同步的,应将计数器复位至0。我们希望能够暂停计数器,而不是总是在每个时钟周期递增,因此 slowena 输入指示计数器何时应该递增。

此题相当于加入了使能信号
module top_module (
input clk,
input slowena,
input reset,
output [3:0] q
);
always @ (posedge clk)begin
if(reset)
q <= 4'b0;
else if(slowena)begin
if(q == 4'd9)
q <= 4'b0;
else
q <= q + 4'b1;
end
else
q <= q;
end
endmodule
Count 1-12
设计具有以下输入和输出的 1-12 计数器:
- 重置同步****高电平有效复位,强制计数器为 1
- enable信号设置为高电平以使计数器运行
- 时钟正边沿触发时钟输入 Q[3:0]计数器的输出


3079

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



