Está en la página 1de 31

CHNG5

MY TRNG THI (STATE MACHINE)

MY TRNG THI (STATE MACHINE)

5.1

My trng thi v lu my trng thi

5.2 5.3

My trng thi MEALY My trng thi MOORE

MY TRNG THI
H tun t cn c tn gi khc l my trng thi (State Machine), tn ny thng s dng khi dng mt h tun t iu khin 1 h thng s

thc hin mt th tc hoc mt thut ton tng bc mt. C th nh


ngha cc my trng thi bng cc gin trng thi, hoc mt kiu lu c bit c gi l lu my trng thi hay lu SM (State Machine) dng m t c tnh lm vic ca mt my trng thi. Trong thit k s, thng s dng t my trng thi ch cc mch ng b nh mch m cc gi tr ra thay i t mt trng thi

nh phn ny sang mt trng thi nh phn khc khi mch c cung cp


xung clock. SM c hai loi: Moore v Mealy.

My trng thi kiu MEALY


S khi my trng thi kiu MEALY nh sau:

Lu : Tn hiu ng ra ph thuc c vo trng thi hin ti v tn hiu vo

Q1, Q2, , Qk: trng

thi hin ti ca FF
Q+1, Q+2, , Q+k: trng thi k tip ca FF Trng thi k tip = F (trng thi hin ti Qi v cc ng vo Xj)

Gi tr ng ra = G (trng thi hin ti Qi v cc ng vo Xj)

biu din mi quan h gia trng thi k tip, cc ng ra ph thuc

vo trng thi hin ti v cc ng vo, ngi ta s dng bng trng thi


v gin trng thi.

* Bng trng thi (State Table):

* Gin trng thi (State Graph):

Khi thay i gi tr ng vo th gi tr ng ra cng thay i nhng

trng thi hin ti gi nguyn khng i cho ti khi c xung clock.

My trng thi kiu MOORE


S khi my trng thi kiu MOORE nh sau:

Lu : Tn hiu ng ra ch ph thuc vo trng thi trong

Q1, Q2, , Qk : trng thi hin ti ca FF


Q+1, Q+2, , Q+k : trng thi k tip ca FF Trng thi k tip = F (trng thi hin ti Qi v cc ng vo Xj)

Gi tr ng ra = G (trng thi hin ti Qi)

* Bng trng thi (State Table):

* Gin trng thi (State Graph):

* V Gin trng thi cho bng trng thi sau:

LU MY TRNG THI
Ngi ta cn gi h tun t l my trng thi thut ton (ASM algorithmic state machine) hay n gin hn l my trng thi (SM -

sate machine), y ta gi tt l SM. Lu SM c to bi cc khi


SM; mi khi SM m t hot ng trong 1 trng thi. Trng thi ca h thng c biu din bng mt Hp trng thi (state box). Hp trng thi c th cha mt Danh sch xut (output list),

M trng thi (state code), Tn trng thi (state name), Hp quyt nh


(decision box), iu kin trong hp quyt nh l mt biu thc Boole, Hp xut theo iu kin (conditional ouput box) cha danh sch cc bin xut theo iu kin.

Ba thnh phn chnh ca mt lu SM:

Hp trng thi (state box): biu din trng thi ca h thng. Hp trng thi c th cha mt Danh sch xut (output list), M trng thi (state code), Tn trng thi (state name). Hp quyt nh (decision box), iu kin trong hp quyt nh l mt biu

thc Boole.
Hp xut theo iu kin (conditional ouput box) cha danh sch cc bin xut theo iu kin.

Mt khi SM cha chnh xc mt hp trng thi cng vi cc hp quyt nh v cc hp xut theo iu kin lin h vi trng thi . Mt khi SM c chnh

xc mt ng vo v mt hoc nhiu ng ra. Mt ng dn i qua khi


SM t ng vo n ng ra c gi l ng dn lin kt (link path).

Theo hnh ta c: khi vo trng thi S1, cc gi tr ra Z1 v Z2 bng 1. Nu cc gi tr vo X1 v X2 u bng 0, Z3 v Z4 cng bng 1, v cui thi gian trng thi, my i vo trng thi k qua ng ra 1. Ngc li nu X1=1 v X3=0, gi tr ra Z5=1 v i vo trng thi k qua ng ra 3.

Khi SM c th c v bng nhiu dng khc nhau. Hai khi SM (a) v (b) l tng ng nhau.

Mt lu SM c th biu din mt h t hp khi ch c mt trng thi v khng c s thay i trng thi xy ra. Z1 = A + ABC = A + BC

