30
VHDL 프로그래밍 VHDL 프로그래밍 3. VHDL 설계 단위 학습 목표 학습 목표 Entity, Architecture의 사용법 알기 3가지 하드웨어 기술 방식 파악 하드웨어 기술 방식을 자유자재로 활용 하드웨어 기술 방식을 자유자재로 활용 Process문 사용알기 간단한 VHDL code 작성 하기 2/60

VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Embed Size (px)

Citation preview

Page 1: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

VHDL 프로그래밍VHDL 프로그래밍

3. VHDL 설계 단위

학습 목표학습 목표

Entity, Architecture의 사용법 알기

3가지 하드웨어 기술 방식 파악

하드웨어 기술 방식을 자유자재로 활용하드웨어 기술 방식을 자유자재로 활용

Process문 사용법 알기사용 알기

간단한 VHDL code 작성 하기

2/60

Page 2: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

ContentContent

Entity 선언 및 사용법

Architecture 선언 및 사용법Architecture 선언 및 사용법

Behavioral description

Dataflow description

Structural descriptionStructural description

Process문 사용법

계층적 설계

간단한 VHDL code간단한 VHDL code

3/60

VHDL Design UnitsVHDL Design Units

Entity설계하고자 하는 모델의 외형 즉 symbol을 기y술

ArchitectureArchitecture모델의 기능 즉 schematic을 정의

C fi tiConfigurationEntity와 Architecture의 연결 기능 제공

PackageVHDL에서 공동으로 사용되는 코드의 모임VHDL에서 공동으로 사용되는 코드의 모임Package declaration, Package body로 구성

4/60

Page 3: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

VHDL Design UnitsVHDL Design Units

5/60

Entity declaration syntaxEntity declaration syntax

Entity 선언 양식entity entity name isentity entity_name is

[Generic Declarations]Port DeclarationsPort Declarations

end [entity_name];

genericparameter를 사용한 설계 기능 제공

portport입출력 신호, 즉 pin/ball 정보 기술

6/60

Page 4: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Entity: generic 선언 예Entity: generic 선언 예

tit tit ientity entity_name isGeneric (constant tplh, tphl : time := 5ns;

n te : c nstant is assumed and is n t required-- note : constant is assumed and is not requiredtpha, tplz : time := 3ns;default value : integer := 1;default_value : integer := 1;cnt_dir : string := “up”);

Port DeclarationsPort Declarations end [entity_name];

상수값을 정의하는 부분component instantiation 시 generic default 값을 재정의 가능

7/60

Entity: generic 선언 예Entity: generic 선언 예

8/60

Page 5: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Entity: port 선언 예Entity: port 선언 예

tit tit ientity entity_name isGeneric DeclarationsP rt (signal clk: in std l gic;Port (signal clk: in std_logic;

-- note : signal is assumed and is not requiredq: out std logic);q: out std_logic);

end [entity_name];

선언 형식 : object_name:<mode><type>;object_name: identifier<mode> : in, out, inout, buffer, , ,<type> : 제 1강 자료 참고

9/60

Entity 선언(포트끼리의 연결 예)Entity 선언(포트끼리의 연결 예)

상위모듈

inout

하위모듈

in inoutin or

inout

in orinout

out buffer

out orbuffer

out or inout

10/60

Page 6: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Generic 사용 예Generic 사용 예

tit i

Generic 선언 예

entity reg is-- parameter: width of the data

i ( idth i t 4)generic (width : integer := 4); -- input and output signals

t ( CLK t i td l iport ( CLK, reset : in std_logic; D : in std_logic_vector(width-1 downto 0); Q d l i ( id h 1 d 0))Q : out std_logic_vector(width-1 downto 0));

end reg;g

11/60

Generic 사용 예Generic 사용 예

library IEEE;use IEEE.std_logic_1164.all;entity delay is

signal Ds : std_logic_vector(7 downto 0);begin

entity delay isport( clk : in std_logic;

Din : out std_logic_vector(7 downto 0);Dout : out std_logic_vector(7 downto 0) );

U0: reg generic map (width=>8) port map (CLK=>clk, D=>Din, Q=>Ds);

g ( ) )end delay;architecture str of delay iscomponent reg

U1: reg generic map (width=>8)port map(CLK=>clk, D=>Ds, Q=>Dout);

end str;generic (width : integer := 4); port ( CLK, reset : in std_logic; D : in std_logic_vector(width-1 downto 0);

( ))

