EunSeong Lee Portfolio
Project
AI_mini_prj
Avoid Bullets
Digital Clock
Subsubcategory 1
Subsubcategory 2
post-03
Study
AI Algorithm Structure
LAB
ASIC FrontEnd
post-01
post-02
Arm Architecture
post-01
CMOS VLSI Design
LAB
THEORY
CPU Design
CODE
LAB
THEORY
FPGA
LAB
THEORY
comment system
Home
markdown
portfolio
Contact
Copyright © 2024 |
Yankos
Home
>
Study
>
CPU Design
> LAB
Please wait ...
LAB
DedicatedProcessor ALUOP
DedicatedProcessor ALUOP ✅ 과제 ⚒️ 코드 ⚒️ ⚒️[DedicatedProcessor ALUOP.sv] ✅ Schematic ✅ 시뮬레이션 ✅ 분석 반복별 레지스터 값 1회: R1=3, R2=2, R3=3, R4=5 → Yes 2회: R1=7, R2=6, R3=9, R4=15 → Yes 3회: R1=15, R2=14, R3=21, R4=35 → Yes 4회: R1=31, R2=30, R3=45, R4=75 → Yes 5회: R1=63, R2=62, R3=93, R4=155 → Yes 6회: R1=127, R2=126, R3=189, R4=59 → No ⇒ halt ➡️ 첫 번째 반복 시작 값: (R1, R2, R3, R4) = (1, 0, 0, 0) **계산 순서** R2 = R1 + R1 (1 + 1 = 2) ➞ (1, **2**, 0, 0) R3 = R2 + R1 (2 + 1 = 3) ➞ (1, 2, **3**, 0) R4 = R3 - R1 (3 - 1 = 2) ➞ (1, 2, 3, **2**) R1 = R1 | R2 (1 | 2 = 3) ➞ (**3**, 2, 3, 2) R4 = R4 & R3 (2 & 3 = 2) ➞ (3, 2, 3, **2**) R4 = R2 + R3 (2 + 3 = 5) ➞ (3, 2, 3, **5**) 조건 확인: R4 > R2 (5 > 2) ➞ ✅ Yes, 계속 진행 ➡️ 두 번째 반복 시작 값: (R1, R2, R3, R4) = (3, 2, 3, 5) **계산 순서** R2 = R1 + R1 (3 + 3 = 6) ➞ (3, **6**, 3, 5) R3 = R2 + R1 (6 + 3 = 9) ➞ (3, 6, **9**, 5) R4 = R3 - R1 (9 - 3 = 6) ➞ (3, 6, 9, **6**) R1 = R1 | R2 (3 | 6 = 7) ➞ (**7**, 6, 9, 6) R4 = R4 & R3 (6 & 9 = 0) ➞ (7, 6, 9, **0**) R4 = R2 + R3 (6 + 9 = 15) ➞ (7, 6, 9, **15**) 조건 확인: R4 > R2 (15 > 6) ➞ ✅ Yes, 계속 진행 ➡️ 세 번째 반복 시작 값: (R1, R2, R3, R4) = (7, 6, 9, 15) **계산 순서** R2 = R1 + R1 (7 + 7 = 14) ➞ (7, **14**, 9, 15) R3 = R2 + R1 (14 + 7 = 21) ➞ (7, 14, **21**, 15) R4 = R3 - R1 (21 - 7 = 14) ➞ (7, 14, 21, **14**) R1 = R1 | R2 (7 | 14 = 15) ➞ (**15**, 14, 21, 14) R4 = R4 & R3 (14 & 21 = 4) ➞ (15, 14, 21, **4**) R4 = R2 + R3 (14 + 21 = 35) ➞ (15, 14, 21, **35**) 조건 확인: R4 > R2 (35 > 14) ➞ ✅ Yes, 계속 진행 ➡️ 네 번째 반복 시작 값: (R1, R2, R3, R4) = (15, 14, 21, 35) **계산 순서** R2 = R1 + R1 (15 + 15 = 30) ➞ (15, **30**, 21, 35) R3 = R2 + R1 (30 + 15 = 45) ➞ (15, 30, **45**, 35) R4 = R3 - R1 (45 - 15 = 30) ➞ (15, 30, 45, **30**) R1 = R1 | R2 (15 | 30 = 31) ➞ (**31**, 30, 45, 30) R4 = R4 & R3 (30 & 45 = 12) ➞ (31, 30, 45, **12**) R4 = R2 + R3 (30 + 45 = 75) ➞ (31, 30, 45, **75**) 조건 확인: R4 > R2 (75 > 30) ➞ ✅ Yes, 계속 진행 ➡️ 다섯 번째 반복 시작 값: (R1, R2, R3, R4) = (31, 30, 45, 75) **계산 순서** R2 = R1 + R1 (31 + 31 = 62) ➞ (31, **62**, 45, 75) R3 = R2 + R1 (62 + 31 = 93) ➞ (31, 62, **93**, 75) R4 = R3 - R1 (93 - 31 = 62) ➞ (31, 62, 93, **62**) R1 = R1 | R2 (31 | 62 = 63) ➞ (**63**, 62, 93, 62) R4 = R4 & R3 (62 & 93 = 28) ➞ (63, 62, 93, **28**) R4 = R2 + R3 (62 + 93 = 155) ➞ (63, 62, 93, **155**) 조건 확인: R4 > R2 (155 > 62) ➞ ✅ Yes, 계속 진행 ➡️ 여섯 번째 반복 (마지막) 시작 값: (R1, R2, R3, R4) = (63, 62, 93, 155) **계산 순서** R2 = R1 + R1 (63 + 63 = 126) ➞ (63, **126**, 93, 155) R3 = R2 + R1 (126 + 63 = 189) ➞ (63, 126, **189**, 155) R4 = R3 - R1 (189 - 63 = 126) ➞ (63, 126, 189, **126**) R1 = R1 | R2 (63 | 126 = 127) ➞ (**127**, 126, 189, 126) R4 = R4 & R3 (126 & 189 = 120) ➞ (127, 126, 189, **120**) R4 = R2 + R3 (126 + 189 = 315) 8-bit Wrapping (오버플로우): 8비트 레지스터는 255까지만 표현 가능하므로, 315는 256을 뺀 나머지 값인 59가 된다. (315 - 256 = 59) R4 최종 값 ➞ (127, 126, 189, **59**) 조건 확인: R4 > R2 (59 > 126) ➞ ❌ No, 중단 (Halt)
Study
· 2025-08-12
DedicatedProcessor Adder
DedicatedProcessor Adder ✅ 과제 ⚒️ 코드 ⚒️ ⚒️[DedicatedProcessor ALUOP.sv] ✅ Schematic ✅ 시뮬레이션 ✅ 분석 반복별 레지스터 값 1회: R1=3, R2=2, R3=3, R4=5 → Yes 2회: R1=7, R2=6, R3=9, R4=15 → Yes 3회: R1=15, R2=14, R3=21, R4=35 → Yes 4회: R1=31, R2=30, R3=45, R4=75 → Yes 5회: R1=63, R2=62, R3=93, R4=155 → Yes 6회: R1=127, R2=126, R3=189, R4=59 → No ⇒ halt ➡️ 첫 번째 반복 시작 값: (R1, R2, R3, R4) = (1, 0, 0, 0) **계산 순서** R2 = R1 + R1 (1 + 1 = 2) ➞ (1, **2**, 0, 0) R3 = R2 + R1 (2 + 1 = 3) ➞ (1, 2, **3**, 0) R4 = R3 - R1 (3 - 1 = 2) ➞ (1, 2, 3, **2**) R1 = R1 | R2 (1 | 2 = 3) ➞ (**3**, 2, 3, 2) R4 = R4 & R3 (2 & 3 = 2) ➞ (3, 2, 3, **2**) R4 = R2 + R3 (2 + 3 = 5) ➞ (3, 2, 3, **5**) 조건 확인: R4 > R2 (5 > 2) ➞ ✅ Yes, 계속 진행 ➡️ 두 번째 반복 시작 값: (R1, R2, R3, R4) = (3, 2, 3, 5) **계산 순서** R2 = R1 + R1 (3 + 3 = 6) ➞ (3, **6**, 3, 5) R3 = R2 + R1 (6 + 3 = 9) ➞ (3, 6, **9**, 5) R4 = R3 - R1 (9 - 3 = 6) ➞ (3, 6, 9, **6**) R1 = R1 | R2 (3 | 6 = 7) ➞ (**7**, 6, 9, 6) R4 = R4 & R3 (6 & 9 = 0) ➞ (7, 6, 9, **0**) R4 = R2 + R3 (6 + 9 = 15) ➞ (7, 6, 9, **15**) 조건 확인: R4 > R2 (15 > 6) ➞ ✅ Yes, 계속 진행 ➡️ 세 번째 반복 시작 값: (R1, R2, R3, R4) = (7, 6, 9, 15) **계산 순서** R2 = R1 + R1 (7 + 7 = 14) ➞ (7, **14**, 9, 15) R3 = R2 + R1 (14 + 7 = 21) ➞ (7, 14, **21**, 15) R4 = R3 - R1 (21 - 7 = 14) ➞ (7, 14, 21, **14**) R1 = R1 | R2 (7 | 14 = 15) ➞ (**15**, 14, 21, 14) R4 = R4 & R3 (14 & 21 = 4) ➞ (15, 14, 21, **4**) R4 = R2 + R3 (14 + 21 = 35) ➞ (15, 14, 21, **35**) 조건 확인: R4 > R2 (35 > 14) ➞ ✅ Yes, 계속 진행 ➡️ 네 번째 반복 시작 값: (R1, R2, R3, R4) = (15, 14, 21, 35) **계산 순서** R2 = R1 + R1 (15 + 15 = 30) ➞ (15, **30**, 21, 35) R3 = R2 + R1 (30 + 15 = 45) ➞ (15, 30, **45**, 35) R4 = R3 - R1 (45 - 15 = 30) ➞ (15, 30, 45, **30**) R1 = R1 | R2 (15 | 30 = 31) ➞ (**31**, 30, 45, 30) R4 = R4 & R3 (30 & 45 = 12) ➞ (31, 30, 45, **12**) R4 = R2 + R3 (30 + 45 = 75) ➞ (31, 30, 45, **75**) 조건 확인: R4 > R2 (75 > 30) ➞ ✅ Yes, 계속 진행 ➡️ 다섯 번째 반복 시작 값: (R1, R2, R3, R4) = (31, 30, 45, 75) **계산 순서** R2 = R1 + R1 (31 + 31 = 62) ➞ (31, **62**, 45, 75) R3 = R2 + R1 (62 + 31 = 93) ➞ (31, 62, **93**, 75) R4 = R3 - R1 (93 - 31 = 62) ➞ (31, 62, 93, **62**) R1 = R1 | R2 (31 | 62 = 63) ➞ (**63**, 62, 93, 62) R4 = R4 & R3 (62 & 93 = 28) ➞ (63, 62, 93, **28**) R4 = R2 + R3 (62 + 93 = 155) ➞ (63, 62, 93, **155**) 조건 확인: R4 > R2 (155 > 62) ➞ ✅ Yes, 계속 진행 ➡️ 여섯 번째 반복 (마지막) 시작 값: (R1, R2, R3, R4) = (63, 62, 93, 155) **계산 순서** R2 = R1 + R1 (63 + 63 = 126) ➞ (63, **126**, 93, 155) R3 = R2 + R1 (126 + 63 = 189) ➞ (63, 126, **189**, 155) R4 = R3 - R1 (189 - 63 = 126) ➞ (63, 126, 189, **126**) R1 = R1 | R2 (63 | 126 = 127) ➞ (**127**, 126, 189, 126) R4 = R4 & R3 (126 & 189 = 120) ➞ (127, 126, 189, **120**) R4 = R2 + R3 (126 + 189 = 315) 8-bit Wrapping (오버플로우): 8비트 레지스터는 255까지만 표현 가능하므로, 315는 256을 뺀 나머지 값인 59가 된다. (315 - 256 = 59) R4 최종 값 ➞ (127, 126, 189, **59**) 조건 확인: R4 > R2 (59 > 126) ➞ ❌ No, 중단 (Halt)
Study
· 2025-08-11
DedicatedProcessor Counter
DedicatedProcessor Counter ✅ 과제 ⚒️ 코드 ⚒️ ⚒️[DedicatedProcessor ALUOP.sv] ✅ Schematic ✅ 시뮬레이션 ✅ 분석 반복별 레지스터 값 1회: R1=3, R2=2, R3=3, R4=5 → Yes 2회: R1=7, R2=6, R3=9, R4=15 → Yes 3회: R1=15, R2=14, R3=21, R4=35 → Yes 4회: R1=31, R2=30, R3=45, R4=75 → Yes 5회: R1=63, R2=62, R3=93, R4=155 → Yes 6회: R1=127, R2=126, R3=189, R4=59 → No ⇒ halt ➡️ 첫 번째 반복 시작 값: (R1, R2, R3, R4) = (1, 0, 0, 0) **계산 순서** R2 = R1 + R1 (1 + 1 = 2) ➞ (1, **2**, 0, 0) R3 = R2 + R1 (2 + 1 = 3) ➞ (1, 2, **3**, 0) R4 = R3 - R1 (3 - 1 = 2) ➞ (1, 2, 3, **2**) R1 = R1 | R2 (1 | 2 = 3) ➞ (**3**, 2, 3, 2) R4 = R4 & R3 (2 & 3 = 2) ➞ (3, 2, 3, **2**) R4 = R2 + R3 (2 + 3 = 5) ➞ (3, 2, 3, **5**) 조건 확인: R4 > R2 (5 > 2) ➞ ✅ Yes, 계속 진행 ➡️ 두 번째 반복 시작 값: (R1, R2, R3, R4) = (3, 2, 3, 5) **계산 순서** R2 = R1 + R1 (3 + 3 = 6) ➞ (3, **6**, 3, 5) R3 = R2 + R1 (6 + 3 = 9) ➞ (3, 6, **9**, 5) R4 = R3 - R1 (9 - 3 = 6) ➞ (3, 6, 9, **6**) R1 = R1 | R2 (3 | 6 = 7) ➞ (**7**, 6, 9, 6) R4 = R4 & R3 (6 & 9 = 0) ➞ (7, 6, 9, **0**) R4 = R2 + R3 (6 + 9 = 15) ➞ (7, 6, 9, **15**) 조건 확인: R4 > R2 (15 > 6) ➞ ✅ Yes, 계속 진행 ➡️ 세 번째 반복 시작 값: (R1, R2, R3, R4) = (7, 6, 9, 15) **계산 순서** R2 = R1 + R1 (7 + 7 = 14) ➞ (7, **14**, 9, 15) R3 = R2 + R1 (14 + 7 = 21) ➞ (7, 14, **21**, 15) R4 = R3 - R1 (21 - 7 = 14) ➞ (7, 14, 21, **14**) R1 = R1 | R2 (7 | 14 = 15) ➞ (**15**, 14, 21, 14) R4 = R4 & R3 (14 & 21 = 4) ➞ (15, 14, 21, **4**) R4 = R2 + R3 (14 + 21 = 35) ➞ (15, 14, 21, **35**) 조건 확인: R4 > R2 (35 > 14) ➞ ✅ Yes, 계속 진행 ➡️ 네 번째 반복 시작 값: (R1, R2, R3, R4) = (15, 14, 21, 35) **계산 순서** R2 = R1 + R1 (15 + 15 = 30) ➞ (15, **30**, 21, 35) R3 = R2 + R1 (30 + 15 = 45) ➞ (15, 30, **45**, 35) R4 = R3 - R1 (45 - 15 = 30) ➞ (15, 30, 45, **30**) R1 = R1 | R2 (15 | 30 = 31) ➞ (**31**, 30, 45, 30) R4 = R4 & R3 (30 & 45 = 12) ➞ (31, 30, 45, **12**) R4 = R2 + R3 (30 + 45 = 75) ➞ (31, 30, 45, **75**) 조건 확인: R4 > R2 (75 > 30) ➞ ✅ Yes, 계속 진행 ➡️ 다섯 번째 반복 시작 값: (R1, R2, R3, R4) = (31, 30, 45, 75) **계산 순서** R2 = R1 + R1 (31 + 31 = 62) ➞ (31, **62**, 45, 75) R3 = R2 + R1 (62 + 31 = 93) ➞ (31, 62, **93**, 75) R4 = R3 - R1 (93 - 31 = 62) ➞ (31, 62, 93, **62**) R1 = R1 | R2 (31 | 62 = 63) ➞ (**63**, 62, 93, 62) R4 = R4 & R3 (62 & 93 = 28) ➞ (63, 62, 93, **28**) R4 = R2 + R3 (62 + 93 = 155) ➞ (63, 62, 93, **155**) 조건 확인: R4 > R2 (155 > 62) ➞ ✅ Yes, 계속 진행 ➡️ 여섯 번째 반복 (마지막) 시작 값: (R1, R2, R3, R4) = (63, 62, 93, 155) **계산 순서** R2 = R1 + R1 (63 + 63 = 126) ➞ (63, **126**, 93, 155) R3 = R2 + R1 (126 + 63 = 189) ➞ (63, 126, **189**, 155) R4 = R3 - R1 (189 - 63 = 126) ➞ (63, 126, 189, **126**) R1 = R1 | R2 (63 | 126 = 127) ➞ (**127**, 126, 189, 126) R4 = R4 & R3 (126 & 189 = 120) ➞ (127, 126, 189, **120**) R4 = R2 + R3 (126 + 189 = 315) 8-bit Wrapping (오버플로우): 8비트 레지스터는 255까지만 표현 가능하므로, 315는 256을 뺀 나머지 값인 59가 된다. (315 - 256 = 59) R4 최종 값 ➞ (127, 126, 189, **59**) 조건 확인: R4 > R2 (59 > 126) ➞ ❌ No, 중단 (Halt)
Study
· 2025-08-11
UART
DAY2 ✅ 버튼 구조 버튼을 누를 때, 노이즈나 진동에 의해 짧은 시간 내에 ON/OFF가 반복됨 이 현상을 바운스(Bounce) 라고 하며, 디바운싱(Debounce) 처리가 필요 ✅ Shift Register를 이용한 디바운싱 💡 Shift Register 역할 버튼 입력(in_data)을 8클럭 동안 시프트 저장 sh_reg 값이 전부 1이면, 버튼이 안정적으로 눌림 상태라고 판단 ✅ shift_register 모듈 코드 module shift_register ( input logic clk, input logic reset, input logic in_data, output logic [7:0] out_data ); always_ff @(posedge clk or posedge reset) begin if(reset) begin out_data <= 0; end else begin out_data <= {in_data, out_data[7:1]}; // right shift //out_data <= {out_data[6:0], in_data}; // left shift end end endmodule ✅ 엣지 검출기 (Edge Detector) 🔍 개요 디바운싱된 버튼 입력(debounce)의 변화를 감지하여 상승 엣지(rising_edge) 하강 엣지(falling_edge) 또는 둘 다(both_edge)를 검출하는 회로 ✅ 동작 원리 edge_reg[1] ← 이전 상태 edge_reg[0] ← 현재 상태 변화 조건 - 상승 엣지: 이전 0 → 현재 1 - 하강 엣지: 이전 1 → 현재 0 - 둘 다: 둘 중 하나라도 발생 시 assign debounce = &sh_reg; //assign out_button = debounce; logic [1:0] edge_reg; always_ff @(posedge clk or posedge reset) begin if(reset) begin edge_reg <= 0; end else begin edge_reg[0] <= debounce; edge_reg[1] <= edge_reg[0]; end end assign rising_edge = edge_reg[0] & ~edge_reg[1]; assign falling_edge = ~edge_reg[0] & edge_reg[1]; assign both_edge = rising_edge | falling_edge; ✅ 전체 구조 (Button Detector) `timescale 1ns / 1ps module button_detector( input logic clk, input logic reset, input logic in_button, output logic rising_edge, output logic falling_edge, output logic both_edge ); logic clk_1khz; logic debounce; logic [7:0] sh_reg; logic [$clog2(100000)-1:0] div_counter; always_ff @(posedge clk or posedge reset) begin if(reset)begin div_counter <= 0; clk_1khz <= 0; end else begin if(div_counter == 100000 - 1)begin clk_1khz <= 1; div_counter <= 0; end else begin div_counter <= div_counter + 1; clk_1khz <= 0; end end end shift_register u_shift_register( .clk (clk_1khz), .reset (reset), .in_data (in_button), .out_data (sh_reg) ); assign debounce = &sh_reg; //assign out_button = debounce; logic [1:0] edge_reg; always_ff @(posedge clk or posedge reset) begin if(reset) begin edge_reg <= 0; end else begin edge_reg[0] <= debounce; edge_reg[1] <= edge_reg[0]; end end assign rising_edge = edge_reg[0] & ~edge_reg[1]; assign falling_edge = ~edge_reg[0] & edge_reg[1]; assign both_edge = rising_edge | falling_edge; endmodule module shift_register ( input logic clk, input logic reset, input logic in_data, output logic [7:0] out_data ); always_ff @(posedge clk or posedge reset) begin if(reset) begin out_data <= 0; end else begin out_data <= {in_data, out_data[7:1]}; // right shift //out_data <= {out_data[6:0], in_data}; // left shift end end endmodule ✅ 검증 (Test Bench) 클래스 정의 (transaction) rand bit button : 랜덤 생성 1비트 버튼 값 function bit run_random() : 현재 button 값을 반환 class transaction; rand bit button; function bit run_random(); return button; endfunction endclass 초기화 clk = 0, reset = 1 10ns 후 reset = 0 in_button = 0으로 초기화, 20ns 대기 버튼 누름 (Push) in_button = 1로 변경 60회 반복: tr.randomize()로 버튼 값 랜덤 생성 in_button에 랜덤 값 적용 1ns 대기 in_button = 1로 고정, 150ns 대기 // push button in_button = 1; for(int i= 0; i < 60; i++)begin tr.randomize(); in_button = tr.run_random(); #1; end in_button = 1; #150; 버튼 놓음 (Release) in_button = 0으로 변경 30회 반복: 랜덤 버튼 값 생성 및 적용 1ns 대기 in_button = 0로 고정, 100ns 대기 in_button = 0; for(int i= 0; i < 30; i++)begin tr.randomize(); in_button = tr.run_random(); #1; end in_button = 0; #100; $finish; ✅ 주요 특징 버튼 입력 바운스(Bounce) 효과를 랜덤 패턴으로 구현 상승/하강/양쪽 에지 검출 기능 검증 클래스 기반 랜덤 입력 생성으로 테스트 확장성 확보
Study
· 2025-08-08
Button Detector
DAY2 ✅ 버튼 구조 버튼을 누를 때, 노이즈나 진동에 의해 짧은 시간 내에 ON/OFF가 반복됨 이 현상을 바운스(Bounce) 라고 하며, 디바운싱(Debounce) 처리가 필요 ✅ Shift Register를 이용한 디바운싱 💡 Shift Register 역할 버튼 입력(in_data)을 8클럭 동안 시프트 저장 sh_reg 값이 전부 1이면, 버튼이 안정적으로 눌림 상태라고 판단 ✅ shift_register 모듈 코드 module shift_register ( input logic clk, input logic reset, input logic in_data, output logic [7:0] out_data ); always_ff @(posedge clk or posedge reset) begin if(reset) begin out_data <= 0; end else begin out_data <= {in_data, out_data[7:1]}; // right shift //out_data <= {out_data[6:0], in_data}; // left shift end end endmodule ✅ 엣지 검출기 (Edge Detector) 🔍 개요 디바운싱된 버튼 입력(debounce)의 변화를 감지하여 상승 엣지(rising_edge) 하강 엣지(falling_edge) 또는 둘 다(both_edge)를 검출하는 회로 ✅ 동작 원리 edge_reg[1] ← 이전 상태 edge_reg[0] ← 현재 상태 변화 조건 - 상승 엣지: 이전 0 → 현재 1 - 하강 엣지: 이전 1 → 현재 0 - 둘 다: 둘 중 하나라도 발생 시 assign debounce = &sh_reg; //assign out_button = debounce; logic [1:0] edge_reg; always_ff @(posedge clk or posedge reset) begin if(reset) begin edge_reg <= 0; end else begin edge_reg[0] <= debounce; edge_reg[1] <= edge_reg[0]; end end assign rising_edge = edge_reg[0] & ~edge_reg[1]; assign falling_edge = ~edge_reg[0] & edge_reg[1]; assign both_edge = rising_edge | falling_edge; ✅ 전체 구조 (Button Detector) `timescale 1ns / 1ps module button_detector( input logic clk, input logic reset, input logic in_button, output logic rising_edge, output logic falling_edge, output logic both_edge ); logic clk_1khz; logic debounce; logic [7:0] sh_reg; logic [$clog2(100000)-1:0] div_counter; always_ff @(posedge clk or posedge reset) begin if(reset)begin div_counter <= 0; clk_1khz <= 0; end else begin if(div_counter == 100000 - 1)begin clk_1khz <= 1; div_counter <= 0; end else begin div_counter <= div_counter + 1; clk_1khz <= 0; end end end shift_register u_shift_register( .clk (clk_1khz), .reset (reset), .in_data (in_button), .out_data (sh_reg) ); assign debounce = &sh_reg; //assign out_button = debounce; logic [1:0] edge_reg; always_ff @(posedge clk or posedge reset) begin if(reset) begin edge_reg <= 0; end else begin edge_reg[0] <= debounce; edge_reg[1] <= edge_reg[0]; end end assign rising_edge = edge_reg[0] & ~edge_reg[1]; assign falling_edge = ~edge_reg[0] & edge_reg[1]; assign both_edge = rising_edge | falling_edge; endmodule module shift_register ( input logic clk, input logic reset, input logic in_data, output logic [7:0] out_data ); always_ff @(posedge clk or posedge reset) begin if(reset) begin out_data <= 0; end else begin out_data <= {in_data, out_data[7:1]}; // right shift //out_data <= {out_data[6:0], in_data}; // left shift end end endmodule ✅ 검증 (Test Bench) 클래스 정의 (transaction) rand bit button : 랜덤 생성 1비트 버튼 값 function bit run_random() : 현재 button 값을 반환 class transaction; rand bit button; function bit run_random(); return button; endfunction endclass 초기화 clk = 0, reset = 1 10ns 후 reset = 0 in_button = 0으로 초기화, 20ns 대기 버튼 누름 (Push) in_button = 1로 변경 60회 반복: tr.randomize()로 버튼 값 랜덤 생성 in_button에 랜덤 값 적용 1ns 대기 in_button = 1로 고정, 150ns 대기 // push button in_button = 1; for(int i= 0; i < 60; i++)begin tr.randomize(); in_button = tr.run_random(); #1; end in_button = 1; #150; 버튼 놓음 (Release) in_button = 0으로 변경 30회 반복: 랜덤 버튼 값 생성 및 적용 1ns 대기 in_button = 0로 고정, 100ns 대기 in_button = 0; for(int i= 0; i < 30; i++)begin tr.randomize(); in_button = tr.run_random(); #1; end in_button = 0; #100; $finish; ✅ 주요 특징 버튼 입력 바운스(Bounce) 효과를 랜덤 패턴으로 구현 상승/하강/양쪽 에지 검출 기능 검증 클래스 기반 랜덤 입력 생성으로 테스트 확장성 확보
Study
· 2025-08-07
<
>
Touch background to close