You are on page 1of 39

N MN HC

MN HC

.
Nhm sinh vin: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Lp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Gio vin hng dn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Thi Nguyn 2011

Nhn xt ca gio vin hng dn


................................................................................................................................................................................................................................
................................................................................................................................................................................................................................
................................................................................................................................................................................................................................
................................................................................................................................................................................................................................
................................................................................................................................................................................................................................

Thi Nguyn, Ngy

Thng

Nm 20...

Gio Vin hng dn

(K ghi r h tn)

Nhn xt ca gio vin chm


................................................................................................................................................................................................................................
................................................................................................................................................................................................................................
................................................................................................................................................................................................................................
................................................................................................................................................................................................................................

Thi Nguyn, Ngy

Thng

Nm 20...

Gio Vin hng dn

(K ghi r h tn)

TRNG HKTCN
KHOA IN T

CNG HO X HI CH NGHA VIT NAM


c lp - T do - Hnh phc

BM K thut My tnh

N MN HC
Mn hc:..
Nhm Sinh vin:
..
..
Lp: ..

Ngnh:.

S .................................................................
Ngy giao : . Ngy hon thnh: .
1.Tn ti

.
2. Ni dung thuyt minh tnh ton

.
3. Cc bn v, chng trnh, th

.
Thng qua phn
Xc nh yu cu

Thng qua phn


Thit k

T TRNG B MN

Thng qua phn


Xy dng h thng

ng cho bo v

GIO VIN HNG DN

ThS. Nguyn Tun Linh

LI NI U

Ngy nay i a s cc lnh vc sn xut, iu khin, gim st, o lng


u c trang b h thng t ng ha. Mt trong s vi mch c s dng l
k thut vi iu khin. Nh tnh nng u vit ca b vi iu khin nh: kh nng
lp trnh ph hp vi thit k nh v ln cng nh giao tip vi cc thit b ngoi
vi v my tnh em li s hon ho, chnh xc v tnh mm do cao thng
qua giao tip gia ngi v my.
Vi iu khin qun l v iu khin hot ng ca h thng thng qua phn
mm, nh vy m ta c th m rng v thay i hot ng mt cch d dng bng
cch thay i mt s thng s ca chng trnh. Vi iu khin hot nh theo
chng trnh np sn, c cc tn hiu t bn ngoi a vo sau lu tr v x
l, trn c s a ra cc thng bo, tn hiu iu khin cc thit b bn ngoi
hot ng theo ng thng s v yu cu ca h thng.
H thng in t s s dng b vi iu khin v my tnh trong cc dy
chuyn sn xut cng nghip, thc hin nhim v iu khin v gim st h thng.
Ngoi ra, vi iu khin cng c mt trong cc sn phm cng nghip v tiu dng
nh: l vi ba, l si, my git, h thng cnh bo v gim st ca cc phng tin
giao thng v trong nhiu thit b cng nghip khc.

CHNG 1

KHO ST V PHN TCH BI TON

1.1 Kho st cc h thng iu khin ng c.


Hin nay trong rt nhiu lnh vc i sng v sn xut cc loi ng c in
ngy cng c ng dng rng ri hn so vi nhng loi ng c s dng nng
lng nh xng, du, kh t..Nhng loi ng c in ny c nhng u im
hn hn v hiu sut s dng, cu to nh gn, gi thnh hp l, d dng iu
chnh tc , o chiu, cng bc cc qu trnh khi ng, qu trnh hm dng d
dng.Trong thc t c rt nhiu loi ng c in c s dng bao gm:
+ng c in c in 3 pha c chia lm cc loi c bn l: ng c in 3
pha dy qun v 3 pha roto lng sc, ng c in 1 pha.
+ng c in 1 chiu bao gm cc loi nh: kch t song song v loi kch t
ni tip.
Thng thng vi nhng ng c thng xuyn i hi o chiu,tng,
gim, hm dng th thng s dng ng c in 1 chiu l ch yu, v s d dng
iu khin hn so vi ng c xoay chiu. tin hnh iu khin ng c 1
chiu, c rt nhiu bin php c ng dng nh l: thay i in p phn ng,
thay i t thng, hoc s dng in tr ph mc thm vo phn ng ca ng c.
lm c iu , chng ta cn i xy dng nhng h thng iu khin, c rt
nhiu h thng c ng dng nh l: cc h thng iu khin PID, iu khin
ng c bng Vi iu khin, hay c th iu khin bng cch s dng cc loi kh
c in. Trong ti ny chng em s tin hnh nghin cu cc qu trnh iu
khiu ng c bng phng php s dng Vi iu khin h 8051.