end str;

Q : out std_logic_vector(width-1 downto 0));end component;

generic map과 port map 사이에는세미콜론 (;) 이 없다 !!

12/60

세미콜론 (;) 이 없다 !!

Page 7: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Architecture 기술 방법Architecture 기술 방법

하드웨어의 효과적인 기술을 위해 3가지의 기술 방법 제공지의 기술 방법 제공많은 경우 3가지 방식을 동시 사용

Behavioral Description알고리즘 기술 위주알고리즘 기술 위주

Dataflow Descriptionb l 수식 위주boolean 수식 위주

Structural Descriptioncomponent 간의 연결을 기술계층적 설계에 주로 사용

13/60

계층적 설계에 주로 사용

Behavioral DescriptionBehavioral Description

회로의 동작을 behavioral level에서 기술Algorithm 기술에 용이Algorithm 기술에 용이Sequential statement를 주로 사용

process 문을 이용한 기술을 주로 사용

14/60

Page 8: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Dataflow DescriptionDataflow Description

주로 Boolean 수식을 직접 기술단순 로직에 주로 사용단순 로직에 주로 사용Concurrent statement를 주로 사용

process 문을 사용하지 않고도 기술 가능

15/60

Structural DescriptionStructural Description

Component들 간의 연결정보로 회로를표현표현계층적 설계에 주로 사용됨

16/60

Page 9: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

4:1 Mux의 구현 예4:1 Mux의 구현 예

3가지 기술 방법을 이용한 4:1 Mux의구현 예구현 예

각 기술 방법의 장단점 파악 필요과적인 기술 방법의 선택 필효과적인 기술 방법의 선택 필요

i0i1 zi1i2i3

z

i3

sel2

17/60

Behavioral description(4:1mux)Behavioral description(4:1mux)

library IEEE ;use IEEE.std_logic_1164.all;entity MUX41 isport(i0, i1, i2, i3 : in std_logic;

sel : in std_logic_vector(1 downto 0);Z : out std_logic );

end MUX41;architecture behavior of MUX41 isbegin

P0 (i0 i1 i2 i3 l)P0: process (i0,i1,i2,i3,sel) begincase sel is

h “00” > Z < i0;when 00 => Z <= i0;when “01” => Z <= i1;when “10” => Z <= i2;when others => Z <= i3;when others => Z <= i3;

end case;end process;end behavior;

Process문을 주로 사용

18/60

end behavior;

Page 10: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Data flow description (4:1mux)Data flow description (4:1mux)

architecture dataflow of MUX41 is

beginbegin

Z <= ((not sel(1)) and (not sel(0)) and I0) or

((not sel(1)) and sel(0) and I1) or((not sel(1)) and sel(0) and I1) or

(sel(1) and (not sel(0)) and I2) or

(sel(1) and sel(0) and I3);(sel(1) and sel(0) and I3);

end dataflow;

Boolean equation을 표현한 형태임.

C t i l i t문을 주로 사용함Concurrent signal assignment문을 주로 사용함.

19/60

Structural description(4:1mux 구조)Structural description(4:1mux 구조)

4:1 mux 를 2:1 mux들의 조합으로 구성4:1 mux 를 2:1 mux들의 조합으로 구성.

U1U2

D1Y

D1

U2

Y

I3

Z

B

D0S D0

Y

S

I2A

D1

U0

YI1 D1

D0

Y

S

I1

I0

20/60

sel(0) sel(1)

Page 11: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Structural description(code)Structural description(code)

architecture structure of MUX41 iscomponent MUX21p

port ( D1, D0, S : in std_logic;Y : out std_logic );

end component;end component;signal A, B : std_logic;

BegingU0 : MUX21 port map (D0=>I0, D1=>I1, S=>sel(0), Y=>A);U1 : MUX21 port map (D0=>I2, D1=>I3, S=>sel(0), Y=>B);U2 : MUX21 port map (D0 >A D1 >B S >sel(1) Y >Z);U2 : MUX21 port map (D0=>A, D1=>B, S=>sel(1), Y=>Z);

end structure;

21/60

Configuration 선언(mux41)Configuration 선언(mux41)

configuration config_struct of MUX41 is

for structure -- archi. name

for ALL : MUX21for ALL : MUX21

use entity WORK.MUX21( MUX21_arch)

end for; --- entity, archi. name

end for;end for;

end config_struct;

22/60

Page 12: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

