You are on page 1of 22

Chng 2

THIET KE MAY TRANG THAI BANG LU O MAY TRANG THAI


I. LU O MAY TRANG THAI: Ngi ta con goi he tuan t la may trang thai thuat toan (ASM - algorithmic state machine) hay n gian hn la may trang thai (SM - sate machine), ay ta goi tat la SM. Lu o SM c tao bi cac khoi SM; moi khoi SM mo ta hoat ong trong 1 trang thai. - Trang thai cua he thong c bieu dien bang mot Hop trang thai (state box). Hop trang thai co the cha mot Danh sach xuat (output list), Ma trang thai (state code), Ten trang thai (state name), Hop quyet nh (decision box), ieu kien trong hop quyet nh la mot bieu thc Boole, Hop xuat theo ieu kien (conditional ouput box) cha danh sach cac bien xuat theo ieu kien.
Ten trang thai Danh sach xuat trang thai nay Hop ieu kien T Danh sach xuat theo ieu kien X xxx ng vao khoi ASM Ma trang thai Hop trang thai

ieu kien

F Hop xuat theo ieu kien

Cac ng ra en cac khoi ASMkhac

- Mot khoi SM cha chnh xac mot hop trang thai cung vi cac hop quyet nh va cac hop xuat theo ieu kien lien he vi trang thai o. Mot khoi SM co chnh xac mot ng vao va mot hoac nhieu ng ra. Mot ng dan i qua khoi SM t ngo vao en ngo ra c goi la ng dan lien ket (link path).

Theo hnh ta co: khi vao trang thai S1, cac gia tr ra Z1 va Z2 bang 1. Neu cac gia tr vao X1 va X2 eu bang 0, Z3 va Z4 cung bang 1, va cuoi thi gian trang thai, may i vao trang thai ke qua ng ra 1. Ngc lai neu X1=1 va X3=0, gia tr ra Z5=1 va i vao trang thai ke qua ng ra 3.

- Khoi SM co the c ve bang nhieu dang khac nhau.

- Mot lu o SM co the bieu dien mot he to hp khi ch co mot trang thai va khong co s thay oi trang thai xay ra. Z1 = A + ABC = A + BC

- Ta phai tuan theo mot so qui tac nhat nh khi xay dng mot khoi SM. * Vi moi ket hp cac bien vao hp le phai co chnh xac mot ng ra c nh ngha. ieu nay la can thiet v moi to hp vao c cho phep phai dan en mot trang thai ke duy nhat. * Khong cho phep co ng hoi tiep noi trong mot khoi SM.

(a) Sai

(b) ung

- Khoi SM co 2 dang: song song va noi tiep

Ta co the chuyen de dang gian o trang thai cua may tuan t sang lu o SM tng ng.
S0 Za S0 Za X 00 0/0 0/Z1
1

1/0 S1 Zb

1/0 S2 Zc

1/Z2

0/0

S1 Zb X

01

S2 Zc
0

11

Z1

Z2

Ta khao sat gian o nh th cho lu o SM hnh tren vi chuoi vao X=1, 1, 1, 0, 0, 0. Trong th du nay, tat ca cac thay oi trang thai xay ra ngay sau canh len cua xung nhp. V cac bien ra Moore (Za, Zb, Zc) phu thuoc vao trang thai, chung ch co the thay oi sau mot thay oi trang thai. Cac bien ra Mealy (Z1, Z2) co the thay oi ngay sau mot thay oi trang thai hoac mot thay oi gia tr vao. Trong bat c trng hp nao, tat ca cac gia tr ra se co gia tr ung cua chung canh tch cc cua xung nhp.

