0~99 까지 count를 하는 회로이다.
2개가 존재하는데
1개는 99에서 멈추고
다른 1개는 다시 0으로 초기화가 된다.
HW이므로 Parallel 하게 실행된다.
`timescale 1ns/1ps
module counter(
input clk ,
input reset_n ,
output [6:0] o_cnt ,
output [6:0] o_cnt_always
);
// 100에서 멈추는 counter
reg [6:0] cnt100;
assign o_cnt = cnt100;
always @(negedge reset_n, posedge clk) begin
if(!reset_n)
cnt100 <= 0;
else if(cnt100<99)
cnt100 <= cnt100 +1;
end
// 0 -> 1 -> ... -> 99 -> 0
reg [6:0] cnt;
assign o_cnt_always = cnt;
always @(negedge reset_n, posedge clk) begin
if(!reset_n)
cnt <= 0;
else if(cnt>=99) // == 보다 안정적
cnt <= 0;
else
cnt <= cnt +1;
end
endmodule
'전자공학 > 디지털회로' 카테고리의 다른 글
[Verilog] 125MHz -> 1KHz 분주기 (0) | 2022.12.29 |
---|---|
[Verilog] 1/1000 prescaler (0) | 2022.12.27 |
[Verilog] Gate-Level에서 D Latch & D Flip-Flop (0) | 2022.12.25 |
[Verilog] Latches and Flip-floops (0) | 2022.12.22 |
[Verilog] Arithmetic Circuit (0) | 2022.12.21 |
댓글