2:1 Mux2:1 Muxlibrary IEEE; use IEEE.std_logic_1164.all;entity MUX21 is

port ( D0 D1 S : in std logic; Y : out std logic );port ( D0, D1, S : in std_logic; Y : out std_logic );end MUX21;architecture MUX21_arch of MUX21 isbegin

process(D0, D1, S) beginbegin

if (S = ‘0’) then Y <= D0;else Y <= D1 ;

end if;end process;

end MUX21 archend MUX21_arch

23/60

ConfigurationConfiguration

configuration <identifier> of <entity_name> is

for <architecture name>for <architecture_name>--

d fend for;

end;end;

VHDL model 사이의 연결 작업 수행Entity와 Archhitecture 사이의 연결 작업component와 Entity-Architecture 사이의 연결 작업

Simulation 환경에서 주로 사용

24/60

논리 합성 시에는 제한적으로 지원되거나 지원 안됨

Page 13: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

VHDL Design Unit 예VHDL Design Unit 예

25/60

Process 문의 실행Process 문의 실행

Architecture body 내의 구성 요소Architecture body 내의 구성 요소

ti l

process

tsequential

statement

concurrentstatement

...

sequential

......

statement concurrent

statementstatement

26/60

Page 14: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Entity 선언Entity 선언

A

B Xt1

BC

t2C

CA

Yt2

t3t3

Entity first isEntity first isPort (A, B, C : in std_logic;

X Y : out std logic);X, Y : out std_logic);End first;

27/60

Architecture bodyArchitecture body

architecture netlist of first isbegingprocess (A,B,C)variable t2 : std_logic;g ;begint2 := B and C;X <= (A and B) or t2;Y <= t2 or (C and A);

end process;end netlist;

What happens?

주의: 변수는 process문 밖에서 쓸 수 없음!!

28/60

Page 15: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Y<=… outside of processY<=… outside of process

hi li f fi iarchitecture netlist of first is

begin

process (A,B,C)

variable t2 : std_logic;

begin

t2 := B and C;

X <= (A and B) or t2;

end process;p ;

Y <= (B and C) or (C and A);

end netlist;end netlist;

No Problem?29/60

No Problem?

To share AND gate ?To share AND gate ?

architecture netlist of first is

Signal t2 : std logic;Signal t2 : std_logic;

begin

t2 <= B and C;t2 <= B and C;

process (A, B, t2)

beginbegin

X <= (A and B) or t2;

d end process;

Y <= t2 or (C and A);

d liend netlist;

30/60

Page 16: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Process statesProcess states

Three states of process statements

활성화 상태대기 상태 실행 상태

event

발생

process

선택

process 실행완료

31/60

Process 문에서 waitProcess 문에서 wait

Process 상태: wait activation run

Event 표시방법: sentivity list or wait문Event 표시방법: sentivity list, or wait문

32/60

Page 17: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Wait 문의 종류Wait 문의 종류

wait on <sig_list>;

sig list 의 signal들의 값의 변화를 기다린다-- sig_list 의 signal들의 값의 변화를 기다린다. (suspended) sensitivity list와 동일!!

wait until <condition>;wait until <condition>;

-- condition이 만족될 때까지 기다린다. (suspended)

it f <ti >;wait for <time>;

-- 주어진 시간동안 기다린다.

( d d f fi d i d i )-- (suspended for fixed time duration)

wait ;

-- 무한대기 상태가 된다.

33/60

Wait 사용 예Wait 사용 예

wait on A,B until en = ‘1’;

-- A 또는 B 신호에 event가 발생하고 en=‘1’이되면

-- 대기상태에서 깨어남

wait on A B until en = ‘1’ for 10 ns;wait on A,B until en = 1 for 10 ns;

-- A 또는 B 신호에 event가 발생하고 en=‘1’이되거나

-- 10ns가 경과하면 대기상태에서 깨어남

34/60

Page 18: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

실제적인 사용 예 (wait)실제적인 사용 예 (wait)

P2: process

begin

wait on CLK until clk = ‘1’;wait on CLK until clk = 1 ;

Q <= D;

end process;

위 문장이 구현하는 로직은?위 문장이 구현하는 로직은?

35/60

다양한 Process문 구현다양한 Process문 구현

두 process문의 차이는?

P3: process

begin

P4: process

beginbegin

wait on A,B,C;

begin

Z <= A or (B and C);

Z <= A or (B and C);

end process;

wait on A,B,C;