II. CAI AT LU O MAY TRANG THAI: Viec cai at (realization) lu o SM la tm c phng trnh cua cac bien ra va cac bien trang thai ke tiep. Cac bc thc hien nh sau: - Thc hien gan trang thai cho cac hop trang thai. - Xac nh phng trnh cua bien ra Zi Tm cac trang thai co xuat hien bien ra (Zi = 1). Tai moi trang thai, neu la bien MOORE th ta c tch so (AND) cua cac bien trang thai; con neu la bien MEALY th ta co tch so cua cac bien trang thai va bien ieu kien vao. Phng trnh cua bien ra bang tong (OR) cac tch so a tm thay cac bc tren lai vi nhau. - Xac nh phng trnh cac bien trang thai ke Q+j Tm ra tat ca cac trang thai trong o Qj =1. oi vi moi trang thai nay, tm ra tat ca cac ng dan lien ket (link path) ma dan en trang thai o. Vi moi ng dan lien ket nay, tm ra mot so hang la 1 khi i theo ng dan lien ket nay. Ngha la, vi ng dan lien ket t Sa en Sb, so hang se la 1 tch so cua cac bien trang thai trang thai Sa va cac bien ieu kien e co the dan en Sb. Bieu thc Q+j c tao thanh bang cach lay tong (OR) cac tch so c tm thay bc tren lai vi nhau Chu y: Cac phng trnh bien ra va bien trang thai ket tiep co the c n gian hoa bang cach rut gon bang ba Karnaugh vi cac trang thai khong s dung lam ieu kien dont care

V du: Thc hien lu o SM sau bang cong logic va kch canh lenD-FF

S0 Za

00 = AB

Link 1 0

S1 Zb

01

Link 2 0

S2 Zc X

11

Link 3 1

Z1

Z2

+ Gan trang thai: AB = 00 cho S0, AB = 01 cho S1, va AB = 11 cho S2.

+ Phng trnh cua cac bien ra: Bien ra Moore: Za = AB (ch co trong trang thai S0) Zb = AB (ch co trong trang thai S1) Zc = A B (ch co trong trang thai S2) Bien ra Mealy: Z1 = A B X (tai trang thai S2 va ieu kien X = 0) Z2 = A B X (tai trang thai S2 va ieu kien X = 1)

+ Phng trnh cac bien trang thai ke: Co 3 ng dan lien ket (link1, link2 va link3) trang thai co B =1: B+ = ABX (link 1) + ABX (link 2) + ABX (link 3) = (A + B) X Co 2 ng dan lien ket dan ti trang thai co A=1: A+ = ABX + ABX = BX

Cac phng trnh bien ra va trang thai ke co the c n gian hoa hn bang bang Karnaugh vi trang thai khong s dung (AB=10) lam ieu kien dont care, khi o: Za = AB + (AB) = B Zb = AB Zc = AB + (AB) = A Z1 = ABX + (ABX) = AX Z2 = ABX + (ABX) = AX A+ = BX B+ = ABX + ABX + ABX + (ABX) = X

Z2

Z1 X DA QA Zc

CK

QA

Zb

DB

QB

CK

QB

Za

Clock

V du: Thc hien he tuan t co bang trang thai sau bang lu o SM; s dung PLA va JK-FF kch canh len Hien tai Q1Q2 00 S0 01 S1 11 S2 Ke tiep 00 01 S1 S1 S1 S2 S2 S2 Ngo ra (Z1Z2) X1X2 = 00 01 10 11 11 11 00 01 00 10 10 11

X1X2 =

10 S2 S1 S0

11 S0 S2 S0

11 01 01 11

Thanh lap lu o SM

S0 Z2

00 = Q1Q2

X1

Z1 S1 10 S2
0

X2
0

Z1 11 Z1 Z2
0

X2

X1
1

Z2

Ta co: Z1 = Z2 = Q1+ = Q2+ = Q1 Q2 X1 + Q1 Q2 X1 X2 + Q1 Q2 X1 Q 1 Q2 + Q1 Q2 X 2 + Q 1 Q2 Q1 Q2 X1 + Q1 Q2 X2 + Q1 Q2 X1 X2 + Q1 Q2 X1 + Q1 Q2 X1 Q1 Q2 X1 X2 + Q1 Q2 X2 + Q1 Q2 X1

Rut gon vi trang thai khong gan lam dont care

