You are on page 1of 27

K THUT LP TRNH Chng trnh ngi dng thng c chia nh thnh tng khi logic theo kiu chng

trnh cu trc, gip cho vic lp trnh v sa li thun tin. C nhiu loi khi logic: Khi t chc OB (Organization blocks) Khi hm h thng SFB (System function blocks) v hm h thng SFC (system functions) tch hp trong PLC Khi hm FB (Function blocks) trong th vin hay ngi dng t vit Hm FC (Functions) trong th vin hay ngi dng t vit Khi d liu Instance (Instance Data Blocks ) lin kt vi FB/SFB Khi d liu chia x (Shared Data Blocks ) Khi t chc OB l giao din gia chng trnh ngi dng v h iu hmh ca PLC. OB c gi bi h iu hnh theo chu k hay khi c ngt, c s c hay khi khi ng PLC. C nhiu khi OB v c u tin khc nhau, khi OB c s u tin cao hn c th ngt khi OB s u tin thp hn. Tu theo loi CPU, s lng khi OB s dng c s khc nhau, bng sau lit k cc loi OB Loi OB Chng trnh chnh OB1 Ngt thi gian OB10, OB11, OB12, OB13 OB14, OB15, OB16, OB17 Ngt tr hon OB20 OB21 OB22 OB23 Ngt chu k OB30 OB31 OB32 OB33 OB34 OB35 OB36 OB37 OB38 ngha u tin c gi khi kt thc khi ng hay kt thc 1 OB1, thc hin theo chu k Ngt theo thi gian trong ngy, thng, nm 2 3 4 5 6 Ngt chu k (mc nh 5s) Ngt chu k (mc nh 2s) Ngt chu k (mc nh 1s) Ngt chu k (mc nh 500ms) Ngt chu k (mc nh 200ms) Ngt chu k (mc nh 100ms) Ngt chu k (mc nh 50ms) Ngt chu k (mc nh 20ms) Ngt chu k (mc nh 10ms) 7 8 9 10 11 12 13 14 15

Ngt cng OB40 OB41 OB42 OB43 OB44 OB45 OB46 OB47 OB60 OB70 OB72 OB 73 S c bt ng b OB80 OB81 OB82 OB83 OB84 OB85 OB86 OB87 OB90 Gi bi SFC35 "MP_ALM" Li I/O redundancy ( H CPU) Li CPU redundancy (H CPU) Li Communication redundancy (H CPU) S c chu k qut Li ngun Ngt chn on Ngt do thm bt module Li phn cng CPU Li chng trnh Li module m rng Li truyn thng Warm or cold restart or delete a block being executed in OB90 or load an OB90 on the CPU or terminate OB90 Khi ng m Khi ng nng Khi ng lnh Sai lp trnh Sai I/O

16 17 18 19 20 21 22 23 25 25 28 25 26, 28

29, 0

OB100 OB101 OB102 S c ng b OB121 OB122

27

u tin ca tc nhn gy ra s c

1/ Khi OB1 OB1 c gi sau khi kt thc qu trnh khi ng v sau khi kt thc chnh n, mi OB tr OB90 c th ngt OB1. Khi OB1 c thc hin, h iu hnh gi i d liu ton cc. Trc khi gi li OB1, h iu hnh chuyn b nh m ra module xut , cp nht b m nhp v nhn d liu ton cc. Khi thc hin OB1, chng trnh trong khi c thc hin, d liu xut ra module xut c cp tm trong b nh. Chng trnh trong OB1 c th gi cc hm hay khi hm. Thi gian thc hin OB1 gi l thi gian qut, h iu hnh n nh thi gian qut ti a (150ms) v ti thiu, c th ci t bng Step 7. Nu chu k qut ko di th gi OB80 hay chuyn sang STOP, nu chu k qut ngn qu th thm tr hon hay gi OB90. OB1 gm phn m chng trnh, do ngi dng vit; bng bin cc b (local block) cn gi l bng khai bo bin (variable declaration table) gm 20 byte

Ct th nht l a ch trong vng bin cc b, ct th hai khai bo loi bin, temp ngha l tm thi, gi tr ca bin thay i sau mi vng qut ca OB, ct th ba l cc tn ca d liu, c ngha nh sau (gii thch trong ct ch thch 6):
OB1_EV_CLASS: OB1_SCAN_1: gi tr B#16#11 c ngha OB1 tch cc B#16#01: hon tt warm restart B#16#02: hon tt hot restart B#16#03: hon tt chu k B#16#04: hon tt cold restart gi tr 1 s OB l 1 d tr d tr thi gian vng qut trc (ms) thi gian vng qut ngn nht thi gian vng qut di nht ngy gi OB1 bt u thc hin (8 byte)

OB1_PRIORITY: OB1_OB_NUMBR: OB1_RESERVED_1: OB1_RESERVED_2: OB1_PREV_CYCLE: OB1_MIN_CYCLE: OB1_MAX_CYCLE: OB1_DATE_TIME:

Cc gi tr trn ngi dng khng thay i c, ngi dng c th thm cc bin vo t a ch 20.0 tr i, cc bin ny l bin tm, thay i sau mi vng qut. Cc bin thm vo ny s dng cho lp trnh v gi cc chng trnh con FC, SFC, FB, SFB. Chng trnh STEP 7 dng lp trnh cho PLC S7-300, S7-400. Chng trnh ny c version 5.0 dng cho Win 98, Version 5.1 v 5.3 dng cho Win XP. Khi kch chut vo biu tng Simatic Manager s xut hin ca s Hnh , bm Next chn loi CPU