d ;end process; end process;

36/60

Page 19: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

다양한 Process문 구현

두 문의 차이는?

다양한 Process문 구현

P4: process두 process문의 차이는?

P5: process (A,B,C)

beginbegin

Z < A (B d C);begin

Z <= A or (B and C);Z <= A or (B and C);

wait on A,B,C;end process; end process;

초기에 process 내부의 모든 문장들이 순차적으로 한번씩실행된 뒤에 대기 상태에 들어감.

sensitivity list는 wait on 문을 대신함i i i li 와 i 문 동시 사용 오류 발생

37/60

sensitivity list와 wait 문 동시 사용 오류 발생

Process 문 간의 실행 의존관계Process 문 간의 실행 의존관계

P7: process (b,c)

beginprocessbbegin

z <= b and c;P7

z

b

end process; c

d

P8 : process (z,a,c)

begin

processP8

begin

d <= a xor z;a

e

e <= not c;

end process;

38/60

end process;

Page 20: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Delta timeDelta time

T0 : y <= b and c; 2 delta 시간 소요됨T1 : z <= not y; b,c 변화 z변화

하나의 신호할당에하나의 신호할당에

1 delta time 소요b

zy

Delay 지정

S f 10

c z

S <= a after 10 ns;

39/60

파형 생성 신호 할당문파형 생성 신호 할당문

A <= ‘1’, ‘0’ after 5 ns, ‘1’ after 12 ns ;

0 5 ns 12 ns

40/60

Page 21: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Delta 시간 고려 signal 변화Delta 시간 고려 signal 변화

P1: process (a,b,c)

variable x,y,z : std_logic;

begin시간 a b c d

t ‘0’ ‘1’ ‘0’ ‘0’x := b;

y := x;

t 0 1 0 0

t+Δ: ‘1’ ‘1’ ‘0’ ‘0’

a <= y;

c <= a;

t+2Δ ‘1’ ‘1’ ‘1’ ‘0’

t+3Δ ‘1’ ‘1’ ‘1’ ‘1’

d <= c;

z := y;y

end process;

41/60

Multiple driverMultiple driver

두 hit t 의 차이는?

architecture con of architecture seq of drv is

두 architecture의 차이는?

architecture con ofdrv is

architecture seq of drv is

beginbegin

A <= B;process(B,C)

beginA < B;

A <= C;begin

A <= B;end con; A <= C;

end process;end process;

end seq;

42/60

Page 22: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Multiple driverMultiple driver

수정된 d

( )architecture oneprc of drv is

수정된 code

P3: process(B, C)begin

architecture oneprc of drv isbeginP3: process(B C)

gif(B = ’1’) then

A <= B;

P3: process(B,C) begin

A < BA < B;

elseA <= C;

A <= B;if ( B = ‘1’) then

A <= C; end if;

d

A <= C;end if;

end process;end process;end oneprc;

43/60

end oneprc;

Multiple driversMultiple drivers

diff t 예architecture twoprc of drv is

different process 예

beginP1: process (B) beginbegin

A <= B;end process;. . .P2: process (C) beginbegin. . .

A <= C;end process;end twoprc;

44/60

Page 23: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Process 문 관련 요약Process 문 관련 요약

Signal 할당 문에서 RHS signal의 value는 현재 값, 또는 event 발생 시의 값을 의미또는 event 발생 시의 값을 의미

Signal의 update는 end process에 가서야 실제assignment가 일어남 (또는 정해진 시간 후에)assignment가 일어남. (또는 정해진 시간 후에)

한 process 내에서의 같은 signal에 대한i t는 l t 만 lid함assignment는 last one만 valid함.

45/60

계층적 설계와 Configuration계층적 설계와 Configuration

Component declaration (컴포넌트 선언)

Component instantiation (컴포넌트 실체화)

Generate 문Generate 문

46/60

Page 24: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

C t 사용 계층구조형성Component 사용 - 계층구조형성

architecture AA of A iscomponent B -- component declarationcomponent B component declaration

port ( ... );end component ;end component ;...B i i i iBegin -- component instantiation U0 : B port map ( ... ) ; ... -- U0 instance nameend AA;end AA;

47/60

Port associationPort association

positional association :

port map (signal1_name, ... , signalN name)signalN_name)

named association :

port map(port1 name=>signal1 name portN(port1_name >signal1_name, ... ,portN_name => signalN_name)

48/60

Page 25: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Port association 예Port association 예

U1 : DFF port map (IN1, CLK, OUT1, OUT2);OUT2);

