Quality control (2)/Digital System Design

DSD - Behavioral Modeling(1) / Procedure constructs ( initial )

빈그레 2023. 4. 6. 02:33

 

 


Behavioral Modeling

 

 

 

 

 

 

Behavioral Modeling

 

 

- This level describes a system by concurrent(동시) algorithms.

 

- 각각의 알고리즘들은 순차적이다. //전체적으로는 concurrent하나, algorithm내에서는 sequential

  순차적이라는 것은 하나씩 실행되는 명령어들의 집합으로 이루어졌다는 것을 의미한다.

 

- Functions, Tasks , always blcok이 main element이다 ( 6주차에 배움)

 

- no regard to the structural realization of the design

 

 

 

 

 

 

 

[GPT said]

 

Behavioral modeling is a type of high-level abstraction for digital circuit design.

The behavior or functionality of a system is specified in terms of its inputs and outputs, rather than its underlying hardware implementation details.
//하드웨어 구현에 대한 detail이 아닌, input,output의 측면에서 지정된다.

The designer specifies the input/output behavior of the circuit using procedural code that describes the operations to be performed on the inputs to produce the desired output.
This procedural code is similar to a software program, where the program code defines the functionality of the system.

Behavioral modeling is a flexible approach to circuit design, as it allows the designer to focus on the desired behavior of the system, rather than the specific details of how it is implemented.
//implementation보다는 동작 위주로 flexible하게 접근 가능

To create a behavioral model in Verilog, the designer defines a module and its inputs and outputs. The module then contains a procedural block of code, typically written in the form of an always block or an initial block, that defines the behavior of the circuit.
//always, initial 사용

 

 

 

 

Properties of Behavioral Modeling

 

- Description of Design Funtionality in an High Level

 

- always block / initial block

 -Two main Structured procedure in behavioral modeling 

- Each activity flow starts at time 0
  //0에서 동시에 시작

- They cananot be Nested
  // 2중으로 하는 것이 불가능 

- They can have multiple statements between the keyword begin and end
   //여러줄 쓸 수 있음, begin과 end는 C에서의 중괄호 역할
   // 코드 한 줄일 때는 필요 없고 always,initial내부에서 step by step일 때 begin-end 필요

 

 

- Two types of Procedural blocks in Verilog HDL

- initial
: initial blocks execute only once at time zero ( start execution at time zero)
  //C에서의 main 함수 역할로서, instruction 하나씩 한 번 돌고 끝

- always
: always blocks loop to execute over and over again, //begin-end-begin-end.....(무한 loop)
   (in other words as name means), it executes always.

 

( *** Procedural ) 

: Procedural refers to a type of behavior that is defined using a set of instructions or procedures that are excuted in a specific order.Procedural behavior can be concurrent, meaning that multiple processes can execute simultaneously, but the order of execution is still defined by the procedural code. 

// 즉, 명령어의 집합으로 정의된 것!

 

 

 

 

 

 


 

 

 

 

 

 

 

 

 


Procedure Constructs (initial)

 

 

 

 

 

 

Properties of initial statements

 

An initial blocks

 

- is composed of all statements inside an initial staement

 

- executes exactly once during simulation

  //시뮬레이션 동안 오직 한번!

 

- is used to initialize signals(신호값 초기화), or monitor waveforms

  //신호값 초기화하거나, waveform 볼 때 사용

 

- starts to execute concurrently at simulation time 0

  and finishes execution independently when multiple initial blocks exist.

  //initial block 여러개일 때, 시작은 time0 0에 동시에 하나, 끝은 각자 독립적으로

 

 

 

 

 

명시적 initial  없는 initialization

 

[ Regular Declaration ]

reg clk; // regular declaration
initial clk = 0;

 

 

[ Combined variable declaration and initialization ]

//which can be declared as a single statement instead
reg clk = 0; // can be used only at module level

 

위 코드는 initial이 암묵적으로 쓰인 것이다. 너무 software같은 code이다. 궁극적으로 hw 엔지니어답게!

 

 

 

 


 

 

 

 

[ Combined port/data declaration and initialization ]

module adder(x, y, c , sum, c_out); 
input [3:0] x, y;
input c_in;
output reg [3:0] sum = 0;
output reg c_out = 0;

port는 기본적으로 wire지만, reg를 달아줌으로써 sum,out이 FF에서 나갈 것임을 알려주었다.

위 코드는 sum, c_out port에 연결된 register를 0을 만들어 주고 시작하는 것을 의미한다. 즉, sum과 c_out에 대한 output port 이전에 FF에 0이라는 값이 저장되어 있다가, 저장된 값을 port로 뽑아가라는 뜻이다.

 

위 코드에서는 sum과 c_out에 initial이 숨겨져 있다. 

출력값이 동작을 하기 전에 초기화 시켜주고 싶은,,software적 사고가 반영되었다고 볼 수 있다...

initial은 testbench에서 사용하는 것이지, module내에서 초기화를 해버리는 것은 좋지 않은 초기화 방법이다.

//Flip Flop에 누가 0이라고 써줄거야~? 

 

 

 

 

 

회로에서 초기화란? ( 추천하는 초기화 방법 )

 

하드웨어에서 초기화는 rst (Reset) 을 시켜주는 것이다.

암묵적인 initial을 사용하지 말고, 대놓고 reset을 시켜주는 것이 best이다.

 

Flip Flop에는 clk, rst이 무조건 set로 들어간다. modeling할 때는 rst없이 clk만 들어가기도 하지만, 실제 circuit에서는 rst없이 clk만 들어가는 ff은 없다. (Circuit에서 초기화 중요하기 때문에)

 

///   Initial로 초기화하지 말자!!!!!!!! 초기화는 reset으로 하자!!!!!!!!!!!!!!!!!!!!!

      여기서는 behavioral modeling이라서 가능은하지만,,,, initial로 초기화 하지 말자!!!!!!!!!!!!!

 

 

 

 

 

Multiple initials

 

: if multiple initial block exist, each of them starts concurrently and finish independently of the other blocks.

module stim; reg x,y,a,b,m ;

initial m = 1’b1; 

initial begin
#5 a = 1’b1;
#25 b = 1’b0; end

initial begin
#10 x = 1’b0;
#25 y = 1’b1;
end

initial #50 $finish;  //simulation을 끝내라!

endmodule

 

 

위에서 initial 를 C에서의 main 함수에 비유한 적이 있으나, initial은 main함수와 다르게 한번에 여러개 쓰일 수 있다.

 

위 코드에서는 initial이 4개가 있다. 위 4개의 initial은 start time인 0에서 동시에 시작하게 된다. (concurrent)