본문 바로가기
HW Design/1. Verilog HDL Basic

[Basic Verilog Module] 3. 베릴로그 모듈 예시

by 한PU 2024. 1. 2.
728x90
반응형
  • synchronous counter 설계 예시
    • parameter를 사용
    • 두 개의 instances로 instantiate
  • instantiation
    • 12-bits output instance
    • 8-bits output instance
  • RTL 제외, module IO 와 연결은 정의
  • counter module
    • 2 inputs
      • clock
      • reset
    • 1 output
      • counter value
    • parameter
      • output bits에 숫자를 정의하기 위함.
    • counter module 예시 코드

counter module 예시 코드

// Verilog 2001 module
module counter #(
    parameter WIDTH = 8
)
(
    input clock,
    input reset,
    output reg [WIDTH-1:0] count
);

// Verilog 1995 module
module counter (
    clock,
    reset,
    reg
);

parameter WIDTH = 8;

input clock;
input reset;
output reg [WIDTH-1:0] count

endmodule
  • 이후는 2001 표준 모듈만 이용
  • 위 카운터의 인스턴스 두 개를 instantiate 하는 모듈 필요
    • 2 inputs
      • clock
      • reset
    • 2 outputs
      • instantiated couters의 value
    • parameter WIDTH = 8 이므로...
      • 8 bits output을 정의할때는 overriding 되지 않음.
      • 12 bits output을 정의할때는 WIDTH 값을 재정의하여 12로 설정해야 함.
module top_level (
    input clock,
    input reset,
    output reg [7:0] count_8,
    output reg [11:0] count_12
);

    // 8bits instantiation
    // parameter 재정의 없이 그냥 사용 가능
    counter 8_bit_count(
        .clock (clock),
        .reset (reset),
        .count (count_8)
    );

    // 12bits instantiation
    // parameter 재정의
    counter #(.WIDTH (12)) 12_bit_count (
        .clock (clock),
        .reset (reset),
        .count (count_12)
    );

endmodule
728x90
반응형