Anda di halaman 1dari 70

Bi Hng Hu - Bi Gip

thc hnh S7 300

Ti liu hng dn

i. Gii thiu
B iu khin lp trnh (PLC - Programmable Logic Control),
l loi thit b cho php thc hin linh hot cc thut ton iu
khin s thng qua mt ngn ng lp trnh, thay cho vic phi
thc hin thut ton bng mch s. Nh vy, vi chng trnh
iu khin trong mnh, PLC tr thnh b iu khin nh gn, d
thay i thut ton v c bit d trao i thng tin vi mi trng xung quanh (vi cc PLC khc hoc my tnh). Ton b chng
trnh c lu nh trong b nh ca PLC di dng cc khi chng trnh
(khi OB, FC hoc FB) v c thc hin lp theo chu k ca vng
qut (scan).
thc hin c mt chng trnh iu khin, tt nhin PLC
phi c tnh nng nh mt my tnh, ngha l phi c mt b vi x
l (CPU), mt h iu hnh, b nh lu chng trnh iu
khin, d liu v tt nhin phi c cc cng vo/ ra giao tip
vi i tng iu khin v trao i thng tin vi mi trng
xung quanh. Bn cnh , nhm phc v bi ton iu khin s,
PLC cn cn phi c thm cc khi lng chc nng c bit khc
nh b m (Counter), b thi gian (Timer)... v nhng khi hm
chuyn dng (hnh1.1).
1.1

Cu trc ca PLC S7 300.

1.1.1 Tng quan


PLC S7-300 c cu trc dng modul gm cc loi sau:
-

Cc loi CPU: 312IFM, 313, 313C, 314, 314IFM, 314C,

315, 315-2DP, 316-2DP, 318-2.


-

Modul tn hiu SM, xut nhp tn hiu tng

ng/s: SM321, SM322, SM323, Sm311, SM332, SM334,


SM338, SM374.
-

Modul chc nng FM.

Modul truyn thng CP.

Modul ngun PS307 cp ngun 24VDC cho CPU v

cc modul khc, c cc mc dng 2A, 5S, 10A.


Cng ty TBT v PTCN Ngc Huy

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Modul ghp ni IM: IM360, IM361, IM365.

Cc modul gn trn thanh ray nh hnh di, mi ray c th gn


ti a c 8 modul SM/FM/CP bn phi CPU, to thanh mt rack
kt ni vi nhau qua bus connect gn mt sau ca modul. Mi
modul c gn mt slot tnh t tri qua phi, modul ngun l slot1,
modul CPU l slot2, modul k tip c th l cc modul vo ra
digital, analog hoc l cc modul ng dng khc v c s bt u
t slot 4.

B tr th t cc modul trn ray


Nu c nhiu modul th b tr thnh niu rack (tr CPU312IFM
v CPU313 ch c mt rack), CPU rack 0, slot2, k l modul
pht IM360, slot 3, c nhim v kt ni rack 0 vi rack 1, 2, 3 trn
mi rack ny c modul kt ni thu IM361, bn phi modul IM l cc
modul SM/FM/CP. Cp ni hai modul IM di ti a l 10m. Cc modul
c nh s theo slot v dng lm c s t a ch u
cho cc modul ng vo ra tn hiu. i vi CPU 315-2DP, 316-2DP,
318-2 c th gn a ch tu cho cc modul.

Cng ty TBT v PTCN Ngc Huy

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Mi a ch ng vi mt byte, vi cc modul s a ch mt ng
vo hay ra l x, y, x l ic ch byte, y c gi tr t 0 n 7. V d
modul SM321 DI 32 c 32 ng vo gn k CPU slot 4 c a ch
l I0.y, I1.y, I2.y I l k hiu ch ng vo s. Modul analog c
a ch theo word, v d modul SM332 A04 c 4 ng ra analog
gn slot 5 rack 1 c a ch PQW400, PQW402, PQW404,
PQW406, ng ra s c k hiu l Q cn ng vo analog c k hiu
l PIW.
- CPU 312IFM, 314IFM, 31xC c tch hp sn mt s modul m
rng.
- CPU 312IFM, 312C c 10 ng vo s i ch I124.0 n
I127.0, I125.1, c 6 ng ra s Q12.0 n Q124.5.
- CPU 313C 24DI c I124.0 n I126.7, 16DO c Q12.0 n
Q125.7 ng vo tng t AI c i ch 752 n 761, hai ng ra AO
752 n 755.
- CPU 314IFM c 20 ng vo ra s I124.0 n I126.3, 16 ng
ra s Q124.0 n Q125.7, c 4 ng vo tng t PIW128, PIW130,
PIW132, PIW134, mt ng ra tng t PQW128.

Cng ty TBT v PTCN Ngc Huy

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

1.1.2 Module CPU


Module CPU l loi module c cha b vi x l, h iu hnh, b
nh, cc b thi gian, b m, cng truyn thng (RS 485)... v c
th cn c mt vi cng vo ra s. Cc cng vo/ra s c trn
module CPU c gi l cng vo/ra onboard.
Cc modul CPU khc nhau v hnh dng chc nng, vn tc x l
lnh. Loi 312IFM, 314IFM khng c th nh, loi 312IFM, 313 khng
c pin EPROM, loi 315-2DP, 316-2DP, 318-2 c cng truyn thng
DP
ngha ca cc n bo trn CPU.
- SF sng bo li phn cng hay phn mm.
- BATF sng bo li pin nui.
- DC5V sng xanh l cy bo ngun 5V bnh thng.
- FRCE sng vng force request tch cc.
- RUN sng xanh l cy bo CPU ang chy, chp sng lc
start-up w, 1Hz; mode HALT w, 0,5Hz.
- STOP sng vng khi CPU dng hay HALT hay start-up, chp khi
memory reset request.
-

BUSF sng bo li phn cng hay phn mm giao

din PROFIBUS

Cng ty TBT v PTCN Ngc Huy

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Kho mode c 4 ch :
- RUN-P ch lp trnh v chy.
- RUN ch chy chng trnh.
- STOP ngng chy chng trnh.
- MRES reset bj nh.
Th nh c dung lng t 16KB n 4MB, cha chng trnh t PLC
chuyn qua v chuyn chng trnh ngc tr li cho CPU.
Pin nui gip lu chng trnh v d liu khi b mt in (pin c
th nuI ti a1 nm), ngoi ra cn nui c ng h thi gian
thc. Vi loi CPU khng c pin nui th cng c mt phn vng nh
c duy tr.
Thng qua cng truyn thng MPI (Multi Point Interface) c th
ni: my tnh lp trnh, mn hnh OP (Operator panel), cc PLC c
cng MPI (S7-200, S7-300, M7-300, S7-400, C7-6xx, ) vn tc
truyn n 187,5kbs (12Mbps vi CPU 318-2, 10,2kbps vi S7-200).

Cng ty TBT v PTCN Ngc Huy

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Cng Profibus DP ni cc thit b trn theo mng Profibus vi tc


truyn ln n 12Mbps.
Cc vng nh ca PLC
Vng nh chng trnh: (load memory) cha cc chng trnh
ngi dng (khng cha a ch k hiu v ch thch) c th l
RAM hay EEPROM trong CPU hay trn th nh.
Vng nh lm vic (working memory) chnh l RAM, cha chng trnh do vng nh chng trnh chuyn qua; ch cc phn chng trnh cn thit mi c chuyn qua, phn no khng cn th
li vng nh chng trnh, v d nh block header, data block.
Vng nh h thng;(system memory) phc v cho chng
trnh ngi dng, bao gm time, counter, vng nh d liu M, b nh
m xut nhp
Trn CPU 312IFM v 314 IFM vng nh chng trnh l RAM v
EEPROM; cc CPU khc c pin nui, v vng nh chng trnh l RAM
v th nh. Khi mt ngun hay ch MRES th RAM s b xo.
Mt s vng nh ca RAM (time, counter, vng nh M, khi d liu)
c th c khai bo l lu gi (retentive) bng phn mm
chuyn cc vng ny sang b nh lu gi (NVRAM non volative) d
khng c pin nui kch thc c th loi CPU.
1.1.3 Module m rng
Cc loi module m rng c chia thnh 5 loi chnh:
1) PS (Power supply): Module ngun nui. C 3 loi 2A, 5A v 10A.
2) MS (Signal module): Module m rng cng tn hiu vo/ra,
bao gm:
a) DI (Digital input): Module m rng cc cng vo s. S cc
cng vo s m rng c th 8, 16 hoc 32 tu thuc vo tng loi
module.
b) DO (Digital output): Module m rng cc cng ra s. S cc
cng ra s m rng c th 8, 16 hoc 32 tu thuc vo tng loi
module.

Cng ty TBT v PTCN Ngc Huy

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

c) DI/DO (Digital input/Digital output): Module m rng cc cng


vo/ra s. S cc cng vo ra m rng c th 8 vo/8 ra hoc 16
vo/16 ra tu thuc vo tng loi module.
d) AI (Analog input): Module m rng cc cng vo tng t. V
bn cht chng chnh l nhng b chuyn i tng t 12 bist
(AD), tc l mi tn hiu tng t c chuyn thnh mt tn hiu
s (nguyn) c di 12 bit. S cc cng vo tng t c th 2, 4
hoc 8 tu tng loi module.
e) AO (Analog input): Module m rng cc cng ra tng t.
Chng chnh l nhng b chuyn i s tng t (DA). S cc
cng ra tng t c th l 4 hoc nhiu hn tu tng loi module.
f) AI/AO (Analog input/Analog output): Module m rng cc cng
vo/ra tng t . S cc cng vo tng t c th l 4 vo/2 ra,
hoc 4 vo/4 ra tu tng loi module.
3) IM (Interface module): Module ghp ni. y l loi module
chuyn dng c nhim v ni tng nhm cc module m rng li vi
nhau thnh mt khi v c qun l chung bi mt module CPU.
Thng thng cc module m rng c g lin vi nhau trn mt
thanh gi l rack. Trn mi mt rack ch c th g c nhiu
nht 8 module m rng (khng k module CPU, module ngun
nui). Mt module CPU S7 300 c th lm vic trc tip c vi
nhiu nht 4 rack v cc rack ny phi c ni vi nhau bng
module IM.
4) FM (Function module): Module c chc nng iu khin ring,
v d nh module iu khin ng c bc, module iu khin
ng c servo, module PID, module iu khin vng kn, ...
5) CP (Communication module): Module phc v truyn thng
trong mng gia cc PLC vi nhau hoc gia PLC vi my tnh.
1.2 Kiu d liu v phn chia b nh:
1.2.1 Kiu d liu:
Mt chng trnh ng dng trong S7 300 c th s dng cc
kiu d liu sau:
Cng ty TBT v PTCN Ngc Huy

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