Yu cu ca bi ton.
o

Thit k v xy dng mch iu khin ng c DC 12v vi yu cu quay


thun, quay ngc, tng, gim v o chiu quay.

o Thc hin thao tc iu chnh cc chc nng trn thng qua cc nt n


bao gm :nt khi ng ng c,nt iu khin quay thun, nt iu
khin quay ngc, nt tng tc, nt gim tc, v nt dng ng c, thng
qua cc nt n ny cho php ta c th iu chnh ng c lm vic 1
tc nh mong mun.
o H thng cho php hin th tc lm vic c th s dng LCD hoc
LED 7 thanh, ng thi c cc led n thng bo trng thi quay thun,
quay ngc, dng cn gi tr tc ng c c hin th chi tit l bao
nhiu trn LED 7 on.
o Thng qua ti, lm quen vi cch thc, nguyn l iu khin i

tng ng c 1 chiu.

o Tm hiu thc t cc linh kin, cc loi IC, hot ng ca cc loi cm


bin.
o

Vit chng trnh cho vi iu khin thc hin thnh cng theo yu cu
ra.

o nh gi v sai s, cht lng h thng iu khin.

o Tm hiu cc hng pht trin ca ti, nng cao cht lng ca h


thng
o Chi ph cho c h thng khng qu cao, m bo tnh kinh t

Chng 2

THIT K H THNG

2.1 S tng quan.

KHI IU
CHNH
NG C

KHI T
TC

KHI VK
KHI
HIN TH
CM BIN

KHI
NGUN
NUI

Nguyn l hot ng
H thng hot ng theo cc bc sau: Khi ngun nui cung cp nng lng cho
ton b h thng. Ban u ng c cha c cp ngun. iu khin ng c
quay ta iu khin n cc nt trn khi t tc . Tn hiu ny c a n khi
vi iu khin. Khi vi iu khin x l tn hiu v cp xung cho khi iu chnh
ng c. Khi iu chnh ng c hot ng cung cp ngun cho ng c hot
ng theo tc t v trng thi mong mun. Encoder gn trn trc ng c c
tc dng phn hi tn hiu xung v vi iu khin x l v a ra khi hin th.
+Khi ngun nui:
Ngun nui c tc dng cung cp in nng cho ton b h thng bao gm:
Khi iu khin tc t, khi vi iu khin, khi hin th, iu chnh ng c,
cm bin.

+Khi hin th
Lm nhim v hin th tc ng ng c v chiu quay ca n.
+Khi vi iu khin.
iu khin hot ng ca h thng theo ngi lp trnh. Khi vi iu khin l
b no
trung tm ca ton h thng.Nhn tn hiu ca khi iu
khin tc t ra lnh cho khi iu chnh ng c tng, gim, o chiu. Cm
bin thu thp phn hi tc di dang xung gi v vi iu khin. Vi iu khin
x l tn hiu m ho dang s thp phn ri hin th ra led 7 thanh
+Khi iu chnh ng c
iu chnh ng c quay theo mun ca ngi lp trnh.
+Khi cm bin.
Phn hi li tc ca ng c hin th ra qua khi hin th t hiu chnh
li h thng.
+ Khi iu khin tc t:
Gm cc nt bm c tc dung ra lnh iu chnh tc o chiu v tt my

2.1.1 S c t cc khi
2.1.1.1 Khi ngun
Module ny to ra in p mt chiu t ngun xoay chiu 220V cung
cp cho cc linh kin trong h thng. S dng bin p bin in p xoay chiu
220V thnh in p xoay chiu 12V, dng chnh lu t 12V xoay chiu sang 12V
mt chiu, dng IC n p ly ra in p n nh 5V ng ra.

2 0

1
2~

i o t
4

ie

a u
1
C
C

I N
1

a p

2. Hnh 2.4.: Module ngun cp

2.1.1.2 Khi hin th


S dng led 7 thanh hin th tc ng c

4
O

G N D

2 V

7 8
U

0 5
3
T

c
C
C

- 5
2

Hnh 2.3 Hnh dng LED 7 thanh


Lm nhim v hin th cc gi tr cn o trong mch v th hin n bng s c th
nhn thy c.

