The document provides guidance for a practical training exercise on sorting and counting products on a conveyor line using a PLC. It describes using a PLC and sensors to classify products by length into short, medium, and long categories and count the products. The training involves programming the PLC to sort and count to requirements, maintaining counts of classified and rejected products. It also provides details on detecting product length using the PLC inputs and setting appropriate output signals.
31. Taøi lieäu höôùng daãn thöïc taäp toát nghieäp
2. Khôûi taïo Project
Choïn New trong menu File (xem hình), hoaëc click (nhaán mouse) treân thanh coâng cuï.
3. Vieát/söûa chöông trình
Duøng mouse choïn caùc phaàn töû caàn söû duïng töø danh saùch leänh (duøng chuoät ñeå keùo phaàn töû
hoaëc double click vaøo phaàn töû ñeå choïn) ñeå veõ sô ñoà LADDER, sau ñoù ñaët teân cho caùc phaàn töû
nhö ví duï trong hình veõ sau :
Chuù yù:
– Moät sô ñoà ñieàu khieån daïng ladder thöôøng bao goàm nhieàu network “maéc song song” vôùi nhau.
– Keát thuùc sô ñoà ñoái vôùi Step7-MicroWin 32 ta khoâng baét buoäc phaûi coù leänh keát thuùc khoâng ñieàu
kieän END
4. Caùc chuù thích cuûa chöông trình
a. Nhaán mouse vaøo haøng chöõ Network 1(2,3...) ñeå ñaët teân cho Network.
b. Nhaán mouse vaøo haøng chöõ POU Comment (Project Component Comments) ñeå ghi chuù veà
caùc thaønh phaàn cuûa Project.
c. Nhaán mouse vaøo haøng chöõ Network Comment ñeå chuù thích cho Network.
Phaàn höôùng daãn veà PLC
32. Taøi lieäu höôùng daãn thöïc taäp toát nghieäp
5. Dòch leänh (compile) vaø gôõ roái (debug) chöông trình
- Dòch leänh : vaøo menu PLC choïn leänh Compile :
Luùc naøy chöông trình seõ kieåm tra cuù phaùp cuûa sô ñoà ñieàu khieån vaø thoâng baùo veà kích thöôùc
cuûa chöông trình vaø caùc loãi cuù phaùp cuûa chöông trình :
6. Löu giöõ chöông trình: vaøo menu File choïn leänh Save as, neáu chæ söûa chöông trình thì duøng leänh
Save.
7. Naïp chöông trình vaøo CPU cuûa PLC
a. Ñònh CPU ôû cheá ñoä STOP theo moät trong hai caùch:
• Gaït contact treân boä PLC qua vò trí STOP
• Gaït contact treân boä PLC qua vò trí TERM roài vaøo menu PLC choïn Stop.
b. Vaøo menu File, choïn Download.
c. Neáu chöông trình ñöôïc naïp vaøo PLC thaønh coâng thì seõ coù thoâng baùo Download hoaøn thaønh.
8. Kieåm tra söï vaän haønh cuûa chöông trình
Ñònh CPU ôû cheá ñoä RUN theo moät trong hai caùch:
• Gaït contact treân boä PLC qua vò trí RUN
• Gaït contact treân boä PLC qua vò trí TERM roài vaøo menu PLC choïn Run.
Phaàn höôùng daãn veà PLC
33. Taøi lieäu höôùng daãn thöïc taäp toát nghieäp
Caáu truùc döõ lieäu soá trong PLC
1. Caùc oâ nhôù ñaëc bieät:
SM0.0 Bit naøy luoân luoân ON.
SM0.1 Bit naøy chæ ON trong chu kyø queùt ñaàu tieân cuûa PLC.
SM0.5 Bit naøy taïo xung clock 1 giaây (0,5s ON vaø 0,5s OFF).
SM0.4 Bit naøy taïo xung clock 1 phuùt.
2. Caáu truùc oâ nhôù trong PLC Siemens:
1 Byte = 8 Bit QB0 ≡ Q0.0→Q0.7
1 Word = 2 Byte = 16 Bit (lieân tieáp) QW0 ≡ QB0→QB1
1 Double Word = 4 Byte = 32 Bit (lieân tieáp) QD0 ≡ QB0→QB3
3. Caáu truùc oâ nhôù cuûa döõ lieäu soá:
Soá Byte (B) 1 byte ~ Byte
Soá Integer (I): 2 byte ~ Word
Soá Long Integer (D) 4 byte ~ Double Word
Soá Real (R) 4 byte ~ Double Word
Leänh xaùc ñònh caïnh leân
- Tieáp ñieåm phaùt hieän caïnh leân P seõ chæ ON trong
moät chu kyø queùt cuûa PLC khi tín hieäu ngay tröôùc P
(I0.4) chuyeån traïng thaùi töø 0 leân 1.
Phaàn höôùng daãn veà PLC
34. Taøi lieäu höôùng daãn thöïc taäp toát nghieäp
PHAÀN HÖÔÙNG DAÃN PLC:
USS TOOLBOX
1. USS TOOLBOX :
Trình töï laäp trình söû duïng caùc leänh USS nhö sau :
- Ñaët leänh USS_INIT trong chöông trình. Leänh USS_INIT chæ neân ñöôïc goïi trong moät
chu kyø queùt ñeå thieát laäp hay thay ñoåi caùc thoâng soá giao tieáp cuûa giao thöùc USS.
- Ñaët chæ moät leänh DRV_CTRL cho moãi moät bieán taàn tích cöïc trong chöông trình. Coù
theå theâm vaøo nhieàu leänh USS_RPM_x vaø USS_WPM_x neáu caàn thieát, nhöng chæ moät
bieán taàn ñöôïc tích cöïc taïi moät thôøi ñieåm.
- Thieát laäp caùc thoâng soá bieán taàn ñeå phuø hôïp vôùi toác ñoä baud vaø ñòa chæ cuûa bieán taàn
ñöôïc duøng trong chöông trình.
- Noái caùp giao tieáp giöõa CPU vaø caùc bieán taàn..
Caùc leänh USS Protocol
Thö vieän leänh STEP7 – Micro/Win cho pheùp ñieàu khieån caùc boä bieán taàn MicroMaster
moät caùch deã daøng baèng caùc haøm leänh ñaëc bieät ñöôïc thieát keá söû duïng giao thöùc USS ñeå
giao tieáp vôùi bieán taàn. Vôùi caùc leänh USS, ta coù theå ñieàu khieån bieán taàn vaø coù theå
ñoïc/ghi caùc thoâng soá cuûa bieán taàn.
Caùc leänh USS naøy naèm trong thö muïc Libraries cuûa caây leänh STEP7 – Micro/Win.
USS_INIT
Leänh naøy duøng ñeå khôûi ñoäng giao thöùc USS keát noái PLC vaø (maïng) bieán taàn.
Leänh USS_INIT ñöôïc duøng ñeå cho pheùp vaø
thieát laäp hay khoâng cho pheùp giao tieáp vôùi bieán
taàn MicroMaster. Leänh USS phaûi ñöôïc thöïc
hieän maø khoâng coù loãi xuaát hieän tröôùc khi baát cöù
leänh USS Protocol naøo coù theå ñöôïc duøng. Leänh
naøy hoaøn thaønh vaø bit Done ñöôïc set laäp töùc
tröôùc khi tieáp tuïc tôùi leänh keát tieáp.
Leänh naøy ñöôïc thöïc hieän moãi khi ngoõ vaøo EN
ñöôïc ON. Leänh USS_INIT neân ñöôïc thöïc thi
moãi khi coù thay ñoåi traïng thaùi giao tieáp. Moät khi
giao thöùc USS Protocol ñaõ ñöôïc thieát laäp , giao
thöùc USS phaûi ñöôïc disable bôûi vieäc thöïc thi
moät leänh USS_INIT môùi tröôùc khi coù thay ñoåi
trong caùc thoâng soá giao tieáp.
Phaàn höôùng daãn veà PLC
35. Taøi lieäu höôùng daãn thöïc taäp toát nghieäp
Giaù trò cuûa ngoõ vaøo USS cho pheùp choïn giao thöùc giao tieáp. Giaù trò 1 cho pheùp
duøng port 0 cho giao thöùc USS. Giaù trò 0 gaùn port 0 cho giao thöùc PPI vaø disable
giao thöùc USS.
Ngoõ vaøo BAUD thieát laäp toác ñoä baud : 1200, 2400, 4800, 9600, 19,200, hay
38,400 baud.
Ngoõ vaøo ACTIVE chæ ra bieán taàn naøo ñöôïc tích cöïc. Ñoái vôùi bieán taàn MM3 thì
hoã trôï ñòa chæ töø 0 ñeán 30.
MSB LSB
31 30 29 28 3 2 1 0
D31 D30 D29 D2 D1 D0
D0 Drive 0 active bit; 0 = drive not active, 1 = drive active
D1 Drive 1 active bit; 0 = drive not active, 1 = drive active
.
.
.
Active Drive Description and Format
Khi leänh USS_INIT hoaøn taát, bit DONE ñöôïc set leân 1. Ngoõ ra ERR (byte)
chöùa keát quaû cuûa vieäc thöïc thi leänh.
Caùc toaùn haïng vaø kieåu döõ lieäu duøng cho leänh USS_INIT
Inputs/Out Operands Data
puts Types
USS VB, IB, QB, MB, SB, SMB, LB, AC, Constant, BYTE
*VD, *AC, *LD
BAUD VW, IW, QW, MW, SW, SMW, LW, T, C, AIW, WORD
Constant, AC *VD, *AC, *LD
ACTIVE VD, ID, QD, MD, SD, SMD, LD, AC, Constant, DWORD
*VD, *AC, *LD
DONE I, Q, M, S, SM, T, C, V, Long an BOOL
ERR VB, IB, QB, MB, SB, SMB, LB, AC, *VD, *AC, BYTE
*LD
Phaàn höôùng daãn veà PLC
36. Taøi lieäu höôùng daãn thöïc taäp toát nghieäp
USS_CTRL
Leänh naøy duøng ñeå ñieàu khieån bieán taàn chaïy, döøng, ñaûo chieàu vaø thay ñoåi toác
ñoä.
Leänh USS_CTRL ñöôïc duøng ñeå ñieàu khieån moät
bieán taàn MM ñöôïc tích cöïc. Leänh USS_CTRL
ñaët caùc leänh choïn tröôùc trong boä ñeäm giao tieáp.
Caùc leänh ñaët trong boä ñeäm ñöôïc göûi cho bieán
taàn coù ñòa chæ ñöôïc choïn trong thoâng soá DRIVE,
neáu ñòa chæ bieán taàn ñoù ñaõ ñöôïc choïn trong
thoâng soá ACTIVE cuûa leänh USS_INIT . Moãi
bieán taàn chæ neân coù moät leänh DRV_CTRL .
Ngoõ vaøo EN phaûi ñöôïc ON ñeån cho pheùp leänh
DRV_CTRL(leänh naøy phaûi luoân luoân ñöôïc cho
pheùp).
Ngoõ vaøo RUN (RUN/STOP) cho pheùp bieán taàn
laø on (1) hay off (0). Khi RUN laø ON, boä bieán
taàn MM nhaän ñöôïc leänh baét ñaàu chaïy taïi toác ñoä
vaø chieàu ñaõ ñònh tröôùc. Ñeå bieán taàn chaïy thì:
• DRIVE phaûi ñöôïc choïn tích cöïc ACTIVE
trong USS_INIT.
• OFF2 vaø OFF3 phaûi ñöôïc set baèng 0.
• FAULT vaø INHIBIT phaûi laø 0.
Khi RUN laø OFF thì moät leänh ñöôïc göûi tôùi MM
ñeå giaûm toác ñoä xuoáng theo haøm doác cho tôùi khi
ñoäng cô döøng haún.
Bit OFF2 ñöôïc duøng ñeå cho pheùp bieán taàn MM
taét lao doác. Bit OFF3 ñöôïc duøng ñeå MM döøng
Phaàn höôùng daãn veà PLC
37. Taøi lieäu höôùng daãn thöïc taäp toát nghieäp
nhanh choùng.
Bit F_ACK (Fault Acknowledge) ñöôïc duøng ñeå xaùc nhaän loãi trong bieán taàn.
Bieán taàn seõ xoaù loãi (FAULT) khi F_ACK ñi töø möùc thaáp ñeán möùc cao.
Bit DIR (direction) ñaûođchieàu quay cuûa ñoäng cô.
Ngoõ vaøo DRIVE (drive address) chæ ra ñòa chæ cuûa bieán taàn MM maø leänh
DRV_CTRL ñaõ ñieàu khieån. Ñòa chæ coù giaù trò töø 0 ñeán 30.
Ngoõ vaøo TYPE choïn loaïi bieán taàn. Vôùi bieán taàn MicroMaster 3 choïn Type = 0,
vôùi bieán taàn MicroMaster 4 choïn Type = 1.
Ngoõ vaøo Speed_SP (speed setpoint) nhaäp toác ñoä cuûa ñoäng cô döôùi daïng phaàn
traêm cuûa toác ñoä toái ña (-200.0% tôùi 200.0%). Giaù trò aâm cuûa Speed_SP laøm
ñoäng cô ñaûo chieàu quay.
Bit Resp_R (Response Received) laø phaûn hoài töø bieán taàn. Moãi khi CPU nhaän
phaûn hoài töø bieán taàn thì bit Resp_R ñöôïc set ON trong moät chu kyø queùt.
Bit Error laø moät byte löu keát quaû cuûa laàn giao tieáp môùi nhaát vôùi bieán taàn.
Ngoõ ra STATUS chöùa traïng thaùi cuûa bieán taàn.
Ngoõ ra SPEED löu toác ñoä cuûa ñoäng cô döôùi daïng phaàn traêm cuûa toác ñoä ñònh
möùc (-200.0% tôùi 200.0%).
Ngoõ ra RUN_EN (DRIVE RUN Enable) chæ ra raèng bieán taàn ñang chaïy (1) hay
ñaõ döøng(0).
Ngoõ ra D_DIR chæ ra chieàu quay cuûa ñoäng cô.
Ngoõ ra INHIBIT chæ ra traïng thaùi cuûa bit caám trong bieán taàn (0 - not inhibited,
1 - inhibited). Ñeå xoaù bit caám thì bit FAULT phaûi ñöôïc OFF vaø caùc bit vaøo
RUN, OFF2, vaø OFF3 phaûi laø OFF.
Ngoõ ra FAULT chæ ra traïng thaùi cuûa bit loãi (0 - no fault, 1 - fault). Boä bieán taàn
seõ hieån thò maõ loãi. Ñeå xoaù bit FAULT thì phaûi khaéc phuïc loãi vaø set ON bit
ACK.
Phaàn höôùng daãn veà PLC
38. Taøi lieäu höôùng daãn thöïc taäp toát nghieäp
Caùc toaùn haïng vaø kieåu döõ lieäu duøng cho leänh USS_CTRL
Inputs/ Data
Operands
Outputs Types
RUN I, Q, M, S, SM, T, C, V, L, Power Flow BOOL
OFF2 I, Q, M, S, SM, T, C, V, L, Power Flow BOOL
OFF3 I, Q, M, S, SM, T, C, V, L, Power Flow BOOL
F_ACK I, Q, M, S, SM, T, C, V, L, Power Flow BOOL
DIR I, Q, M, S, SM, T, C, V, L, Power Flow BOOL
DRIVE, VB, IB, QB, MB, SB, SMB, LB, AC, Constant, BYTE
TYPE *VD, *AC, *LD
Speed_SP VD, ID, QD, MD, SD, SMD, LD, AC, *VD, *AC, REAL
*LD, Constant
Resp_R I, Q, M, S, SM, T, C, V, L BOOL
Error VB, IB, QB, MB, SB, SMB, LB, AC, *VD, *AC, *LD BYTE
STATUS VW, T, C, IW, QW, SW, MW, SMW, LW, AC, WORD
AQW, *VD, *AC, *LD
SPEED VD, ID, QD, MD, SD, SMD, LD, AC, *VD, *AC, REAL
*LD
RUN_EN I, Q, M, S, SM, T, C, V, L BOOL
D_DIR I, Q, M, S, SM, T, C, V, L BOOL
INHIBIT I, Q, M, S, SM, T, C, V, L BOOL
FAULT I, Q, M, S, SM, T, C, V, L BOOL
Phaàn höôùng daãn veà PLC
39. Taøi lieäu höôùng daãn thöïc taäp toát nghieäp
USS_RPM_x
Leänh naøy duøng ñeå ñoïc moät thoâng soá töø bieán taàn veà PLC.
Leänh USS_RPM_x ñoïc moät thoâng soá kieåu word
khoâng daáu. Leänh USS_RPM_x hoaøn taát khi MM
xaùc nhaän hay khi nhaän ñöôïc error.
Ngoõ vaøo EN phaûi ñöôïc ON ñeå cho pheùp truyeàn
yeâu caàu xuoáng MM vaø neân giöõ nguyeân traïng
thaùi ON cho ñeán khi bit DONE ñöôïc set baùo
hieäu söï hoaøn taát. Moät yeâu caàu USS_RPM_x
ñöôïc truyeàn tôùi MM ôû moãi chu kyø queùt khi ngoõ
vaøo XMT_REQ laø ON. Vì theá ngoõ vaøo
XMT_REQ neân ñöôïc kích leân möùc 1 qua moät boä
phaùt hieän caïnh leân nhaèm chæ cho pheùp moät yeâu
caàu ñöôïc truyeàn ñi ôû moãi caïnh leân cuûa ngoõ vaøo
EN .
Ngoõ vaøo DRIVE laø ñòa chæ cuûa bieán taàn MM maø leänh USS_RPM_x ñöôïc göûi ñi.
Ñòa chæ coù giaù trò töø 0 ñeán 31.
Ngoõ vaøo PARAM xaùc ñònh thoâng soá caàn ñoïc. Ngoõ vaøo INDEX laø giaù trò index
cuûa thoâng soá caàn ñoïc.
Ñòa chæ cuûa moät boä ñeäm 16–byte phaûi ñöôïc cung caáp cho ngoõ vaøo DB_PTR. Boä
ñeäm naøy ñöôïc söû duïng bôûi leänh READ_PM ñeå löu keát quaû nhaän ñöôïc töø bieán
taàn MM.
Khi leänh READ_PM hoaøn taát thì ngoõ ra DONE ñöôïc set ON vaø ngoõ ra
ERROR(byte) chöùa keát quaû cuûa vieäc thöïc thi leänh.
Ngoõ ra VALUE laø giaù trò thoâng soá ñoïc veà.
Caùc toaùn haïng vaø kieåu döõ lieäu duøng cho leänh READ_PM
Inputs/Out Operands Data
puts Types
XMT_REQ I, Q, M, S, SM, T, C, V, L, Power Flow BOOL
conditioned by a rising edge detection element.
DRIVE VB, IB, QB, MB, SB, SMB, LB, AC, Constant, BYTE
*VD, *AC, *LD
Phaàn höôùng daãn veà PLC
40. Taøi lieäu höôùng daãn thöïc taäp toát nghieäp
PARAM VW, IW, QW, MW, SW, SMW, LW, T, C, AIW, WORD
Constant, AC *VD, *AC, *LD
INDEX VW, IW, QW, MW, SW, SMW, LW, T, C, AIW, WORD
Constant, AC *VD, *AC, *LD
DB_PTR &VB DWORD
DONE I, Q, M, S, SM, T, C, V, L BOOL
ERROR VB, IB, QB, MB, SB, SMB, LB, AC, *VD, *AC, BYTE
*LD
VALUE VW, T, C, IW, QW, SW, MW, SMW, LW, AC, WORD
AQW, *VD, *AC, *LD
USS_WPM_x
Leänh naøy duøng ñeå ghi moät thoâng soá töø PLC leân bieán taàn.
Leänh USS_WPM_x ghi moät giaù trò word khoâng
daáu vaøo moät thoâng soá xaùc ñònh. Leänh
USS_WPM_x hoaøn taát khi MM xaùc nhaän hay
khi nhaän ñöôïc error.
Ngoõ vaøo EN phaûi laø ON ñeå cho pheùp truyeàn moät
yeâu caàu vaø neân giöõ nguyeân traïng thaùi ON cho
ñeán khi bit DONE ñöôïc set baùo hieäu söï hoaøn taát.
Moät yeâu caàu USS_WPM_x ñöôïc truyeàn tôùi MM
ôû moãi chu kyø queùt khi ngoõ vaøo XMT_REQ laø
ON. Vì theá ngoõ vaøo XMT_REQ neân ñöôïc kích
leân möùc 1 qua moät boä phaùt hieän caïnh leân nhaèm
chæ cho pheùp moät yeâu caàu ñöôïc truyeàn ñi ôû moãi
caïnh leân cuûa ngoõ vaøo EN.
Ngoõ vaøo DRIVE laø ñòa chæ cuûa bieán taàn MM maø leänh USS_WPM_x ñöôïc göûi
ñi. Ñòa chæ coù giaù trò töø 0 ñeán 31.
Phaàn höôùng daãn veà PLC
41. Taøi lieäu höôùng daãn thöïc taäp toát nghieäp
Ngoõ vaøo PARAM xaùc ñònh thoâng soá caàn ghi. Ngoõ vaøo INDEX laø giaù trò index
cuûa thoâng soá caàn ghi. Ngoõ ra VALUE laø giaù trò caàn ghi vaøo thoâng soá.
Khi ngoõ vaøo EEPROM ñöôïc baät leân 1 thì leänh naøy ñöôïc ghi vaøo caû RAM vaø
EEPROM cuûa bieán taàn. Khi ngoõ vaøo naøy bò taét ñi thì leänh chæ ñöôïc ghi vaøo
RAM cuûa bieán taàn. Do MicroMaster 3 khoâng hoã trôï chöùc naêng naøy neân ngoõ vaøo
naøy phaûi off ( =0).
Ñòa chæ cuûa moät boä ñeäm 16–byte phaûi ñöôïc cung caáp cho ngoõ vaøo DB_PTR. Boä
ñeäm naøy ñöôïc söû duïng bôûi leänh USS_WPM_x ñeå löu keát quaû nhaän ñöôïc töø bieán
taàn MM.
Khi leänh USS_WPM_x hoaøn taát thì ngoõ ra DONE ñöôïc set ON vaø ngoõ ra
ERROR(byte) chöùa keát quaû cuûa vieäc thöïc thi leänh.
Caùc toaùn haïng vaø kieåu döõ lieäu duøng cho leänh WRITE_PM
Inputs/Out Operands Data
puts Types
XMT_REQ I, Q, M, S, SM, T, C, V, L, Power Flow BOOL
conditioned by a rising edge detection element.
DRIVE VB, IB, QB, MB, SB, SMB, LB, AC, Constant, BYTE
*VD, *AC, *LD
PARAM VW, IW, QW, MW, SW, SMW, LW, T, C, AIW, WORD
Constant, AC *VD, *AC, *LD
VALUE VW, IW, QW, MW, SW, SMW, LW, T, C, AIW, WORD
Constant, AC *VD, *AC, *LD
DB_PTR &VB DWORD
DONE I, Q, M, S, SM, T, C, V, L BOOL
ERROR VB, IB, QB, MB, SB, SMB, LB, AC, *VD, *AC, BYTE
*LD
Phaàn höôùng daãn veà PLC
42. Programming Concepts, Conventions, and Features Chapter 5
Using STEP 7–Micro/WIN to Create Your Programs
To open STEP 7–Micro/WIN, double-click on the STEP 7–Micro/WIN icon, or select the Start > SIMATIC >
STEP 7 MicroWIN 3.2 menu command. As shown in Figure 5-1, the STEP 7–Micro/WIN project window
provides a convenient working space for creating your control program.
The toolbars provide buttons for shortcuts to frequently used menu commands. You can view or hide any
of the toolbars.
The navigation bar presents groups of icons for
accessing different programming features of
STEP 7–Micro/WIN.
The instruction tree displays all of the project
objects and the instructions for creating your
control program. You can drag and drop
individual instructions from the tree into your
program, or you can double-click an instruction to
5
insert it at the current location of the cursor in the
program editor.
Program Editor
The program editor contains the program logic
and a local variable table where you can assign Instruction tree
symbolic names for temporary local variables.
Subroutines and interrupt routines appear as Navigation bar
tabs at the bottom of the program editor window.
Click on the tabs to move between the
subroutines, interrupts, and the main program. Figure 5-1 STEP 7–Micro/WIN
STEP 7–Micro/WIN provides three editors for creating your program: Ladder Logic (LAD), Statement List
(STL), and Function Block Diagram (FBD). With some restrictions, programs written in any of these
Program program editors can be viewed and edited with the other program editors.
Editor
Features of the STL Editor
The STL editor displays the program as a text-based language. The STL editor allows you to create
control programs by entering the instruction mnemonics. The STL editor also allows you to create
programs that you could not otherwise create with the LAD or FBD editors. This is because you are
programming in the native language of the S7-200, rather than in a graphical editor where some
restrictions must be applied in order to draw the diagrams correctly. As shown in Figure 5-2, this
text-based concept is very similar to assembly language programming.
The S7-200 executes each instruction in the
order dictated by the program, from top to
LD I0.0 //Read one input
bottom, and then restarts at the top.
A I0.1 //AND with another input
STL uses a logic stack to resolve the control = Q1.0 //Write value to output 1
logic. You insert the STL instructions for handling
the stack operations. Figure 5-2 Sample STL Program
Consider these main points when you select the STL editor:
- STL is most appropriate for experienced programmers.
- STL sometimes allows you to solve problems that you cannot solve very easily with the LAD or FBD
editor.
- You can only use the STL editor with the SIMATIC instruction set.
- While you can always use the STL editor to view or edit a program that was created with the LAD or
FBD editors, the reverse is not always true. You cannot always use the LAD or FBD editors to
display a program that was written with the STL editor.
51
43. S7-200 Programmable Controller System Manual
Features of the LAD Editor
The LAD editor displays the program as a graphical representation similar to electrical wiring diagrams.
Ladder programs allow the program to emulate the flow of electric current from a power source through a
series of logical input conditions that in turn enable logical output conditions. A LAD program includes a
left power rail that is energized. Contacts that are closed allow energy to flow through them to the next
element, and contacts that are open block that energy flow.
The logic is separated into networks. The
program is executed one network at a time, from
left to right and then top to bottom as dictated by
the program. Figure 5-3 shows an example of a
LAD program. The various instructions are
represented by graphic symbols and include
three basic forms.
5 Contacts represent logic input conditions such as
switches, buttons, or internal conditions.
Coils usually represent logic output results such
as lamps, motor starters, interposing relays, or
internal output conditions.
Boxes represent additional instructions, such as
timers, counters, or math instructions. Figure 5-3 Sample LAD Program
Consider these main points when you select the LAD editor:
- Ladder logic is easy for beginning programmers to use.
- Graphical representation is easy to understand and is popular around the world.
- The LAD editor can be used with both the SIMATIC and IEC 1131–3 instruction sets.
- You can always use the STL editor to display a program created with the SIMATIC LAD editor.
Features of the FBD Editor
The FBD editor displays the program as a graphical representation that resembles common logic gate
diagrams. There are no contacts and coils as found in the LAD editor, but there are equivalent instructions
that appear as box instructions.
Figure 5-4 shows an example of an FBD
program.
FBD does not use the concept of left and right
power rails; therefore, the term “power flow” is
used to express the analogous concept of control
flow through the FBD logic blocks. Figure 5-4 Sample FBD Program
The logic “1” path through FBD elements is called power flow. The origin of a power flow input and the
destination of a power flow output can be assigned directly to an operand.
The program logic is derived from the connections between these box instructions. That is, the output from
one instruction (such as an AND box) can be used to enable another instruction (such as a timer) to
create the necessary control logic. This connection concept allows you to solve a wide variety of logic
problems.
Consider these main points when you select the FBD editor:
- The graphical logic gate style of representation is good for following program flow.
- The FBD editor can be used with both the SIMATIC and IEC 1131–3 instruction sets.
- You can always use the STL editor to display a program created with the SIMATIC FBD editor.
52
44. S7-200 Programmable Controller System Manual
Accessing the Data of the S7-200
The S7-200 stores information in different memory locations that have unique addresses. You can
explicitly identify the memory address that you want to access. This allows your program to have direct
access to the information. Table 4-1 shows the range of integer values that can be represented by the
different sizes of data.
Table 4-1 Decimal and Hexadecimal Ranges for the Different Sizes of Data
Representation Byte (B) Word (W) Double Word (D)
Unsigned Integer 0 to 255 0 to 65,535 0 to 4,294,967,295
4 Signed Integer
0 to FF
–128 to +127
0 to FFFF
–32,768 to +32,767
0 to FFFF FFFF
–2,147,483,648 to +2,147,483,647
80 to 7F 8000 to 7FFF 8000 0000 to 7FFF FFFF
Real Not applicable Not applicable +1.175495E–38 to +3.402823E+38 (positive)
IEEE 32-bit Floating Point –1.175495E–38 to –3.402823E+38 (negative)
To access a bit in a memory area, you specify the address, which includes the memory area identifier, the
byte address, and the bit number. Figure 4-3 shows an example of accessing a bit (which is also called
“byte.bit” addressing). In this example, the memory area and byte address (I = input, and 3 = byte 3) are
followed by a period (“.”) to separate the bit address (bit 4).
I 3 . 4
Process-image Input (I) Memory Area
Bit of byte, or bit number:
bit 4 of 8 (0 to 7) 7 6 5 4 3 2 1 0
Period separates the Byte 0
byte address from the bit Byte 1
number Byte 2
Byte address: byte 3 (the Byte 3
fourth byte) Byte 4
Memory area identifier Byte 5
Figure 4-3 Byte.Bit Addressing
You can access data in most memory areas (V, I, Q, M, S, L, and SM) as bytes, words, or double words by
using the byte-address format. To access a byte, word, or double word of data in the memory, you must
specify the address in a way similar to specifying the address for a bit. This includes an area identifier,
data size designation, and the starting byte address of the byte, word, or double-word value, as shown in
Figure 4-4.
Data in other memory areas (such as T, C, HC, and the accumulators) are accessed by using an address
format that includes an area identifier and a device number.
24