1) BOOL: vi dung lng mt bit v c gi tr l 0 hoc 1 (ng


hoc sai). y l kiu d liu cho bin hai tr.
2) BYTE: gm 8 bit, thng c dng biu din mt s
nguyn dng trong khong t 0 n 255 hoc m ASCII ca
mt k t. V d:
L

B#16#14

// Np s nguyn 14 vit theo h c s 16

di 1 byte vo ACCU1
3) WORD: gm 2 byte, biu din mt s nguyn dng t 0
n 65535. V d:
L

930

W#16#3A2

4) INT: cng c dung lng l 2 byte, dng biu din mt s


nguyn trong khong 32768 n +32767. V d:
L

930

W#16#3A2

5) DINT: gm 4 byte, dng biu din mt s nguyn t


2147483648 n +2147483647. V d:
L

930

DW#16#3A2

6) REAL: gm 4 byte, dng biu din mt s thc du phy


ng. V d:
L

1.234567e+13

930.0

7) S5T (hay S5TIME): khong thi gian, c tnh theo


gi/pht/giy/mili giy. V d:
L

S5T#2h_1m_0s_5ms.

l lnh to khong thi gian l hai ting, mt pht v 5


miligiy.
8) TOD: biu din gi tr thi gian tnh theo gi/pht/giy. V
d:
L

TOD#5:45:00.

L lnh khai bo gi tr thi gian trong ngy l 6 gi km 15


pht.
Cng ty TBT v PTCN Ngc Huy

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

9) DATE: biu din gi tr thi gian tnh theo nm/thng/ngy.


V d:
L

DATE#1999128.

L lnh khai bo ngy mng 8 thng 12 nm 1999.


10) CHAR: biu din mt hoc nhiu k t (nhiu nht l 4 k
t). V d:
L

ABCD

1.2.2 Cu trc b nh ca CPU


B nh ca S7 300 c chia lm ba vng chnh:
1) Vng cha chng trnh ng dng. Vng nh chng trnh c
chia thnh 3 min:
a) OB (Organisation Block): Min cha chng trnh t chc.
b) FC (Function): Min cha chng trnh con, c t chc thnh
hm c bin hnh thc trao i d liu vi chng trnh
gi n.
c) FB (Function Block): Min cha chng trnh con, c t chc
thnh hm v c kh nng trao i d liu vi bt c mt khi chng trnh no khc. Cc d liu ny phi c xy dng thnh mt
khi d liu ring (gi l DB Data block).
1) Vng cha tham s ca h iu hnh v chng trnh ng
dng, c phn chia thnh 7 min khc nhau, bao gm:
a) I (Process image input): Min b m cc d liu cng vo
s. Trc khi bt u thc hin chng trnh, PLC s c gi tr
logic ca tt c cc cng u vo v ct gi chng trong vng nh
I. Thng thng, chng trnh ng dng khng c trc tip trng
thi logic ca cng vo s m ch ly d liu ca cng vo t b
m I.
b) Q (Process image output): Min b m cc d liu cng ra
s. Kt thc giai on thc hin chng trnh, PLC s chuyn gi tr
logic ca b m Q ti cc cng ra s. Thng thng, chng trnh
khng trc tip gn gi tr ti tn cng ra m ch chuyn chng
vo b m Q.
Cng ty TBT v PTCN Ngc Huy

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

c) M: Min cc bin c. Chng trnh ng dng s dng vng nh


ny lu gi cc tham s cn thit v c th truy cp n theo bit
(M), Byte (MB), t (MW) hay t kp (MD).
d) T: Min nh phc v b thi gian (Timer) bao gm vic lu tr
gi tr thi gian t trc (PVPreset Value), gi tr m thi gian
tc thi (CVCurrent Value), cng nh gi tr logic u ra ca b thi
gian.
e) C: Min nh phc v b m (Counter) bao gm vic lu tr
gi tr t trc (PVPreset Value), gi tr m tc thi (CVCurrent
Value) v gi tr logic u ra ca b m.
g) PI: Min a ch cng vo ca cc module tng t (I/O
External Input). Cc gi tr tng t ti cng vo ca module tng
t s c module c v chuyn t ng theo nhng a ch.
Chng trnh ng dng c th truy nhp min nh PI theo tng Byte
(PIB), tng t (PIW) hoc theo tng t kp (PID).
h) PQ: Min a ch cng ra cho cc module tng t (I/O
External Output). Cc gi tr theo nhng a ch ny s c
module tng t chuyn ti cc cng ra tng t. Chng trnh ng
dng c th truy cp min nh PQ theo tng Byte (PQB) tng t
(PQW) hoc theo tng t kp (PQD).
2) Vng cha cc khi d liu, c chia thnh 2 loi:
a) DB (Data Block): Min cha cc d liu c t chc thnh
khi. Kch thc cng nh s lng khi do ngi s dng quy nh, ph
hp vi tng bi ton iu khin. Chng trnh c th truy nhp
min ny theo tng bit (DBX), byte (DBB), t (DBW) hoc t kp
(DBD).
b) L (Local data block): Min d liu a phng, c cc khi
chng trnh OB, FC, FB t chc v s dng cho cc bin nhp tc
thi v trao i d liu ca bin hnh thc vi nhng khi chng
trnh gi n. Ni dung ca mt s d liu trong min nh ny s
b xo khi kt thc chng trnh tng ng trong OB, FC, FB. Min
ny c th c truy nhp t chng trnh theo bit (L), byte (LB) t
(LW) hoc t kp (LD).
Cng ty TBT v PTCN Ngc Huy

10

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

1.2.3 Vng qut chng trnh:


PLC thc hin chng trnh theo chu trnh lp. Mi vng lp c gi l vng qut (scan). Mi vng qut c bt u bng giai
on chuyn d liu t cc cng vo s ti vng b m o I, tip
theo l giai on thc hin chng trnh. Trong tng vng qut, chng trnh c thc hin t lnh u tin n lnh kt thc ca
khi OB1 (Block End). Sau giai on thc hin chng trnh l giai
on chuyn cc ni dung ca b m o Q ti cc cng ra s.
Vng qut c kt thc bng giai on truyn thng ni b v
kim li (hnh 1.2)

Truyn thng v
kim tra ni b

Chuyn dliu t cng


vo t i v ng
m o I

Chuyn dliu t v ng
m o Q t i cng ra
Thc hin
ch ng tr
nh

Hnh 1.2 Vng qut chng trnh


Ch rng, b m I v Q khng lin quan ti cc cng vo/ra tng t nn cc lnh truy nhp cng tng t c thc hin trc
tip vi cc cng vt l ch khng thng qua b m.
Thi gian cn thit PLC thc hin c mt vng qut gi l
thi gian vng qut (Scan time). Thi gian vng qut khng c
nh, tc l khng phi vng qut no cng c thc hin trong
mt khong thi gian nh nhau. C vng qut c thc hin lu, c
vng qut c thc hin nhanh tu thuc vo s lnh trong chng
trnh c thc hin, vo khi lng d liu c truyn thng ...
trong vng qut .
Cng ty TBT v PTCN Ngc Huy

11

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Nh vy, gia vic c d liu t i tng x l, tnh ton v


vic gi tn hiu iu khin ti i tng c mt khong thi gian
tr ng bng thi gian vng qut. Ni cch khc, thi gian vng
qut quyt nh tnh thi gian thc ca chng trnh iu khin
trong PLC. Thi gian vng qut cng ngn, tnh thi gian thc ca
chng trnh cng cao.
Nu s dng cc khi chng trnh c bit c ch ngt,
v d nh khi OB40, OB80..., chng trnh ca cc khi s c
thc hin trong vng qut khi xut hin tn hiu bo ngt cng
chng loi. Cc khi chng trnh ny c th c thc hin ti mi
im trong vng qut ch khng b g p l phi trong giai
on thc hin chng trnh. Chng hn, nu mt tn hiu bo
ngt xut hin khi PLC ang giai on truyn thng v kim tra
ni b, PLC s tm dng cng vic truyn thng, kim tra, thc
hin khi chng trnh tng ng vi tn hiu bo ngt . Vi
hnh thc x l tn hiu ngt nh vy, thi gian vng qut s cng
ln khi cng c nhiu tn hiu ngt xut hin trong vng qut. Do
, nng cao tnh thi gian thc cho chng trnh iu
khin, tuyt i khng nn vit chng trnh x l ngt qu di
hoc qu lm dng vic s dng ch ngt trong chng trnh
iu khin.
Ti thi im thc hin lnh vo/ra, thng thng lnh khng
lm vic trc tip vi cng vo/ra m ch thng qua b m o
ca cng trong vng nh tham s. Vic truyn thng gia b m
o vi ngoi vi trong cc giai on 1 v 3 do h iu hnh CPU
qun l. mt s module CPU, khi gp lnh vo/ra ngay lp tc,
h thng s cho dng mi cng vic khc, ngay c chng trnh x
l ngt, thc hin
trc tip vi cng vo/ra.
Lnh 1

1.2.4 Cu trc chng


trnh
300 c lu trong b nh
Cng ty TBT v PTCN Ngc Huy

Lnh 2

OB1

...

Chng trnh cho S7

Vng
qut

Lnh cui cng

12

Hnh 1.3 Lp trnh tuyn

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

ca PLC vng dnh ring cho chng trnh v c th c lp trnh