D8
LED-YELLOW

R13
R19
R18
R17
R16
R15
R12
R14
10k10k10k10k10k10k10k10k

P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P3.7/RD

39
38
37
36
35
34
33
32
21
22
23
24
25
26
27
28

P2.0

10
11
12
13
14
15
16
17

2.1.1.3 Khi vi iu khin.

C2
X1
22p

C1
33p

U1
19

XTAL1

CRYSTAL
18

C3

XTAL2

RST

1u
29
30
31

R10
1k

1
2
3
4
5
6
7
8

PSEN
ALE
EA

P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
AT89C51

iu khin hot ng ca h thng theo ngi lp trnh.

2.1.1.4Khi iu chnh ng c

P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P3.7/RD

39
38
37
36
35
34
33
32
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17

tocdo

Q2
R10

Q1

1k

TIP41

D1

D2

10BQ040

10BQ040

tocdo

R20
10k

R11
1k

R21
TIP41

10k

Q6

Q5
thuan

2N3415

Q4

nguoc

+88.8

Q3

D3

D4

TIP42

10BQ040

10BQ040

2N3415

TIP42

iu chnh ng c quay theo mun ca ngi lp trnh.

2.1.1.1,5 Khi cm bin.


Phn hi li tc ca ng c hin th ra qua khi hin th t hiu
chnh li h thng.

2.2 La chn gii php


2.2.1 Gii php cng ngh
Vi iu khin s cp xung ng m trasistor iu chnh rng
xung in p cp cho ng c DC nhm tng gim tc ng c m
khng lm gim mmen quay ca ng c.
S dng cm bin o tc trn trc ng c v hin th ln Led 7
thanh.
Thay i tc ng c khi bm nt tng hoc gim.
o chiu ng c bng cc nt bm.

2.2.2 Gii php thit k


Thit k l mt quy trnh quan trng, nh hng rt nhiu n s thnh cng
ca sn phm. Thit k thng minh s gip qu hnh hon thin sn phm c d
dng, gip chnh xc ho cng vic ca mi ngi. Cc quy trnh thit k thng
c s dng nh: Top-Down, Bottom-Up hoc kt hp c hai quy trnh trn. Bi
ton trn c gii php cng ngh c v phn mm cng nh phn cng. Cc gii

php ny c pht trin trc cc ng dng khc v vy bn em quyt


nh s dng quy trnh Top-Down gii quyt bi ton trn
a, S khi quy trnh k top-down hnh di y:
Phn tch vn
(Analyze the proplem)

Cc yu cu v iu kin
rng buc cho h thng
mi

Cc yu cu v cc iu kin rng
buc c xc nh c th
Thit k nguyn l
(High level design)
S khi v cc biu lung d liu

Thit k k thut
(Engineering design)
Cc cu trc d liu
Cc giao tip vo ra
Biu quan h gia cc
khi chc nng
Xy dng h thng
(Implementation)
Phn cng
Phn mm
Khng t
yu cu

Kim tra
(Test)
t yu cu

Trong thc t chng ta s thy, bn cht hay mu cht ca quy trnh l vn tm


hiu v xc nh bi ton, lm sao xc nh c chnh xc v y nht cc
yu cu cng cc rng buc m h thng phi t c

2.2.3 S CALLGRAPH

VI IU
KHIN

QUT

LED

KHUYCH
I

TRANSISTOR

HIN TH

LED

CH
HOT NG

BUTTON

2.2.4 Cc yu cu v gii hn cho h thng


2.2.4.1 Cc yu cu
- iu chnh c tc ng c loi nh t 3-24v vi nhiu cp tc .
- D dng thay i tc ca ng c v o chiu.
- Hin th tc thc t ln led 7 thanh
- Chi ph cho h thng khong 150.000 vn.
2.2.4.2 Gii hn cho h thng
-S dng ngun in 220v /50Hz(hoc c th thay th bng ngun 1
chiu nh hn 24v)
-Kch thc ph hp vi ngi s dng, h thng nh gn d dng di
chuyn.

La chn tng quan linh kin


Vi iu khin AT89C51
2.3.1.1

Kin trc ca b vi iu khin

IC vi iu khin 8051/8031 thuc h MCS51 c cc t im sau :

4 kbyte ROM (c lp trnh bi nh sn xut ch c 8051)