Z1 Q1 Q2 00 X1X2 00 01 11 10 01 11 10

Z2 X1X2 Q1 Q2 00 01 11 10

1 1

X X X

1 1 1 1

00 01 11 10

1 1 1 1

X X X X 1 1 1 1

Z 1 = Q 2 + Q 1 X1 + Q 1 X 2
Q1+ X1X2 Q1Q2 00 01 11 10 Q2+ X1X2

Z2 = Q1 + Q2 X1 + Q2 X2
Q1Q2 00

01

11

10

00 01 11 10

1 1

X X X

1 1

1 1 1 1

00 01 11 10

X X X 1 X

1 1 1 1

X J1 = X1 + X2 K1 = Q2 X1

J2 = Q1 X2 + Q1 X1 X2 K2 = X1

PLA X1 X2 Z1 Z2 J1 Q1 K1 J2 Q2 K2 K2 K1 J2 Q2 J1 Q1

Q1 0 0 0 1 0 -

Q2 1 1 0 1 -

X1 0 1 0 1 1 1

X2 0 1 0 1 0 -

Z1 1 1 1 0 0 0 0 0 0 0 0 0

Z2 0 0 0 1 1 1 0 0 0 0 0 0

J1 0 0 0 0 0 0 1 1 0 0 0 0

K1 0 0 0 0 0 0 0 0 1 0 0 0

J2 0 0 0 0 0 0 0 0 0 1 1 0

K2 0 0 0 0 0 0 0 0 0 0 0 1

CK

* N GIAN HOA HAM BOOLE BANG CACH THEM BIEN VAO BA KARNAUGH Khi dung bang Karnaugh, neu ta co so bien vao ln hn 4 bien th s rut gon tren bang Karnaugh bat au hi phc tap. e giai quyet van e tren, ngi ta a cac bien vao trong bang Karnaugh. Neu bien Pi c at trong o mj cua bang Karnaugh cua ham, co ngha la F = 1 khi Pi = 1 va cac bien c chon e mj =1. Cho trc mot bang vi cac bien P1, P2, c a vao mot so o, dang toi thieu tong cac tch cua F co them c tm nh sau: F = MS0 + P1 MS1 + P2 MS2 + + MS0 la tong toi thieu (Minimum Sum) co c bang cach at P1 = P2 = = 0. + MS1 la tong toi thieu co c bang cach at P1 =1, cac Pj = 0 (j 1), va thay the tat ca cac 1 tren bang bang cac dont care (X). + MS2 la tong toi thieu co c bang cach at P2 =1, cac Pj = 0 (j 2), va thay the tat ca cac 1 tren bang bang cac dont care (X). Bieu thc nay se la toi thieu mien la cac gia tr cua cac bien c a vao bang co the c gan mot cach oc lap. V du: Cho ham sau: G(A, B, C, D, E, F) = m0 + m2 + m3 + E m5 + E m7 + F m9 + m11 + m15 + (m1 + m11 + m13)

Ta co ket qua:

G = AB + A C D + E AD + F A D
KTS2-C2-Tr.11

V du:

F(A, B, C, D) = ABC + ABC + ABCD + ABCD + (ABC)

F = AC + D (C + AB) = AC + C D + AB D V du: F(A, B, C, D, E) = m(0, 4, 5, 7, 9) + d(6, 11) + E (m1 + m15)


F AB CD 00 01 11 10 00 01 11 10

1 E

1 1 1 X E 1 X

F(A, B, C, D, E) = AB + ACD + A BD + AC E + B C D E V du: F(A, B, C, D, E) = AB D + ABCDE + (A B)

Bien a vao ba K co the la ham cua nhieu bien. Vi P = CE, ta co F (A, B, D, P) = m2 + P m0 + (m6 + m7)
F D 0 1 AB 00 01 11 10

X X

F = B D + ADP = B D + ACDE

KTS2-C2-Tr.12

