Presentation is loading. Please wait.

Presentation is loading. Please wait.

VHDL의 기본 Lecture #4.

Similar presentations


Presentation on theme: "VHDL의 기본 Lecture #4."— Presentation transcript:

1 VHDL의 기본 Lecture #4

2 강의 내용 VHDL의 기본 VHDL 문장 VHDL 모델링 모바일컴퓨터특강

3 1. VHDL의 기본

4 VHDL의 기본 - 강의순서 VHDL Lexical Elements VHDL Design Description Object
Data Type Attribute Operator Statements Concurrent vs. Sequential Statements 모바일컴퓨터특강

5 VHDL 어휘 요소 (1) 주석(comment) 식별어(Identifier)
연자부호(‘-’)를 연속적으로 2개(‘—’)로 시작하는 문장 예: entity AND_OR is -- Entity declaration port( A, B, C : in std_logic; Y : OUT std_logic); end AND_OR; 식별어(Identifier) 신호명, 변수명, 엔티티 이름 등과 같이 VHDL에서 식별 목적으로 사용하는 공백을 갖지 않는 문자열 대소문자 구분하지 않음 모바일컴퓨터특강

6 VHDL 어휘 요소 (2) 식별어(Identifier) (계속) 식별어 작성법 사용 예: 잘못 사용 예:
식별어는 영문자, 숫자 그리고 밑줄(‘_’)로 구성 식별어는 반드시 영문자로 시작해야 한다 식별어는 밑줄로 시작 또는 끝이 나면 안된다 식별어는 연속적으로 밑줄을 포함행서는 안된다 사용 예: Counter, next_value, s_1, s_2, generate_read_cycle 잘못 사용 예: last-value, _a0, a0_, clock__pulse, 4bit_counter 모바일컴퓨터특강

7 VHDL 어휘 요소 (3) 지정어(keyword) VHDL 구문을 위해 미리 지정된 문자열
대소문자 구분 없으며, 식별자로 사용할 수 없다 모바일컴퓨터특강

8 VHDL 어휘 요소 (4) 리터럴(Literal) 일련의 수치 값을 표현 정수 리터럴 / 실수 리터럴로 구분
정수 리터럴: 소수점이 없는 10진수, (예) 20, 0, 146 실수 리터럴: 소수점을 갖는 10진수, (예) 23.1, 0.0, 3.14 진수 표기가 가능 – 2진수, 8진수, 10진수 표기법 – 진수#수치데이터# 예 – 2진수 : 2# # 8진수 : 8#0375# 16진수 : 16#FD# 밑줄(‘_’) 문자 사용 가능 긴 숫자 데이터를 읽기 쉽게 작성 예 – 123_456, 3.141_592_6, 2#1111_0101_1100_0000# 모바일컴퓨터특강

9 VHDL 어휘 요소 (5) 문자(Characters) 문자열(Strings) 비트 문자열(Bit Strings)
하나의 문자 데이터를 정의 단일 인용부호(single quotation) ‘ ‘ 를 사용 예 – ‘A’, ‘z’, ‘2’, ‘,’, ‘-’, ‘ ‘ etc. 문자열(Strings) 2개 이상의 문자들로 구성된 문자 배열 이중 인용부호(double quotation) “ “를 사용 예 – “A string”, “ ”, etc. 비트 문자열(Bit Strings) 비트열을 2/8/16 진수 형태의 문자열로 표현 정의 형식 –”비트열”앞에 진수표시 문자(b/o/x)을 지정 예 – b”1111_0101_0000”, o”0375”, x”0d”, etc. 모바일컴퓨터특강

10 VHDL 어휘 요소 (6) 특수 기호(Special Symbols)
1개 또는 2개의 문자로 구성 예 - +, -, *, /, =, =>, <=, :=, etc. 모바일컴퓨터특강

11 VHDL Design Description
VHDL design description은 설계하고자 하는 논리회로를 정의하는 entity와 architecture로 구성 Entity 하드웨어 외부입출력 인터페이스를 정의 하드웨어 블록의 이름과 입출력 PORT를 선언 Architecture 하드웨어의 내부를 표현 내부회로의 연결, 동작 또는 구조 등을 표현 모바일컴퓨터특강

12 Entity Declarations (1)
논리회로를 하나의 ‘Black Box’로 간주 Entity는 논리회로를 정의하는 이름과 외부와의 인터페이스 신호(I/O Signal)을 정의 BLACK_BOX rst d[7:0] clk q[7:0] co entity 논리회로이름 is port( rst : in std_logic; co : out std_logic); end 논리회로이름; 모바일컴퓨터특강

13 Entity Declarations (2)
논리회로의 인터페이스 신호는 PORT 문장을 이용하여 정의 정의 형식 : 예 : port( rst : in std_logic; co : out std_logic ); PORT (signal_name : mode data_type); 모바일컴퓨터특강

14 Entity – Signal Mode The port mode describes the direction in which data travels with respect to the component in : data comes in this port and can only be read out : data travels out this port buffer : data may travel in either direction, but only one signal driver may be on at any one time inout : data may travel in either direction with any number of active drivers allowed ; requires a Bus Resolution Function 모바일컴퓨터특강

