반응형
- 모듈 선언 구문
Verilog에서 모듈은 디지털 시스템을 설명하는 데 사용되는 기본 빌딩 블록(fundamental building block)입니다. 모듈 선언 구문은 다음과 같습니다.
module module_name (list_of_ports);
// Declarations and statements
endmodule
module_name은 모듈의 이름이고 list_of_ports는 모듈에 대한 연결을 나타내는 입력, 출력 및 입력 포트의 쉼표로 구분된 목록입니다.
- 모듈 정의
모듈 정의는 일반적으로 다음 구성 요소로 구성됩니다.
포트 선언 : 모듈의 input, output 및 inout 포트를 정의합니다.
데이터 유형 선언 : 모듈 내에서 사용되는 내부 신호 및 변수를 정의합니다.
회로 기능 : 여기에는 모듈의 동작을 정의하는 연속 할당문, 절차 블록 및 하위 프로그램이 포함됩니다.
모듈 인스턴스화 : 정의 중인 모듈이 다른 모듈로 구성되어 있으면 현재 모듈 내에서 인스턴스화하여 연결할 수 있습니다.
module xor_gate(input wire A, B, output wire Y);
// Internal signal declaration
wire A_and_B, A_or_B;
// Instantiate AND and OR gates
and and_gate1(A_and_B, A, B);
or or_gate1(A_or_B, A, B);
// Define the output using a continuous assignment statement
assign Y = A_and_B ^ A_or_B;
endmodule
- 모듈 계층(hierarchy)
최상위 모듈: 전체 디지털 시스템을 나타내는 설계 계층의 최상위 모듈입니다. 일반적으로 하위 수준 모듈을 인스턴스화하고 연결합니다.
하위 수준 모듈: 이 모듈은 다른 모듈 내에서 인스턴스화되며 전체 시스템의 더 작고 관리하기 쉬운 부분을 나타냅니다.
계층적 연결: 서로 다른 계층 수준에 있는 모듈 간의 연결은 포트 연결을 사용하여 이루어집니다. 이를 통해 데이터 및 제어 신호가 계층 구조의 모듈 간에 흐를 수 있습니다.
// Full adder module
module full_adder(input wire A, B, Cin, output wire Sum, Cout);
// ...
endmodule
// 2-bit adder module
module two_bit_adder(input wire [1:0] A, B, output wire [1:0] Sum, output wire Cout);
wire carry_out_1;
// Instantiate full adders
full_adder FA1(A[0], B[0], 1'b0, Sum[0], carry_out_1);
full_adder FA2(A[1], B[1], carry_out_1, Sum[1], Cout);
endmodule
// Top-level module
module top_module();
// ...
endmodule
반응형