본문 바로가기
Digital Logic/Verilog

[기초 개념] Verilog 문법 한눈에 보기

by 고뭉나무 2021. 4. 12.

Verilog 문법

1)     The module keyword

-       보통 파일 1개에 module 1개만 (module – endmodule은 한 세트)

 

2)     규칙

-       Always 함수 안에는 wire 타입에 값을 넣을 수 없음   
         (보통 clk이 변경되었을 때 always 함수 안을 수행하므로 같은 clk base reg를 사용해서 문제 발생 안함)

-       Assign은 특정 파라미터에 값을 지정해줄 때 쓰는데 이는 wire 타입만 가능함 (reg 타입 불가)

 

3)     보통 코드 구성 방식

-       Module문 시작

-       Input, output 파라미터 선언

-       Always 함수 생성

-       그 안에 if, for, while, case, repeat 등 사용

 

 

※Verilog 코드 예시

module reg_adder (
     input            clk,
     input      [2:0] a, b,
     output reg [3:0] out
);

reg [3:0] sum;

always @(a or b)
   sum = a + b;

always @(negedge clk)
   out <= sum;


endmodule

 

 

 

4)     Continuous & Procedural assignments

-       Continuous: 파라미터 선언만 했을 때

-       Procedural: always 함수 사용했을 때 (Testbench에선 initial)

 

 

5)     Combinational & Sequential procedure

 

-       Combinational: 파라미터 값에 맞춰서 always 문이 수행될 때

always @(a or b)
   sum = a + b;

 

-       Sequential: clk에 맞춰서 always 문이 수행될 때

always @(negedge clk)
   out <= sum;

 

6)     Blocking & Nonblocking assignments

그림1. Event Based Timing Control
그림2. Coding RTL Verilog

 

-       Combinational procedure 형태에서는 blocking 사용 (=)

-       Sequential procedure 형태에서는 non-blocking 사용 (<=)

*Sequential clk timing에 의해 always가 수행되고 (<=) 이것 또한 다음 cycle에 적용되는 것이므로 매칭이 됨.

 

 

7)     Delta cycle and simulation time

-       Edge-sensitive timing control: @

-       Simple delays: #

-       Level-sensitive timing control: wait

 

※delay 코드 예시

A = 5;
#10 A = B + C;  //A=5 를 실행한 뒤에, 10ns뒤에 실행.
#5 D = ~A + 1;  //윗줄 진행 후, 5ns 뒤에 위 문장 실행.

 

 

설계 시 Tip

1)     Input floating x (floating 되면 chip damage 생김, match 잘 시키기)

2)     Latch 사용 x

3)     Feedback loop 사용 x

4)     Race condition x (clk base sequiential logic에서 blocking 사용할 때)

 

 

반응형

댓글