일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 스텝모터
- tff
- Multiple outstanding
- ABMA
- cacheable
- Interoperability
- AXI3
- stepmotor
- STM32
- AXI4
- SoC
- atomic access
- ordering model
- Verilog
- Multiple transaction
- FGPA #반도체설계 #verilog #시프트레지스터 #uart
- T flip flop
- 임베디드시스템
- 카운터
- 펌웨어
- AMBA
- Low-power Interface
- ERROR RESPONSE
- FPGA
- 구조적모델링
- 레지스터슬라이스
- APB3
- QoS
- single copy atomic size
- out-of-order
Archives
- Today
- Total
CHIP KIDD
[FPGA] Clock에 필요한 모듈 4) Up/Down Counter Verilog Code 본문
clk 신호에 맞춰 카운터 하는것을 생각해보자,
그렇다면 1초마다 생성되는 clock 신호에 맞춰 카운트가 된다고하면, 자연스럽게 1초간격으로 값이 올라가는 시계를 만들수 있다.
다음은 clk 신호에 맞춰 카운트 다운/업 하는 code이다.
module counter_up_down(
input up_down,
input up_down_clk,
input reset,
output reg [3:0] count_100 = 0,
output reg [3:0] count_1000 = 0,
output reg dec_clk = 0
);
always @(posedge up_down_clk or posedge reset) begin
if(reset) begin
count_100 <= 0;
count_1000 <= 0;
end
else begin
if(!up_down) begin
if(count_100 == 9) begin
count_100 <= 0;
if(count_1000 == 5) begin
count_1000 <= 0;
end
else begin
count_1000 <= count_1000 + 1;
end
end
else begin
count_100 <= count_100 + 1;
end
end
else begin
if(count_100 == 0) begin
count_100 <= 9;
if(count_1000 == 0)begin
count_1000 <= 5;
dec_clk <= 1;
end
else begin
count_1000 <= count_1000 - 1;
end
end
else begin
count_100 <= count_100 - 1;
dec_clk <= 0;
end
end
end
end
endmodule
module counter_up_down_csec(
input up_down,
input up_down_clk,
input reset,
output reg [3:0] count_1 = 0,
output reg [3:0] count_10 = 0,
output reg inc_clk = 0
);
always @(posedge up_down_clk or posedge reset) begin
if(reset) begin
count_1 <= 0;
count_10 <= 0;
end
else begin
if(!up_down) begin
if(count_1 == 9) begin
count_1 <= 0;
if(count_10 == 9) begin
count_10 <= 0;
inc_clk <= 1;
end
else begin
count_10 <= count_10 + 1;
end
end
else begin
count_1 <= count_1 + 1;
inc_clk <= 0;
end
end
else begin
if(count_1 == 0) begin
count_1 <= 9;
if(count_10 == 0)begin
count_10 <= 9;
end
else begin
count_10 <= count_10 - 1;
end
end
else begin
count_1 <= count_1 - 1;
end
end
end
end
1. Prescaler
2021.04.01 - [반도체/FPGA - Verilog] - [FPGA] Clock에 필요한 모듈 1) Prescaler Verilog Code
2. FND Switcher
2021.04.01 - [분류 전체보기] - [FPGA] Clock에 필요한 모듈 2) FND 4digit switcher Verilog Code
3. Decoder 7_seg
2021.04.01 - [분류 전체보기] - [FPGA] Clock에 필요한 모듈 3) Decoder for 7 Segments Verilog Code
'반도체 > FPGA - Verilog' 카테고리의 다른 글
[FPGA] ADC ADC-Mux 설계 (세팅) (0) | 2021.04.01 |
---|---|
[FPGA] Timer Verilog Code (0) | 2021.04.01 |
[FPGA] Clock에 필요한 모듈 3) Decoder for 7 Segments Verilog Code (1) | 2021.04.01 |
[FPGA] Clock에 필요한 모듈 2) FND 4digit switcher Verilog Code (0) | 2021.04.01 |
[FPGA] Clock에 필요한 모듈 1) Prescaler Verilog Code (0) | 2021.04.01 |