III. THANH LAP LU O MAY TRANG THAI: V du 1: Lap lu o SM cho bo chia nh phan song song Ta xet thiet ke bo chia song song cho cac so nh phan dng. Th du ta se thiet ke 1 he chia so b chia (dividend) 6 bit cho so chia (divisor) 3 bit e co c thng so 3 bit. Minh hoa cho qua trnh chia:

Ta nhan thay viec chia co the thc hien c bang cac phep toan tr va dch. e xay dng bo chia ta se dung thanh ghi so b chia 7 bit va thanh ghi so chia 3 bit co s o khoi nh sau:

Tn hieu vao St (Start): St = 1 cho phep bat au chay he thong. No se la 1 trong thi gian 1 xung nhp, va roi se gi la 0 cho en khi he ieu khien quay ve trang thai ban au.
KTS2-C2-Tr.13

Tn hieu vao C: la ngo ra cua bo so sanh; neu so chia ln hn 4 bit tan cung ben trai cua so b chia th C = 0, ngc lai C=1. Mach ieu khien tao ra chuoi cac tn hieu dch va tr mong muon. Bat c khi nao C=1, tn hieu tr c tao ra va bit thng so c at len 1. Tn hieu ra V (Overflow): Neu ban au x7x6x5x4 y3y2y1 (ngha la neu 4 bit trai cua thanh ghi so b chia vt qua hoac bang so chia), thng so se ln hn 7 va xay ra tran tren (overflow).

Do vay, neu gia tr ban au cua C la 1, thng so se can 4 bit tr len. Do o bo chia dng va bao hieu tran tren bang cach cho bien V=1. Tn hieu dch Sh (Shift): khi Sh = 1 se dch so b chia sang trai mot v tr. Tn hieu tr Su (Subtract): Bat c khi nao C = 1, tn hieu Su = 1. Khi o he se tr so chia cho 4 bit tan cung ben trai cua thanh ghi so b chia va at bit thng so (bit tan cung ben phai trong thanh ghi so b chia) len 1.

KTS2-C2-Tr.14

00 = AB

01

10

11

Lu o SM cua bo chia nh phan.

KTS2-C2-Tr.15

V du 2: Thanh lap lu o SM cho phan ieu khien bo nhan. Ta se thiet ke bo nhan song song cho cac so nh phan dng, nhan nh phan ch can cac phep toan dch va cong. Minh hoa cho bai toan nhan nh phan: So b nhan So nhan

Nhan hai so 4 bit can 1 thanh ghi so b nhan (multiplicand register) 4 bit, 1 thanh ghi so nhan (multiplier) 4 bit va thanh ghi 8 bit danh cho so hang tch. Thanh ghi tch so lam viec nh thanh ghi tch luy la tong tch luy cac tch tng phan. Thay v phai dch so b nhan sang trai trc khi cong, ngi ta se dch thanh ghi tch sang phai. Ta co s o khoi cua bo ieu khien nhan

Ad: tn hieu cong;

Sh: tn hieu dch; Clk: xung nhp; Done: thc hien xong;

M: bit cua so nhan; C: so nh (carry)


KTS2-C2-Tr.16

St: tn hieu bat au;

Th du nhan (13 x 11) c lam lai sau ay ch v tr cac bit trong cac thanh ghi moi thi iem xung nhp. Noi dung ban au cua thanh ghi tch: (Cong so b nhan v M=1) Sau khi cong Sau khi dch (Cong so b nhan v M=1) Sau khi cong Sau khi dch (bo qua cong v M=0) Sau khi dch (Cong so b nhan v M=1) Sau khi cong Sau khi dch (ap so): ng chia gia so nhan va tch so

Gian o trang thai cho phan ieu khien bo nhan.

KTS2-C2-Tr.17

Trong trng hp tong quat hn, neu can nhan so bit ln, ngi ta chia he ieu khien thanh bo em va ieu khien cong - dch. - Phan ieu khien cong - dch co trang thai S1 la trang thai sau khi dch, va trang thai S2 la trang thai sau khi cong. - Phan bo em tao ra tn hieu K. Tn hieu hoan tat (K) co t bo em e lam dng bo nhan sau khi a hoan tat u so lan dch. e xac nh xem khi nao hoan tat viec nhan, moi lan tn hieu dch c tao ra se lam tang bo em. Neu bo nhan co n bit, tong so lan dch can la n. Ta se thiet ke bo em e tn hieu hoan tat (K) c tao ra sau khi xay ra (n-1) lan dch.

