§7.1. :\16 hloh hoa trcn mtle call true
Cae 11li.ICh .... 6 lhuang dU'~K hiJu (lien theo tn¢1 cAu Inic phil.n cAp Gle
th':11lh phfin. Moi thi:mh phAn c6 t~IP ht,1p cae crlng d6 lien ket \'oi d.c thanh
phan klute. M(lt 1hi61 kc haa g6m mot t(lp hap nhling phi0n h,in cU.;! m:.teh xci Hen nhCing muc 09 chi lict khac nhau. MQt phicn b;111 ll1i.\ch tren ml?t mlfe chi
tie"! Cl,l the Cll<1 thiel kf duVe tao th~tnh tit de mCl tii nhung phdn It'r !ren mtle
cbi tiel d6 va nhD'ng ph,i.n tu nity dU<;1C lien ket Ih()og qua cae tin hi¢u \'.Ii de
cong ella chung xel !rcn mile chi tiet nilY. Khi ruo 1a nwch b~ng ng6n ngt1'
VHDL, \'i~c ph{lIl cap Ihiel ke duae tlwe hiGH thong qua c{le khai hclO th;lllh
ph;i.n nwch va cAe bieu thue m6 ta phien bAn ella thunh phall.
Khi m6 til. hanh vi ella nwch. thanh phiin Cd s0 ella hilnh vi Ii\. de call
\<';nh m6 ta qua tdoh ( process ), cfm khi ma ta dIll true, don vi co so' se l~l dc cau I~nh m{l til phien bAn ella Ibanh ph,in. Nhung cau I¢nb ma I,i qua
Irlnh d. cac CUll I¢nh ma t.1 phicn bi.ln Ihanh phfin dn phi.1i dUge g(~li \'ito lrung Ihi.ln ella mt'J Ii.i kie~n true. CAe m6 t.;i. kien true sc co ehue nung phfm tach d.c dan \'j Ihi-:t le. MQt trong nhung d(tc tll1h quan tl"9ng ella VHDL li\
ngon ngu nily eho phep 1116 hinh hmi Ihit't kc treo nhung mlre d6 trLrll Ilt'<:mg
va chi tiC:I khae nhau. N6i mOt d.ch khac. m(lt bicu di~n kie'n true c6 the haa gam c;le dll I~nh m() t:\ lJml Irlnh. cae GIU ICnh ma I,i thimh philO.
1. Khai hao thanh pluln
M()t kicn true co th~ sU: d\,l11g nhi1'ng tiwe the da dUQ"e m(') ti.'t m()t Ci.tch d(lC
l,~p. NhLrng tl1l/c th~ nay dU0c chua trong tlllI vi~n thiet ke V~l co the d1\'(/( Slr
dung Irong de khai bao th~\Jlh phal1 va nhLmg cau I~nh m6 ti.l cac phi":n bi'tn
cua thZll1h phAn. Trong phtin m6 tii eua thiet kc, moi cau I~nh khai h<.lO Ib:mh
phAn 11J'l1ilg {t'ng \'('ii m(lt thlfC the. D~ e6 Iht ma phong ho~\e t6ng IH!P Il1QI thie"t kc min d6, th~rc th~ va cae m6 til ki6n true ella tfil d. de thanh ph[ll1
lTIi;leh phi.li duqc bien d~eh tru6c trong tluI vi¢n thiet ke.
Trang lrinh It! 1116 phong ho,Jc t6ng hQ'p thie~1 kc. Ihl!c th~ vl\ m6 lil kicn Irue dcii voi n19i thanh phall ph<ij dUQ"c bien d(ch trang tim vi¢n Ihiet ke.
Cach thuc 1116 t,\ cau Irue eua thanh phan eling tuong III nhu each thlre 1110 t,illwc Ihe. Truac het de 1116 ta cau tnk eua thanh philn, chLing ta phui xae djnh r6 cae giao di¢n eua thimh phan. Cic giao di¢n nay chinh la eae chrbng tin hi¢u vao vii ra khai thanh phan. TrLfCte khi duqe su dYllg, cae thanh phan phai du~'iC khai bao !TI¢t eaeh tuO'ng minh thea quy t~c eu phap nhu sau:
component < ten_lhanh_phan >
[port « khaLbao_cong_cl)c_ho »1
end cumponent;
Vi dl:!, ehung ta m6 t;i thanh ph,in eua h¢ C(lllg d<.iy du fullAdJcr. I3Q e(mg Jay uu 1l1(;>1 bit ell ha uUdng tin hi¢u vao:
Duling vao :\, n Ia uuong tin hi¢u tUdng LIng voi hang ehtl s6 1\)11' k
ella hal so h'-.\Ilg;
DU'dng \'i:10 Cin Ia duong tin hi¢u tuffilg ll'llg \'6i hi:mg gia Ir! nh6 tv hang ehu ~6 thu k-I vao hang chu so thu k;
va hai uuO'ng tin hi¢u ra:
DU(J'ng tin hi¢u Sum Ia tong cua cac duang tin hi~u A, B, Cin:
Duong tin hi¢u Coul 1a hang gia trl nila Ill' hang ehtl so thtl' ~ \'210 hang chu s6 thd k+ I.
Ye m~lt <.:ilu true. neu xet tren mile 16gic, b¢ c¢ng d,Iy du I bit du('ic \,.10 thanh tu cac philn tLI' AND, OR \'a XOR. Trell sO do cau Irue, b(l ujng 1121:' (hrqc 1110 ta trcn hlnh 7.1 b. Nhu v,)y, b¢ eQng g6111 eo hai ph,in tu X()R, hai pb,tn tU' AND va Hl¢t phfin tu OR. Cae ph<in tu nay d~u III nhu'ng phan tt"r <.;6 hai dAu VilO va mt)i ph,tn tu logic se (tuqc !TI6 t.\ btll1g cae khai bao th2mh phan nhu ulf6i uflY.
B
Cill
component Or1 ___ .f!atc
port ((0, I \: in STD U)(jIC; 0: out STD_LOCilC); end component:
compullcnt XOl'_g,I\C
port (iO.II: in STU UKiIC, (). out SID_UKiIC), end component
component Alldl_galc
port (10, II: in STD_LOCilC: 0: out STD_LO(iIC);
elld C0I111101H'nt:
('<Ie th;'lllh ph:IIl 1ll() [,'t Irong \..i.Yn Ink ell the (hfoe l,.h('ji lao h:lI1g (,Ie (,Ill k'nh 1'.lll pilie]} b,'llI Ih:l1lh ph~lll. T,li CIC \'1 11'1 dunc 1',lll ra. phlen h"lll ella Ih:llIh
ph~1ll dl(l/c hi2u dl~n Ih(mg 'ILIa (;IC Ihu(lC tinh hen ng():11 nhL!' lcn, kieu Iw,h.: illf('mg llll ill~'Ll lal de e(lng \'iHl/ra. llhung de 1111 hl0u hen Ir(lng th<lllh ph'\ll klH)llg dune hieu dien Il!'(\ng 111ll1h. Cic e,"al I~llh kh('l'i [,.10 ~inh ra de ph!Cll
hall ell.! Ih:lll!t ph;\n \':1 kc't n(li ch(illg d2' 1,.10 nell tnl)1 danh _~,ieh li('ll kd L"ll,l '1]11::" 1..0
Chl knh lao phi('l1 h,lll Ih,lllh ph:ill e6 C[ILl Inie eLi phjp nlHl' ":IU':
< nh;'in_klHl'i_ tao >:< knJh:lllh_philll >
port map ( [ < tl:l1J()ng _ttl..:_ hn > => [ < hleu link> 1, [ < tL'II __ ,,'(lllt:_CllC_h(:l > ---,-> 1 < bi2u th{re > \ ):
Trollg d6, < llh;"in_khuL_ t:lll > 1:\ 1011 ella phicn h,in \'Lra llLrqe lao r,1 ula
th:l1llt ph:\Il. Mtll C.'lll 10nh qo phll'll h:tn Ih:lIlh philn IUllll ph,'li (1uae kl-'1l1 \'('ii
lll(l! nh:ln _kh(1i_-,ao. eie nhJn 11:1) s': dU\K 111;1111 eltie'tl 16i Imng de (ill! hlnh eua Ih:lllit ph:ll1.
CYu Ink port map ,ll1h :-"'.1 cil' cling cLla ph~ln tlr \ilo dlc lin hJ~u. Anh ,'<,1 n:IY c{l Ihe !tiel! nhLT \'I¢C 10..0'1 n6i c6ng luang Ll'llg eLla ph:in ILl' \':10 dUt)'ng lill hieu. ek e{)n& du'(!c m() 1,\ Irong kiwi h:IO Ihi\llh phein 1:\ nilll'!lg e6ng cue hll.
Iln.rc. Trong C.lC cilu l¢nh 1, .. 0 phi~ll Ixin thanh ph'lll, ci'u tnk pOl'1 IllHp <1(11 IU"lmg Crng mbi Cl)ng tlll.re eua phien h,'l11 v6i mol cl'lng cuc b() clla Ih2lnh ph:in. i'-1lll c(ing tlurc pllai Iii c16i lUQ"ng dang f{1I lii~;II. Trong ngl'lll ngO: VHDL clua I"a hai phuo'ng phCtp ,inh xa de C{)ng eye h¢ \';10 e,le eong th~rc: ,Iuh X,_l then
v~ trf V~l ,inh Xii then ten.
a) b) Cin A .. ~~--\D- c) BTHL>--t-"~ I~D- ~-!:2~ Sum
lIillh 7.2, ClLl tnie pil,ill C[lp ell,\ b(l e(lllg mol hJt: <1) C~\lI tnie DO 1l1f.\ tlillg IlH'1t hll.
h) \:1)-" dUllg be) c(JIl¥ day elll llH')! bit tir e,ie b6 Illfa tong; e) elll tic'"1 h(i e(lllg day till
lll(ll hit tlf de pkilllLf lo~le AND. OR. XOR.
Khi slr ch.tng anh Xl.! then vi Iri. chung ta dua ra danh s,kh C,IC tin hi~Ll tU{ll1lhco dung tr,~lliu l11a ecing dUQ"c kh<u belo.
Doi v6i tru6ng hcm unh xa theo len, chung ta SLr dl.l1lg cfiu true ,\nll xa
tuang minh d{lt tlf(ing ling moi c(:)ng w'.li d.e tin hicu tlll.rc: < kll_cong_cuc b(l>::::> < ten tin_hleu thuc >.
Chung la hay xci VI d,1 ml'l d. c,i'u true cLla h(~ 11I1a tong 111l)1 bil. trong d6 h¢ c(mg duqc lao thanh ttl de philnllt k)gic AND. XOR Iheo s(1 cl6 Ircll hlnh
7.2a.
an:hitl'l'turc Insl of IlallAd(\.:r is componcnt Xnr2
port ( 10, II: in STD_LOGIC: 0: out STD __ L()O\C ): cnd component;
component And2
port (10, ll: ill SrD LUCile. o. out STD_LO(IIC 1. end cumponenL
hq,!,in
(II: Xor2 port Illap ( A, n, Sum ):
e;2: And2 port Ill<lp ( 10 => A, II => It 0 -=> COlli ):
l'nd In,,!:
Trong VI dl,l 11;1)', rh1Cll Ixtll Ci\ clla ph:il1 Ill' Xor2 c6 CitC ct'ing dw,J"c ,tnil
\',1 Ihl'O \'i Iri \'ito dc dUCfng lin hi¢u A. B \',1 Sum: c6n phicn b,in (;2 CUd
ph,\l1 Itl' And2 dlf(~'C ,inh xa wong 1l1111h Iheo 10n ella e(;ng n,lC hCl \'it dll'(\ng
lin hicll.
rhCmg 111tfci11g, m6i th:lllh rh:in ,,13 Ihe: hien 111\)1 Ihut Ihe' d6c \;1r cLla Ihll,'t k0', nlm \',~y, CitC rhicn han eua th:lIlh ph~ill _"l'- lao nell de kip ph:ln C[lp ClI,l 111lel f..('. Dlcu nil)' ChHlC 1l111lh hOd tren hlnh 7.2. Trnng VI lil.l ll~ty chung IiI
IllSy du Inlc ella Ix) Cl~llg (hlY (hi mr)1 hft du'Ot' xtty ch..rng Iren cO" _,,(')' Clla 11(1
!lira IC'ing 1ll1)1 bil d ph:lllILt' OR ( hlnh 7.2b ). Trong kill d6, b6 nU'a IC)ng Illll\ hit cling l'6 Ille du'()C wi 1:\ m()1 thue tile del( I:tp \',\ C() d"u tnk' (hl'()c \,.10
th:lIlil 11'1' dc ph'lll tlf A:-.iD \':'t XOR ( hlnh 7.2i1 ). NhtI \',:IY thi61 ke' hi:) c(1I1,g
l'() Ille dlf(lC hieu dl':n Ihen h~\I 1()'[1: 16p c.:iL- ht) Illl'a t(ing v6'i ph[in Ill' O[{ \':\
kyp clll 11(,'t \'6i CiiL- phdl] l\f \(l~ic AND, OR, xnR.
Clll kllh kitui (:.tll G:Il<..'rall' 1;\ dLl 1¢llh song ,,>Ollg dll\K d!nh n~hl;1 b'::n trung de ki('n Irlic d dU'CK dllllg ,1': 1116 I •• ell' pllil'n ball thilllh pll[il1, Cill knh Generate c6 C;tll Inlc ell ph;ip nhll' ~all:
< nhan_kh(~i_',.\o > : < so __ d6_khi1i __ 'i.IO > generate
I < dCJ;\u_l¢nll_sollg_~ong > I
Trong ng.{lIl ngl-r Vl-IDL. e6 hai loa] so (U) kh(1i t'.IO: s(1 do kh()'i tao for \'21 sO'
(It) kh<\'i 1,.10 if.
212
So' d{; for tilIng de IllO t,i dc ei[U truc co tl11h quy IU':It. SCi till 1121)' (ilra
ra cue tham ,,6 kh()'i 1',10 \'21 ute bU{J"c I~\p. Cie tham :0,(\ khc)'] {'.Io kh6ng c:in ph"ll khai \XIO \ru'6e. (ji,) tri eLm chung kh(lJlg th~ g,l11 ho(1C Inly~n ra ngoill c:iu In'lc kiwi lao 11l'l.C till VIIDL eho phcp sLf dl,lIlg dU'lllg. hen Ir()n~ Celli laic.
('oUI ~- FA(3) FA(2) Z(2) FA(1) I !.II) FA(O) /.(0)
lIinh 7 .. l XiI)' dll'llg h6 C·('Il).!. b<lll hllllr c,ic btl l"OIl~ (LIY tiLl l\Illl bit
'Il'
Vi duo h0 Cllng h<"in bil co th~ dU'i)"c x,'ty dung Ill' h6n b() u)ng d:i.y du m(\1
hilll1l'o ..,(~ d{) IrCll hlnh 7.3. l\6u slr dung du kllh kh('l'i (an \'6i 'i(~ (ki for
«I'll trele elta h(l U:lllg b(ill hll so: dlf(iC 1116 1,'[ nlur sal!: architeclun: (iell hlr of FuilAddcr4 i!';
signal X. y, Z : STD_LO(iIC_ VECTOI{ ( 3 downto () ):
si~llal C"a' : ,m 1/)(,1(,:
,<;ignal fmp . STD_J.DCiIC_ VECTOR ( 4 downto 0 1:
component full:\ddcr
port( A, B, C: in STD_LOCiIC:
S. CO: out STD_LOUIC):
end component:
he~in
Tmp ( 0 ) <= .()';
li: for I in 0 to ~ generate
FA: fu!!Addcr port map ( X( I ). Y( I ),
Tmp( I ). Z( I ). Tmp( 1+ I ) ): end gener<lte;
Cout <= Tmp( 4 );