128 byte RAM.
4 port I/O 8 bit.
hai b nh thi 16 bits.
giao tip ni tip.
64KB b nh chng trnh ngoi.
64KB khng gian b nh d liu ngoi.
b x l lun l(thao tc trn cc bit n )
21 bit c a ch ha.
b nhn/chia 4s.

2.3.1.2 Cu trc bn trong ca AT89C51

Phn chnh ca vi iu khin 8051 l b x l trung tm (CPU: central processing


unit ) bao gm :
Thanh ghi tch ly A.
Thanh ghi tch ly ph B, dng cho php nhn v php chia.
n v logic hc (ALU : Arithmetic Logical Unit )
T trng thi chng trnh (PSW : Prorgam Status Word)
Bn bng thanh ghi.
Con tr ngn xp.
Ngoi ra cn c b nh chng trnh, b gii m lnh, b iu khin thi
gian v logic.
Trong vi iu khin 8051 / 8031 c hai thnh phn quan trng khc l b
nh v cc thanh ghi :

B nh gm c b nh Ram v b nh Rom (ch c 8031) dng lu tr d


liu v m lnh.
Cc thanh ghi s dng lu tr thng tin trong qu trnh x l. Khi CPU lm vic
n lm thay i ni dung ca cc thanh ghi.

2.3.1.2 Chc nng cc chn ca vi iu khin

U1
19
18

29
30
31

1
2
3
4
5
6
7
8

XTAL1
XTAL2

RST

PSEN
ALE
EA

P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7

P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/W R
P3.7/RD

39
38
37
36
35
34
33
32
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17

AT89C51

Hnh 2.2: S chn ca AT89C51 h 8051


Vi iu khin 8051 c 32 trong 40 chn c chc nng nh l cc cng I/O, trong
oa 24 chn c s dng vi hai mc ch. Ngha l ngoi chc nng cng I/O,
mi chn c cng dng kp ny c th l mt ng iu khin ca Bus a ch
hay Bus d liu hoc l mi chn hot ng mt cch c lp giao tip vi cc
thit n bit nh l cng tc, LED, transistor
+ Port 0 : l port c 2 chc nng trn chn t 32 n 39 ca MC 8051. Trong
cc thit k c nh khng dng b nh ngoi, PO c s dng nh l nhng cng

I/O. Cn trong cc thit k ln c yu cu mt s lng ng k b nh ngoi th


PO tr thnh cc ng truyn d liu v 8 bit thp ca bus a ch.
+ Port 1::l mt port I/O chuyn dng trn cc chn 1-8 ca MC8051. Chng
c s dng vi mt mc ch duy nht l giao tip vi cc thit b ngoi khi cn
thit.
+ Port 2: l mt cng c cng dng kp trn cc chn 21 28 ca MC 8051.
Ngoi chc nng I/O, cc chn ny dng lm 8 bit cao ca bus a ch cho nhng
m hnh thit k c b nh chng trnh ROM ngoi hoc b nh d liu RAM c
dung lng ln hn 256 byte.
+ Port 3: l mt cng c cng dng kp trn cc chn 10 17 ca MC 8051.
Ngoi chc nng l cng I/O, nhng chn ny kim lun nhiu chc nng khc
na lin quan n nhiu tnh nng c bit ca MC 8051, c m t trong bng
sau :
Bit

Tn

Chc nng chuyn i

P3.0

RXD

D liu nhn cho port ni tip

P3.1

TXD

D liu pht cho port ni tip

P3.2

INTO

Ngt 0 bn ngoi

P3.3

INT1

Ngt 1 bn ngoi

P3.4

TO

Ng vo ca timer 0

P3.5

T1

Ng vo ca timer 1

P3.6

WR

hiu ghi b nh d liu ngoi

P3.7

RD

Tn hiu c b nh d liu ngoi


Chc nng ca cc chn trn port 3.

+ PSEN (Program Store Enable ) : 8051 c 4 tn hiu iu khin. PSEN l tn hiu


ra trn chn 29. N l tn hiu iu khin cho php truy xut b nh chng
trnh m rng v thng c ni n chn OE (Output Enable) ca mt EPROM
cho php c cc byte m lnh ca chng trnh. Tn hiu PSEN mc thp
trong sut phm vi qu trnh ca mt lnh.

PSEN s mc thp trong thi gian ly lnh. Cc m nh phn ca chng trnh