(a) ieu khien bo nhan

(b) Gian o trang thai cong-dch

(c) Gian o trang thai cuoi cung cua bo ieu khien cong dch
KTS2-C2-Tr.18

trang thai S1, la trang thai co c sau khi dch, neu K = 0 th hoat ong bnh thng. Neu K=1, ta kiem tra M: neu M = 0, ta xuat tn hieu dch cuoi cung va dng lai; con neu M=1, ta cong trc khi dch va i vao trang thai S2. trang thai S2, neu K=1, ta xuat ra them 1 tn hieu dch na va roi i vao trang thai S3. Tn hieu dch cuoi cung se reset bo em ve 0, ong thi ieu khien cong-dch quay ve trang thai dng. Bo em em so lan dch va xuat K=1 va trc khi lan dch cuoi cung xay ra.

S0

00 = Q1Q2

St

Load S1 11

Sh S2
0

Ad 01 Sh
1 0

K
1

S3

10 Done

Lu o SM cua bo nhan nh phan.


KTS2-C2-Tr.19

V du 3: Thiet ke tro chi xuc xac ien t.

S o khoi tro chi xuc xac. Nh vay sau khi gieo xuc xac (roll), tong cua cac gia tr trong 2 bo em nam trong dai t 2 en 12. Cac qui tac chi nh sau: 1. Sau lan gieo xuc xac (roll) lan th nhat, ngi chi thang neu tong la 7 hoac 11. Ngi chi thua neu tong la 2, 3, hoac 12. Ngc lai tong co c trong lan roll th nhat c xem nh iem cua ngi chi va phai roll xuc xac lan na. 2. lan roll th hai hoac ke tiep, ngi chi thang neu tong bang iem cua ngi chi va thua neu tong la 7. Ngc lai ngi chi phai roll lan na cho en khi cuoi cung ngi chi thang hoac thua. 3. Sau khi thang hoac thua, ngi chi phai an nut Reset e bat au tro chi mi. Co 2 nut nhan: Rb (Roll button=nut gieo) va Reset. Reset c dung e khi ong tro chi mi. Khi an nut roll (gi Rb), cac bo em xuc xac em toc o cao, v vay khong the oc c tren hien th. Khi nha nut Rb, cac gia tr trong 2 bo em c hien th va tro chi co the tien hanh. Neu en Win (thang) hoac en Lose (thua) khong sang, ngi chi an nut roll lan na.
KTS2-C2-Tr.20

Cac tn hieu vao he ieu khien c nh ngha nh sau: D7 = 1 neu tong cua xuc xac la 7. D11 = 1 neu tong cua xuc xac la 11. D2312 = 1 neu tong cua xuc xac la 2, 3, hoac 12. Eq=1 neu tong cua xuc xac bang so iem cat trong thanh ghi iem. Rb = 1 khi an nut gieo xuc xac Rb. Reset = 1 khi an nut Reset. Cac bien ra cua he ieu khien c nh ngha nh sau: Roll = 1 cho phep cac bo em xuc xac. Sp = 1 se cat tong vao thanh ghi iem (Sp=Save points). Win = 1 lam cho en Win sang (thang). Lose = 1 lam cho en Lose sang (thua).

Lu o tro chi xuc xac.


KTS2-C2-Tr.21

S0

000 = ABC

Rb

S1 Roll
1

001

Rb
0

D711
0 1

S2

010 Win

D2312
0 0

S3

011 Lose

Reset

Sh S4 100
0

Reset

Rb

S5 Roll
1

101

Rb
0

Eq
0

D7
1

Lu o SM cua tro chi xuc xac


KTS2-C2-Tr.22