본문 바로가기
Design

[RTL Design] Clock Divider (2)

by VIR&US 2025. 7. 11.
반응형

목차

    이전에 Clock Divider에 대해 쓴 글이 있습니다. 

    2023.07.21 - [Language/Verilog & SV] - [Verilog] Frequency(Clock) Divider

     

    [Verilog] Frequency(Clock) Divider

    목차 Frequency(Clock) Divider D F/F를 이용한 주파수 분할입니다. 간단하게 하나의 F/F를 거치면 2 분할됩니다. 카운터를 활용해서 분할할 수 도 있습니다. 생산 이후에 Clock divider를 잘못설계하면(ex. 홀

    vir-us.tistory.com

    Clock Divider에 대해 학생 수준에서 설계를 진행할때, 보통은 D F/F를 이용하거나, Counter를 이용해서 Clock Divider를 만듭니다. 위 글도 마찬가지입니다.

    Clock Divider를 설계하는데 Deskewer가 왜 필요해?

    간단한 짝수분주라면 D F/F를 사용해도 문제는 없지만,  공정이 발전하고 연산과정이 빨라지고 나노초(ns)단위의 Clock이 사용되는 상황에서 Counter를 사용한 분주방식은 Clock간의, Clock과 Data간의 Skew문제를 직면하게 됩니다.

     

    정확한 타이밍에 동작해야만하는 하드웨어에서 Clock의 Glitch나 Skew는 필히 고려해야만 합니다. 합성 이후 하드웨어로 구현될 상황에는 위 문제를 고려하여 설계를 할 수 밖에 없습니다.

     

    Deskewer란 무엇인가?

    "Dskewer"는 디지털 회로, 특히 클럭 생성기(clock generator) 설계에서 사용되는 중요한 기술로, 클럭 신호 간의 시간 차이(skew)를 보정하여 정확한 동기화를 가능하게 합니다. 미국 특허 US6507230B1은 이러한 deskewer 회로를 포함한 클럭 생성기에 대해 설명하고 있습니다.

    https://patents.google.com/patent/US6507230B1/en

     

    US6507230B1 - Clock generator having a deskewer - Google Patents

    BACKGROUND OF THE INVENTION 1. Technical Field The present invention relates to digital circuits in general, and in particular to clock generation circuits. Still more particularly, the present invention relates to a clock generator having a deskewer. 2. D

    patents.google.com

    Deskewer in US6507230B1

    Waveform Generator

    입력 클럭을 기반으로 파형 신호를 생성합니다. 

    Deskewer

    이 파형 신호를 입력 클럭과 게이팅(gating)하여 출력 클럭을 생성합니다. 이 과정에서 출력 클럭이 입력 클럭과의 skew가 최소화되도록 조정됩니다. 즉, 출력 클럭이 입력 클럭과 더 정밀하게 정렬되도록 deskewing이 수행됩니다.

    왜 Deskewer가 필요한가?

    • 정확한 동기화 보장
      • 디지털 회로는 클럭의 상승/하강 에지에 맞춰 동작합니다.
      • 클럭 skew가 존재하면 일부 회로는 너무 일찍, 일부는 너무 늦게 동작하여 데이터 오류가 발생할 수 있습니다.
    • 고속 회로에서의 안정성 확보
      • 클럭 주파수가 높아질수록 skew의 영향은 더 커집니다.
      • Deskewer는 고속 회로에서 타이밍 마진 확보에 필수적입니다.
    • 멀티 클럭 도메인 간의 인터페이스 안정화
      • 서로 다른 클럭 도메인 간의 통신에서는 skew 보정이 없으면 메타스테이블 상태가 발생할 수 있습니다.

    설계해보기

    Deskewer

    위 그림에서는 F/F 두개와 and2 3개와 or3 1개로 되어있습니다.

    그림과 코드에서 다른점이 하나 있습니다.

    and와 or보다 nand가 fet의 개수가 적게 필요하다는 점에서 같은 동작을 하는 nand2 3개와 nand3 1개로 교체하였습니다. 

    사담으로 요새는 합성툴이 많이 좋아져서 사람이 알아보기 쉽게 코드를 짜도 최적화를 잘해줍니다.

     

     

    FSM

     

    아래는 이전에 작성해놓은 해당 코드에 대한 상세한 설명입니다.

     

    CLKDIV_FSM Verilog Module Explanation

    Overview

    The CLKDIV_FSM module is a finite state machine (FSM) used in a clock divider system. It generates two control signals, p and q, based on a programmable division ratio and an enable signal. These outputs are used to control the timing of the output clock in conjunction with other modules.

     

    Module Interface

    Port Direction Description
    clk input Clock signal
    resetn input Active-low reset
    enable input Enable signal for the FSM
    divratio input Division ratio (parameterized width)
    p output FSM output signal p
    q output FSM output signal q

     

    Internal Signals

    • div_odd: Indicates if the division ratio is odd.
    • add1_divratio: divratio + 1, used for mid-point calculation.
    • divcount: Counter that increments with each clock cycle when enabled.
    • curr_st: Current FSM state.
    • next_st: Next FSM state.

    FSM States

    State Binary p q Description
    PQNEG 00 0 0 Idle state
    NODIV 01 0 1 Disabled or reset state
    PNEG 10 0 1 Intermediate state for odd division
    PQPOS 11 1 1 Active state

     

    State Transitions

    • NODIV → PQPOS: When enable is high.
    • PQPOS → PNEG: If divcount == (divratio + 1) >> 1 and div_odd is true.
    • PQPOS → PQNEG: If divcount == (divratio + 1) >> 1 and div_odd is false.
    • PNEG → PQNEG: Always transitions to PQNEG.
    • PQNEG → PQPOS: When divcount == 0.

    Output Logic

    • p = &curr_st: p is high only in state PQPOS (11).
    • q = |curr_st: q is high in all states except PQNEG (00).

    Functional Summary

    The FSM cycles through states based on the division ratio and generates control signals p and q that are used to shape the output clock. It supports both even and odd division ratios by inserting an intermediate state (PNEG) when needed.

     

    CLKDIV

     

    위 두 module를 연결해주면 Clock Divider 설계가 끝이 납니다. 

    해당 IP의 idle값이 필요하다면, FSM에서 현재 상태가 NODIV일때를 이용하시면 됩니다. 

     

    마무리

    이번 글에서는 Clock Divider를 설계해보았습니다.

    실제 하드웨어로 구현되는 언어인 Verilog HDL은 소프트웨어와 다르게 신경써줘야할 내용들이 있습니다. 

    728x90
    반응형

    'Design' 카테고리의 다른 글

    [RTL Design] NOR Gate  (0) 2024.05.24
    [RTL Design] XNOR Gate  (0) 2024.05.24
    [RTL Design] And gate  (0) 2024.05.24
    [RTL Design] Inverter (Not gate)  (0) 2024.05.22
    [RTL Design] Wire 2  (0) 2024.05.22