MAC에서 테스트해보기.
1. Brew 설치
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2. 환경변수 설정
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
3. icarus-verilog 설치
brew install icarus-verilog
4. 설치 완료 확인
iverilog -v
5. AND 게이트 모듈 + 테스트벤치 ( example.v )
`timescale 1ns / 1ps
// ✅ AND 게이트 모듈 정의
module and_gate (
input wire A,
input wire B,
output wire OUT
);
assign OUT = A & B;
endmodule
// ✅ Testbench
module tb_and_gate;
reg A;
reg B;
wire OUT;
// DUT (Device Under Test) 인스턴스
and_gate uut (
.A(A),
.B(B),
.OUT(OUT)
);
initial begin
$display("Time\tA\tB\tOUT");
$monitor("%0dns\t%b\t%b\t%b", $time, A, B, OUT);
// 시뮬레이션 입력 시나리오
A = 0; B = 0; #10;
A = 0; B = 1; #10;
A = 1; B = 0; #10;
A = 1; B = 1; #10;
$finish;
end
endmodule
6. Python 코드 (main.py)
import os
def run_simulation(verilog_file='example.v'):
compile_cmd = f"iverilog -o sim_out {verilog_file}"
run_cmd = "vvp sim_out"
print("🛠️ Verilog 컴파일 중...")
os.system(compile_cmd)
print("▶️ 시뮬레이션 실행 중...")
os.system(run_cmd)
# 실행
run_simulation()
7. 결과
- Time 아래 0ns, 10ns, 20ns, 30ns 는 시뮬레이션 타임 단위와 정밀도에 의해 결정됩니다.
- 1ns (나노초)
- 1ps: 시간 정밀도(해상도), 1피코초
- 40000 -> 총 시뮬레이션 시간이 40ns라는 뜻
- TestBench에서 #10 씩 4번 진행 -> 총 40ns
'Python' 카테고리의 다른 글
Verilog 개념 이해하기 (0) | 2025.07.08 |
---|---|
LLM과 관련된 필수 라이브러리(accelerate, PEFT, Bitsandbytes) 3가지 설명 (0) | 2025.06.02 |
[Python] Softeer.ai Level.2. 연탄의 크기 문제풀이 (0) | 2024.10.29 |
윈도우 가상환경 virtualenv 사용하기 (0) | 2024.07.26 |
윈도우 virtualenv 가상환경 우분투로 옮겨서 환경 옮겨가기 (1) | 2024.07.23 |