vi hai dng cu trc khc nhau:
1) Lp trnh tuyn tnh: Ton b chng trnh iu khin nm
trong mt khi trong b nh. Loi hnh cu trc tuyn tnh ny ph
hp vi nhng bi ton t ng nh, khng phc tp. Khi c chn
phi l khi OB1, l khi m PLC lun qut v thc hin cc lnh
trong n thng xuyn, t lnh u tin n lnh cui cng v quay
li lnh u tin (hnh 1.3).
2) Lp trnh c cu trc: Chng trnh c chia thnh nhng
phn nh vi tng nhim v ring v cc phn ny nm trong
nhng khi chng trnh khc nhau. Loi hnh cu trc ny ph hp
vi nhng bi ton iu khin nhiu nhim v v phc tp. PLC S7
300 c bn loi khi c bn:
- Loi khi OB (Organization Block): Khi t chc v qun l chng trnh iu khin. C nhiu loi khi OB vi nhng chc nng
khc nhau, chng c phn bit vi nhau bng mt s nguyn i
sau nhm k t OB, v d nh OB1, OB35, OB40, OB80, ...
- Loi khi FC (Program Block): Khi chng trnh vi nhng chc
nng ring ging nh mt chng trnh con hoc mt hm (chng
trnh con c bin hnh thc). Mt chng trnh ng dng c th
c nhiu khi FC v cc khi FC ny c phn bit vi nhau bng
mt s nguyn i sau nhm k t FC. Chng hn nh: FC1, FC2, ...
- Loi khi FB (Function Block): L loi khi FC c bit, c kh
nng trao i mt lng d liu ln vi cc khi chng trnh khc.
Cc d liu ny phi c t chc thnh khi d liu ring c tn
gi l Data block. Mt chng trnh ng dng c th c nhiu khi
FB v cc khi FB ny c phn bit vi nhau bng mt s nguyn
i sau nhm k t FB. Chng hn nh: FB1, FB2, ...
- Loi khi DB (Data block): Khi cha cc d liu cn thit
thc hin chng trnh. Cc tham s ca khi do ngi dng t t.
Mt chng trnh ng dng c th c nhiu khi DB v cc khi DB
ny c phn bit vi nhau bng mt s nguyn sau nhm k t
DB. V d DB1, DB2, ...
Cng ty TBT v PTCN Ngc Huy

13

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

- Chng trnh trong cc khi c lin kt vi nhau bng cc lnh


gi khi, chuyn khi. Xem nhng phn chng trnh trong cc
khi nh l cc chng trnh con th S7 300 cho php gi chng
trnh con lng nhau, tc l t chng trnh con ny gi mt chng
trnh con khc v t chng trnh con c gi li gi ti mt chng
trnh con th 3.... S cc lnh gi lng nhau ph thuc vo tng
chng loi module CPU m ta s dng. V d nh vi module CPU 414
th s lnh gi lng nhau nhiu nht c th cho php l 8. Nu s
ln gi khi lng nhau m vt qu con s gii hn cho php PLC s t
chuyn sang ch STOP v t c bo li.
1.2.5 Nhng khi OB c bit
Trong khi khi OB1 c thc hin u n tng vng qut
trong giai on thc hin chng trnh (giai on 2) th cc khi
OB khc ch c thc hin khi xut hin tn hiu bo ngt tng
ng, ni cch khc chng trnh vit cho cc khi OB ny chnh l
chng trnh x l tn hiu ngt (event). Chng bao gm:
1) OB10 (Time of Day Interrupt): Chng trnh trong khi OB10 s
c thc hin khi gi tr ca ng h thi gian thc nm trong mt
khong thi gian c quy nh. OB10 c th c gi mt ln,
nhiu ln cch u nhau tng pht, tng gi, tng ngy, .... Vic
quy nh khong thi gian hay s ln gi OB10 c thc hin nh
chng trnh h thng SFC28 hoc trong bng tham s ca
module CPU nh phm mm STEP 7.
2) OB20 (Time Delay Interrupt): Chng trnh con trong khi
OB20 s c thc hin sau mt khong thi gian tr t trc k t
khi gi chng trnh h thng SFC32 t thi gian tr.
3) OB35 (Cyclic Interrupt): Chng trnh con trong OB35 s c
thc hin cch u nhau mt khong thi gian c nh. Mc
nh, khong thi gian ny s l 100ms, song ta c th thay i
n trong bng tham s ca module CPU nh phm mm STEP 7.
4) OB40 (Hardware Interrupt): Chng trnh trong OB40 s c
thc hin khi xut hin mt tn hiu bo ngt t ngoi vi a vo

Cng ty TBT v PTCN Ngc Huy

14

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

module CPU thng qua cc cng vo/ra s onboard c bit,


hoc thng qua cc module SM, CP, FM.
5) OB80 (Cycle Time Fault): Chng trnh trong khi OB80 s c
thc hin khi thi gian vng qut (scan time) vt qu khong thi
gian cc i quy nh hoc khi c mt tn hiu bo ngt gi
mt khi OB no m khi OB ny cha kt thc ln gi trc.
Mc nh, scan time cc i l 150ms, nhng c th thay i n
thng qua bng tham s ca module CPU nh phm mm STEP 7.
6) OB81 (Power Supply Fault): Module CPU s gi chng trnh
trong khi OB81 khi pht hin thy c li v ngun nui.
7) OB82 (Diagnostic Interrupt): Chng trnh trong OB82 c gi
khi CPU pht hin c s c t cc module vo/ra m rng. Cc
module m rng ny phi l nhng module c kh nng t kim tra
mnh (diagnostic cabilities).
8) OB85 (Not Load Fault): CPU s gi khi OB85 khi pht hin
thy chng trnh ng dng c s dng ch ngt nhng chng
trnh x l tn hiu ngt li khng c trong khi OB tng ng.
9) OB87 (Communication Fault): Khi OB87 s c gi khi CPU
pht hin thy li trong truyn thng v d nh khng c tn hiu
tr li t i tc.
10) OB100 (Start Up Information): Khi OB100 s c thc hin
mt ln khi CPU chuyn sang trng thi t STOP (dng) sang RUN
(chy).
11) OB101 (Cold Start Up Information Ch c vi S7300): Khi
OB101 s c thc hin mt ln khi cng tc ngun ca CPU
chuyn trng thi t OFF (tt) sang ON (m).
12) OB121 (Synchronous error): Khi OB121 s c thc hin khi
CPU pht hin thy li logic trong chng trnh nh: i sai kiu d
liu hoc li truy nhp khi DB, FC, FB khng c trong b nh ca
CPU.
13) OB122 (Synchronous error): Khi OB122 s c thc hin khi
CPU pht hin thy li truy nhp module trong chng trnh, v d

Cng ty TBT v PTCN Ngc Huy

15

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

chng trnh c lnh truy nhp module vo/ra m rng nhng li


khng tm thy module ny.

Cng ty TBT v PTCN Ngc Huy

16

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

II. Hng dn s dng STEP7


1. Ci t Step 7 v chn ch lm vic
Step7 l mt phn mm h tr:
-

Khai bo cu hnh cng cho mt trm PLC thuc h Simatic


S7-400/400.

Xy dng cu hnh mng gm nhiu trm PLC S7-400/400


cng nh th tc truyn thng gia chng.

- Son tho v ci t chng trnh iu khin cho mt hoc


nhiu trm.
- Quan st vic thc hin chng trnh iu khin mt trm
PLC v g ri chng trnh.
Ngoi ra, Step7 cn c c mt th vin y vi cc hm chun
hu ch, phn tr gip online rt mnh c kh nng tr li mi cu
hi ca ngi s dng v cch s dng Step7, v c php lnh trong
lp trnh, v xy dng cu hnh cng ca mt trm cng nh ca
mt mng gm nhiu trm PLC...
2.1 Ci t Step 7:
C nhiu phin bn ca b phn mm gc ca Step7 hin c ti
Vit Nam. ang c s dng nhiu nht l phin bn (version) 4.2
v 5.0. Trong khi phin bn 4.2 kh ph hp vi PC c cu hnh trung
bnh (CPU 80586, 8MB RAM, 90MB cn trng trong cng, mn
hnh VGA) nhng li i hi tuyt i phi c bn quyn th phin
bn 5.0 tr ln, mc d i hi cu hnh PC phi mnh tc
nhanh nhng khng i hi phi c bn quyn mt cch tuyt i,
tc l phin bn ny vn chy ( mc hn ch) khi khng c bn
quyn.
Phn ln cc a gc ca Step 7 u c kh nng t thc hin
chng trnh ci t (autorun). Bi vy ta ch cn cho a vo
CD v thc hin theo ng cc dn hin trn mn hnh. Ta cng
c th ch ng thc hin vic ci t bng cch gi chng
trnh setup.exe c trn a. Cng vic ci t Step7, v c bn,
khng khc nhiu so vi vic ci t cc phn mm ng dng khc
(Window, Office ...), tc l cng bt u bng vic chn ngn ng
Cng ty TBT v PTCN Ngc Huy

17

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

trong ci t (mc nh l ting Anh), chn nh mc ch trn


cng (mc nh l c:\siemens), kim tra dung tch cn li trn
ch, chn ngn ng s c s dng trong qu trnh lm vic vi
Step7 sau ny...
Tuy nhin, so vi cc phn mm khc th vic ci t Step 7 s
c vi im khc bit cn phi c gii thch r thm:
Khai bo m hiu sn phm : M hiu sn phm lun i km theo
phn Step7 v c in ngay trn a cha b ci Step7. Khi trn
mn hnh hin ra ca s yu cu cho bit m hiu sn phm, ta
phi in y vo tt c cc mc ca ca s , k c tn
v a ch ngi s dng. Sau n phm continue tip tc.
1) Chuyn bn quyn: Bn quyn ca Step7 nm trn mt a
mm ring. Trong qu trnh ci t, trn mn hnh s xut hin
ca s yu cu chuyn sang ch (mc nh l c:\) c dng nh
sau:

Tn a
cha bn
quyn

Tn a
ch

