산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Industrial programming >> verilog

모든 범위에서 Verilog Timescale 이해 및 출력하기

기본 타임스케일 (Default Timescale)

Verilog 모듈은 모듈 전에 timescale이 정의되어 있을 것으로 예상되지만, 시뮬레이터는 기본 timescale을 삽입할 수 있습니다. Verilog 엘리보레이트된 계층 구조에서 어떤 범위든 적용되는 실제 timescale은 $printtimescale 시스템 태스크로 출력할 수 있으며, 이는 범위를 인자로 받습니다.

module tb;
  initial begin
    // 이 모듈의 timescale 출력
    $printtimescale(tb);
    // $printtimescale($root);
  end
endmodule

이 모듈 앞에 timescale 지시자가 없었음에도 시뮬레이터가 1ns/1ns timescale 값을 적용했음을 볼 수 있습니다.

시뮬레이션 로그

xcelium> run
Time scale of (tb) is 1ns / 1ns
xmsim: *W,RNQUIE: Simulation is complete.

표준 타임스케일 범위 (Standard Timescale Scope)

기본적으로 파일에 배치된 timescale 지시자는 다른 timescale 지시자 정의가 나올 때까지 뒤따르는 모든 모듈에 적용됩니다.

`timescale 1ns/1ps
module tb;
  des m_des();
  alu m_alu();
  initial begin
    $printtimescale(tb);
    $printtimescale(tb.m_alu);
    $printtimescale(tb.m_des);
  end
endmodule

module alu;
endmodule

`timescale 1ns/10ps
module des;
endmodule

위 예제에서 tb와 alu는 1ns/1ps timescale을 가지게 되고, des는 des 모듈 정의 전에 지시자가 교체되어 1ns/10ps timescale을 가지게 됩니다.

시뮬레이션 로그

xcelium> run
Time scale of (tb) is 1ns / 1ps
Time scale of (tb.m_alu) is 1ns / 1ps
Time scale of (tb.m_des) is 1ns / 10ps
xmsim: *W,RNQUIE: Simulation is complete.

Verilog 파일 간 범위 (Scope Between Verilog Files)

다른 파일은 `include 지시자로 현재 파일에 포함될 수 있으며, 이는 전처리기 지시자로 컴파일러가 포함된 파일의 내용을 컴파일 전에 현재 파일에 배치하게 합니다. 즉, 다른 파일의 전체 내용을 이 메인 파일에 붙여넣는 것과 동일합니다.

// main.v
`timescale 1ns/1ps
module tb;
  des m_des();
  alu m_alu();
  initial begin
    $printtimescale(tb);
    $printtimescale(tb.m_alu);
    $printtimescale(tb.m_des);
  end
endmodule

`include "file_alu.v"
`include "file_des.v"

// file_alu.v
module alu;
endmodule

// file_des.v
`timescale 1ns/10ps
module des;
endmodule

결과가 이전 예제와 정확히 동일함을 볼 수 있습니다. alu는 파일 내 다른 위치에 배치되었음에도, 컴파일러가 alu 정의를 찾기 전까지 마지막 지시자가 유효했으므로 1ns/1ps timescale을 가집니다. des는 정의 전에 지시자가 교체되어 1ns/10ps timescale을 가집니다.

시뮬레이션 로그

xcelium> run
Time scale of (tb) is 1ns / 1ps
Time scale of (tb.m_alu) is 1ns / 1ps
Time scale of (tb.m_des) is 1ns / 10ps
xmsim: *W,RNQUIE: Simulation is complete.

파일 순서 변경으로 타임스케일 변경

파일 포함 순서가 timescale 지시자 재정의에 중요한 역할을 함을 아래 예제에서 확인할 수 있습니다.

// main.v
`timescale 1ns/1ps
module tb;
  des m_des();
  alu m_alu();
  initial begin
    $printtimescale(tb);
    $printtimescale(tb.m_alu);
    $printtimescale(tb.m_des);
  end
endmodule

// 포함 순서 변경!
`include "file_des.v"
`include "file_alu.v"

// file_alu.v
module alu;
endmodule

// file_des.v
`timescale 1ns/10ps
module des;
endmodule

이제 모듈 alu가 1ns/10ps timescale을 가짐을 볼 수 있습니다.

시뮬레이션 로그

xcelium> run
Time scale of (tb) is 1ns / 1ps
Time scale of (tb.m_alu) is 1ns / 10ps
Time scale of (tb.m_des) is 1ns / 10ps
xmsim: *W,RNQUIE: Simulation is complete.

이것이 파일 상단에 timescale 지시자를 두어 파일 포함 순서와 관계없이 해당 파일의 모든 모듈이 올바른 timescale을 가정하게 하는 이유 중 하나입니다.

하지만 이 접근법은 각 파일을 변경하지 않고 다른 timescale 정밀도(빗금 뒤 값)로 컴파일하기 어렵게 만들 수 있습니다. 많은 컴파일러와 시뮬레이터는 모든 모듈에 적용될 기본 timescale 값을 오버라이드하는 옵션도 제공합니다.

verilog

  1. 버릴로그(Verilog) 입문: 디지털 회로 설계를 위한 하드웨어 기술 언어
  2. Verilog 결합(Concatenation) & 복제(Replication) 연산자 실전 가이드
  3. Verilog 할당문 이해: 유형, 문법, 모범 사례
  4. Verilog 차단 vs 비차단 할당: 핵심 차이점 완벽 이해
  5. Verilog 함수 마스터하기: 효율적인 RTL 설계를 위한 활용법
  6. Verilog 태스크 이해: 함수와의 차이점, 문법, 활용법
  7. Verilog 계층적 참조 범위 마스터하기: 모듈과 블록 간 이름 충돌 방지
  8. Verilog 클럭 생성기: 설계 및 구현 가이드
  9. Verilog 수학 함수 마스터하기: 효율적인 하드웨어 설계를 위한 활용
  10. Verilog $timeformat 마스터하기: 정밀도 및 표시 제어