c c t EPROM qua bus v c cht vo thanh ghi lnh ca 8051 gii m
lnh. Khi thi hnh chng trnh trong ROM ni PSEN s mc cao.
+ ALE (Address Latch Enable ) :
ALE l tn hiu cht a ch vo mt thanh ghi bn ngoi trong na u ca chu
k b nh. Sau , cc ng Port 0 dng xut hoc nhp d liu trong na sau
chu k ca chu k b nh.
Cc xung tn hiu ALE c tc bng 1/6 ln tn s dao ng trn chip v c th
c dng l ngun xung nhp cho cc h thng. Nu xung trn 8051 l 12MHz th
ALE c tn s 2MHz. Chn ny cng c lm ng vo cho xung lp trnh cho
EPROM trong 8051.
+ EA (External Access) :
Tn hiu vo EA trn chn 31 thng c ni ln mc cao (+5V) hoc mc thp
(GND).
+ RST (Reset) :
Ng vo RST trn chn 9 l ng reset ca 8051. Khi tn hiu ny c a ln mc
cao (trong t nht 2 chu k my ), cc thanh ghi trong 8051 c a vo nhng
gi tr thch hp khi ng h thng.
+ OSC:
Nh thy trong cc hnh trn, 8051 c mt b dao ng trn chip. N thng
c ni vi thch anh gia hai chn 18 v 19. Tn s thch anh thng thng l
12MHz.
+ POWER:
8051 vn hnh vi ngun n +5V. Chn Vcc c ni vo chn 40 v Vss (GND) c ni vo
chn 20

Led 7 on
a. Gii thiu
LED 7 thanh l mt cng c thng dng c dng hin th cc thng s
di dng cc s t 0 n 9. Mc d cng c LCD gip ta th hin cc thng s
mt cch linh ng hn nhng LED 7 thanh vn c s dng nhiu trong cng
nghip do cc u th ca n nh: t chu nh hng ca nhit , d to s ch
v gc nhn rng.

Hnh 2.3 Hnh dng LED 7 thanh


b. Cu to

LED 7 thanh bao gm 7 thanh LED c nh du l cc k t a, b, c, d, e,


f, g v mt du chm thp phn k hiu l dp. Ta c th xem LED 7 thanh l
mt t hp gm 8 LED. 8 LED ny c mt u (Anode hoc Cathode) c
ni chung v c b tr theo mt qui tc nht nh dng hin th cc ch s
thp phn. C hai loi LED 7 thanh, l loi Anode chung (cc Anode ca
cc LED c ni chung vi nhau) v loi Cathode chung (cc Cathode ca
cc LED c ni chung vi nhau). Ty theo tng loi LED m ta c cc
phng php iu khin cc LED trong t hp sng tt mt cch thch hp.
i vi loi Anode chung, mt LED s c bt sang nu mc logic a vo
chn iu khin on LED l mc logic 0. i vi loi Cathode chung, mt

LED s c bt sng nu mc logic a vo chn iu khin on LED l


mc logic 1.
Phng php qut LED.

Khi kt ni chung cc ng d liu ca LED 7 on (hnh v), ta khng


th cho cc LED ny sng ng thi (do nh hng ln nhau gia cc LED) m
phi thc hin phng php qut, ngha l ti mi thi im ch sng mt Led v
tt cc LED cn li. Do hin tng lu nh ca mt, ta s thy cc LED sng ng
thi.

ng c 1 chiu 12V
a, Gii thiu

ng c in mt chiu l ng c in hot ng vi dng in mt chiu.


Cu to ca ng c gm c 2 phn: stato ng yn v rto quay so vi stato. Phn
cm (phn kch t-thng t trn stato) to ra t trng i trong mch t, xuyn
qua cc vng dy qun ca phn ng (thng t trn rto). Khi c dng in chy
trong mch phn ng, cc thanh dn phn ng s chu tc ng bi cc lc in t
theo phng tip tuyn vi mt tr rto, lm cho rto quay. Chnh xc hn, lc
in t trn mt n v chiu di thanh dn l tch c hng ca vect mt t
thng B v vect cng dng in I. Dng in phn ng c a vo rto
thng qua h thng chi than v c gp. C gp s gip cho dng in trong mi
thanh dn phn ng c i chiu khi thanh dn i n mt cc t khc tn vi

cc t m n va i qua (iu ny lm cho lc in t c sinh ra lun lun to


ra mmen theo mt chiu nht nh).

