Input And Output Ports
Coddy Verilog 여정의 기초 섹션에 포함된 레슨. 90개 중 31번째.
Input 및 output 포트는 모듈이 외부 세계와 통신할 수 있도록 하는 연결입니다. 이는 칩의 핀과 같습니다. 포트는 모듈과 설계의 나머지 부분 사이의 인터페이스입니다.
모든 module에는 다음이 있습니다:
- Input ports: module로 들어오는 신호
- Output ports: module에서 나가는 신호
Input 포트
Input 포트는 외부에서 데이터를 받습니다. 모듈 내부에서는 변경할 수 없으며, only 읽을 수 있습니다.
input clk; // 단일 비트 입력
input [7:0] data; // 8비트 입력 벡터
input a, b; // 한 줄에 여러 입력inputs 규칙:
- 모듈 내부에서 값을 할당할 수 없음
reg로 선언할 수 없음- 항상
wire(기본값)
출력 포트
출력 포트는 외부로 데이터를 보냅니다. assign 또는 always 블록에 의해 구동될 수 있습니다.
output out; // 단일 비트 출력
output [3:0] result; // 4비트 출력
output reg busy; // 출력은 reg일 수 있음
output wire ready; // 출력은 wire일 수 있음출력에 대한 규칙:
wire(assign사용) 또는reg(always사용)일 수 있습니다.- 모듈 내부의 무언가에 의해 구동되어야 합니다.
포트 선언 구문
포트 선언 구문은 모듈에서 입력 및 출력 포트를 작성하는 구체적인 방식입니다. 이는 각 포트에 대해 Verilog에 세 가지를 알려 줍니다:
- 방향: input, output 또는 inout인가요?
- 크기: 너비가 몇 비트인가요?
- 이름: 무엇이라고 called 되나요?
module example (
input [7:0] data_in, // 입력 벡터
input clk, // 단일 입력
input enable, // 단일 입력
output reg [7:0] out, // 출력 reg
output busy // 출력 wire
);포트 방향이 중요한 이유
방향은 Verilog에 다음을 알려 줍니다:
- 모듈이 read할 수 있는 신호 (inputs)
- 모듈이 write할 수 있는 신호 (outputs)
- 허용되는 연결 유형
잘못된 방향을 사용하면 컴파일 오류가 발생합니다.
코드 예제
module port_demo (
input [3:0] a, // 읽기만 가능
input [3:0] b, // 읽기만 가능
output reg [3:0] sum, // 쓰기 가능 (reg)
output [3:0] diff // 쓰기 가능 (wire)
);
always @(*) begin
sum = a + b; // output reg에 쓰기
end
assign diff = a - b; // output wire에 쓰기
endmodule챌린지
포트 선언 완성하기
할 일:
- Add 8-bit input called
data_in - Add single-bit input called
clk - Add 4-bit output called
result(reg 사용: always 블록에서 할당됨) - Add single-bit output called
valid(wire 사용: assign으로 할당됨)
직접 해보기
module port_challenge (
// Task 1: data_in이라는 8비트 입력을 추가하세요
// Task 2: clk이라는 단일 비트 입력을 추가하세요
// Task 3: result라는 4비트 출력을 추가하세요 (reg 사용)
// Task 4: valid라는 단일 비트 출력을 추가하세요 (wire 사용)
);
reg [3:0] counter;
always @(posedge clk) begin
counter <= counter + 1;
result <= counter;
end
assign valid = (counter > 8);
endmodule이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.
기초의 모든 레슨
4Operators Part 1
Arithmetic OperatorsModulo OperatorComparison OperatorsRecap - Simple MathBitwise Operators7Assign And Gates
Continuous AssignmentAssign With OperatorsBuilt In Gate PrimitivesAND OR NOT GatesXOR XNOR GatesRecap - Logic Gate Circuit10Decision Making
If StatementIf - ElseRecap - Simple ComparatorCase StatementCasex And CasezRecap - ALU Design5Operators Part 2
Logical OperatorsReduction OperatorsShift OperatorsConcatenation OperatorConditional OperatorRecap - Operator Challenge3Number System
Binary RepresentationSized NumbersUnsized NumbersNegative NumbersSpecial Values X And ZRecap - Number Formats6Modules
Module StructureInput And Output PortsInout PortsModule InstantiationPort Mapping By NamePort Mapping By OrderRecap - Build A Module9Procedural Blocks
Always BlockInitial BlockSensitivity ListBlocking AssignmentNon Blocking AssignmentRecap - Always vs Initial15Traffic Light Controller
Defining The StatesState Machine Logic직접 연습해 보세요: 온라인 Verilog 컴파일러