15 Entity – Signal Type 1 bit signal: bit, std_logic
2 bit 이상의 signal: bit_vector, std_logic_vector 2bit -- bit_vector(1 downto 0) std_logic_vector(1 downto 0) 4bit -- bit_vector(0 to 3) std_logic_vector(0 to 3) std_logic, std_logic_vector : IEEE 1164 Standard Signal Type으로 std_logic, std_logic_vector 이 사용될 때는 아래의 문장이 Entity문장 전에 미리 사용 되어야 함. Library ieee; Use ieee.std_logic_1164.all; 모바일컴퓨터특강

16 Entity 정의 예제 : ex_1 entity ex_1 is port ( A : in std_logic;
B : inout std_logic; C : out std_logic; Y : buffer std_logic ); end ex_1; 모바일컴퓨터특강

17 Architecture Bodies (1)
논리회로의 동작, 내부회로의 연결 또는 내부 구조 등을 묘사 두 부분으로 구성 : 선언부 : 문장부에서 사용하는 신호, 변수, 상수 등을 정의하는 영역 type declarations, signal declarations, component declarations, subprogram declarations 병행문장부 : 논리회로의 내부 동작이나 구조를 묘사한 병행 문장을 포함하는 영역 concurrent signal assignment statements, process statements, component instantiation statements 모바일컴퓨터특강