U1 : DFF port map (D=>IN1, CLK=>CLK, Q=>OUT1, QBAR=>OUT2);

U1 : DFF port map (D=>IN1 CLK=>CLKU1 : DFF port map (D=>IN1, CLK=>CLK, QBAR=>OUT2, Q=>OUT1);

U1 : DFF port map (CLK=>CLK, D=>IN1, Q=>OUT1, QBAR=>OUT2);, )

49/60

연결되지 않는 포트 기술연결되지 않는 포트 기술

Named association

U1 : DFF port map (D=>IN1, CLK=>CLK, Q=>OUT1 QBAR=>open);Q >OUT1, QBAR >open);

Positional association

U1 : DFF port map (IN1, CLK, OUT1, );

50/60

Page 26: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

4 bit adder 덧셈기의 구조4 bit adder 덧셈기의 구조

Adder4

Fulladder1 Fulladder1Fulladder1Fulladder1

HA1 OR2 HA1 OR2 HA1

HA1

OR2 HA1

HA1

OR2

HA1 HA1

51/60

OR2OR2

library IEEE;use IEEE std logic 1164 all;

architecture beh of OR2 isbeginuse IEEE.std_logic_1164.all;

entity OR2 is -- 2 input OR gate

beginprocess(i1 , i2) beging

generic(delay : time := 2 ns);port(i1, i2 : in std_logic;

beginz <= ‘0’ after delay;if(i1 = ‘1’ or i2 = ‘1’) then

z : out std_logic);end OR2;

if(i1 1 or i2 1 ) thenz <= ‘1’ after delay;

end if;end process ;end beh;

52/60

Page 27: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

HAHA

lib IEEElibrary IEEE;

use IEEE.std_logic_1164.all;

entity HA is -- half adder module

generic (delay : time := 3 ns);generic (delay time 3 ns);

port ( A, B : in std_logic; Sum, Carry : out std_logic );

end HA;end HA;

architecture dataflow of HA is

begin

Sum <= A xor B after delay;

Carry <= A and B after delay;

end dataflow;

53/60

end dataflow;

FullAdder1FullAdder1component OR2library IEEE;

use IEEE.std_logic_1164.all;entity FullAdder1 is -- 1 1bit full adder

component OR2 generic (delay : time := unit_delay);port ( i1, i2 : in std_logic;

)y

generic (unit_delay : time );port ( X, Y, Cin : in std_logic;

Sout Cout : out std logic );

z : out std_logic ); end component ;signal t_s, t_c1, t_c2 : std_logic ;Sout, Cout : out std_logic );

end FullAdder1;beginH0 : HA port map (A=>X B=>Y

architecture struct of FullAdder1 iscomponent HA

i (d l i i d l 2)

H0 : HA port map (A >X, B >Y, Sum=>t_s, Carry=>t_c1);

H1 : HA port map (A=>t_s, B=>Cin, Sum=>Sout, Carry=>t_c2);

generic (delay : time := unit_delay * 2);port ( A, B : in std_logic;

Sum, Carry : out std_logic);

, y )u_or : OR2 generic map (delay => 1 ns)port map (i1=>t_c1, i2=>t_c2, z=>Cout);end struct ;

end component ;end struct ;

54/60

Page 28: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

add4add4

hi f Add 4 ilibrary IEEE;use IEEE.std_logic_1164.all;entity Adder4 is

architecture struct_top of Adder4 iscomponent FullAdder1

generic (unit_delay : time := unit_delay);t ( X Y Ci : i td l i ;

entity Adder4 isgeneric (unit_delay : time );port ( DA, DB : in std_logic_vector(3

downto 0);

port ( X, Y, Cin : in std_logic;Sout, Cout : out std_logic );

end component ;signal t : std logic vector (2 downto 0);Ci : in std_logic ;

S : out std_logic_vector(3 downto 0); Co : out std_logic );

d Add 4

signal t : std_logic_vector (2 downto 0);beginU0: FullAdder1 port map (X=>DA(0), Y=>DB(0),

Cin=>Ci, Cout=>t(0), Sout=>S(0));end Adder4;

Cin Ci, Cout t(0), Sout S(0));U1: FullAdder1 port map (X=>DA(1), Y=>DB(1),

Cin=>t(0), Cout=>t(1), Sout=>S(1));U2: FullAdder1 port map (X=>DA(2), Y=>DB(2),

Ci >t(1) C t >t(2) S t >S(2));Cin=>t(1), Cout=>t(2),Sout=>S(2));U3: FullAdder1 port map (X=>DA(3), Y=>DB(3),

Cin=>t(2), Cout=>Co, Sout=>S(3));end struct top;end struct_top;

