Vous êtes sur la page 1sur 1

BothFCsandFBshavesimilardeclarationtables,youcansetupparametersoftypesIn,Out,InOut,andTempinordertoparametrizethem.

However,FBshaveanextratype,Statparameters.TheseStatparametersarelinkedtotheIDB,theinstanceDBassociatedwiththeFB.The
valueoftheseparametersisavailableatanytimeduringtheexecutionofthePLCprogram,toanyblock;whereastheparametersofanFCare
onlyavailabletoanotherblockwhiletheFCisactuallycalled.
WhendoyouneedaFBversusanFC?hereisagoodindicator:ifyouwriteanFC,andinsidethatFCyoustarttoMOVparameterdatatoan
externaldatablockorMmemorybecauseyouneedtomemorizethemorusethemelswhereinyourprogram,thenyouneedStatvariables,ergo
anFB.
Hereisasuggestion:openthemanual"SystemandStandardfunctions",itisinstalledonyourPCwhithSimaticManagerdocumentation(Step
7).Youwillfindpreprogrammedblocksthatcanbeinsertedinyourprogram;theycoveralargerangeofutilities.ThereareSFCs(systemFCs)
andSFBs(systemFBs).
Now:toreadorwritetotheSystemClockofthePLC,youuseaSFC(noneedtomemorizethedata,youjustread/writeonce).Tosetupatimer
oracounter(youmightneedtoaccesstheactualvalueofthecounter/timersomewhereelseinyourprogram)youwillneedanSFB.
AnotherwayoflookingatthisisthatFBsaremostcommonlyusedforsubroutinesthatdirectlycontrolthemachine,whileFCsareusedfor
manipulatingdataorperformingcalculations.
AtypicalprogramshouldconsistofanumberofFBsthatdotheactualcontrolwork,withsomeoftheFBscallingFCstoperformspecial
purposecalculationsordataoperations.AnFCshouldneverhavereasontocallanFB.TheFCshouldoperateonitsinputparametersandoutput
theresultthroughitsoutputparameters.
AsMr.Chartierhassaid,theremaybecasesnowandagainwhereyouneedtouseanFBtocontainanalgorithmbecauseyouneedpersistent
data(storedintheinstancedatablock).Ontheotherhand,youshouldneveruseanFCtodomachinecontrolfunctions.
AprogramwillalwayshaveanumberofFBs(unlessyouwritethewholethinginOB1),butmaynotnecessarilyhaveanyFCs.Thereisnothing
tostopyoufromusingFBsandFCsforwhateveryouwant,buttheaboveisthestandardconventionforIEC611313.
Simple,thinkofFCsas"functions"inaregularprogramminglanguage.Thatis,theysimplyreturnavaluetothecallingprogram.
FBsontheotherhandaremorelike"procedures"inatraditionallanguage;theyhaveadatablockassociatedwiththemandcanstorevalueson
thatdatablockforfutureuseorforotherprocedures.
ThebiggestadvantageofFCsisifyouonlyneedtoperformataskandreturnavalue,theoverheadislesssinceyoudon'tneedtodeclareaDB
forthecall(aninstancedatablock).IfyoudidthesamethingwithaFB,youwouldhavetopassaDBwitheachone.
YouCOULDmakeeachworkliketheotherhowever.Thatis,itispossibletohaveafunctionstoredataanduseotherDBs,anditispossibleto
haveaFBreturnavalue(viaaglobalDB)

Vous aimerez peut-être aussi