T`a c th chuyn bn quyn t a mm sang c:\ ngay


trong khi ci t Step7 bng cch cho a bn quyn vo A:
ri n phm Next. Ta cng c th b qua v s chuyn bn quyn
sau vo lc khc bng cch chn No,
install authorization later. Trong trng
hp b qua th sau
ny,
lc b
chuyn
Khng
c thit

t s
EPROM
bn quyn, ta phi
dng chng
C thit b t
EPROM ca PG

Cng ty TBT v PTCN Ngc Huy


Thit b t ri bn
ngoi

18

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

trnh chuyn bn quyn c tn AuthorsW.EXE cng c trn a


bn quyn hoc c cng trong a CD vi phn mm Step7 gc.
Ch rng a mm cha bn quyn (Author) c bo v cm
sao chp. Cho d bn quyn c chuyn t a mm sang
cng v trn a mm khng cn bn quyn, nhng n vn l mt
a c bit c ch cha bn quyn. Bn quyn c sao chp
sang cng s nm trong th mc Ax nf zz. Nu th mc ny b
hng, ta s mt bn quyn. Bi vy, mi khi mun ci t li h
thng hay dn dp li a cng th trc phi rt bn quyn ra
khi c:\ v chuyn n tr v a mm Author cng bng chng
trnh AuthorsW. EXE.

2) Khai bo thit b t EPROM:


Ca s:
Chng trnh Step7 c kh nng t chng trnh ng dng ln th
EPROM cho PLC. Nu my tnh PC ca ta c thit b t EPROM
th cn phi thng bo cho Step7 bit khi trn mn hnh xut
hin ca s:
3) Chn giao din PC/PLC:
Chng trnh Step 7 c ci t trn PC hoc PG h tr vic
son tho cu hnh cng cng nh chng trnh cho PLC, tc l sau
ton b nhng g son tho s c dch v chuyn sang
PLC. Khng nhng th Step7 cn to kh nng quan st vic thc
hin chng trnh ca PLC. Mun nh vy ta cn phi c b giao
din ghp ni gia PC vi PLC truyn thng d liu. Step7 cn
to kh nng quan st ghp ni vi PLC qua nhiu giao din khc
nhau nh qua th MPI, qua b chuyn PC/PPI, qua th PROFIBUS
(CP)... nhng chng phi c khai bo s dng.
Cng ty TBT v PTCN Ngc Huy

19

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Ngay sau khi Step7 va c ci t xong, trn mn hnh xut


hin ca s thng bo cho ta chn cc b giao din s c s dng.
Ca s ny c dng nh sau:

Cc b giao
din c th
chn ci
t

Mun chn b giao din no, ta nh du b giao din


pha bn tri ri n phm Install. Nhng b giao din c chn
s c ghi li vo pha bn phi. Sau khi chn xong cc b giao
din s dng, ta cn phi t tham s lm vic cho nhng b
giao din bao gm tc truyn, cng ghp ni vi my
tnh... Chng hn, khi chn b giao din PC Adapter ta phi
t tham s lm vic cho n thng qua ca

mn hnh:
Cng ghp ni vi PC
Tc truyn (baud)

2.1 t tham s lm vic

Cng ty TBT v PTCN Ngc Huy

20

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Sau khi ci t xong Step7, trn mn hnh (desktop) s xut


hin biu tng (icon) ca n nh hnh bn. ng thi trong Menu
ca Window cng c th mc Simatic vi tt c cc tn ca nhng
thnh phn lin quan, t cc phn mm tr gip n cc phn
mm t cu hnh, ch lm vic ca Step7...
Khi va c ci t, Step 7 c cu hnh mc nh v ch
lm vic caSimatic, chng hn nh c php cc lnh li c vit
theo ting c nh JU c vit thnh SPA, JC thnh SPB, CAD thnh
TAD ... Mun chuyn v dng thng dng quc t ta phi t li
cu hnh cho Step7.
lm vic ny, trc ht ta phi vo Step7 bng cch nhy kp
phm chut tri ti biu tng ca n. Trn mn hnh s xut hin
ca

chnh

ca

Step7.

Chn

tip

OptionCustomizieLanguageIEC ri n phm OK (xem hnh di ).

Tt nhin, bn cnh vic chn ngn ng cho c php lnh ta cn


c th sa i nhiu chc nng khc ca Step7 nh ni s cha chng trnh trn a cng, nhng thanh ghi s c hin th ni
dung khi g ri chng trnh..., song cc vic khng nh hng
quyt nh ti vic s dng Step7 theo thi quen ca ta nh ngn
ng c php lnh.
2. Son tho mt Proiject
Khi nim Project trong Simatic khng n thun ch l chng
trnh ng dng m rng hn bao gm tt c nhng g lin quan

Cng ty TBT v PTCN Ngc Huy

21

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

n vic thit k phn mm ng dng iu khin, gim st


mt hay nhiu trm PLC. Theo khi nim nh vy, trong mt Project
s c:
a)

Bng cu hnh cng v tt c cc module ca tng trm PLC.

b)

Bng tham s xc nh ch lm vic cho tng module ca


mi trm PLC.

c)

Cc logic block cha chng trnh ng dng ca tng trm PLC.

d)

Cu hnh ghp ni v truyn thng gia cc trm PLC.

e)

Cc mn hnh giao din phc v vic gim st ton b mng


gim st tng trm PLC ca mng.
y, trong khun kh phn mm Step7, chng ti ch gii

thiu vic son tho mt Project gm cc phn a), b), v c). Nhng
phn cn li bn c c th tham kho thm trong ti liu[1].
2.1 To mt Project mi v xy dng cu hnh cho trm.
to mt Project mi, t giao din mn hnh ca Step7 ta chn
FileNew Project/Library. Xut hin giao din sau:

Nhn Next > tip tc.

Cng ty TBT v PTCN Ngc Huy

22

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Trong Tab CPU ta chn loi CPU ca trm, trng hp loi CPU ca
trm khng c trong th vin th ta phi tin hnh ci t cu
hnh cng cho loi CPU m ta dng.
Nhn Next > tip tc.

t tn cho Project v kt thc qu trnh.


Cng ty TBT v PTCN Ngc Huy

23

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Sau khi qu trnh kt thc th xut hin giao din sau: Na


ca s bn tri sp xp cc th mc con, click chut vo
m cc th mc con. Bm vo dng SIMATIC 300 Station v m
Hardware

Gi s cu hnh n gin gm cc modul DI, DI/DO, ta click


chut vo dng SIMATIC 300, SM-300, chn cc modul ph hp dng
chut ko vo cc Slot ca Station t v tr s 4 tr i (Slot 3 dnh
cho modul IM), kt thc qu trnh khai bo cu hnh cng.
Cng ty TBT v PTCN Ngc Huy

24

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Trn Station cho ta bit cc thng s v tn, a ch, s lng


cc u vo ra ca CPU cng nh ca cc modul.
Tr li Projetc, click vo mc Block ta thy xut hin OB1, nu
ta lp tnh tuyn tnh ngha l khng dng cc khi FC, FB t to
th m OB1 ra v tin hnh vit chng trnh trn .

Bm vo menu View chn STL, LAD, FBD cch vit chng


trnh, trong qu trnh vit ta c th dng cc a ch tuyt i
(I0.0, MW2, T5) hoc ta cng c th dng cc a ch k hiu
(Start, Speed, Delay). Dng cc a ch k hiu gip chng
trnh d hiu hn. C hai loi k hiu l k hiu cc b v k hiu
ton cc (hay chia s), K hiu cc b khai bo trong bng khai bo
bin ca khi v ch c ngha trong phm vi khi , k hiu
ton cc khai bo trong bng k hiu Symbols, c ngha trong
ton b cc khi ca Project. Vic khai bo k hiu ton cc c th
thc hin trc hay sau khi vit m. Khi logic c ti a l 999
network, mi netword c ti a 2000 hng, mi hng gm nhn,
lnh, a ch v cc dng ch thch.
Cc bc thc hin khai bo bin ton cc nh sau:

Cng ty TBT v PTCN Ngc Huy

25

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Cc bin k hiu c a vo cc dng, di ti a 24 k t s,


k t c bit tr du nhy , khng phn bit ch hoa v ch
thng. Bng k hiu cha ti a 16380 k hiu. Sau khi khai
bo xong cc bin, vo menu Symbol Table - Save lu bng. Vo
ca s ca khi chn View Display with Symbol Representation
hin th a ch k hiu trong chng trnh, k hiu tuyt
i c ng khung bng du , k hiu cc b c du # ng trc.
2.1 Khai bo cc khi ngt.
Khi OB1 c thc hin theo chu k v c th b ngt bi cc
s kin khi ta ci t thm cc cc khi OB khc vo Project hoc
khi xy ra cc s c. Cc khi OB ph hp c gi x l ngt nh
cc chng trnh phc v ngt. Khi OB c u tin cao c th ngt
cc khi c u tin thp hn. Ta c th thm cc khi OB bng cch
bm phi chut trong ca s Project Insert New Object
Organization block, chn s OB sau m khi OB v lp trnh.

Cng ty TBT v PTCN Ngc Huy

26

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

2.1 To cc khi logic.


Cc chng trnh ln thng c vit dng cu trc, gm khi
OB1, cc khi chng trnh FB, FC, cc khi chng trnh h thng
SFC, SFB. S dng lp trnh cu trc gip chng trnh d qun l
v thay i, thun cho vic lp trnh theo nhm. Khi OB1 v cc
khi FC, FB c th gi cc khi FC, FB, SFC, SFB.

2.2.3.1 Khi FB.


Khi FB l khi logic vi cc bin in, out, in-out, static v temp,
c to ra trong bng bin a phng i km. Cc bin in, out, inout l cc tham s hnh thc c a ch c th do chng trnh
gi truyn n, bin static l bin trong chng trnh FB c lu li
khi ra khi khi FB. Km vi FB l khi d liu data block cha cc
Cng ty TBT v PTCN Ngc Huy

27

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

bin in, out, in out v static. C th c nhiu data block cho mt


Fb khi mt FB dng cho cc nhim v khc nhau gi l instance data
block. Khi chng trnh gi FB cn phi km theo instance data
block tng ng. Vo ca s Project n chut phi chn Insert New
Object Function block thm vo khi FB1. Click chut vo khi FB1
son chng trnh cho khi. Ta vo bng khai bo khai bo
bin hnh thc cho khi theo th t in, out, in out, static v temp.
V d ta c bng bin ca khi FB1 nh sau:
Address
0.0
0.1
0.2
0.3
2.0
4.0
6.0
6.1
6.2
6.3
8.0
10.0
12.0
14.0
16.0

Declaration
IN
IN
IN
IN
IN
IN
OUT
OUT
OUT
OUT
IN_OUT
STAT
STAT
STAT
STAT

Name
Start
Stop
Response
Reset_Maint
Timer_No
Response_Time
Fault
Start_Dsp
Stop_Dsp
Maint
Motor
Time_bin
Time_BCD
Starts
Start_Edge

Type
BOOL
BOOL
BOOL
BOOL
TIMER
S5TIME
BOOL
BOOL
BOOL
BOOL
BOOL
WORD
WORD
INT
BOOL

Initial Value
FALSE
FALSE
FALSE
FALSE
S5T#0MS
FALSE
FALSE
FALSE
FALSE
FALSE
W#16#0
W#16#0
0
FALSE

Ta c th thm cc khi DB project vi cc tn DB1, DB2, DB3


loi Intance DB v thuc FB1.

Cc bin trong DB1 s c t ng to ra theo bng khai bo


bin ca khi FB1, tng t cho cc khi DB1 v DB3.

Cng ty TBT v PTCN Ngc Huy

28

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

2.2.3.1 Khi FC
Khi FC c cc bin hnh thc in, out v in out do chng
trnh gi cung cp cc a ch c th, ngoi ra cn c cc
bin temp s dng ni b. Khi FC khng c b nh nn d liu
mt i khi ra khi khi. Ta thm vo project khi FC1v khai bo
cc bin trong bng khai bo bin km theo v vit chng trnh
cho FC1.
Address Declaration
Name
0.0
IN
Open
0.1
IN
Close
2.0
OUT
Dsp_Open
2.1
OUT
Dsp_Closed

Type Initial Value


BOOL
FALSE
BOOL
FALSE
BOOL
FALSE
BOOL
FALSE

4.0 IN_OUT Valve BOOL FALSE


2.2.3.1 S dng hm th vin
Cc hm th vin do hng vit sn thuc cc loi FC, FB, SFC,
SFB gip ngi dng thun tin trong lp trnh, dng cc hm
th vin trong khi logic no th ta m khi logic , click chut
vo lnh CALL gi hm th vin, vo menu Insert Program
Element Libraries chn cc hm th vin ph hp ri gi chut v
ko ra hoc g CALL tn hm th vin. Cc hm th vin cn
chuyn gi tr cho cc bin hnh thc v ta phi cung cp cho
hm gi theo quy nh ca hm th vin.
Cng ty TBT v PTCN Ngc Huy

29

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

3. Lm vic vi PLC
2.1 Quy nh a ch MP1 cho module CPU:
Khi ni v vic ci t Step7 ta c cp n vn
ghp ni my tnh hay my lp trnh (PG) vi trm PLLC. My
tnh /my lp trnh c ghp ni vi module CPu qua cng truyn
thng ni tip RS232 (COM) ca my tnh hay cng MPI (MPI Card)
hay cng (CP Card) l cn tu thuc vo b giao din c s dng.
Tng t cng c nhiu kh nng ni PLC vi my tnh, song
truyn thng nh Step7 th PLC lun phi c ni vi my tnh qua
cng lp trnh (RS485).
Sau khi ghp ni module vi CPU vi my tnh v phn cng ta
cn phi nh ngha thm a ch truyn thng cho trm PLC.
iu ny l cn thit v mt my tnh/ my lp trnh c th cng
mt lc lm vic c vi nhiu trm PLC. Mc nh, cc module
CPU u c a ch l 2(a ch MPI). Mun thay i a ch
module CPU ta nhy kp phm chut tri ti tn ca module trong
bng khai bo cu hnh cng vo ch t li tham s lm
vic (trang 173), trong ta li chn tip GeneralMPI v sa li
a ch MPI nh hnh di m t.

Cng ty TBT v PTCN Ngc Huy

30

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Thay i a ch MPI ca CPU


ti y

Sau khi nh ngha ti a ch MPI cho trm PLC, ta phi ghi li


a ch ln module CPU v chi khi module CPU mi thc s
lm vic theo a ch mi ny. Cng vic ghi a ch MPI mi ny
ln module CPU c thc hin cng vi vic ghi tt c tham s quy
nh ch lm vic ca module bng cch kch vo biu tng
Down load trn thanh cng c hoc chn PLCDown load.
Bn cnh vic ghi cu hnh cng va son tho vo module
CPU ta cng c th c ngoc bng cch kch chut vo biu tng
Up load trn thanh cng c ca mn hnh (hoc chn PLCUp
load . Vi vic c cu hnh cng ny ta cng c c lun c
ton b chng trnh hin c trong memory ca module CPU vo
Project.
2.1 Ghi chng trnh ln moduel CPU
C hai cch chng trnh ng dng, sau khi son tho
xong, vo module CPU c th l vo vng Load memory) nh sau:
1) t mn hnh son tho chng trnh bng cch kch vo
biu tng Down load trn thanh cng c ca mn hnh. Vi cch
ny, ch ring khi chng trnh ang mn hnh son
tho s c vo module CPU.
2) t mn hnh chnh ca Step7 cng bng cch kch vo
biu tng Down load. Vi cch ny ta c th ton b chng trnh ng dng c dng c trong th mc Block hoc
Cng ty TBT v PTCN Ngc Huy

31

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

nhng khi m ta nh du. Mun ton b th mc


Block ta phi kch chut vo tn th mc trc sau mi c
kch v Down load. Trong trng hp ch mt s khi, ta
nh du nhng khi s c trc bng cch gi phm CTRL
ng thi kch chut ti tn ca tng khi. Cui cng, sau khi
chn xong cc khi th kch chut vo biu tng Down load.
2.1 Gim st vic thc hin chng trnh
Sau khi ghi chng trnh ln module CPU th ni dung Load
memory ca module CPU v ca th mc Block ca Project trong
my tnh s ng nht. Nu bt cng tc module CPU t STOP
sang RUN, CPU s thc hin chng trnh trong Local memory ca
n theo vng qut v qu trnh thc hin lnh ny c Step7 gim
st thng qua chng trnh tng ng trong Project.
Vic gim st chng trnh c Step7 tin hnh bng cch cho
hin th ni dung cc thanh ghi ca CPU trc v sau khi thc hin
tng lnh ca chng trnh.
vo mn hnh gim st, ta

ch cn kch chut ti phm

Monitor trn thanh cng c ca mn hnh son tho.


Mc nh, Step7 ch cho hin th ni dung cc bit RLO, STA (t
thanh ghi trng thi) v ca ACCU1. Tuy nhin ta c th cho hin
th thm ni dung ton b ni dung ton b thanh ghi trng thi
hoc ca cc thanh ghi trng thi hoc ca cc thanh ghi bng cch
n phm chut bn phi ri chn ShowTn thanh ghi t hp thoi
hin ra.
Chng hn quan st thm ni dung thanh ghi AR1 ch a
ch (con tr) ta kch phm chut bn phi, sau chn Show v
tip chn Show v tip theo l Address Register 1. Tn ca s
gim st s hin ra thm ct hin th ni dung ca thanh ghi con tr
AR1.
Ngoi ra, ta cng c th thay i kiu d liu c hin th.
Mc nh Step7 s cho hin th ni dung cc thanh ghi di dng m
hexadecimal, song ta c th thay i sang cc dng khc nh
Cng ty TBT v PTCN Ngc Huy

32

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

decimal hay s thc bng cch a chut vo vng d liu c hin


th, n phm chut bn phi ri chn RepresentationKiu d liu
trong hp thoi hin ra.
Ch rng ta khng th sa i c chng trnh nu ca s
mn hnh gim st ang trng thi tch cc. Mun quay tr v
ch son tho, ta khng ri khi mn hnh gim st bng cch
n phm Monitor. Tng t, ta cng khng th tch cc c ca s
mn hnh gim st nu chng trnh c trong Project khng ng
nht vi chng trnh c trong Local memory ca module CPU. Bi
vy c th gim st c chng trnh va sa i, cng vic
u tin phi l ghi chng trnh vo module CPU ri sau
mi tch cc ca s mn hnh gim st. Hn na ta cng ch c
th gim st vic thc hin chng trnh trong mt khi v l
khi ang c m mn hnh son tho.
2.1 Gim st module CPU.
Bn cnh vic gim st chng trnh, ta c th gim st c cng
vic ca module CPU bng cch vo ca s PLC trn thanh cng c,
sau chn Diagnose Hardware.
Nu ch mun gim st ring tng module CPU ta kch vo
Module Information. Trn mn hnh s hin tip ra ca s cho
php ta la chn c th hnh thc cng vic c gim st. Chng
hn nu mun quan st b m t chn on ca module ta kch
chut vo Diagnostic Buffer s c c cc thng bo v nguyn
nhn thay i trng thi ca module CPU (StartStop) t trc ti
nay hoc mun quan st thi gian thc hin vng qut ta chn
Scan Cycle Time.
2.1 Quan st nh
Step7 cho php quan st ni dung mi nh thuc System
memory v cc nh c a ch nh nghi nh PI, PQ. Nh nh c quan st phi c khai bo trc trong bng c tn l Variable Table
v lm c iuny ta kch chut ti PLC t thanh cng c
mn hnh chnh ca Step7 sau chn Monitor/Modify Variable.
Cng ty TBT v PTCN Ngc Huy

33

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Sau khi khai bo xong bng tn cc nh c quan st ta kch


phm quan st. Trn thanh cng c c hai phm quan st phn bit
vi nhau k hiu ng h trong 5 biu tng ca phm. Nu kch
phm khng c k hiu ng h th bng quan st s ch th
hin ni dung ca nh ti ng thi im kch. Ngc li khi kch
phm c k hiu ng hf, Step7 s lin tc truy nhp v c ni
dung cc nh ca module CPU th hin vo bng.
Ta cng c th thay i cch trnh by kiu d liu cho tng
nh bng cch di chuyn chut vo nh cn thay i v n phm
phi. Sau chn kiu thch hp trong hp thoi hin ra.

Cng ty TBT v PTCN Ngc Huy

34

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

III. lp trnh ho lad


Bi 1

Cc lnh logic v timer


1.

Cc lnh AND, OR:


Cc cu lnh ny trn chng trnh dng LAD thc cht l cc

k hiu tip im NO, NC trong l thuyt in cng nghip.


s dng cc cu lnh ny ta cho tin hnh nh sau:
Trn cy lnh ca phn son tho chng trnh bn hy
click Bit logic, mn hnh hin ln ca s sau: Nu chn lnh
no th bn nhy p vo , sau bn nhp a ch vo.

VD:

Cc lnh SET v RSET cng nm trong khi cc bt logic.

Cng ty TBT v PTCN Ngc Huy

35

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

4. Cch s dng time.


2.1. Time xung ( S_PULSE).

Time xung hot ng s to ra mt xung ti ng ra theo ng


vo, khi ng vo I0.0 c mt sn ln th ti ng ra Q0.0 cng c
mt sn ln, thi gian tn ti ng ra chnh l gi tr t TV. Nu
thi gian tn ti mc cao ti ng vo I0.0 ln hn gi tr t TV th
ng ra cng mt theo thi gian tn ti ca ng vo. Xem gin
thi gian.

14

i0.0
8

10

q0.0

Gin thi gian ca time S_PULSE

Cng ty TBT v PTCN Ngc Huy

36

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

2.2 Time xung m rng ( S_PEXT ).

V ng vo th S_PEXT ging vi S_PULSE ch khc l ng ra


ca S_PEXT ch cn c sn ln ca ca ng vo. Xem gin
xung.

i0.0
10

10

q0.0

Gin thi gian ca time S_PEXT


2.3

Time ON tr (S_ODT).

Time S_ODT chnh l loi ON_DELAY, khi tn hiu ng vo ln


ON th sau mt khong thi gian t trc (10s) th ng ra ln ON.
Nu ng vo OFF th ng ra cng OFF theo, nu thi gian tn ti
ng vo nh hn gi tr t TV th ng ra khng c tn hiu.

Cng ty TBT v PTCN Ngc Huy

37

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

<10
10

i0.0

q0.0

Gin thi gian ca time S_ODT


2.4 Time ON tr m rng (S_ODTS).
Time S_ODTS hot ng khc S_ODT ch l ch cn c sn ln
ng vo v sau thi gian t TV th ng ra ln ON. Ng ra ch
xung OFF khi c sn ln ng vo reset I0.1. Xem gin thi
gian.

i0.1
10

i0.0

q0.0

Gin thi gian ca time S_ODTS


2.5

Time OFF tr (S_OFFDT).

Time S_OFFDT chnh l loi OFF delay trong cng nghip. Khi
ng vo I0.0 ln ON th ng ra Q0.0 cng ON theo, khi ng vo I0.0
OFF th sau khong thi gian t TV ng ra xung OFF. Xem gin
thi gian.

Cng ty TBT v PTCN Ngc Huy

38

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

10

10

i0.0

q0.0

Gin thi gian ca time S_OFFDT


C th dng lnh TIM to ra mt xung c tn s thay
i c:
Chng trnh nh sau dng lnh TIM to ra mt xung c tn s
0,5Hz.

Cng ty TBT v PTCN Ngc Huy

39

Bi Hng Hu - Bi Gip
thc hnh S7 300

Cng ty TBT v PTCN Ngc Huy

Ti liu hng dn

40

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Bi 2

B m
1. Cch s dng b m (Counter).
Counter l b m thc hin chc nng m sn (cnh) cung
ca tn hiu vo. S7-300 c ti a 256 counter (ph thuc vo
tng loi CPU), n c k hiu bi Cx trong x l s nguyn t 0
n 255.
S sn xung m c ghi vo thanh ghi 2 byte (word) ca b
m gi l thanh ghi C_Word (CV).
Nu CV 0 th C_bt = 1, ngc li nu CV = 0 th C_bit = 0.
Khc vi time, gi tr t trc ca PV (present Value) ca b
m ch c truyn vo C_Word ti thi im xut hin sn ln
ca tn hiu t S (Set).
B m c th c xo bng tn hiu Reset, khi b m c
xo th c C_Word v c C_bit u c gi tr l 0.
Trong S7 300 c 3 loi counter:
3.1

B m ln (S_CU).

CU l ng vo m ln (ch m sn) kiu BOOL.

S l gi tr t vo b m CV. V d y khi c tn hiu


cnh ln I125.1 th CV=10.

PV l gi tr t (ch cch vit phI theo dng C#??? (t 0


n 999).

R l ng vo Reset (gi tr ca CV v C_bt tr v 0).

Q l ng ra trng thI ca Counter. y C0 (C_bit) = Q125.0.

CV l ng ra gi tr tc thi ca Counter dng HEX.

CV_BCD l ng ra gi tr tc thi ca Counter dng BCD.

Cng ty TBT v PTCN Ngc Huy

41

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Ch : Counter m ln n 999 th khng m na.


3.2
-

Counter Down (S_CD).


CD l ng vo tn hiu m xung (ch m sn) kiu
BOOL.

S l gi tr t vo b m CV. V d y khi c tn hiu


cnh ln I125.1 th CV=99.

PV l gi tr t (phi ghi theo dng C#??? (000 n 999).

R l ng vo reset (reset gi tr ca CV v C_bit v 0).

Q l ng ra trng thi ca Counter, y C0 (C_bit) = Q125.0

CV l ng gi tr tc thi ca Counter dng HEX.

CV_BCD l ng ra gi tr tc thi ca Conter dng BCD.

Ch : Counter m xung n 0 th s khng m na, v th


vi S_CD th phair SET gi tr ban u.
3.3

Counter UpDown (S_CUD)

CU l ng vo m ln (ch m sn) kiu BOOL.

CD l ng vo tn hiu m xung.

S l gi tr t vo b m CV. V d y khi c tn hiu


cnh ln I125.1 th CV=99.

PV l gi tr t (ch phi ghi theo dng C#???) t 000 n


999.

R l ng vo reset (gi tr ca CV v C_bit v 0).

Q l ng ra trng thi ca Counter, y C0 (C_bit).

CV l ng ra gi tr tc thi ca Counter dng HEX.

CV_BCD l ng ra gi tr tc thi ca Counter dng BCD.

Cng ty TBT v PTCN Ngc Huy

42

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Ch : S_CUD m xung n 0 v m ln n 999 th s


dng li, nn ta phi reset li Counter cho ln m khc.

Cng ty TBT v PTCN Ngc Huy

43

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Bi 3

Mch t gi (t duy tr) trng thi


I. Mc ch:
ng dng cc kin thc hc v thc hnh v cc loi tip
im xy dng mch c kh nng t gi (duy tr) trng thi.
II. Tm tt kin thc c lin quan:
Mch t gi n ging nh mch khi ng t n trong cng
nghip: Khi dng mt u vo iu khin mt bt ra thng
qua cc bt trung gian c kho lin ng khc. Nh vy, khi u vo
khng cn tch cc na th u ra vn c kch thch. Nh vy,
trng thi c kch thch ca u ra c dng duy tr trng
thi ca chnh n. Trong chng trnh dng cc lnh AND v OR.
III. S ni dy v danh sch vo/ra:
1.S v danh sch u vo:

K hiu

I0.0

Chc nng

I0.1

Chuyn mch u
vomch
s 0 u
Chuyn

vo
s 1
Chung

24VDC
(-)
(+)
2. S v danh sch u ra:
K hiu

Chc nng

Q0.0

n hin th u ra
s 0
Chung

24VDC
(-)
(+)

IV. Cc bc tin hnh:


1. Ni dy theo s v danh sch u vo bng dy dn:
Cc (-) ca ngun mt chiu 24V ni vi u 1M pha u vo ca

Cng ty TBT v PTCN Ngc Huy

44

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

PLC. Cc (+) ca ngun ni vi u chung ca cc chuyn mch


u vo (Module contac).
2. Ni dy theo s v danh sch u ra bng dy dn: Cc
(-) ca ngun c ni vi u chung ca cc n u ra v u
chung 1M pha u ra ca PLC. Cc (+) ca ngun c ni vi u
1L ca PLC.
3. S dng phn son tho chng trnh son tho on chng trnh sau:

4. Bt ngun cung cp cho PLC v np chng trnh va son


tho xung PLC.
5. a PLC vo ch RUN.
6. Tc ng ln cc u vo v ghi li chi tit kt qu ca cc
tc ng .
V. Bo co thc hnh:
1. S th t v tn bi.
2. Mc ch ca bi thc hnh.
3. Chng trnh son tho thc hnh.
4. Bng kt qu thc hnh:
Trng thi u vo
I0.0

I0.1

Trng thi
u ra
Q0.0

4. Nhn xt v kt lun.
VI. Cu hi kim tra:
1. C th dng mch t gi cho nhiu u ra c khng? Ti
sao?

Cng ty TBT v PTCN Ngc Huy

45

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

2. Trong s thc hnh trn, nu b bt I0.1 i c c


khng? Ti sao?
3. M hnh ny ging loi kh c in no trong din cng
nghip?

Cng ty TBT v PTCN Ngc Huy

46

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Bi 4

cc lnh set v reset


I. Mc ch:
1. Nm c ngha, tc dng ca lnh set.
2. Nm c ngha, tc dng ca lnh reset.
II. Tm tt kin thc c lin quan:
1. Khi c s dng, lnh Set (S) s t (ng) v duy tr trng
thi ng ca mt bit ra hoc t 1 vo bit ca b nh. im tc
ng c xc nh l: bt u ti a ch xc nh trong lnh
v s im c tc ng l t 1 n 1024 im.
2. Khi c s dng, lnh Reset (R) s m v duy tr trng thi m
ca cun dy u ra hoc xo cc bit b nh v 0. im tc ng
c xc nh l: bt u ti a ch xc nh trong lnh v s
im c tc ng l t 1 n 1024 im.
III. S ni dy v danh sch vo/ra:
1. S v danh sch u vo:

K hiu

Chc nng

I0.0
I0.1

Chuyn mch u
vomch
s 0 u
Chuyn

vo
s 1
Chung

24VDC
(-)
(+)
2. S v danh sch u ra:
K hiu

Chc nng

Q0.0

n hin th u ra
0 u ra
n hins
th
s 1
Chung

Q0.1
L

24VDC
(-)
(+)

IV. Cc bc tin hnh:

Cng ty TBT v PTCN Ngc Huy

47

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

1. Ni dy theo s v danh sch u vo bng dy dn:


Cc (-) ca ngun mt chiu 24V ni vi u 1M pha u vo ca
PLC. Cc (+) ca ngun ni vi u chung ca cc chuyn mch
u vo (Module contac).
2. Ni dy theo s v danh sch u ra bng dy dn: Cc
(-) ca ngun c ni vi u chung ca cc n u ra v u
chung 1M pha u ra ca PLC. Cc (+)
ca ngun c ni vi u 1L ca PLC.
3. S dng phn son tho chng trnh son tho on chng trnh sau:

4. Bt ngun cung cp cho PLC v np chng trnh va son


tho xung PLC.
5. a PLC vo ch RUN.
6. Tc ng ln cc u vo v ghi li chi tit kt qu ca cc
tc ng .
V. Bo co thc hnh:
1. S th t v tn bi.
2. Mc ch thc hnh.
3. Chng trnh son tho thc hnh.
4. Bng kt qu thc hnh:
Trng thi u vo
I0.0
I0.1

Cng ty TBT v PTCN Ngc Huy

Trng thi u ra
Q0.0

48

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

5. Nhn xt v kt lun.

Cng ty TBT v PTCN Ngc Huy

49

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Bi 5

lnh di chuyn d liu mov


I. Mc ch:
Nm c khi nim, tc dng ca lnh di chuyn d liu.
II. Tm tt kin thc c lin quan:
Cc lnh di chuyn word: T n MOVW (Move Word), di
chuyn t kp MOVD (Move Double Word), v di chuyn s thc
MOVR (Move Real) di chuyn d liu t vng nh IN ti vng nh OUT
m khng thay i gi tr gc.
Khi lnh MOV c iu kin thc hin th lnh nay s copy ni
dung ca word c a chir ngun sang word ch m khng lm
thay i ni dung ca a ch ngun .
III. S ni dy v danh sch vo/ra:
1. S v danh sch u vo:

K hiu

I0.0
I0.1
24VDC
(-)
(+)

Chc nng

Chuyn mch u
vo
s 0u
Chuyn
mch
vo s 1
Chung

2. S v danh sch u ra:

Cng ty TBT v PTCN Ngc Huy

50

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

K hiu

Chc nng

Q0.0

n hin th u ra
0 u ra
n hins
th
1 u ra
n hins
th

Q0.1
Q0.2
Q0.3
Q0.4
Q0.5
Q0.6
Q0.7
L

2 u ra
n hins
th
3 u ra
n hins
th
4 u ra
n hins
th
5 u ra
n hins
th
6 u ra
n hins
th
s 7
Chung

24VDC
(+ )
(-)

IV. Cc bc tin hnh:


1. Ni dy theo s v danh sch u vo bng dy dn:
Cc (+) ca ngun mt chiu 24V ni vi u COM ca modul push
button. Cc (-) ca ngun ni vi u chung M ca modul nput .
2. Ni dy theo s v danh sch u ra bng dy dn: Cc
(-) ca ngun c ni vi u chung ca cc n u ra v u
chung COM pha u ra ca PLC. Cc (+) ca ngun c ni vi cc
u ca ra ca PLC qua cc bng n.
3. S dng phn son tho chng trnh son tho on chng trnh sau:

Cng ty TBT v PTCN Ngc Huy

51

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Khi c tn hiu bt I0.0 c tn hiu th lnh s coppy gi tr


ca C0 ra byte QB0
4. Bt ngun cung cp cho PLC v np chng trnh va son
tho xung PLC.
5. a PLC vo ch RUN.
6. Tc ng ln cc u vo v ghi li chi tit kt qu ca cc
tc ng .
V. Bo co thc hnh:
1. S th t v tn bi.
2. Mc ch ca bi thc hnh.
3. Chng trnh son tho thc hnh.
4. M t kt qu thc hnh: Ghi li chi tit cc tc ng v hin
tng xy ra.
5. Nhn xt v kt lun.

Cng ty TBT v PTCN Ngc Huy

52

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn
Bi 6

lp trnh xc nh v tr
I.

Mc ch:
1. S dng cc nt n trn contac module to tn hiu u
vo cho PLC.
2. Bit cch ghp ni cc thit b ngoi vi vi PLC v lp trnh
iu khin cc thit b ngoi vi.

II.

Tm tt kin thc c lin quan:

Bi thc hnh ny s dng cc nt n to tn hiu vo

PLC. T tn hiu vo ny, lp trnh PLC xc nh c nt no


c n. ng thi iu khin hin th LED 7 thanh hin th s
ca nt n c n bng cch m ho bng m BCD. M BCD ny
c a vo u vo ca IC gii m v iu khin hin th 4511.
III.

S ni dy v danh sch vo/ra:


1.S v danh sch u vo:
K
hiu
I0.0

Chc nng

I0.1

Nt n 1

I0.2

Nt n 2

I0.3

Nt n 3

1M

Chung

24VDC
(+)
(-)

Nt n 0

2.S v danh sch u ra:

IV.

K
hiu
Q0.0

Chc nng
Tn hiu ra

A1

Q0.1

Tn hiu ra

B1

Q0.2

Tn hiu ra

C1

Q0.3

Tn hiu ra

D1

1L+

Chung

1M

Chung

5VDC
(+)

(-)

Chun b thit b, dng c th nghim:


Cng ty TBT v PTCN Ngc Huy

53

Bi Hng Hu - Bi Gip
thc hnh S7 300

TT
1
2
3
4

V.

Thit b, dng c

Ti liu hng dn

SL

Ghi
ch

Bn th nghim
01 chic
Khung th nghim c panen PLC 01 chic
S7-300
Module nt n
01
module
- ng h vn nng
01 chic
- B dy ni c cht cm
01 b
- Tuc n vt, km vn nng.
01 b

Cc bc tin hnh:
1. Ni dy theo s v danh sch u vo bng dy dn:
Cc (+) ca ngun mt chiu 24V ni vi u chung L+ cc cng
tc u vo. Cc (-) ca ngun ni vi u M ca PLC.
2. Ni dy theo s v danh sch u ra bng dy dn:
Cc (+5V) ca ngun c ni vi u chung COM u ra (OUT
PUTS) ca PLC. Cc (-) ca ngun c ni vi u M ca PLC.
3. S dng phn son tho chng trnh son tho chng
trnh sau:

Cng ty TBT v PTCN Ngc Huy

54

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

4. Bt ngun cung cp cho PLC v np chng trnh va son


tho xung PLC.
5. a PLC vo ch RUN.
6. Tc ng ln cc u vo (n nt) sau , ghi li chi tit
hin tng xy ra.
VI.

Bo co thc hnh:
1. S th t v tn bi.
2. Mc ch thc hnh.
3. Chng trnh son tho thc hnh.
4. Vit kt qu thc hnh: hin tng xy ra i vi cc u ra
ca PLC v module LED 7 thanh (7 segments display) khi tc ng
ln cc u vo I0.0, I0.1, I0.2, I0.3.
5. Nhn xt v kt lun.

Cng ty TBT v PTCN Ngc Huy

55

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Bi 7

Lp trnh o chiu quay ng c in 3 pha


I.

Mc ch:
1. Hiu ngha v nguyn l lm vic ca mch in o
chiu quay ng c in 3 pha.
2. S dng PLC, lp rp v u c mch in o chiu
quay ng c in 3 pha.

II.

Tm tt l thuyt:

Trang b in ca mch
+

Cu ch F.

B khi ng t kp gm: Cng tc t K1, K2 v r le

nhit OL.
+

ng c xoay chiu ba pha r to lng sc M.

B nt n (3 phm, 1 tng tip im)

PB0, PB1, PB2.

Trong :
Nt n PB0: Dng ng c (stop).
Nt n PB1: ng c quay thun (Forward).
Nt n PB2: ng c quay ngc (Revert).

Nguyn l hot ng
+

M my cho ng c chy thun:


ng p t mt ngun.
n nt PB1, cun ht cng tc t K 1 c in s
ng cc tip im K11 (cp ngun cho ng c hot
ng) v K12 (duy tr cho cng tc t K1). ng c
quay theo chiu thun (theo quy c) do mch ng lc
c ni nh sau:
Angun a.c
Bngun b.c
Cngun c.c

Dng ng c:
n nt PB0, cun ht cng tc t K1 mt in s nh cc
tip im K11 v K12. ng c ngng hot ng.

Cng ty TBT v PTCN Ngc Huy

56

Bi Hng Hu - Bi Gip
thc hnh S7 300
+

Ti liu hng dn

o chiu ng c:
n nt PB2, cun ht cng tc t K 2 c in s ng cc

tip im K21 (cp ngun cho ng c hot ng) v K22


(duy tr cho cng tc t K2). ng c quay theo chiu ngc
do th t ca hai pha vo ng c b o. Mch ng
lc c ni nh sau:
Angun c.c
Bngun b.c
Cngun a.c
+

Chc nng kho (lin ng):

Trong qu trnh lm vic, 2 cng tc t khng th lm vic


ng thi, trnh gy hin tng ngn mch mch ng lc.
V vy, khi cng tc t ny lm vic th n phi kho cng tc
t kia. Trong mch ny ta dng tip im thng ng ca cng
tc t ny khng ch s hot ng ca cng tc t kia.

A
B
C
0
F4

OL
F1 F2 F3
PB 0
K 21

K 11

PB 1
OL

III.

K 12

K 23
K1

PB 2
K 22
K 13
K2

S ni dy v danh sch vo/ra:


T nguyn l hot ng trn, c th dng PLC v contactor
module lp rp c mch ny, vi s cc u vo/ra nh
sau:
Cng ty TBT v PTCN Ngc Huy

57

Bi Hng Hu - Bi Gip
thc hnh S7 300

1.

2.

Ti liu hng dn

S v danh sch u vo:


K
hiu
I0.0

Chc nng

I0.1

Nt n quay ngc

I0.2

Nt n Stop

1M

Chung

24VDC
S
(+)v danh
(-) sch u ra:
K
hiu
Q0.0

Chc nng
iu khin K1

RL1

Q0.1

iu khin K2

RL2

1L+

Chung

1M

Chung

24VDC
(+)
(-)

Trong , cc tip im ca cc R le: RL1, RL2 c dng


ng, ct in cho cc cng tc t K1, K2.
IV.

Chun b thit b, dng c th nghim:


TT
1
2
3
4
5

V.

Thit b, dng c

SL

Ghi
ch

Bn th nghim
01 chic
Khung th nghim c panen PLC 01 chic
S7-300
Contactor module
01
module
Module nt n
01
module
- ng h vn nng
01 chic
- B dy ni c cht cm
01 b
- Tuc n vt, km vn nng.
01 b

Cc bc tin hnh:
1. Ni dy theo s v danh sch u vo bng dy dn:
Cc (+) ca ngun mt chiu 24V ni vi u chung ca cc nt
n. Sau , u ra ca cc cng tc ny li c a n u vo
ca PLC. Cc (-) ca ngun ni vi u M ca PLC.

Cng ty TBT v PTCN Ngc Huy

58

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

2. Ni dy theo s v danh sch u ra bng dy dn:


Cc (+) ca ngun c ni vi u chung COM u ra (OUT
PUTS) ca PLC. Cc (-) ca ngun c ni vi u 1M ca PLC. Cc
u ra ca PLC ni vi cun ht ca cc r le RL1, RL2. Cc tip
im thng m ca cc r le ny c dng ng ct in
cho cc cng tc t K1, K2.
3. S dng phn son tho chng trnh son tho chng
trnh sau:

4. Bt ngun cung cp cho PLC v np chng trnh va son


tho xung PLC.
5. a PLC vo ch RUN.
6. Tc ng ln cc u vo (n nt) sau , ghi li chi tit
hin tng xy ra.
VI.

Bo co thc hnh:
1. S th t v tn bi.
2. Mc ch thc hnh.
3. Chng trnh son tho thc hnh.

Cng ty TBT v PTCN Ngc Huy

59

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

4. Vit kt qu thc hnh: Vit r hin tng xy ra khi n nt


Start v Stop vi khong thi gian t khi n nt Start n lc n
Stop l khc nhau.
5. Nhn xt v kt lun.
VII.

Cu hi kim tra:
1. C th to thi gian tr khi o chiu quay ca ng c c khng? Ti sao? Nu c th chng trnh s c vit nh th
no?
2. C th dng sensor hoc cc thit b khc to tn hiu
o chiu quay ng c c khng? Ti sao?

Cng ty TBT v PTCN Ngc Huy

60

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Bi 8

Lp trnh vi tn hiu analog


I. mc ch:
Sau khi hc xong bi ny th hc sinh cn nm c cc ni
dung sau:
- Bit cch u ni cc tn hiu vo/ra cho knh analog.
- Bit cch c tn hiu analog t cc thit b khc v modul.
II. Tm tt l thuyt:

Modul analog l mt cng c x l cc tn hiu tng t

thng qua vic x l cc tn hiu s.

Analog input thc cht l mt b chuyn i tng t - s

(ADC), n chuyn mt tn hiu tng t u vo thnh mt tn


hiu s thun tin cho vic tnh ton. N c ng dng
kt ni cc thit b o nh cm bin nhit , m, trng lng... vi cc thit b iu khin nh l nhit, ng c...

Analog output thc cht l b chuyn i s - tng t

(DAC), n chuyn i tn mt tn hiu s u vo thnh mt


tn hiu tng t u ra. Thng c dng iu khin cc
thit b vi tn hiu vo iu khin tng t nh gc m ca Van
t 0 100%, hay iu khin tc ca bin tn 0 50Hz.

Nguyn l hot ng ca thit b o vo modul analog nh

sau :
in p chun 0 10V, 0 5V....
Dng in 0 20mA, 4 20mA...

Cng ty TBT v PTCN Ngc Huy

61

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Thit bb cn
bin

Tn hiu
vo
khng
in

u
o

Thit
bb
chuy
n i

Module
analog
0 10V

420mA

Analog Input
( A/D)
Cc con s

Tn hiu

Analog
Output
( D/A)

tng t

Cc con s

ra

Trang b in ca mch.

CPU 313C c 4 knh analog vo in p, 1 knh vo in tr


dng Pt100 v 2 knh ra analog.
Knh ra l gi tr in p, tng ng vi gi tr digital cha
trong PQW tng ng.
III. ni dung.
Cp ngun cho mch suy gim MODULE BUTTON ly
in p ra ti chn gia ca VR1 l in p thay i t 0
n 10 V. Tn hiu ny c kt ni n PIW0 ca CPU313C
(ch chiu ca in p). Khi ta iu chnh VR1 th in p
ti chn (+) ca knh PIW0 thay i t 0 10V.
1.

S v danh sch u ra:

Cng ty TBT v PTCN Ngc Huy

62

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

qv0

ch0 v0

qv1

ch1 v0

Dng ng h VAO o in p 1 chiu ti cc knh ra.


IV. Cc bc tin hnh:
1. Thit lp cc thng s cho knh analog.
Sau khi khai bo xong cu hnh cng th ta c bng cu hnh
nh sau.

Click tri chut vo AI4/AO2 xut hin bng thng s sau:

Cng ty TBT v PTCN Ngc Huy

63

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

t cc thng s, nh bng trn, knh 0 v knh 1 o in tr,


knh 2 v knh 3 o in p.
3. S dng phn son tho chng trnh son tho chng
trnh sau:

4. Bt ngun cung cp cho PLC v np chng trnh va son


tho xung PLC.
Cng ty TBT v PTCN Ngc Huy

64

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

5. a PLC vo ch RUN.
6. Tc ng ln cc u vo (n nt) sau , ghi li chi tit
hin tng xy ra.
v. Bo co thc hnh:
1. S th t v tn bi.
2. Mc ch thc hnh.
3. Chng trnh son tho thc hnh.
4. Vit kt qu thc hnh:
5. Nhn xt v kt lun.

Cng ty TBT v PTCN Ngc Huy

65

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Bi 9

Lp cng thc cn chnh tn hiu u vo analog


I. mc ch:
Sau khi hc xong bi ny th hc sinh cn nm c cc ni
dung sau:
- Bit cch u ni cc tn hiu vo/ra cho cc knh analog.
- Bit thc hin cc php ton s nguyn v s thc trn PLC.
- Bit lp cng thc cn chnh tn hiu vo analog.
II. Tm tt l thuyt:
Dng modul th nghim analog ni vi knh 0 ca modul analog,
sao cho khi ta chnh VR th in p ti chn IN ca knh 0
thay i t 0 10V.
Yu cu: Vit chng trnh c gi tr nhit ti knh 0 v lu
gi tr c c vo a ch MD10 di dng s thc (real). Dng
cm bin o nhit Pt100 gi tr o 0 150 0C, tn hiu ra
0 5 V.
u vo
0
C
1500
C
?0C
u ra s
N

32000

Tn hiu

Cng ty TBT v PTCN Ngc Huy

66

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Ama
Ain
Ami
Gi tr s ng vi

Dmi

Dout

Dma
x

Lp phng trnh ng c tnh th hin s ph thuc ca


gi tr nhit vo i vi gi tr s nhn c. V tn hiu nhit
vo l tuyn tnh nn phng trnh ca ng c tnh l phng trnh ca mt c thng c dng:
y = x + b
l h s gc
b l hng s.
Ta d dng thy c tg =
Vy ta c phng trnh

A max A min
D max D min

tnh Ain nh sau:


A max A min
Dout D min A min
D max D min

Ain

Trong :

Ain l gi tr nhit thc.


Amax l gi tr nhit max.
Amin l gi tr nhit min.
Dmax l gi tr s max ng vi nhit max.
Dmin l gi tr s min ng vi nhit min.
Dout l gi tr s c c ng vi nhit ti u cm

bin.
IV. Cc bc tin hnh:
1. Thit lp cc thng s cho knh analog.
Sau khi khai bo xong cu hnh cng th ta c bng cu hnh
nh sau.

Cng ty TBT v PTCN Ngc Huy

67

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Ni u d Pt100 vi drive qua cc u dy Brown v Blue,


tn hiu ra analog ti chn V_out v GND c ni n knh 0 ca
phn o in p.
3. Son chng trnh.
T giao din Blocks to mt Function t tn l FC1, khai bo
cc bin nh sau:
Bin
IN
OUT
TEMP

Tn
Din
Dmin
Dmax
Amin
Amax
Ain
TempR1
TempD1
TempDI1
TempR2

nh dng
Int
Int
Int
Real
Real
Real
Real
Int
DInt
Real

Chng trnh:

Cng ty TBT v PTCN Ngc Huy

68

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

M khi OB1 v gi chng trnh FC1 (Doc A)

Cng ty TBT v PTCN Ngc Huy

69

Bi Hng Hu - Bi Gip
thc hnh S7 300

Ti liu hng dn

Din l gi tr s nguyn (Int) c c ti tn hiu vo analog


(PIW272).
Dmin l gi tr s nguyn b nht ca Din (0)
Dmax l gi tr s nguyn ln nht ca Din (32000).
Amin l gi tr s thc b nht ca nhit (0.0)
Amax l gi tr s thc ln nht ca nhit (150.0).
Gi trinh nhit thc Ain lu vo MD10.
4. Bt ngun cung cp cho PLC v np chng trnh va son
tho xung PLC.
5. a PLC vo ch RUN.
v. Bo co thc hnh:
1. S th t v tn bi.
2. Mc ch thc hnh.
3. Chng trnh son tho thc hnh.
4. Vit kt qu thc hnh:
5. Nhn xt v kt lun.

Cng ty TBT v PTCN Ngc Huy

70