Cm bin Encoder
Nguyn l hot ng ca cm bin encoder : c nhiu loi encoder khc nhau.
Mi loi li c mt nguyn l hot ng khc nhau, trong khun kh bo co n
em xin trnh by phn nguyn l loi encoder trong ti m em s dng :
Incremental encoder.

M hnh th 1.
Incremental encoder v c bn l mt a trn quay quanh mt trc c c l
nh hnh trn.

2 bn mt ca ci a trn , s c mt b thu pht quang. Trong qu trnh


ENCODER quay quanh trc, nu gp l rng th nh sng chiu qua c, nu gp
mnh chn th tia sng khng chiu qu c. Do tn hiu nhn c t

SENSOR quang l mt chui xung. Mi encoder c ch to s bit sn s xung


trn mt vng. Do ta c th dng vi iu khin m s xung trong mt n
v thi gian v tnh ra tc ng c.
Ci ENCODER m em s dng trong n ca mnh, hon ton ging vi m
hnh trn. Tuy nhin, m hnh trn c nhc im ln l: ta khng th xc nh
c ng c quay tri hay quay phi, v c quay theo chiu no i na th ch c
mt dng xung a ra. Ngoi ra im bt u ca ng c, ta cng khng th no
bit c.
Ci tin m hnh 1 bng m hnh 2 nh sau:
M hnh th 2

Trong m hnh ny, ngi ta c tt c l 2 vng l. Vng ngoi cng ging


nh m hnh 1, vng gia pha so vi vng ngoi l 90 . Khi , dng xung ra t
2 vng trn nh sau :

Hai xung a ra t 2 vng lch nhau 90 , nu vng ngoi nhanh pha hn


vng trong th chc chn ng c quay t tri sang phi v ngc li.
Mt l vng trong cng dng pht hin im bt u ca ng c. C th
vit chng trnh cho vi iu khin nhn bit : nu c mt xung pht ra t vng
trong cng ny, tc l ng c quay ng mt vng.
Vi nhng c tnh trn, encoder dng rt ph bin trong vic xc nh v tr
gc ca ng c..
Vn quan trng trong vic tm mua nhng loi ng c c gn ENCODER
nh th ny lm n i vi sinh vin l: cp mt quang 2 bn encoder to
xung thng b cht v khng c thay th.

Tranzitor
a. nh ngha
Transistor c hnh thnh t ba lp bn dn ghp vi nhau hnh thnh hai
mi tip gip P-N ,nu ghp theo th t PNP ta c Transistor thun , nu ghp
theo th t NPN ta c Transistor ngc. v phng din cu to Transistor
tng ng vi hai Diode u ngc chiu nhau. Cu trc ny c gi l
Bipolar Junction Transitor (BJT) v dng in chy trong cu trc ny bao gm c
hai loi in tch m v dng (Bipolar ngha l hai cc tnh). Ba lp bn dn c
ni ra thnh ba cc, lp gia gi l cc gc k hiu l B (Base), lp bn dn B rt
mng v c nng tp cht thp. Hai lp bn dn bn ngoi c ni ra thnh
cc pht (Emitter) vit tt l E, v cc thu hay cc gp (Collector) vit tt l C,

vng bn dn E v C c cng loi bn dn (loi N hay P ) nhng c kch thc v


nng tp cht khc nhau nn khng hon v cho nhau c.

Hnh 2.15: Hnh nh transistor

b. Nguyn tc hot ng ca Transitor:


Trong ch tuyn tnh hay cn gi l ch khuych i, Transitor l phn
t khuych i dng in vi dng Ic bng ln dng bazo (dng iu khin )
Trong l h s khuych i dng in : IC = .IB

T in
nh ngha: T in l linh kin in t th ng c s dng rt rng ri
trong cc mch in t, chng c s dng trong cc mch lc ngun, lc nhiu,
mch truyn tn hiu xoay chiu, mch to dao ng.

Hnh 2.16: Mt s loi t in

Nt n
Vai tr ca nt n: Dng iu khin quay thun, quay nghch, tng gim, o
chiu, dng ng c

Hnh nh v nt bm

Chng 3:

XY DNG H THNG
3.1. Xy dng h thng
3.1.1. S mch tng qut

C1

X1

33p

CRYSTAL

C2
22p

U1

R3

XTAL1
XTAL2

1k
9

29
30
31

R4R8R5R7R6
4k74k74k74k74k7
E1
E2
E3
E4
E5
f1
f2

