Decade counter
Build a decade counter that counts from 0 through 9, inclusive, with a period of 10. The reset input is synchronous, and should reset the counter to 0.

1 module top_module (
2 input clk,
3 input reset, // Synchronous active-high reset
4 output [3:0] q);
5 always @(posedge clk)begin
6 if(reset || q >= 4'd9)begin //这里是什么意思?
7 q<=4'b0;
8 end
9 else begin
10 q<=q+1'b1;
11 end
12 end
13
14 endmodule
再写:
构建一个十进制计数器,从0-9,循环
对于注释“if(reset || q >= 4'd9)begin //这里是什么意思?”,这里等于是将两种情况,一个是重置,一个是循环到头,两者一起写了
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 begin
if(q==4'd9)begin
q<=0;
end
else begin
q<=q+1'b1;
end
end
end
endmodule

浙公网安备 33010602011771号