날짜 : 04.12
제목 : up/down counter
module counter_up_down(
input up_down_clk,
input down,
input reset,
output reg [3:0] BCD_1=0,
output reg [3:0] BCD_10=0,
output reg dec_clk=0
);
always @ (posedge up_down_clk or posedge reset) begin
if(reset) begin
BCD_1 <= 0;
BCD_10 <= 0;
end
else begin
if(down) begin
if(!BCD_1) begin
BCD_1 <= 9;
if(!BCD_10) begin
BCD_10 <= 5;
dec_clk <= 1;
end
else BCD_10 = BCD_10 - 1;
end
else begin
BCD_1 <= BCD_1 - 1;
dec_clk <= 0;
end
end
else begin
if(BCD_1 == 9) begin
BCD_1 <= 0;
if(BCD_10 == 5) BCD_10 <= 0;
else BCD_10 <= BCD_10 + 1;
end
else BCD_1 <= BCD_1 + 1;
end
end
end
endmodule
'FPGA' 카테고리의 다른 글
[FPGA] XADC 활용 (0) | 2021.04.15 |
---|---|
stopwatch (0) | 2021.04.14 |
cook timer - 구조적 모델링 (0) | 2021.04.13 |
cook timer- 동작적 모델링 (0) | 2021.04.12 |
[FPGA] 초기 세팅 (0) | 2021.04.12 |