1
2
3
4
5
6
7
8

RST

PSEN
ALE
EA

P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7

P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P3.0/RXD
P3.1/TXD
P3.2/INT0
P3.3/INT1
P3.4/T0
P3.5/T1
P3.6/WR
P3.7/RD

A1
A2
A3
A4
A5
A6
A7
A8

39
38
37
36
35
34
33
32
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17

R9

f1

thuan
nguoc

Quay nguoc
f2
D2(K)

B1
B2
B3
B4
tocdo

AT89C51

Q2

R20

R10

Q1

1k

TIP41

D1

D2

10BQ040

10BQ040

10k

tangtoc

E1

giamtoc

E2

quaythuan

E3

tat may

E4

quaynguoc

E5

330R

Quay thuan

B1
B2
B3
B4

18

tocdo

1u

19

A1
A2
A3
A4
A5
A6
A7
A8

C3

R11
1k

R21
TIP41

10k

Q6

Q5
thuan

2N3415

Q4
Q3

D3

D4

TIP42

10BQ040

10BQ040

nguoc

2N3415

TIP42

3.1.2. s mch in

3.1.3. Lu thut ton

Begin

Khi to
Timer 0 : ch 16 bit trn
50.000 us
Timer 2: Ch 16bit
Timer 1: ch couter 16 bit

Kim tra nt bm

QT

TR2=1

TT

QN
S

PWM

GT

stop

Tin hiu
DKDC

ng c
End

Ngt
Tmer
0

m ++

Couter 1

m==
4

Hin th

Xung
Encoder

3.1.4 Chng trnh lp trnh

M lp trnh:
#include <REGX52.H>
/*********************Mo ta chuong trinh******************/
/****Chuong trinh dieu khien dong co DC*******************/
/****Ho va ten Sv thuc hien de tai:
1.Trn Trng Tun MSSV: 11110750066
2. Bi Ngc Tnh

MSSV:11110750047

3.Phng Vn Tnh MSSV:11110750046


***********************************************************/
int count=0;
int dem=0;
void khoitao(void)// Ham khoi tao
{
P3=0xFF;
TMOD=0x61;
IE=0xAA;
TR0=1;
TR1=1;
TH0=0x3C;
TL0=0xB0;
//T2MOD=0xc9;//Timer 2 che do 2 8 bit auto reload,tine1 16 bit
T2CON=0x04; //timer 2 o che do tu nap 16 bit va nap boi RCAPL2

RCAP2H=0x9b; //Cho timer2 o che do dem 50.000 micro giay


RCAP2L=0x9b;
ET2=1;// Cho phep ngat timer 0
EA=1;// Cho phep ngat toan cuc
TR2=1;// Chay timer 0 bat dau dem so chu ki may

}
long k;
void delay(long time)
{
for (k=0;k<time;k++)
{
;
}
}
void timer()interrupt 1
{
TR0=0;
TR1=0;
dem++;
TH0=0x3C;
TL0=0xB0;
if(dem==4)
{

count=TL1;
TL1=TH1=0;
dem=0;
}
TR0=1;
TR1=1;
}
/
*****************************************Hamngat***************
***************************/
unsigned char xung;
unsigned char phantramxung;
unsigned char chay=0;// Khai bao bien dem de dem tu 1 den 10
void timer2(void) interrupt 5 //Ngat timer 2
{
TR2=0;
TF2=0;

// Dung chay timer 2

chay++;
if(chay<=phantramxung) P2=xung; // Neu bien dem < phan tram xung thi dua
gia tri 1 ra chan
else P2=0;

// Neu dem = phan tram xung

if(chay==10) chay=0; // Neu dem du 10 thi gan lai bang 0 de bat dau chu ki
moi
TR2=1; // Cho chay timer
}