Ta phi tun theo mt s qui tc nht nh khi xy dng mt khi SM. Vi mi kt hp cc bin vo hp l phi c chnh xc mt ng ra c nh ngha. iu ny l cn thit v mi t hp vo c cho php phi dn n mt trng thi k duy nht.

Khng cho php c ng hi tip ni trong mt khi SM.

(a) Sai

(b) ng

Khi SM c 2 dng: song song v ni tip

(a) Dng song song

(b) Dng ni tip

Ta c th chuyn d dng gin trng thi ca my tun t sang lu SM

tng ng
S0 Za 0/0

1/0 S1 Zb

1/0 1/Z2 0/0 S2 Zc

0/Z1

Gin trng thi ny c c 2 bin Moore v Mealy. Lu

SM tng ng c 3 khi,
mi khi tng ng vi mt trng thi.

Cc bin ra Moore (Za, Zb, Zc) c t trong cc hp trng thi, t


chng khng ph thuc vo bin vo. Cc bin ra Mealy (Z1, Z2) xut hin trong cc hp xut theo iu kin, chng ph thuc vo c trng thi v bin vo.

THNH LP LU SM
Phng php suy ra lu SM cho mt h iu khin tun t th ging vi phng php dng suy ra gin trng thi:

1. V s khi ca h thng m ta ang iu khin


2. nh ngha cc tn hiu vo v ra cn cho h iu khin. 3. Xy dng lu SM kim tra cc tn hiu vo v ra cn cho h iu khin. 4. Xy dng lu SM kim tra cc tn hiu vo v to ra chui

cc tn hiu ng.

Th d: Xy dng mt khi SM c ba bin vo (A, B, C), 4 bin ra


(W, X, Y, Z), v ng ra (1 v 2). Vi khi ny, ng ra Z lun lun l 1, v W l 1 nu c hai A v B bng 1. Nu C = 1 v A = 0 th Y = 1 v

i ra ng 1. Nu C = 0 hoc A = 1 th X = 1 v i ra ng 2.

CI T LU MY TRNG THI:
Vic ci t lu SM l tm c phng trnh ca cc bin ra

v cc bin trng thi k tip. Cc bc thc hin nh sau:


Thc hin gn trng thi cho cc hp trng thi.

Xc nh phng trnh ca bin ra Zi


Tm cc trng thi c xut hin bin ra (Zi = 1). Ti mi trng thi, nu l bin MOORE th ta c

tch s (AND) ca cc bin trng thi; cn nu l bin


MEALY th ta c tch s ca cc bin trng thi v bin

iu kin vo.
Phng trnh ca bin ra bng tng (OR) cc tch s tm thy cc bc trn li vi nhau.

- Xc nh phng trnh cc bin trng thi k Q+j


Tm ra tt c cc trng thi trong Qj =1. i vi mi trng thi ny, tm ra tt c cc

ng dn lin kt m dn n trng thi .

Vi mi ng dn lin kt ny, tm ra mt s

hng l 1 khi i theo ng dn lin kt ny. Ngha l,


vi ng dn lin kt t Sa n Sb, s hng s l 1 tch s ca cc bin trng thi trng thi Sa v cc bin iu kin c th dn n Sb.

Biu thc Q+j c to thnh bng cch ly tng

(OR) cc tch s c tm thy bc trn li vi nhau

V d: Thc hin lu SM sau bng cng logic v kch cnh ln D-FF

+ Gn trng thi: AB = 00 cho S0, AB = 01 cho S1, v AB = 11 cho S2.


+ Phng trnh ca cc bin ra:

Bin ra Moore: Za = AB (ch c trong trng thi S0)


Zb = AB (ch c trong trng thi S1) Zc = A B (ch c trong trng thi S2)

Bin ra Mealy: Z1 = A B X (ti trng thi S2 v iu kin X = 0)


Z2 = A B X (ti trng thi S2 v iu kin X = 1) + Phng trnh cc bin trng thi k:

C 3 ng dn lin kt (link1, link2 v link3) trng thi c B =1:


B+ = ABX (link 1) + ABX (link 2) + ABX (link 3) = (A + B) X C 2 ng dn lin kt dn ti trng thi c A=1:

A+ = ABX + ABX = BX

Cc phng trnh bin ra v trng thi k c th c n

gin ha hn bng bng Karnaugh vi trng thi khng s dng (AB=10) lm iu kin dont care, khi :
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

DA

QA

Zc

CK

QA

Zb

DB

QB

CK

QB

Za

Clock