Bm tip Next chn cc khi OB, bt buc l OB1, cc OB khc c th thm vo sau.

Chn cch lp trnh STL, LAD hay FBD, trong lc lp trnh c th tu thay i. Bm tip Next t tn cho Project, sau bm Finish, xut hin ca s lp trnh

Na ca s bn tri sp xp dng th mc, kch chut vo m ra cc mc con. Bm vo dng SIMATIC 300 STATION bn tri ri bm tip vo Hardware bn phi t cu hnh phn cng ca PLC (cng vic ny cng c th thc hin sau)

Ga s cu hnh n gin gm cc module DI/DO, AI/AO, ta kch chut vo dng SIMATIC 300, SM- 300 , chn cc module ph hp, dng chut ko vo cc slot ca Station t s 4 tr i, (slot 3 dng cho module IM), sau vo menu Station Save ri Close. Ta s tr li vn cu hnh mc

Tr li Project, bm vo mc Blocks, ta thy xut hin OB1, bm vo OB1 nu lp trnh tuyn tnh, ngha l khng dng cc khi logic FC, FB t to

Bm vo menu View, chn STL, LAD, FBD chn cch lp trnh. Khi lp trnh ta c th dng a ch tuyt i ( I0.0, MW2, T5) hay a ch k hiu (Start, Speed, Delay). a ch k hiu gip chng trnh d hiu hn. C hai loi l k hiu cc b (bin cc b) v k hiu ton cc (hay chia x) , 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 thc hin trc hay sau khi vit m. Khi logc c th c ti a 999 network, mi network c ti a 2000 hng , mi hng gm nhn , lnh, a ch v ch thch (sau //) Th tc lp k hiu ton cc nh sau: bm chut vo i tng Symbols (Xem hnh ).

Cc bin k hiu c a vo tng dng mt, di ti a 24 k t ch 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 bin tp xong, vo menu Symbol Table- Save lu bng. Vo ca s bin tp ca khi chn View- Display with - Symbolic Representation nhn thy a ch k hiu trong chng trnh, k hiu ton cc c ng khung bng du , cn k hiu cc b c du # ng trc. Nu dng View- Display with- Symbol Information th hin th c k hiu, a ch tuyt i , v ch thch i km. Cc loi bin cho php trnh by trong bng , tm a ch c th ph thuc loi CPU
IEC I Description Input bit Data Type BOOL Address Range 0.0 .. 65535.7

IB IW ID Q QB QW QD M MB MW MD PIB PQB PIW PQ W PID PQD T C OB FB DB FC SFB SFC VAT UDT

Input byte Input word Input double word Output bit Output byte Output word Output double word Memory bit Memory byte Memory word Memory double word Peripheral input byte Peripheral output byte Peripheral input word Peripheral output word Peripheral input double word Peripheral output double word Timer Counter Organization block Function block Data block Function System function block System function Variable table User defined data type

BYTE, CHAR WORD, INT, S5TIME, DATE DWORD, DINT, REAL, TOD, TIME BOOL BYTE, CHAR WORD, INT, S5TIME, DATE DWORD, DINT, REAL, TOD, TIME BOOL BYTE, CHAR WORD, INT, S5TIME, DATE DWORD, DINT, REAL, TOD, TIME BYTE, CHAR BYTE, CHAR WORD, INT, S5TIME, DATE WORD, INT, S5TIME, DATE DWORD, DINT, REAL, TOD, TIME DWORD, DINT, REAL, TOD, TIME TIMER COUNTER OB FB DB, FB, SFB, UDT FC SFB SFC UDT

0 .. 65535 0 .. 65534 0 .. 65532 0.0 .. 65535.7 0 .. 65535 0 .. 65534 0 .. 65532 0.0 .. 65535.7 0 .. 65535 0 .. 65534 0 .. 65532 0 .. 65535 0 .. 65535 0 .. 65534 0 .. 65534 0 .. 65532 0..65532 0 .. 65535 0 .. 65535 1 .. 65535 0 .. 65535 1 .. 65535 0 .. 65535 0 .. 65535 0 .. 65535 0 .. 65535 0 .. 65535 0..511 0..511 0..1023 0..1023 0..1024

Chng trnh OB c th s dng cc bin tm di hnh thc k hiu (c du # trc) hay a ch L trong vng bng khai bo bin ca khi , bt u t a ch 20.0 tr i. V d1: on chng trnh sau s dng bin tm Enable khai bo trong bng bin cc b, a ch 20.0, chuyn sang dng STL, dng thm bin ph L21.0 cn trng m khng cn khai bo trong bng nu khng dng a ch k hiu.

V d 2: lp trnh cho n b hnh, bnh thng khi khng c yu cu qua ng (I0.0, I0.1), n xanh xe (Q0.7) v n b hnh (Q0.0) sng. Khi c yu cu n vng xe (Q0.6) sng trong 3s , sau n xe (Q0.5) sng v n xanh b hnh (Q0.1) sng trong 10s, ht thi gian ny n b hnh v xe cng sng, sau 6s n vng xe v xe cng sng v sau 3 s n xanh xe sng , xa yu cu qua ng
A( A( O O ) A O ) AN = AN = A L SD A A( ON O ) = A A = A L SD A AN = A A L SD A A( ON O ) ON = A A L SD Q 0.5 S5T#10S T 3 Q 0.5 T 3 Q 0.1 //Bt n xanh b hnh, thi gian 10s M 0.0 T 3 S5T#6S T 4 //Thi gian 6 s xe v b hnh cng sng M 0.0 T T M Q 2 3 0.0 0.0 // Bt n b hnh

I I T M T M M Q

0.0 0.1 6 0.0

// C yu cu qua ng ca khch b hnh

5 //xa yu cu 0.0 // ghi nhn yu cu 0.0 // nu khng c yu cu th 0.7 // n xanh xe sng

M 0.0 S5T#3S T 2 M 0.0 T T Q M T Q 2 4 0.6 //n vng xe 3s 0.0 2 0.5 //n xe sau 3s

M 0.0 //Bt n v vng xe T 4 S5T#3S T 5 //Chuyn sang xanh xe sau 3s

A Q 0.7 L S5T#1S SD T 6 //Thi gian tr hon 1s nhn yu cu khi xanh xe va sng

Sau lp bng k hiu:

A( A( O "Switch_right" O "Switch_left" ) A "Ped_delay_green" O "Pedestrian_light" ) AN "Car_red_orange_phase" = "Pedestrian_light" AN "Pedestrian_light" = "Car_green" A "Pedestrian_light"

A A = A L SD A AN = A A L SD

"Pedestrian_light" "Car_orange_phase" "Car_red" "Car_red" S5T#10S "Ped_green_phase" "Car_red" "Ped_green_phase" "Ped_green" "Pedestrian_light" "Ped_green_phase" S5T#6S "Car_delay_red"

L S5T#3S SD "Car_orange_phase" A "Pedestrian_light" A( ON "Car_orange_phase" O "Car_delay_red" ) = "Car_orange" A "Pedestrian_light" A( ON "Car_orange_phase" O "Car_delay_red" ) = "Car_orange"

A A( ON O ) ON = A A L SD A L SD

"Pedestrian_light" "Car_orange_phase" "Ped_green_phase" "Pedestrian_light" "Ped_red" "Pedestrian_light" "Car_delay_red" S5T#3S "Car_red_orange_phase" "Car_green" S5T#1S "Ped_delay_green"

Sau khi bin son chng trnh ta c th chy m phng khng cn PLC nh phn mm S7 PLC Sim theo cc bc sau: - Vo menu Simatic Manager- Options- chn Simulate Modules. Ca s sau xut hin

Vo menu PLC- Download np khi chng trnh xung PLC m phng Vo ca s S7-PLCSIM menu Insert chn cc vng nh mun quan st

Vo menu PLC- chn Power On, vo menu Execute chn Scan Mode Continuous Scan. - Chn RUN hay RUN P - Tc ng vo cc bit I 0.0, I0.1 xem hot ng ca chng trnh. - Tr li Simatic Manager, chn View- Online, m khi logic mun quan st (OB1), bm Debug- Monitor Trong trng hp mun tp trung cc bin vo mt ch d quan st, ta dng bng khai bo bin VAT (Variable Table). Trong ca s Manager vo menu Insert- S7 BlockVariable Table (hay bm chut phi Insert New Object- Variable Table) ta c khi VAT1, m khi ny ra v thm vo cc a ch vng nh mun quan st.

Vo menu PLC- Connect to Configured CPU. Vo menu Variable- Monitor. Vo menu Operating mode iu khin ch PLC.

Trng hp c sn PLC, u tin ta phi kt ni my tnh vi PLC thng qua cp ni thch hp, vo menu PLC- Display Accessible Nodes, sau PLC- Operating mode chn ch PLC l Stop, PLC- Download np chng trnh xung PLC.

2/ 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 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 con c ci t. Khi OB u tin cao c th ngt khi c u tin thp hn. Ta c th thay i u tin ca OB trong S7-400 v S7-300-CPU318. Thm OB b ng cch bm chut phi trong ca s Project- Insert New Object- Organization block, chn s OB, sau m khi OB v lp trnh

3/ To cc khi logic Cc chng trnh ln thng c vit dng cu trc, gm khi OB1, cc khi chng trnh FC, FB, cc khi chng trnh h thng SFC, SFB. S dng lp trnh cu trc gip chng trnh d qun l v sa li, thun tin cho vic lp trnh theo nhm. Khi OB1 v cc khi FC, FB c th gi FC, FB, SFC, SFB bng lnh CALL

V d 3: lp trnh cho h thng trn hai cht lng A v B (H ), ta chia qu trnh thnh nhiu khi nh (H ) : bm cht A, bm cht B, bn trn v van x. Ta nhn thy hai khi bm lp trnh ging nhau, ch khc cc ng vo/ra. Trc khi lp trnh ta phi c m t k thut cho hot ng ca cc khi. Khi A/B gm c bm v van vo, van ra - Bm c cng sut 100KW, vng quay 1200 rpm, lu lng 400l/pht. Bm c iu khin bi nt Start/Stop trn bng iu khin, s ln start c hin th tin bo tr. Bm c php hot ng khi:

o bn khng y, o van x ng, o nt emergency khng tc ng. Bm tt khi cm bin lu lng bo khng c dng chy sau 7 s k t khi khi ng bm hay khi cm bin lu lng bo ngng chy. - Van c iu khin bi solenoid, m khi c in vo van. Van phi m t nht 1s sau khi bm chy. Khi bn trn c ng c trn, cc cm bin mc. c cng sut 100KW, vng quay 1200 rpm, lu lng 400l/pht. ng c c iu khin bi nt Start/Stop trn bng iu khin, s ln start c hin th tin bo tr. ng c c php chy khi: o Mc cht lng trn mc ti thiu , o Van x ng o Nt Emergency khng tc ng ng c c tt khi vn tc khng t nh mc sau khi khi ng 10s. C ba cm bin mc dng contact . Cm bin y thng ng, khi bn y th h ra. Cm bin mc ti thiu thng h , khi mc cht lng thp th ng li. Cm bin cn, h nu bn cn Van x c iu khin t bng iu khin. Van x c hot ng nu ng c trn ngng, cm bin mc bo bn cha cn, nt emergency khng tc ng. Van x ng nu cm bin mc bo bn cn. Bng iu khin dng iu khin v bo trng thi cc ng c, van x, bo mc bn, bo bo tr v dng khn cp.

C ba ng c c th lp trnh bng khi logic chung (Hnh) . Su ng vo l hai nt nhn Sart/Stop, nt nhn Reset_Maint xa n bo tr, tn hiu bo ng c chy, ngng hay bo c dng chy (Response), s hiu Timer (Timer No) v thi gian timer (Response_Time). Bn ng ra l bo li (Fault), n bo ng c chy, ngng (Start_Dsp, Stop_Dsp), bo bo tr (Maint), Tn hiu vo/ra l iu khin Motor. Ngoi ra cn mt bin l Starts cho bit s ln khi ng ng c. Khi logic ny lp trnh di dng khi hm FB v cn lu tr gi tr bin. Cc van cng c iu khin bng khi logic FC (Hnh) . Hai tn hiu vo l nt nhn m /ng van (Open/ Close) Tn hiu ra l n bo trng thi van ( Dsp_Open, Dsp_Closed). Tn hiu vo/ ra iu khin van (Valve). Khi ny khng c lu bin v thc hin bng FC. Cu trc chng trnh nh Hnh . Chng trnh chnh OB1 gi hm FB1 iu khin ng c, c ba ng c ng vi ba khi d liu DB1, DB2, DB3. Hm FC1 c OB1 gi khi iu khin van. Cc khi FB v FC phi c lp trnh trc khi OB. Vo ca s Project Symbols lp bng k hiu cho cc bin (Bng )

Symbolic Name Feed_pump_A_start Feed_pump_A_stop Flow_A Inlet_valve_A Feed_valve_A Feed_pump_A_on Feed_pump_A_off Feed_pump_A Feed_pump_A_fault Feed_pump_A_maint Feed_pump_B_start Feed_pump_B_stop Flow_B Inlet_valve_B Feed_valve_B Feed_pump_B_on Feed_pump_B_off Feed_pump_B

Address I0.0 I0.1 I0.2 Q4.0 Q4.1 Q4.2 Q4.3 Q4.4 Q4.5 Q4.6 I0.3 I0.4 I0.5 Q5.0 Q5.1 Q5.2 Q5.3 Q5.4

Data Type BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL

Description Starts the feed pump for ingredient A Stops the feed pump for ingredient A Ingredient A flowing Activates the inlet valve for ingredient A Activates the feed valve for ingredient A Lamp for feed pump ingredient A running" Lamp for feed pump ingredient A not running" Activates the feed pump for ingredient A Lamp for feed pump A fault" Lamp for feed pump A maintenance" Starts the feed pump for ingredient B Stops the feed pump for ingredient B Ingredient B flowing Activates the inlet valve for ingredient A Activates the feed valve for ingredient B Lamp for feed pump ingredient B running" Lamp for feed pump ingredient B not running" Activates the feed pump for ingredient B

Feed_pump_B_fault Feed_pump_B_maint Agitator_running Agitator_start Agitator_stop Agitator Agitator_on Agitator_off Agitator_fault Agitator_maint Tank_below_max Tank_above_min Tank_not_empty Tank_max_disp Tank_min_disp Tank_empty_disp Drain_open Drain_closed Drain Drain_open_disp Drain_closed_disp EMER_STOP_off Reset_maint Motor_block Valve_block DB_feed_pump_A DB_feed_pump_B DB_agitator

Q5.5 Q5.6 I1.0 I1.1 I1.2 Q8.0 Q8.1 Q8.2 Q8.3 Q8.4 I1.3 I1.4 I1.5 Q9.0 Q9.1 Q9.2 I0.6 I0.7 Q9.5 Q9.6 Q9.7 I1.6 I1.7 FB1 FC1 DB1 DB2 DB3

BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL BOOL FB1 FC1 FB1 FB1 FB1

Lamp for feed pump B fault" Lamp for feed pump B maintenance" Response signal of the agitator motor Agitator start button Agitator stop button Activates the agitator Lamp for "agitator running" Lamp for "agitator not running" Lamp for agitator motor fault" Lamp for agitator motor maintenance" Sensor mixing tank not full" Sensor mixing tank above minimum level" Sensor mixing tank not empty" Lamp for "mixing tank full" Lamp for "mixing tank below minimum level" Lamp for "mixing tank empty" Button for opening the drain valve Button for closing the drain valve Activates the drain valve Lamp for "drain valve open" Lamp for "drain valve closed" EMERGENCY STOP switch Reset switch for the maintenance lamps on all motors FB for controlling pumps and motor FC for controlling the valves Instance DB for controlling feed pump A Instance DB for controlling feed pump B Instance DB for controlling the agitator motor

3.1 Lp trnh khi FB FB l khi logc vi cc bin in, out, in_out, static v temp, c to ra trong bng bin a phng i km. Cc bin in, out, in_ out l cc tham s hmh 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, bin temp mt gi tr khi ra khi khi FB. Km vi FB l khi d liu data block cha cc 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. Ta vo ca s Project bm chut phi Insert New Object Function block thm vo khi FB1. Bm chut vo khi FB1 son chng trnh cho khi. Ta vo bng khai bo bin khai bo cc bin hnh thc cho khi theo th t in, out, in_out, static v temp. Vi v d trn, bng bin ca FB1 Motor_Block nh sau:
Address 0.0 0.1 0.2 0.3 2.0 4.0 6.0 6.1 6.2 6.3 Declaration IN IN IN IN IN IN OUT OUT OUT OUT Name Start Stop Response Reset_Maint Timer_No Response_Time Fault Start_Dsp Stop_Dsp Maint Type BOOL BOOL BOOL BOOL TIMER S5TIME BOOL BOOL BOOL BOOL Initial Value FALSE FALSE FALSE FALSE S5T#0MS FALSE FALSE FALSE FALSE

8.0 10.0 12.0 14.0 16.0

IN_OUT STAT STAT STAT STAT

Motor Time_bin Time_BCD Starts Start_Edge

BOOL WORD WORD INT BOOL

FALSE W#16#0 W#16#0 0 FALSE

Cc bin STAT Time_ bin v Time_BCD l u thi gian timer, Starts lu s ln khi ng motor, nu qu 5000 th bo bo tr , Start_ Edge phc v cho lnh ly cnh ln
Network 1 Start/stop and latching A( O #Start O #Motor ) AN #Stop = #Motor Network 2 Startup monitoring A #Motor L #Response_Time SD #Timer_No AN #Motor R #Timer_No L #Timer_No T #Timer_bin LC #Timer_No T #Timer_BCD A #Timer_No AN #Response S #Fault R #Motor Network 3 Start lamp and fault reset A #Response = #Start_Dsp R #Fault Network 4 Stop lamp AN #Response = #Stop_Dsp Network 5 Counting the starts A #Motor FP #Start_Edge JCN lab1 L #Starts +1 T #Starts lab1: NOP 0 Network 6 Maintenance lamp L #Starts L 5000 >=I = #Maint Network 7 Reset counter for number of starts A #Reset_Maint A #Maint JCN END L0 T #Starts END: NOP 0

Thm khi DB project vi cc tn DB1, DB2, DB3 loi Instance DB v thuc FB1

Cc bin trong DB1 s t to ra theo bng khai bo bin ca khi FB1, gm cc bin loi in, out,in_out v stat, tng t cho cc DB2 v DB3. Khi khi FB c gi s phi m km theo DB tng ng

3.2 Lp trnh 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 bin temp s dng ni b, tuy nhin khng bt buc phi dng tt c cc loi bin ny. Khi FC khng c b nh nn d liu mt i khi ra khi khi. Ta thm vo project khi FC1 v khai bo cc bin trong bng khai bo bin km theo. Sau lp trnh cho FC1
Address Declaration Name Type Initial Value 0.0 IN Open BOOL FALSE 0.1 IN Close BOOL FALSE 2.0 OUT Dsp_Open BOOL FALSE 2.1 OUT Dsp_Closed BOOL FALSE 4.0 IN_OUT Valve BOOL FALSE Network 1 Open/close and latching A( O #Open O #Valve ) AN #Close = #Valve Network 2 Display "valve open" A #Valve = #Dsp_Open Network 3 Display "valve closed" AN#Valve = #Dsp_Closed

Bc tip theo l lp trnh cho OB1, ta khai bo cc bin cho OB1 t a ch 20 tr i


Address 0.0 1.0 2.0 3.0 Declaration TEMP TEMP TEMP TEMP Name OB1_EV_CLASS OB1_SCAN1 OB1_PRIORITY OB1_OB_NUMBR Type BYTE BYTE BYTE BYTE

4.0 5.0 6.0 8.0 10.0 12.0 20.0 20.1 20.2 20.3 20.4 20.5

TEMP TEMP TEMP TEMP TEMP TEMP TEMP TEMP TEMP TEMP TEMP TEMP

OB1_RESERVED_1 OB1_RESERVED_2 OB1_PREV_CYCLE OB1_MIN_CYCLE OB1_MAX_CYCLE OB1_DATE_TIME Enable_motor Enable_valve Start_fulfilled Stop_fulfilled Inlet_valve_A_open Inlet_valve_A_closed

BYTE BYTE INT INT INT DATE_AND_TIME BOOL BOOL BOOL BOOL BOOL BOOL

Chng trnh OB1


Network 1 Interlocks for feed pump A A "EMER_STOP_off" A "Tank_below_max" AN "Drain" = #Enable_Motor Network 2 Calling FB Motor for ingredient A A "Feed_pump_A_start" A #Enable_Motor = #Start_Fulfilled A( O "Feed_pump_A_stop" ON #Enable_Motor ) = #Stop_Fulfilled CALL "Motor_block", "DB_feed_pump_A" Start :=#Start_Fulfilled Stop :=#Stop_Fullfilled Response :="Flow_A" Reset_Maint :="Reset_maint" Timer_No :=T12 Reponse_Time:=S5T#7S Fault :="Feed_pump_A_fault" Start_Dsp :="Feed_pump_A_on" Stop_Dsp :="Feed_pump_A_off" Maint :="Feed_pump_A_maint" Motor :="Feed_pump_A" Network 3 Delaying the valve enable ingredient A A "Feed_pump_A" L S5T#1S SD T 13 AN "Feed_pump_A" R T 13 A T 13 = #Enable_Valve Network 4 Inlet valve control for ingredient A AN "Flow_A" AN "Feed_pump_A" = #Close_Valve_Fulfilled CALL "Valve_block" Open :=#Enable_Valve Close :=#Close_Valve_Fulfilled Dsp_Open :=#Inlet_Valve_A_Open Dsp_Closed:=#Inlet_Valve_A_Closed Valve :="Inlet_Valve_A" Network 5 Feed valve control for ingredient A Network 8 Delaying the valve enable ingredient B A "Feed_pump_B" L S5T#1S SD T 15 AN "Feed_pump_B" R T 15 A T 15 = #Enable_Valve Network 9 Inlet valve control for ingredient B AN "Flow_B" AN "Feed_pump_B" = #Close_Valve_Fulfilled CALL "Valve_block" Open :=#Enable_Valve Close :=#Close_Valve_Fulfilled Dsp_Open :=#Inlet_Valve_B_Open Dsp_Closed:=#Inlet_Valve_B_Closed Valve :="Inlet_Valve_B" Network 10 Feed valve control for ingredient B AN "Flow_B" AN "Feed_pump_B" = #Close_Valve_Fulfilled CALL "Valve_block" Open :=#Enable_Valve Close :=#Close_Valve_Fulfilled Dsp_Open :=#Feed_Valve_B_Open Dsp_Closed:=#Feed_Valve_B_Closed Valve :="Feed_Valve_B" Network 11 Interlocks for agitator A "EMER_STOP_off" A "Tank_above_min" AN "Drain" = #Enable_Motor Network 12 Calling FB Motor for agitator A "Agitator_start" A #Enable_Motor = #Start_Fulfilled A( O "Agitator_stop" ON #Enable_Motor ) = #Stop_Fulfilled CALL "Motor_block", "DB_Agitator" Start :=#Start_Fulfilled

AN"Flow_A" AN"Feed_pump_A" =#Close_Valve_Fulfilled CALL"Valve_block" Open:=#Enable_Valve Close:=#Close_Valve_Fulfilled Dsp_Open:=#Feed_Valve_A_Open Dsp_Closed:=#Feed_Valve_A_Closed Valve :="Feed_Valve_A" Network 6 Interlocks for feed pump B A "EMER_STOP_off" A "Tank_below_max" AN "Drain" = "Enable_Motor Network 7 Calling FB Motor for ingredient B A "Feed_pump_B_start" A #Enable_Motor = #Start_Fulfilled A( O "Feed_pump_B_stop" ON #Enable_Motor ) = #Stop_Fulfilled CALL "Motor_block", "DB_feed_pump_B" Start :=#Start_Fulfilled Stop :=#Stop_Fullfilled Response :="Flow_B" Reset_Maint :="Reset_maint" Timer_No :=T14 Reponse_Time:=S5T#7S Fault :="Feed_pump_B_fault" Start_Dsp :="Feed_pump_B_on" Stop_Dsp :="Feed_pump_B_off" Maint :="Feed_pump_B_maint" Motor :="Feed_pump_B"

Stop :=#Stop_Fullfilled Response :="Agitator_running" Reset_Maint :="Reset_maint" Timer_No :=T16 Reponse_Time:=S5T#10S Fault :="Agitator_fault" Start_Dsp :="Agitator_on" Stop_Dsp :="Agitator_off" Maint :="Agitator_maint" Motor :="Agitator" Network 13 Interlocks for drain valve A"EMER_STOP_off" A"Tank_not_empty" AN"Agitator" = "Enable_Valve Network 14 Drain valve control A "Drain_open" A #Enable_Valve = #Open_Drain A( O "Drain_closed" ON #Enable_Valve ) = #Close_Drain CALL "Valve_block" Open :=#Open_Drain Close :=#Close_Drain Dsp_Open :="Drain_open_disp" Dsp_Closed :="Drain_closed_disp" Valve :="Drain" Network 15 Tank level display AN"Tank_below_max" ="Tank_max_disp" AN"Tank_above_min" ="Tank_min_disp" AN"Tank_not_empty" = "Tank_empty_disp"

Bng sau cho bit s lng khi /kch thc tng cng cc khi logic ca cc loi cpu CPU OB1 DB FB FC 312 6KByte 63/6 KByte 32/6 KByte 32/6 KByte 313, 314 8 KByte 127/8 KByte 128/8KByte 128/8KByte 315 16 KByte 255/16KByte 192/16KByte 192/16KByte 316 16 KByte 511/16 KByte 256/16 KByte 256/16 KByte 318 64 KByte 2047/64 KByte 1024/64 KByte 1024/64 KByte 412 64 KByte 512/64 Kbyte 256/64Kbyte 256/64Kbyte 414, 416 64 KByte 4095/64 KByte 2048/64 KByte 2048/64 Kbyte 417 64 KByte 8192/64 KByte 6144/64 KByte 6144/64 KByte 4. S dng hm th vin Cc hm th vin do Siemens vit sn thuc cc loi FC, FB, SFC, SFB gip ngi dng thun tin trong lp trnh. Mun dng cc hm th vin trong khi logic no th ta m khi logic ra, kch chut vo ch gi hm th vin, vo menu Insert- Program Elements Libraries chn cc hm th vin ph hp ri bm chut kp vo , hoc g CALL tn hm th vin nu ta nh tn hm. Lnh gi hm s c thm vo km theo cc bin in, out v in_out cn trao i

Cc hm th vin cn chuyn gi tr cho cc bin hnh thc v ta phi cung cp cho hm gi theo qui nh ca hm th vin. Nu trong Project c cc hm FB, FC trng tn vi hm th vin th cn phi i tn

Th vin chun ca Step 7 gm c cc th vin con: System Function Blocks: khi hm h thng (SFB) v hm h thng (SFC) S5-S7 Converting Blocks: hm chuyn i chng trnh ca PLC S5 sang S7 TI-S7 Converting Blocks: cc hm a dng IEC Function Blocks: cc hm IEC Organization Blocks: khi t chc (OB) PID Control Blocks : hm iu khin PID Communication Blocks: cc hm mng

Ngoi ra cn c th ci thm cc hm th vin khc nh fuzzy control, neuro system, motion control. Ngi dng c th t vit mt th vin gm cc hm thng dng tin cho cng vic ca mnh. Cc bc to th vin nh sau. - Simatic Manager- File New- Libraries t tn cho th vin- OK

Mun to cc hm trong th vin ta bm File- Open- Libraries chn tn th vin OK

Vo ca s ca th vin Thanh- bm chut phi- Insert New Objects- S7 Program

i tn cho th vin con ny, v d Motion Control, sau m th vin con ny v copy vo cc hm t th vin khc hay t vit cc hm mi

Mun b mt th vin vo Simatic Manager- File - Delete - Libraries chn tn th vin - OK

5 Bng cc hm SFB SFC v FC Bng sau lit k cc hm th vin. Mt s hm s c kho st cc chng sau
No. SFC 0 SFC 1 SFC 2 SFC 3 SFC 4 SFC 5 SFC 6 SFC 7 SFC 9 SFC 10 SFC 11 SFC 12 SFC 13 SFC 14 SFC 15 SFC 17 SFC 18 SFC 19 SFC 20 SFC 21 SFC 22 SFC 23 SFC 24 SFC 25 SFC 26 SFC 27 SFC 28 SFC 29 SFC 30 SFC 31 SFC 32 SFC 33 SFC 34 SFC 35 SFC 36 SFC 37 SFC 38 SFC 39 SFC 40 SFC 41 SFC 42 SFC 43 SFC 44 SFC 46 SFC 47 SFC 48 Short Name SET_CLK READ_CLK SET_RTM CTRL_RTM READ_RTM GADR_LGC RD_SINFO DP_PRAL EN_MSG DIS_MSG DPSYC_FR D_ACT_DP DPNRM_DG DPRD_DAT DPWR_DAT ALARM_SQ ALARM_S ALARM_SC BLKMOV FILL CREAT_DB DEL_DB TEST_DB COMPRESS UPDAT_PI UPDAT_PO SET_TINT CAN_TINT ACT_TINT QRY_TINT SRT_DINT CAN_DINT QRY_DINT MP_ALM MSK_FLT DMSK_FLT READ_ERR DIS_IRT EN_IRT DIS_AIRT EN_AIRT RE_TRIGR REPL_VAL STP WAIT SNC_RTCB Function Set System Clock Read System Clock Set Run-Time Meter Start/Stop Run-Time Meter Read Run-Time Meter Query Logical Address of a Channel Read OB Start Information Trigger a Hardware Interrupt on the DP Master Enable Block-Related, Symbol-Related and Group Status Messages Disable Block-Related, Symbol-Related and Group Status Messages Synchronize Groups of DP Slaves Deactivation and activation of DP slaves Read Diagnostic Data of a DP Slave (Slave Diagnostics) Read Consistent Data of a Standard DP Slave Write Consistent Data to a DP Standard Slave Generate Acknowledgeable Block-Related Messages Generate Permanently Acknowledged Block-Related Messages Query the Acknowledgment Status of the last ALARM_SQ Entering State Message Copy Variables Initialize a Memory Area Create Data Block Delete Data Block Test Data Block Compress the User Memory Update the Process Image Update Table Update the Process Image Output Table Set Time-of-Day Interrupt Cancel Time-of-Day Interrupt Activate Time-of-Day Interrupt Query Time-of-Day Interrupt Start Time-Delay Interrupt Cancel Time-Delay Interrupt Query Time-Delay Interrupt Trigger Multicomputing Interrupt Mask Synchronous Errors Unmask Synchronous Errors Read Error Register Disable New Interrupts and Asynchronous Errors Enable New Interrupts and Asynchronous Errors Delay Higher Priority Interrupts and Asynchronous Errors Enable Higher Priority Interrupts and Asynchronous Errors Retrigger Cycle Time Monitoring Transfer Substitute Value to Accumulator 1 Change the CPU to STOP Delay Execution of the User Program Synchronize Slave Clocks

SFC 49 SFC 50 SFC 51 SFC 52 SFC 54 SFC 55 SFC 56 SFC 57 SFC 58 SFC 59 SFC 60 SFC 61 SFC 62 SFC 63 SFC 64 SFC 65 SFC 66 SFC 67 SFC 68 SFC 69 Station SFC 72 SFC 73 SFC 74 Station SFC 79 SFC 80 SFC 81 SFC 90 No. SFB 0 SFB 1 SFB 2 SFB 3 SFB 4 SFB 5 SFB 8 SFB 9 SFB 12 SFB 13 SFB 14 SFB 15 SFB 16 SFB 19 SFB 20 SFB 21 SFB 22 SFB 23 SFB 29 SFB 30 SFB 32 SFB 33 SFB 34 SFB 35 SFB 36 SFB 37 SFB 38 SFB 39 SFB 41

LGC_GADR RD_LGADR RDSYSST WR_USMSG RD_PARM WR_PARM WR_DPARM PARM_MOD WR_REC RD_REC GD_SND GD_RCV CONTROL AB_CALL TIME_TCK X_SEND X_RCV X_GET X_PUT X_ABORT I_GET I_PUT I_ABORT SET RSET UBLKMOV H_CTRL Short Name CTU CTD CTUD TP TON TOF USEND URCV BSEND BRCV GET PUT PRINT START STOP RESUME STATUS USTATUS HS_COUNT FREQ_MES DRUM ALARM ALARM_8 ALARM_8P NOTIFY AR_SEND HSC_A_B POS CONT_C 1)

Query the Module Slot Belonging to a Logical Address Query all Logical Addresses of a Module Read a System Status List or Partial List Write a User-Defined Diagnostic Event to the Diagnostic Buffer Read Defined Parameters Write Dynamic Parameters Write Default Parameters Assign Parameters to a Module Write a Data Record Read a Data Record Send a GD Packet Fetch a Received GD Packet Query the Status of a Connection Belonging to a Communication SFB Instance Assembly Code Block Read the System Time Send Data to a Communication Partner outside the Local S7 Station Receive Data from a Communication Partner outside the Local S7 Station Read Data from a Communication Partner outside the Local S7 Station Write Data to a Communication Partner outside the Local S7 Station Abort an Existing Connection to a Communication Partner outside the Local S7 Read Data from a Communication Partner within the Local S7 Station Write Data to a Communication Partner within the Local S7 Station Abort an Existing Connection to a Communication Partner within the Local S7 Set a Range of Outputs Reset a Range of Outputs Uninterruptable Block Move Control Operation in H Systems Function Count Up Count Down Count Up/Down Generate a Pulse Generate an On Delay Generate an Off Delay Uncoordinated Sending of Data Uncoordinated Receiving of Data Sending Segmented Data Receiving Segmented Data Read Data from a Remote CPU Write Data to a Remote CPU Send Data to Printer Initiate a Warm or Cold Restart on a Remote Device Changing a Remote Device to the STOP State Initiate a Hot Restart on a Remote Device Query the Status of a Remote Partner Receive the Status of a Remote Device Counter (high-speed counter, integrated function) Frequency Meter (frequency meter, integrated function Implement a Sequencer Generate Block-Related Messages with Acknowledgment Display Generate Block-Related Messages without Values for 8 Signals Generate Block-Related Messages with Values for 8 Signals Generate Block-Related Messages without Acknowledgment Display Send Archive Data Counter A/B (integrated function) Position (integrated function) Continuous Control

SFB 42 CONT_S 1) Step Control SFB 43 PULSEGEN 1) Pulse Generation * SFB29 "HS_COUNT" and SFB30 "FREQ_MES" only exist on the CPU 312 IFM and CPU 314 IFM. SFBs 38 "HSC_A_B" and 39 "POS" only exist on the CPU 314 IFM. For a detailed description, refer to. * SFBs 41 "CONT_C," 42 "CONT_S" and 43 "PULSEGEN" only exist on the CPU 314 IFM. No. FC1 FC2 FC3 FC4 FC5 FC6 FC7 FC8 FC9 FC10 FC11 FC12 FC13 FC14 FC15 FC16 FC17 FC18 FC19 FC20 FC21 FC22 FC23 FC24 FC25 FC26 FC27 FC28 FC29 FC30 FC31 FC32 FC33 FC34 FC35 FC36 FC37 FC38 FC39 FC40 Short Name AD_DT_TM CONCAT D_TOD_DT DELETE DI_STRNG DT_DATE DT_DAY DT_TOD EQ_DT EQ_STRNG FIND GE_DT GE_STRNG GT_DT GT_STRNG I_STRNG INSERT LE_DT LE_STRNG LEFT LEN LIMIT LT_DT LT_STRNG MAX MID MIN NE_DT NE_STRNG R_STRNG REPLACE RIGHT S5TI_TIM SB_DT_DT SB_DT_TM SEL STRNG_DI STRNG_I STRNG_R TIM_S5TI Function Add duration to a time Combine two STRING variables Combine DATE and TIME_OF_DAY to DT Delete in a STRING variable Data type conversion DINT to STRING Extract the DATE from DT Extract the day of the week from DT Extract the TIME_OF_DAY from DT Compare DT for equal Compare STRING for equal Find in a STRING variable Compare DT for greater than or equal Compare STRING for greater than or equal Compare DT for greater than Compare STRING for greater than Data type conversion INT to STRING Insert in a STRING variable Compare DT for less than or equal Compare STRING for less than or equal Left part of a STRING variable Length of a STRING variable Limit Compare DT for less than Compare STRING for less than Select maximum Middle part of a STRING variable Select minimum Compare DT for unequal Compare STRING for unequal Data type conversion REAL to STRING Replace in a STRING variable Right part of a STRING variable Data type conversion S5TIME to TIME Subtract two time values Subtract duration from a time Binary selection Data type conversion STRING to DINT Data type conversion STRING to INT Data type conversion STRING to REAL Data type conversion TIME to S5TIME

You might also like