SemiMatrix / TOPICS / RTL DESIGN & DIGITAL ARCHITECTURES
IC DESIGN — DIGITAL

RTL Design & Digital Architectures

DESIGN

01 บทนำ: RTL Design & Digital Architectures คืออะไร

ในโลกของการออกแบบวงจรรวม (IC Design) RTL (Register Transfer Level) คือระดับ Abstraction หลักในการอธิบายการทำงานของวงจรดิจิทัล โดยเน้นการไหลของข้อมูล (Data Flow) ระหว่างหน่วยความจำชั่วคราวหรือรีจิสเตอร์ (Registers) ผ่านวงจรลอจิกเชิงผสม (Combinational Logic) การออกแบบในระดับนี้จะถูกเขียนขึ้นด้วยภาษาอธิบายฮาร์ดแวร์ (Hardware Description Languages - HDL) เช่น Verilog, SystemVerilog หรือ VHDL จากนั้นเครื่องมือสังเคราะห์วงจร (Logic Synthesis Tools) จะทำหน้าที่แปลงโค้ดเหล่านี้ให้กลายเป็น Gate-level Netlist ที่ประกอบด้วยเกตลอจิกพื้นฐานและฟลิปฟลอปจริงบนซิลิคอน

\n

หัวใจสำคัญที่สุดในการก้าวข้ามจาก Software Programmer สู่ RTL Design Engineer คือการปรับเปลี่ยนกระบวนทัศน์ (Paradigm Shift) ที่ว่า "RTL ≠ Software" ในการเขียนโปรแกรมคอมพิวเตอร์ คำสั่งจะถูกประมวลผลตามลำดับก่อนหลัง (Sequential Execution) แต่ในการออกแบบ RTL ทุกแถวของโค้ดที่เขียนจะถูกสังเคราะห์เป็นวงจรฮาร์ดแวร์กายภาพที่ทำงานพร้อมกันทั้งหมดแบบคู่ขนาน (Parallel Execution) ดังนั้น ทุกๆ บรรทัดของโค้ดจึงหมายถึงโครงสร้างสายไฟ เกต และรีจิสเตอร์ที่เกิดขึ้นจริงในชิป

\n

เพื่อตอบสนองต่อความต้องการของระบบประมวลผลสมัยใหม่ที่ต้องการความเร็วสูงและแบนด์วิดท์มหาศาล สถาปัตยกรรมดิจิทัลจึงต้องพึ่งพาเสาหลักสองประการ ได้แก่ FSM (Finite State Machine) ซึ่งทำหน้าที่เป็นกลไกควบคุม (Control Path) ลำดับขั้นตอนการทำงาน และ Pipelining ซึ่งเป็นเทคนิคการจัดสรรส่วนการทำงาน (Data Path) ให้ทำงานร่วมกันแบบคู่ขนานเพื่อเพิ่ม Throughput และความถี่ในการทำงาน (Clock Frequency) อย่างก้าวกระโดด

\n
ข้อคิดสำคัญสำหรับ Senior RTL Engineer: ความสอดคล้องระหว่างโครงสร้างลอจิกที่ออกแบบกับสถาปัตยกรรมทางกายภาพ (Physical Architecture) คือตัวกำหนดความสำเร็จของชิป การเขียนโค้ดที่สวยงามแต่ไม่คำนึงถึงโครงสร้างฮาร์ดแวร์ปลายทาง จะนำไปสู่ปัญหา Timing Violation ในขั้นตอนการผลิตจริง
📍 CAREER ROADMAP CONTEXT
STAGE 02 — DIGITAL DESIGN & HDL: RTL Design & Hardware Description
เขียน RTL ด้วย Verilog/SystemVerilog — FSM, pipeline, CDC (Clock Domain Crossing), reset strategy, coding style ที่ synthesis-friendly
Tools: Cadence NC-Sim / Synopsys VCS, ModelSim/Questa
Related: VHDL · FSM & Pipeline Design · Clock Domain Crossing (CDC)
Path: IC Design Engineer

02 Verilog Basics

module counter #(parameter WIDTH = 8) (
  input  wire             clk,
  input  wire             rst_n,
  input  wire             en,
  output reg  [WIDTH-1:0] count
);

always @(posedge clk or negedge rst_n) begin
  if (!rst_n)
    count <= {WIDTH{1'b0}};
  else if (en)
    count <= count + 1'b1;
end

endmodule

Verilog module ประกอบด้วย: port declaration, always block (sequential/combinational), assign (continuous assignment), instantiation

03 SystemVerilog Extensions

SystemVerilog เพิ่ม features สำคัญ:

Data Types: logic (4-state), bit (2-state), enum, struct, union, interface

Always blocks: always_ff (sequential), always_comb (combinational), always_latch — ช่วย tool ตรวจ intent

Assertions: assert property — ใส่ใน RTL เพื่อ formal verification

always_ff @(posedge clk or negedge rst_n) begin
  if (!rst_n)
    state <= IDLE;
  else
    state <= next_state;
end

always_comb begin
  unique case (state)
    IDLE:    next_state = start ? RUN : IDLE;
    RUN:     next_state = done  ? IDLE : RUN;
    default: next_state = IDLE;
  endcase
end

04 Synthesis-Friendly Coding Style

กฎสำคัญสำหรับ synthesizable RTL:

• ใช้ non-blocking (<=) ใน sequential blocks, blocking (=) ใน combinational
• ทุก signal ใน sensitivity list ของ combinational block ต้องมี default value
• หลีกเลี่ยง latch — ใส่ default ใน case/if
• ใช้ synchronous reset ยกเว้น power-on reset
• Named port connection (.port(signal)) แทน positional

COMMON MISTAKE
Incomplete case statement โดยไม่มี default สร้าง inferred latch — synthesis tool จะ warn แต่ไม่ error

05 Finite State Machine (FSM)

FSM design pattern:

Moore Machine: output ขึ้นกับ state เท่านั้น — output stable, timing ง่าย
Mealy Machine: output ขึ้นกับ state + input — response เร็วกว่า 1 cycle แต่ timing critical

Best practice: แยก 3 always blocks — state register, next-state logic, output logic

State Encoding: Binary (area-efficient), One-hot (speed, FPGA-friendly), Gray (low switching)

06 Pipeline Design

Pipeline แบ่ง combinational path ยาวเป็น stages ด้วย register — เพิ่ม throughput แลกกับ latency

THROUGHPUT
$$ Throughput = \frac{f_{clk}}{1} \text{ (1 result/cycle)} $$

Pipeline Hazards:
• Data hazard: forwarding / stalling
• Control hazard: branch prediction
• Structural hazard: resource sharing

Balance pipeline stages ให้ delay ใกล้เคียงกัน — stage ที่ช้าสุดกำหนด fclk,max