18 Architecture Bodies (2)
기본 형식 : 병행문장부 begin과 end 사이에 서술된 문장들은 기본적으로 병행 수행 하드웨어 구현을 정의 동작적 표현(Behavioral Representation 자료흐름적 표현(Dataflow Representation) 구조적 표현(Structural Representation) 혼합적 표현(Mixed Representation) architecture 아키텍처_이름 of 엔티티_이름 is {선언부} begin {병행문} end 아키텍처_이름; 모바일컴퓨터특강

19 Entity / Architecture 구성
LIBRARY __library_name; USE __library_name.__package_name.ALL; ENTITY __entity_name IS PORT( __input_name, __input_name : IN STD_LOGIC; __input_vector_name : IN STD_LOGIC_VECTOR(__high DOWNTO __low); __bidir_name, __bidir_name : INOUT STD_LOGIC; __output_name, __output_name : OUT STD_LOGIC ); END __entity_name; ARCHITECTURE a OF __entity_name IS SIGNAL __signal_name : STD_LOGIC; BEGIN -- Process Statement -- Concurrent Procedure Call -- Concurrent Signal Assignment -- Conditional Signal Assignment -- Selected Signal Assignment -- Component Instantiation Statement -- Generate Statement END a; 모바일컴퓨터특강

20 Simple VHDL Code : AND Gate
Library ieee; Use ieee.std_logic_1164.all; Entity and_2 is port( a, b : in std_logic; y : out std_logic ); end and_2; Architecture dataflow of and_2 is begin y <= a and b; end dataflow; Signal Type으로 std_logic이 사용될 때는 항상 사용. Entity 문장 : 입력 a,b, 출력 y를 나타냄 Architecture Body : 회로의 설명 모바일컴퓨터특강

21 객체(Object) VHDL에서 값을 가질 수 있는 객체는 3가지 종류
신호(Signals) 변수(Variables) 상수(Constants) The scope of an object is as follows : Objects declared in a package are available to all VHDL descriptions that use package Objects declared in an entity are available to all architecture associated with that entity Objects declared in an architecture are available to all statements in that architecture Objects declared in a process are available only within that process 모바일컴퓨터특강

22 객체(Object) - 신호 signal a, b, c : std_logic; VHDL 컴포넌트간의 연결에 사용되는 외적 변수
논리회로에서 구성 컴포넌트간을 연결하는 논리 신호(logic signal) 또는 선(wire)을 정의 All VHDL signal assignments require either delta cycle or user-specified delay before new value is assumed 신호는 일정 시간이 지난 시점에서 변한 값을 가진다 정의 형식 : 사용 예: signal a, b, c : std_logic; a <= ‘1’; b <= ‘0’; c <= a and b; SIGNAL signal_name : type_name [ :=value]; 신호 할당 연산자 : 오른쪽에 있는 값을 왼쪽의 시그널에 대입 모바일컴퓨터특강

23 객체(Object) – 신호 초기화 신호는 신호 선언 시에 초기화할 수 있다
신호의 초기화에서는 값을 바로 대입하므로 ‘<=‘ 연산자 대신에 ‘:=‘ 연산자를 사용한다 사용 예 : signal S : integer := 1; signal ONE_state : std_logic := ‘1’; signal Tmp : std_logic (3 downto 0) := “1010”; 모바일컴퓨터특강

24 객체(Object) – 신호 사용 예 Library ieee; Use ieee.std_logic_1164.all;
Entity div_logic is port ( A, B, C : in std_logic; Y : out std_logic ); End div_logic; Architecture dataflow of div_logic is signal aorb : std_logic; signal ONE_state : std_logic := ‘1’; Begin aorb <= A or B; Y <= aorb and C and ONE_state; End dataflow; 모바일컴퓨터특강

25 객체(Object) - 변수 계산 결과를 임시로 저장하는 역할을 수행 프로세스문 또는 부프로그램 내에서만 유효한 내적 변수
Provide convenient mechanism for local storage 프로세스문 또는 부프로그램 내에서만 유효한 내적 변수 변수에 대한 할당연산은 즉시 실행되어 변수에 값이 바로 대입된다 정의 형식 : 사용 예 : variable a, b : std_logic; variable s : integer; a := ‘1’; b := ‘0’; s := 1; VARIABLE variable_name : type_name [ :=value]; 변수 할당 연산자 : 오른쪽에 있는 값을 왼쪽의 변수에 대입 모바일컴퓨터특강

26 객체(Object) – 변수 사용 예 모바일컴퓨터특강

27 객체(Object) - 상수 초기된 후에 값이 변하지 않는 데이터 객체
Allow for easy update and readability 정의 형식 : 사용 예 : constant bits3_0 : std_logic_vector(2 downto 0) := "000"; signal y : std_logic_vector(2 downto_0); y <= bits3_0; CONSTANT constant_name : type_name [ :=value]; 모바일컴퓨터특강

28 객체(Object) – 상수 사용 예 Even/Odd Bit Masking 모바일컴퓨터특강

29 자료형(Data Type) Scalar Types Composition Type 열거형(Enumeration Type)
IEEE 1164 표준 자료형 부울형(Boolean Type) 정수형(Integer Type) 부동소수점형(Floating Type) Composition Type 배열형(Array Type) 레코드형(Record Type) 모바일컴퓨터특강

30 자료형 선언 (1) 자료형 선언 미리 정의된 자료형 이외의 자료형은 사용자가 별도로 선언하여 사용 자료형 선언 형식 :
TYPE 자료형_이름 IS 자료형_명세; 사용 예 : TYPE Bit_4 IS (‘0’, ‘1’, ‘X’, ‘Z’); SIGNAL A : Bit_4; TYPE Digit IS INTERGER RANGE 0 TO 7; SIGNAL S : Digit; A <= ‘Z’; S <= 4; 열거형 자료형 선언 사용자 정의 자료형 선언 모바일컴퓨터특강

31 부자료형 선언 (2) 부자료형 선언 부자료형은 기본 자료형의 부분집합을 정의 부자료형 선언 형식 :
SUBTYPE 부자료형_이름 IS 기본자료형_범위; 사용 예 : SUBTYPE BYTE IS STD_LOGIC_VECTOR(7 DOWNTO 0); SUBTYPE WORD IS STD_LOGIC_VECTOR(15 DOWNTO 0); TYPE ANY_NUMBER IS INTEGER RANGE 0 to 1023; SUBTYPE PART_NUMBER IS ANY_NUMBER RANGE 0 TO 15; 모바일컴퓨터특강

32 Data Type - Scalar Types(1)
열거형(Enumeration Type) 객체가 가질 수 있는 값을 열거하여 새로운 자료형을 정의 사용 예 : TYPE State_type IS (stateA, stateB, stateC); TYPE Bit_2 IS (‘0’, ‘1’); TYPE Bit_3 IS (‘0’, ‘1’, ‘Z’); TYPE Bit_4 IS (‘0’, ‘1’, ‘Z’, ‘X’); signal X : Bit_3; signal Y : State_type; X < = ‘Z’; Y <= stateC; 모바일컴퓨터특강

33 Data Type - Scalar Types(2)
IEEE 1164 Standard Data Types IEEE Library의 std_logic_1164 패키지에서 선언 자료형 종류 : BIT / BIT_VECTOR STD_LOGIC / STD_LOGIC_VECTOR STD_ULOGIC SIGNED / UNSIGNED 논리 0 인 ‘0’과 논리 1 인 ‘1’의 값만 가지는 자료형 고임피던스(high impedance) 상태 등을 표현할 수 없어 현재는 거의 사용하지 않음 BIT_VECTOR – BIT의 배열형 VHDL 표준 IEEE 1076에 미리 정의되어 있음 모바일컴퓨터특강

34 Data Type - Scalar Types(3)
STD_LOGIC / STD_LOGIC_VECTOR IEEE 1164 라이브러리에서 정의된 자료형으로 BIT 자료형 보다 융통성이 높은 자료형 정의된 값 : ‘0’ : Strong Logic 0 / ‘1’ : Strong Logic 1 ‘L’ : Weak Logic 0 / ‘H’ : Weak Logic 1 ‘Z’ : High Impedance ‘X’ : Strong Unknown / ‘W’ : Weak Unknown ‘U’ : Uninitialized / ‘-’ : Don’t Care STD_LOGIC_VECTOR – STD_LOGIC 자료형의 배열형 std_logic_vector(0 to 10) – 오름차순 배열형 정의 std_logic_vector(10 downto 0) – 내림차순 배열형 정의 모바일컴퓨터특강

35 Data Type - Scalar Types(4)
STD_LOGIC / STD_LOGIC_VECTOR 사용 예: C(1)=‘0’, C(2)=‘1’, …,C(4)=‘1’ Byte(7)=‘1’, Byte(6)=‘0’, …,Byte(0)=‘0’ 모바일컴퓨터특강

36 Data Type - Scalar Types(5)
STD_ULOGIC type std_ulogic is (‘U’, ‘X’, ‘0’, ‘1’, ‘Z’, ‘W’, ‘L’, ‘H’, ‘-’); type std_logic is resolved std_ulogic; SIGNED / UNSIGNED SIGNED 자료형 : 부호있는 수 연산에 사용 UNSIGNED 자료형 : 부호없는 수 연산에 사용 사용 패키지 : ieee 라이브러리의 std_logic_arith 패키지 모바일컴퓨터특강

37 Data Type - Scalar Types(6)
부울형(Boolean Types) 참(TRUE)과 거짓(FALSE)의 논리값을 가지는 자료형 TRUE : 1, FALSE : 0 사용 예: TYPE BOOLEAN IS (false, true); signal flag : BOOLEAN; 정수형(Integer Type) 32 비트 크기의 정수를 표현 -231 ~ +(231-1) = ~ 음의 정수는 2의 보수로 표현 산술 연산자를 이용하여 산술 연산에 적용 모바일컴퓨터특강

38 Data Type - Scalar Types(7)
정수형(Integer Type) (계속) “RANGE~TO~” 지정어를 사용하여 작은 크기의 정수형을 정의 사용 예: variable COUNT : INTEGER RANGE 0 TO 19; signal S : INTEGER; bit integer number signal X : INTEGER RANGE -128 TO 127; -- signed 8-bit number signal D : INTEGER RANGE 0 TO 15; bit umber 부동소숫점형(Floating Type) Minimum range for any implementation as defined by standard : E38 to 1.0E38 모바일컴퓨터특강

39 Data Type-Composition Type (1)
배열형(Array Type) 순서화된 데이터들의 집합을 정의 배열 내의 모든 요소들은 같은 자료형을 가지며, 순서가 정해져 있다 제한적 배열 : 배열의 크기를 설정할 수 있는 배열 1차원 배열 TYPE Word IS array(15 downto 0) OF std_logic; TYPE Byte IS array(7 downto 0) OF std_logic; TYPE Mem IS array(1023 downto 0) OF std_logic; signal X : Byte 2 차원 배열 TYPE Mem IS array(0 to 1023) of std_logic_vector(15 downto 0); signal A : Mem; 모바일컴퓨터특강

40 Data Type-Composition Type (2)
배열형(Array Type) 무제한적 배열 : 배열의 크기를 지정하지 않은, 미리 정의되어 있는 배열 예 : TYPE BIT_VECTOR IS ARRAY(natural range <>) OF BIT; TYPE STD_LOGIC_VECTOR IS ARRAY(natural range <>) OF STD_LOGIC; 무제한적 배열에 대해 배열의 크기를 지정하기 위해서는 부자료형을 정의하여 사용 SUBTYPE low_part IS (BIT_VECTOR range 0 to 7); SUBTYPE high_part IS (BIT_VECTOR range 8 to 15); 모바일컴퓨터특강

41 Data Type Conversion 자료형 변환
신호들이 서로 다른 자료형을 갖는 경우에 신호들간의 데이터 할당 또는 연산을 허용되지 않는다 자료형이 혼용되었을 때에 자료형 변환 함수를 사용 CONV_INTEGER CONV_UNSIGNED CONV_SIGNED CONV_STD_LOGIC_VECTOR 자료형 변환 함수는 std_logic_arith 패키지에서 정의 사용 예: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; signal A, B : unsigned(7 downto 0); signal X, Y : integer; signal Z : std_logic_vector(7 downto 0); Y <= conv_integer(A + B); Z <= conv_std_logic_vector(X, 8); 모바일컴퓨터특강

42 속성(Attribute) (1) 속성은 신호에 대한 동작이나 상태를 표현하는 특성 속성 접근 형식 : 신호_이름’속성_이름
미리 정의된 속성(Predefined Attributes) low, high, left, right, pos, val, succ, pred ... X’EVENT -- TRUE when there is an event on signal X X’LAST_VALUE -- returns the previous value of signal X Y’HIGH -- returns the highest value in the range of Y X’STABLE(t) -- TRUE when no event has occurred on signal X in the past ‘t’ time 사용자 정의 속성(User-defined Attributes) 사용자가 필요에 따라 정의하여 사용하는 속성 모바일컴퓨터특강

43 속성(Attribute) (2) ‘event’ 속성 사용 예: 논리회로에서 가장 많이 사용하는 속성
클럭 신호의 에지 상태(rising edge/falling edge)에 따라 동작을 지정하는 경우에 사용 사용 예: 모바일컴퓨터특강

44 연산자(Operators) Defined precedence levels in decreasing order :
Miscellaneous operators : **, abs, not Multiplication operators : *, /, mod, rem Sign operator : +,- Addition operators : sll, srl, sla, sra, rol, ror Relational operators : =, /=, <, <=, >, >= Logical operators : AND, OR, NAND, NOR, XOR, XNOR 연산자 우선순위 모바일컴퓨터특강

45 2. VHDL 문장

46 문장(Statements) (1) 병행 문장(Concurrent Statements)
Signal Assignment, Simple Signal Assignment, Conditional Signal Assignment, Selected Process Statement 순차 문장(Sequential Statements) Wait Statement If Statement Case Statement For Loop Statement 모바일컴퓨터특강

47 문장(Statements) (2) 디지털 논리회로 내의 모든 요소들은 항상 병행적으로 동작하므로 병행문장을 사용하여 표현
일반 프로그램 언어와 같이 논리회로의 동작을 알고리즘 방식으로 정의하기 위해 순차문장을 사용 모바일컴퓨터특강

48 Concurrent Statements - Signal Assignment, Simple
signal_name <= expression; (1) b에 변화가 생길 때마다 b의 값이 y에 출력됨 (2) Sensitivity List : b y <= b; y <= a or b; (1) a 나 b에 변화가 생길 때마다 a or b의 값이 y에 출력됨. (2) Sensitivity List : a,b 모바일컴퓨터특강

49 Concurrent Statements - Signal Assignment, Conditional
signal <= expression1 WHEN boolean_expression1 ELSE expression2 WHEN boolean_expression2 ELSE expression3; (1) boolean_expression1= 참(True)이면 signal <= expression1이 실행되며, (2) boolean_expression2= 참(True) 이면 signal <= expression2이 실행되며, (3) 위의 2가지 조건이 모두 성립하지않으면 signal <= expression3이 실행된다. 모바일컴퓨터특강

50 Concurrent Statements - Signal Assignment, Selected
WITH expression SELECT signal <= expression1 WHEN constant_value1, expression2 WHEN constant_value2, expression3 WHEN constant_value3; (1) expression = constant_value1 이면 signal <= expression1이 실행되며, (2) expresion1 = constant_value2 이면 signal <= expression2이 실행되며, (3) expresion1 = constant_value3 이면 signal <= expression3이 실행된다. 모바일컴퓨터특강

51 Concurrent Statements – Process Statement
복잡한 알고리즘의 구현 시 편리 Sensitivity List에 적혀있는 신호에 변화가 생길 때 begin과 end 내의 문장을 실행 Declaration syntax : [Label:] process [( Sensitivity List)] begin Sequential statements; end process [Label]; 모바일컴퓨터특강

52 Process Statement (1) A process is a VHDL construct used for grouping sequential statements Statements within a process are evaluated sequentially in terms of simulation Processes can be either active or inactive (awake or asleep) A Process typically has a SENSITIVITY LIST When a signal in the sensitivity list changes value, the process becomes active e.g., a process with a clock signal in its sensitivity list becomes active on changes of the clock signal 모바일컴퓨터특강

53 Process Statement (2) [label :] PROCESS (sensitivity list) BEGIN
sequential statements END PROCESS [label]; All signal assignments occur at the END PROCESS statement in terms of simulation time The Process then becomes inactive 모바일컴퓨터특강

54 Process Statement (3) - An Example
Example of sequential statements within a Process: mux: PROCESS (a, b, s) BEGIN IF s = '0' THEN x <= a; ELSE x <= b; END IF; END PROCESS mux; x(3 DOWNTO 0) s a(3 DOWNTO 0) b(3 DOWNTO 0) Note: logic within a process can be registered or combinatorial Note: the order of the signals in the sensitivity list is unimportant 모바일컴퓨터특강

55 The Process Sensitivity List
A Process is invoked when one or more of the signals within the sensitivity list change, e.g., ARCHITECTURE archlist OF list IS BEGIN nand: PROCESS (a,b) c <= NOT (a AND b); END PROCESS nand; END archlist; Note: the process ‘nand’ is sensitive to signals ‘a’ and ‘b’ i.e., whenever signal ‘a’ or ‘b’ changes value, the statements inside of the process will be evaluated 모바일컴퓨터특강

56 Signal Assignment in Processes
Consider a system which is to AND all the bits of a data bus: Input is a_bus Output is x ENTITY my_and IS PORT (a_bus: IN BIT_VECTOR(7 DOWNTO 0); x: BUFFER BIT); END my_and; 모바일컴퓨터특강

57 Signal Assignment in Processes - Incorrect Solution
Solution using a process with sequential statements: ARCHITECTURE wont_work OF my_and IS BEGIN adder: PROCESS (a_bus) x <= ‘1’; FOR i IN a_bus'left downto 0 LOOP x <= a_bus(i) and x; END LOOP; END PROCESS adder; END wont_work; 모바일컴퓨터특강

58 Signal Assignment in Processes - Correct Solution
Solution using a process with sequential statements and a concurrent signal assignment: ARCHITECTURE wont_work OF my_adder IS BEGIN adder: PROCESS (a_bus) VARIABLE b: BIT b := ‘1’; FOR i IN a_bus'left downto 0 LOOP b := a_bus(i) and b; END LOOP; x <= b; END PROCESS adder; END wont_work; 모바일컴퓨터특강

59 Sequential Statements – Wait Statement
wait on signal [, signal] wait until boolean_expression wait for time_expression (1) 동작 - Suspends the sequential execution of a process or subprogram (2) 예 : (1) wait on a, b; (2) wait until ( x < 100 ); (3) wait for 10 ns; a,b에 변화가 생길 때까지 기다린다. X<100일 때까지 기다린다. 10ns동안 기다린다. 모바일컴퓨터특강

60 Sequential Statements – Wait on vs. explicit sensitivity list
wait on statement process begin wait on a, b; y <= a and b; end process; Process 문을 사용하는 두 가지 방식 : 모두 가능함 explicit sensitivity list process (a, b) begin y <= a and b; end process; 모바일컴퓨터특강

61 Sequential Statements – IF Statement
IF expression1 THEN statement1-1; statement1-2; ELSIF expression2 THEN statement2-1; statement2-2; ELSE statement3-1; statement3-2; END IF; 동작 방식 : (1) expression1 = 참(True)이면 statement1-1, state1-2가 실행, (2) expression2 = 참(True) 이면 statement2-1, state2-2가 실행, (3) 위의 2가지 조건 모두 성립하지않으면 statement3-1, state3-2가 실행 모바일컴퓨터특강

62 Sequential Statements – Case Statement
CASE expression IS WHEN constant_value1 => statement1-1; statement1-2; WHEN constant_value2 => statement2-1; statement2-2; WHEN OTHERS => statement3-1; statement3-2; END CASE; 동작 방식 : (1) expression1 = constant_value1 이면 statement1-1, state1-2가 실행, (2) expression1 = constant_value1 이면 statement2-1, state2-2가 실행, (3) 위의 2가지 조건 모두 성립하지않으면 statement3-1, state3-2가 실행 모바일컴퓨터특강

63 Sequential Statements – For Statement (1)
loop_label: FOR index_variable IN range LOOP statement1; statement2; END LOOP loop_label; 동작 방식 : (1) index_variable의 값이 변해가면서 statement1, statement2를 반복적으로 실행. (2) Range는 downto, to의 2가지 형태로 정의 가능 모바일컴퓨터특강

64 Sequential Statements – For Statement (2)
loop_Start: FOR i IN 0 to 3 LOOP y(i) <= a(i) and b(i); END LOOP loop_Start; (a) y(0) <= a(0) and b(0); y(1) <= a(1) and b(1); y(2) <= a(2) and b(2); y(3) <= a(3) and b(3); (b) 모바일컴퓨터특강

65 3. VHDL 모델링

66 VHDL 모델링 방법 추상적 동작 표현(Behavioral Descriptions)
알고리즘방법으로 표현 데이터 흐름 표현(Dataflow Descriptions) 부울대수를 이용해서 표현 구조적 표현(Structural Descriptions) 단순한 선의 연결로 표현 혼합적 표현(Mixed Descriptions) 위의 3가지방법을 혼합 모바일컴퓨터특강

67 Behavioral Descriptions
동작적 표현 방식 논리회로의 동작에 대한 기능적 또는 알고리즘적 표현 논리회로에 대한 최상위 추상화 레벨 논리회로의 내부 구조에 대한 지식을 요구하지 않음 고급언어를 사용한 프로그램 작성방법과 유사 자료보관과 관리가 편리 process() 문을 주로 사용하여 표현 Process 문장 자체는 병행 문장  process 문장간에는 병행 수행 Process 문장 내에서는 순차 실행 모바일컴퓨터특강

68 Behavioral Description - Signal Assignment, Conditional
2 x 1 Multiplexer : library ieee; use ieee.std_logic_1164.all; entity mux21_when is port( a,b : in std_logic; s : in std_logic; y : out std_logic); end mux21_when; architecture a of mux21_when is begin y <= a when (s='0') else b; end a; 2x1 Mux a b s y 동작 명세: if s = 0 then y = a else y = b 마지막 조건은 else 로 처리해야 함 모바일컴퓨터특강

69 Behavioral Description - Signal Assignment, Conditional
모바일컴퓨터특강

70 Behavioral Description - Signal Assignment, Selected
library ieee; use ieee.std_logic_1164.all; entity mux21_with is port( a, b: in std_logic; s : in std_logic; y : out std_logic); end mux21_with; architecture a of mux21_with is BEGIN WITH s SELECT y <= a WHEN ‘0’, b WHEN others; END a; 마지막 조건은 else 로 처리해야 함 모바일컴퓨터특강

71 Behavioral Description – Sequential Statement (IF)
library ieee; use ieee.std_logic_1164.all; entity mux21_if_proc is port( a,b : in std_logic; s : in std_logic; y : out std_logic); end mux21_if_proc; architecture proc of mux21_if_proc is begin process(a,b,s) if( s='0') then y<=a; else y<=b; end if; end process; end proc; a, b,s 에 변화생길 때 실행 마지막 조건은 else로 처리해야 함. 모바일컴퓨터특강

72 Behavioral Description – Process Statement (case)
library ieee; use ieee.std_logic_1164.all; entity mux21_case_proc is port( a,b : in std_logic; s : in std_logic; y : out std_logic); end mux21_case_proc; architecture proc of mux21_case_proc is begin process(a,b,s) case s is when '0' => y<= a; when others => y<= b; end case; end process; end proc; 마지막 조건은 others로 처리해야 함. 모바일컴퓨터특강

73 Behavioral Description – Signal vs. Variable
library ieee; use ieee.std_logic_1164.all; entity andor_2 is port( a, b, c : in std_logic; y : out std_logic); end andor_2; architecture a of andor_2 is begin process(a,b,c) variablel t : std_logic; t :=a and b; y<=t or c; end process; end a; library ieee; use ieee.std_logic_1164.all; entity andor_2 is port( a, b, c : in std_logic; y : out std_logic); end andor_2; architecture a of andor_2 is signal t : std_logic; begin process(a,b,c,t) t<=a and b; y<=t or c; end process; end a; 선언되는 위치차이 Sensitivity List차이 2 1 1 Signal t는 Process문이 끝나는 순간에 일괄적으로 값이 할당. 2 3 Variable은 대입 즉시 값 할당. 모바일컴퓨터특강

74 Dataflow Descriptions
데이터 흐름 표현 입력과 출력과의 관계를 기술한 부울 대수식을 이용한 설계 방식 논로회로를 구성하는 구성 요소의 입출력 그리고 구성 요소간의 신호 흐름을 묘사하는 방식으로 논리회로를 설계 논리회로에 대한 중간 수준의 추상화 레벨 문장의 순서는 무관하다 병행처리문(Concurrent Statement)를 주로 사용 모바일컴퓨터특강

75 Dataflow Description - 2-입력 AND Gate
Library ieee; Use ieee.std_logic_1164.all; Entity and_2 is port( a, b : in std_logic; y : out std_logic ); end and_2; Architecture dataflow of and_2 is begin y <= a and b; end dataflow; Dataflow방식은 부울대수를 그대로 표현 모바일컴퓨터특강

76 Dataflow Description - 2입력 OR Gate
Library ieee; Use ieee.std_logic_1164.all; Entity or_2 is port( a, b : in std_logic; y : out std_logic ); end or_2; Architecture dataflow of or_2 is begin y <= a or b; end dataflow; 모바일컴퓨터특강

77 Dataflow Description - Andor_2 Circuit
library ieee; use ieee.std_logic_1164.all; entity andor_2 is port( a, b, c : in std_logic; y : out std_logic); end andor_2; architecture a of andor_2 is signal t : std_logic; begin t<=a and b; y<=t or c; end a; 모바일컴퓨터특강

78 Dataflow Description – 4 bits OR gate
Bus의사용 library ieee; use ieee.std_logic_1164.all; entity or_4bits is port( a, b : in std_logic_vector(3 downto 0); y : out std_logic_vector(3 downto 0) ); end or_4bits; architecture xxx of or_4bits is begin y <= a or b; end xxx; 모바일컴퓨터특강

79 Dataflow Description - Half Adder
library ieee; Use ieee.std_logic_1164.all; Entity half_add is port( a,b : in std_logic; sum, c_out : out std_logic ); end half_add; Architecture dataflow of half_add is begin sum <= A xor B; c_out <= A and B; end dataflow; 문장의 순서는 무관 모바일컴퓨터특강

80 Dataflow Description - Full Adder
library ieee; use ieee.std_logic_1164.all; entity fulladd is port( a, b, cin : in std_logic; s, cout : out std_logic); end fulladd; architecture a of fulladd is signal t1, t2, t3 : std_logic; begin t1 <= a xor b; t2 <= a and b; t3 <= t1 and cin; s <= t1 xor cin; cout <= t2 or t3; end a; t1 t2 t3 문장의 순서는 무관 모바일컴퓨터특강

81 Dataflow Description - Decoder3_8
library ieee; use ieee.std_logic_1164.all; entity decoder38_data is port( d2, d1, d0 : in std_logic; y0,y1,y2,y3,y4,y5,y6,y7 : out std_logic); end decoder38_data; architecture xxx of decoder38_data is signal nd2, nd1, nd0 : std_logic; Begin nd2 <= not d2; nd1 <= not d1; nd0 <= not d0; y0<= nd2 and nd1 and nd0; y1<= nd2 and nd1 and d0; y2<= nd2 and d1 and nd0; y3<= nd2 and d1 and d0; y4<= d2 and nd1 and nd0; y5<= d2 and nd1 and d0; y6<= d2 and d1 and nd0; y7<= d2 and d1 and d0; end xxx; 모바일컴퓨터특강

82 Structural Descriptions
구조적 표현 논리회로의 구성 요소 및 구성 요소간의 연결까지 표현 가장 하드웨어적 표현에 가까움 Graphic Editor를 이용한 고전적인 설계방식과 동일 Component( ) 문을 이용하여 구성 요소 종류를 선언 Component Instantiation을 통해 구성 요소 객체와 객체간을 연결 정의 port map( ) 문을 이용하여 핀들을 서로 연결. 위치결합(positional association) Port문 내의 Signal의 위치순서대로 나열 이름결합(named association) Port문 내의 Signal의 위치순서와는 상관없이 (port문 내의 형식이름=>실제 이름)의 방식으로 결합 모바일컴퓨터특강

83 Structural Description - Andor_2
library ieee; use ieee.std_logic_1164.all; entity andor_2 is port( a, b, c : in std_logic; y : out std_logic); end andor_2; architecture a of andor_2 is component and_2 port( a, b : in std_logic; y : out std_logic ); end component; component or_2 signal t : std_logic; begin U1 : and_2 port map ( a, b, t ); U2 : or_2 port map( a=> t, b=>c , y=>y); end a; and_2.vhd, or_2.vhd는 미리 작성된 상태임. And_2선언 Or_2선언 Component Instantiation 모바일컴퓨터특강

84 Structural Description - Andor_2
library ieee; use ieee.std_logic_1164.all; entity andor_2 is port( a, b, c : in std_logic; y : out std_logic); end andor_2; architecture a of andor_2 is component and_2 port( a, b : in std_logic; y : out std_logic ); end component; component or_2 signal t : std_logic; begin U1 : and_2 port map ( a, b, t ); U2 : or_2 port map( a=> t, b=>c , y=>y); end a; And_2 :위치결합방식 Or_2 : 이름결합방식 형식이름 모바일컴퓨터특강 실제이름

85 Structural description – 4 bits adder
tcout1 library ieee; use ieee.std_logic_1164.all; entity add_4bits is port( a, b : in std_logic_vector(3 downto 0); cin : in std_logic; sum : out std_logic_vector(3 downto 0); cout : out std_logic ); end add_4bits; architecture a of add_4bits is component fulladd port( a, b, cin : in std_logic; s, cout : out std_logic); end component; signal tcout1, tcout2, tcout3 : std_logic; begin U1 : fulladd port map( a(0), b(0), cin, sum(0), tcout1); U2 : fulladd port map( a(1), b(1), tcout1, sum(1), tcout2); U3 : fulladd port map( a(2), b(2), tcout2, sum(2), tcout3); U4 : fulladd port map( a(3), b(3), tcout3, sum(3), cout); end a; tcout2 tcout3 Fulladd.vhd는 미리 작성된 상태임 모바일컴퓨터특강

86 Structural Description - Mux 8X1
Library ieee; Use ieee.std_logic_1164.all; entity mux8_1 is port( a, b, c, d, e, f, g, h : in std_logic; s2, s1, s : in std_logic; y : out std_logic); end mux8_1; architecture xxx of mux8_1 is component decoder3_8 port( a, b, c : in std_logic; d0,d1,d2,d3,d4,d5,d6,d7 : out std_logic); end component; signal t : std_logic_vector(7 downto 0); signal d0,d1,d2,d3,d4,d5,d6,d7 : std_logic; begin U1: decoder3_8 port map( s2,s1,s0,d0,d1,d2,d3,d4,d5,d6,d7); t(0) <= a and d0; t(1) <= b and d1; t(2) <= c and d2; t(3) <= d and d3; t(4) <= e and d4; t(5) <= f and d5; t(6) <= g and d6; t(7) <= h and d7; y <= t(0) or t(1) or t(2) or t(3) or t(4) or t(5) or t(6) or t(7); end xxx; t(0) t(1) t(2) t(3) t(4) t(5) t(6) t(7) Decoder3_8.vhd는 미리 작성된 상태임 Mixed Modelling : structure + dataflow 모바일컴퓨터특강

87 Structural Description – 4bits Mux 8X1
Library ieee; Use ieee.std_logic_1164.all; Entity mux81_4bits is port( a, b, c, d, e, f, g, h : in std_logic_vector(3 downto 0); s2, s1, s0 : in std_logic; y : out std_logic_vector(3 downto 0)); end mux81_4bits; Architecture a of mux81_4bits is component mux8_1 port( a, b, c, d, e, f, g, h : in std_logic; s2, s1, s0 : in std_logic; y : out std_logic); end component; begin U0: mux8_1 port map (a(0),b(0),c(0),d(0),e(0),f(0),g(0),h(0),s2,s1,s0,y(0)); U1: mux8_1 port map (a(1),b(1),c(1),d(1),e(1),f(1),g(1),h(1),s2,s1,s0,y(1)); U2: mux8_1 port map (a(2),b(2),c(2),d(2),e(2),f(2),g(2),h(2),s2,s1,s0,y(2)); U3: mux8_1 port map (a(3),b(3),c(3),d(3),e(3),f(3),g(3),h(3),s2,s1,s0,y(3)); end a; 모바일컴퓨터특강


Download ppt "VHDL의 기본 Lecture #4."

Similar presentations


Ads by Google