/
**********************************Hamtangtoc********************
*****************/
char tangtoc(void)//ham tang toc dong co
{
if(phantramxung>0)
{
if (P1_0==0)//neu nut tang duoc bam
{
while(P1_0==0) //nut dang giu;
{
;

//khong lam j ca;

}
phantramxung++;
if (phantramxung>9) phantramxung=10;
}
}return phantramxung;
}
/
**************************************Hamgiamtoc***************
********************/
char giam(void)//ham giam toc dong co
{
if (P1_1==0)//neu nut giam duoc bam
{

while(P1_1==0) //nut dang giu;


{
;

//khong lam j ca;

}
phantramxung--;
if (phantramxung<=1) phantramxung=1;
}
return phantramxung;
}
/
*********************************************hamkhoidong********
*******************/
char khoidong(void)//ham khoi dong dong co
{
if(P1_2==0)
{
P1_5=0;
P1_6=1;
xung=0x01;
phantramxung=6;
}
return phantramxung;

/
*********************************************hamquaynguoc*******
********************/
char quaynguoc(void)//ham khoi dong dong co
{
if(P1_4==0)
{
P1_5=1;
P1_6=0;
xung=0x02;
phantramxung=6;
}
return phantramxung;
}
/
*********************************************hamdung***********
****************/
char dung(void)//ham khoi dong dong co
{
if(P1_3==0)
{
P1_5=1;
P1_6=1;
phantramxung=0;
}

return phantramxung;
}

/
****************************************************************
*****************/
void chuso(unsigned char x)// Ham dua du lieu ra PORT
{
switch(x) // Tuy thuoc vao bien dau vao ma dua du lieu ra tu 0...9
{//logic 1 tat led, logic 0 bat led
case 0: { P0=0x40; break; } // So 0
case 1: { P0=0x79; break; } // So 1
case 2: { P0=0x24; break; } // So 2
case 3: { P0=0x30; break; } // So 3
case 4: { P0=0x19; break; } // So 4
case 5: { P0=0x12; break; } // So 5
case 6: { P0=0x02; break; } // So 6
case 7: { P0=0x78; break; } // So 7
case 8: { P0=0x00; break; } // So 8
case 9: { P0=0x10; break; } // So 9
}}
void hienthiso(long n){
int a,b,c,d;
a=n/1000;n=n-1000*a;
b=n/100;n=n-b*100;

c=n/10; n=n-c*10;
d=n;
P3_0=1;chuso(a);delay(1);P3_0=0;
P3_1=1;chuso(b);delay(1);P3_1=0;
P3_2=1;chuso(c);delay(1);P3_2=0;
P3_3=1;chuso(d);delay(1);P3_3=0;
}
// Hm main:
void main(void)
{
khoitao();
while(1)
{
hienthiso(count);
khoidong();
tangtoc();
giam();
dung();
quaynguoc();
}
}

Kt lun:
u im:
Thit k h thng kh n gin chi ph thp
Hin th tc trn phn mm m phng kh tt
n c kh nng ng dung vo thc tin sn xut
Nhc im:
V s dng phng php qut led nn led sng hi m
Ch p dung c cho h thng cng sut nh
Hng pht trin:
- tng tinh chnh xc khi ng dung vo thc tin nn s dung vi
iu khin co xung nhip cao hn, nh pic, avr.
- S dung IC cht hin th led sng r
- Thay th cu s dng Bit bng cu Mosfet cho cng sut cao
hn, hay s dung IC chuyn dng L298 tng hiu sut.
-
Sau mt thi gian tm hiu, di s hng dn nhit tnh ca C Ths.Tng Cm
Nhung, nhm chng em hon thnh ti Thit k xy dng mch iu khin
ng c 12v hin th trn Led 7 thanh.
ng c c iu khin: quay thun,quay ngc, tng tc gim tc bng phm
n. Tc thc t c cp nht qua encoder v hin th ln led 7 thanh.
Qua chng em c cng c kin thc hc, kt hp c vi thc tin,
phc v cho cng vic tng lai rt nhiu.
Chng em c gng ht sc thc hin ti mt cch hon thin v nhanh
nht c th, nhng do trnh cn hn ch nn cn nhiu thiu st, ti mi
dng li vic lm mt chic ng h hin th thi gian n gin.
Cng vi ti ny, trong tng lai chng em s pht trin n mc cao hn, c
th kt hp chng vi cc thit b khc s dng trong thc tin cuc sng
hon thin hn m hnh n ca mnh.

Danh mc ti liu tham kho

Bi ging vi x lvi iu khin i hc K Thut Cng Nghip

Bi ging vi H thng Nhng i hc K Thut Cng Nghip

Gio trnh h vi iu khin 8051 Tng Vn n

Hng dn s dng kit 8051 BKIT HARDWARE CLUB

Programing Embedded Systems II Michael J.Pont Unisversity of Leicester

Cc trang web tham kho:


http://www.keil.com/forum/

http://vagam.dieukhien.net/

http://vidieukhien.net/

http://www.8051projects.net/