55/60

Config DeclConfig. Decl.

configuration cf_adder of Adder4 isfor struct_topfor all : FullAdder1for all : FullAdder1

use entity work.FullAdder1(struct);for structfor all : HA

use entity work.HA(dataflow);end for;end for;for all : OR2

use entity work.OR2(beh);y ( )end for;

end for;end for;end for;

end for;end cf_adder

56/60

_

Page 29: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Generate문 사용한 add4Generate문 사용한 add4

architecture struct_gen2 of Adder4 iscomponent FullAdder1

port ( X Y Cin : in std logic;

g2 : if i = 3 generateU1: FullAdder1

portmap(X=>DA(0),Y=>DB(0), port ( X, Y, Cin : in std_logic;Sout, Cout : out std_logic );

end component ;signal t :

p p( ( ), ( ),Cin=>t(3),Cout=>Co, Sout=>S(0));

end generate;g3: if (i > 0) and (i < 3) generatesignal t

std_logic_vector (2 downto 0);beging0 : for i in 0 to 3 generate

U0:FullAdder1 port map(X=>DA(i),Y=>DB(i),Cin=>t(i),Cout=>t(i+1),

Sout=>S(0));g gg1 : if i = 0 generateU1: FullAdder1 port map(X=>DA(0),Y=>DB(0),Cin=>Ci, Cout=>t(0),

S S(0))

Sout >S(0));end generate;end generate;end struct gen2;

Sout=>S(0));end generate;

end st uct_gen

57/60

Generate문 사용한 add4(v2)Generate문 사용한 add4(v2)

architecture struct_gen ofAdder4 is begin

component FullAdder1

port ( X, Y, Cin :

gen0 : for i in 0 to 3 generate

U0: FullAdder1 port map(X >DA(i) Y >DB(i)

port ( X, Y, Cin

in std_logic;

Sout Cout : out std logic );

(X=>DA(i), Y=>DB(i), Cin=>t(i), Cout=>t(i+1), Sout=>S(i));Sout, Cout : out std_logic );

end component ;

signal t :

Sout=>S(i));

end generate ;

t(0) <= Ci;signal t :

std_logic_vector (4 downto0);

t(0) <= Ci;

Co <= t(4);

d t t ;0); end struct_gen ;

58/60

Page 30: VHDL03 chapter1.ppt [호환 모드] - dasan.sejong.ac.krdasan.sejong.ac.kr/~dihan/vhdl/VHDL03_chapter1.pdf · VHDL 프로그래밍 3. VHDL 설계단위 학습목표 Entity, Architecture의사용법알기

Add4를 위한 testbechAdd4를 위한 testbech

Add4를 component로 포함함.

Cf_add : add4에 대한 config.을 사용함함.

59/60

Add4에 대한 testbench(tb)Add4에 대한 testbench(tb)

library IEEE;use IEEE.std_logic_1164.all;use IEEE.numeric_std.all;

beginUUT : Adder4 generic map

(unit_delay=>unit_delay)use IEEE.std_logic_unsigned.all;entity tb is end tb;architecture sim of tb is

port map (DA=>I1, DB=>I2, Ci=>Ci, S=>S, Co=>Co);

Ci <= '0', '1' after unit_delay * 60 + 10 ns;processcomponent Adder4

generic (unit_delay : time);port ( DA, DB :

i td l i t (3 d t 0)

process begin

I1 <= (others=>'0');I2 <= (others=>'0');in std_logic_vector(3 downto 0);

Ci : in std_logic ; S : out std_logic_vector(3 downto 0);Co : out std logic );

I2 <= (others=> 0 );for i in 1 to 15 loop

for j in 1 to 15 loopwait for unit delay * 20+1 ns;Co : out std_logic );

end component;signal I1, I2, S : std_logic_vector(3

downto 0);

wait for unit_delay * 20+1 ns;I2 <= I2 + "0001";

end loop;I1 <= I1 + "0001";downto 0);

signal Ci, Co : std_logic;constant unit_delay : time := 1 ns;

I1 < I1 0001 ;end loop;

end process ;end sim;

60/60