• No results found

Open environment for programming small controllers according to IEC 61131-3 standard

N/A
N/A
Protected

Academic year: 2020

Share "Open environment for programming small controllers according to IEC 61131-3 standard"

Copied!
12
0
0

Loading.... (view fulltext now)

Full text

(1)

OPENENVIRONMENTFOR PROGRAMMINGSMALL CONTROLLERS ACCORDING

TO IEC 61131-3STANDARD

DARIUSZ RZO‹CA, JANSADOLEWSKI, ANDRZEJ STEC, ZBIGNIEW ‘WIDER, BARTOSZ TRYBUS, AND

LESZEK TRYBUS

Abstrat. AontrolengineeringenvironmentalledCPDevforprogrammingsmallontrollersinST,FBDandILlanguages

ofIEC61131-3standardispresented.Theenvironmentonsistsofaompiler,simulatorandhardwareongurer. Itisopeninthe

sensethat: (1)odegeneratedbytheompileranbeexeutedbydierentproessors,(2)low-levelomponentsoftheontroller

runtimeprogramaredevelopedbyhardwaredesigners,(3)ontrolprogrammersandenelibrarieswithfuntions,funtionbloks

andprograms.

OfthethreeIEClanguages,STStruturedTextisabasisforCPDev. FBDdiagramsaretranslatedtoST.ILompileruses

thesameodegenerator. Theruntimeprogramhas theformofvirtualmahinewhihexeutesuniversal odegenerated bythe

ompiler.ThemahineisanANSICprogramwithsomeplatform-dependentomponents.ThemahinesforAVR,ARM,MCS51

andx86proessorshavebeendevelopedsofar. AppliationsinludetwoontrollersforsmallDCSsystemsandPCequippedwith

I/Oboards. CPDevmaybedownloadedfromhttp://pdev.prz-rzeszow .pl /dem o.

Keywords: ontrolengineeringtool,IEC61131-3standard,STlanguageompiler,multi-platformvirtualproessor

1. Introdution. Remarkablenumberofsmall-and-medium-saleompaniesinEuropemanufature

tran-smitters, atuators, drives, PID and PLC ontrollers, and other ontrol-and-measurement equipment.

Engi-neering tools for programming suh devies are often fairly simple and do not orrespond to IEC 61131-3

standard[4℄, requiredbygrowingnumberofustomers. Theproblem maybesolvedto someextentby

devel-opingopenengineering environmentsforprogrammingsmallontrol deviesbasedonAVR, ARM,MCS51or

othermiroontrollersaordingtoIEC languages(61131-3will bedroppedforbrevity). Developmentofsuh

environmentalledCPDev(Control ProgramDeveloper)wasinitiatedbytheauthorsattheendof2006.

TheCPDevisopenin thefollowingsense:

odegeneratedbytheompileranbeexeutedbydierentproessors,

low-levelomponentsofruntimeprogramareprovidedbyhardwaredesigners,

ontrolprogrammersreatetheirownlibrarieswithreusableprogramunits.

TheCPDevompilergeneratesanintermediate,universalodeexeutedbyruntimeinterpreterattheontroller

side. Dierent proessorsrequiredierentinterpreters. This resembles somewhatthe oneptof Javavirtual

mahines[7℄apableofexeutingprogramsondierentplatforms. HenetheinterpretersoftheCPDevuniversal

odearealsoalledvirtual mahines.

Thesameapproahwasadaptedearlierin ISaGRAFpakagefromISC Triplex[5℄ (nowinRokwell).

IS-aGRAFuniversalodeisalledTIC(TargetIndependent Code) andmaybeexeutedonplatformssupporting

Windows, Linux, VxWorks, QNX and RTX. Muh simplerCPDev does notimpose suh requirements,

how-ever. AnotheropenenvironmentalledBeremiz[11℄ompilesIEC languageodeintoC/C++program,tobe

translatedfurtherintoproessorode. InthisaseommerialrestritionsontheuseofC/C++ompilersmay

mattersometimes.

This paper follows a few earlier publiations, e.g. [9, 10℄, whih reported on CPDev development. The

ontentisorganizedasfollows. ForthereadernotfamiliarwithIECstandard,Se.2providessomeinformation

on programming in high-level ST language. Components of CPDev, user interfae, standard funtions and

librarieswithfuntionbloksaredesribedinSe.3. Setion4haraterizessanner,parserandodegenerator

ofSTompiler, writtenin C#at Ms.NET platform. Someinstrutionsof theuniversalodealledVMASM

(Virtual Mahine Assembler) are also presented. Setion 5 desribes operation and struture of the virtual

mahine. The mahine is written in industry standard C and onsists of universal and platform-dependent

modules. Platform-dependentmodulesarewrittenbyhardwaredesigners. Setion6haraterizesdevelopment

of userfuntion bloks, both in ST andC languages. Bloks written in Cbeome omponents of thevirtual

mahine. Programming in graphial FBD and textual ILlanguages is desribed in Se. 7. FBD diagram is

translatedtoSTandthenompiled. AppliationsofCPDevforprogrammingasmallontrol-and-measurement

Departmentof ComputerandControlEngineering, Faultyof Eletrialand ComputerEngineering, RzeszowUniversityof

(2)

distributed system, ontrollers of ship ontrol-and-positioning system and a softontroller based on PC with

I/OboardsarepresentedinSe.8.

2. A few notes on IEC 61131-3. The IEC 61131-3 standard[4℄ denes veprogramming languages,

LD,IL,FBD,STandSFC,allowingtheuserto hoosetheonesuitableforpartiularappliation. Instrution

list IL and Strutured Text ST are text languages, whereas Ladder Diagram LD, Funtion Blok Diagram

FBD and Sequential Funtion Chart SFC are graphial ones (SFC is not an independent language, sine it

requires omponents written in the other languages). Relatively simple languages LD and IL are used for

small appliations. FBD, ST and SFC are appropriate for medium-sale and large appliations. John and

Tiegelkamp'sbook[6℄isagoodsouretolearnIEC programming.

STisahigh-levellanguageoriginatedfromPasal,espeiallysuitableforompliatedalgorithms. Equivalent

odeforaprogramwritteninanyoftheotherfourlanguagesanbedevelopedinST,butnotvieversa. Hene

mostofengineeringpakagesuseSTas adefaultlanguageforprogramminguserfuntionbloks. Due tosuh

reasons,SThasbeenseletedasabaselanguagefortheCPDevenvironment.

2.1. Datatypes. Datatypes,literals(onstants)andvariablesareommonomponentsofIEClanguages.

Names (identiers) are typial, although there is no distintion between apital and small haraters. The

standarddenestwentyelementarydata types, severalof whih arelistedin Table2.1together withmemory

sizes andranges(inCPDev). BOOL,INT,REALand TIMEaremostommon. FALSE,13,-4.1415and T#1m25s

areexamplesoforrespondingonstants.

Table2.1

SeveralelementaryIECdatatypes

Type Size(range) Type Size(range)

BOOL 1B(

0

,

1

) LREAL 8BIEEE-754format

BYTE 1B(

0

...

255

)

TIME

4B(-T#24d20h31m23s648ms...

WORD 2B(

0

...

65535

) T#24d20h31m23s647ms)

INT 2B(

32768

...

32767

)

TIME_OF_DAY

4B(

00

:

00

:

00

.

00

...

REAL 4BIEEE-754format

23

:

59

:

59

.

99

)

Thestandarddenesthree levelsforaessing variables,LOCAL,GLOBALandACCESS.LOCALsareavailable

in theprogram,funtion blokor funtion. GLOBALs anbeusedin thewholeprojet,butprograms,funtion

bloksorfuntionsmustdelarethemasEXTERNAL.ACCESSvariablesexhangedatabetweendierentsystems.

2.2. POU units. Programs, funtion bloks and funtions, alled jointly Program Organization Units

(POUs), are omponents of IEC projets. Funtion bloks, designed for reuse in dierent parts of program,

are of ruial importane. A blok involvesinputs, outputs and memory for data from previous exeutions.

Therefore the bloks must be delared as instanes. The IEC denes small set of standard bloks, suh as

ip-ops,edgedetetors,timersandounters. Threeofthem areshowninFig.2.1.

Fig.2.1. Examplesofstandardfuntionbloks: RSip-op,R_TRIGrisingedgedetetor,TONon-delaytimer

2.3. Programming. ProgramswritteninSTorotherlanguagesbeginwithdelarationsofvariablesand

instanesoffuntionbloksplaedbetweenVAR_EXTERNALorVARandEND_VARkeywords. GLOBALvariablesare

delared before programs orseparately. Thedelarations are followed by list of statements. Thestatements

involveexpressionswhih,whenevaluated,yieldresultsinoneofdeneddatatypes,i.e. elementary(Table2.1)

(3)

STlanguageprovidesvetypesofstatements:

assignment:=(Pasalsymbol),

seletionsIF,CASE,

loopsFOR,WHILE,REPEAT,

earlyexitsRETURN,EXIT,

funtionandfuntion blokinvoations.

Simpleexamplesarepresentedinthefollowingsetions. Typialprogramlookslikeasequeneoffuntionand

funtionblokinvoations(alls).

3. CPDev environment. The CPDevonsists of threeprograms exeuted by PC andoneby the

on-troller(Fig3.1). ThePCprogramsareasfollows:

CPDevompilerofSTlanguage,

CPSimsimulator,

CPConongurerofhardwareresoures.

Theprogramshavedediated interfaesand exhangedata throughlesin appropriate formats. The CPDev

ompiler(thesamenameasthepakage)generatesuniversalodeexeutedbyvirtualmahine(VM)runbythe

ontroller. TheVMoperatesasaninterpreter. TheuniversalodeisalistofinstrutionsofVMlanguagealled

VMASMassembler. VMASMis notrelated toanypartiular proessor,but loseto typialassemblers. The

ompileremploysSTsyntaxrules,listofVMASMinstrutionsandPOUsfromlibraries. Besidestheuniversal

odetheompilergeneratessomeinformationfordebuggingandsimulationbyCPSim.

Fig.3.1. ComponentsofCPDevenvironment

CongurationofhardwareresouresbymeansofCPConinvolvesmemory,input/outputandommuniation

interfaes. Userspeiationsdene memorytypesandsizes, numbersand typesofI/Osandommuniation

hannels, validity ags, et. Alloation of hardware resoures has the form of a map that assigns symboli

addressesfromSTprogramstophysialones. Byusingit,theompiledodeanbeassembledforapartiular

platformto reatenal, universalexeutableode. FromCPDevviewpoint,hardwareplatformsdieronlyin

hardwarealloationmaps, whereastheompiledodeis idential.

TheCPDev environmenthasbeenreentlyextended by graphieditor of FBDdiagrams andompiler of

ILlanguage. FBD diagramis automatiallyonverted intoST ode andompiled asabove. Compilersof ST

andILdierin detailsonly.

3.1. User interfae. MainwindowofCPDev STompilerisshownin Fig.3.2. The windowonsists of

threeareas:

treeofprojetstruture,ontheleft,

programinSTlanguage,enter,

messagelist,bottom.

Framesoftheareasanbeadjusted andtheontentssrolled.

TreeoftheSTART_STOPprojetshowninthegureinludesPOUunitwiththeprogramPRG_START_STOP,

ve global variables from START to PUMP, task TSK_START_STOP, and two standard funtion bloks TON and

TOFfrom IEC_61131library. The programis written aordingto ST languagerules. Therstpartinvolves

delarations VAR_EXTERNAL of the use of global variables. Loal delarations of the instanes ON_DELAYand

OFF_DELAYofthebloksTON,TOFaretheseondpart. Programbodyonsistsoffourstatements. Therstone

turnsaMOTORonifSTARTispressed,providedthat STOPorALARMarenot. NextthreestatementsturnaPUMP

onandoveseondsafter theMOTOR(FBD diagramorrespondingtothis projetisshowninFig 7.1).

Globalvariablesandthetaskaredenedusingseparatewindows(notshown). AordingtoIECstandard

the variables anbe assigned CONSTANT and RETAINattributes, and logialaddresses. Task anbe exeuted

one, ylially with agiven period, orassoon aspreviousexeution is ompleted. There is no limiton the

numberofprogramsassignedtoatask.

(4)

Fig.3.2.UserinterfaeofSTompiler(START_STOPprojet)

arenomistakes,theompiledprojetis storedin twoles. Therstoneontainsuniversalexeutableodein

binaryformatforthevirtualmahine. Theseondonestoresmnemoni ode,togetherwithsomeinformation

forsimulatorandhardwareongurer(variablenames,et.).

3.2. Funtionsandfuntionbloks. TheCPDevompilerprovidesmostofstandardfuntionsdened

inIEC. Fivegroupsofthemfollowedbyexamplesarelistedbelow:

typeonversions: INT_TO_REAL,TIME_TO_DINT,TRUNC,

numerialfuntions: ADD,SUB,MUL,DIV,SQRT,ABS,LN,

Booleanand bitshiftfuntions: AND,OR,NOT,SHL,ROR,

seletionandomparisonfuntions: SEL,MAX,LIMIT,MUX,GE,EQ,LT,

funtionsoftimedatatypes: ADD,SUB,MUL,DIV(IECusesthesamenamesasfornumerialfuntions).

SeletorSEL,limiter LIMITand multiplexerMUXfrom seletionandomparision grouparepartiularly useful.

Variablesofanynumerialtype,i. e.INT,DINT,REALandLREALareargumentsinmostofrelevantfuntions.

Twolibrariesoffuntionblokareavailable,namely:

(5)

Basi_blokslibrarywithsimpleblokssupplementingthestandard.

Therstone involves: (1) ip-opsandsemaphoreRS,SR, SEMA,(2) risingandfalling edgedetetorsR_TRIG,

F_TRIG, (3) up, down, up-down ounters CTU, CTD, CTUD, (4) pulse, on-delay, o-delay timers TP, TON, TOF.

Blokstypialforsmallmultifuntionontrollersareintheseondlibrary,i.e. integrator,lters,max/minover

time,memories,timemeasurement,et.

4. STlanguageompiler. ThetaskoftheompileristoonvertXMLsourelewiththeprojetinST

languageintoalewithuniversalodeinbinaryformat. Generaldiagramoftheompileroperationinvolving

sanner,parserandodegeneratorisshownin Fig.4.1.

Fig.4.1. STompileromponents

4.1. Sanner, parser and ode generator. The sanner (lexial analyser) analysesharater stream

from STsourele anddeomposesit into lexialunits,i. e. tokens. Thetokensarelassiedinto ategories

suh as identiers, keywords,operators, onstants(a few ategories), delimiters, diretives, omments, white

spaesandinvalidharaters. Thetokenswithategoriesareolletedonalistpassedtotheparser.

The parser operates aording to top-down sheme with syntax direted translation [3℄. By employing

theST syntaxthe parser reognizesonseutivetoken onstrutionsfrom thesanner list. White spaesand

omments are dropped. When orretonstrution isreognized the parser replaesitby aset of mnemoni

instrutionsoftheVMASMassembler. Todoso,theparseremploysbuiltinelementarydatatypes(Table2.1)

andlistofVMASMinstrutions. ExamplesoftheseinstrutionsarepresentedinTable4.1.

Table4.1

ExamplesofVMASMassemblerinstrutions

Instrution Meaning Instrution Meaning

MCD Constantinitialization GE Greaterorequal

MEMCP Assignment SHL Bitshifttotheleft

ADD Addition JMP Unonditionaljump

SUB Subtration JZ Conditionaljump

AND Logiprodut MEMCP Memoryopy

NOT Negation RETURN Returnfromfuntion

NormallyasingleSTstatementistranslatedintoseveralVMASMinstrutions. Sometranslationsrequire

introdutionofauxiliaryvariablesandlabels. DeriveddatatypesandPOUsfromlibraries(funtions,funtion

bloksandprograms)arealsoparsed. Themnemoniodeiswritteninaspeialtextformat. Theodeanbe

onsolidatedwithothermnemoni odes.

In the third step the ode generator onverts the onsolidated mnemoni ode into universal exeutable

odein binaryformat. MnemonisoftheVMASMinstrutions,namesofthevariablesandlabelsarereplaed

by orresponding number identiers. To do so, the generator employs a Library Conguration File (LCF)

withtheidentiersof theinstrutions,numbersand typesoftheoperands,andinformationhowtheoperands

are aquired (operand identier may be an index to variable or a diret value). Eah implementation of

virtual mahine is dened by spei LCF onguration le. Besides binary le with the exeutable ode

theompilergeneratesatext lewithmnemoni ode,someadditionalinformation forCPSimsimulatorand

CPConongurer(variablenames,et.) andompilationreport(HTML).

4.2. Parser and ode generatorlasses. Essentialomponentsoftheompileraredesignedaslasses

in C#language[1,2℄. Eah tokenof STlanguageisenapsulated into anobjetoforresponding lass. The

lassesinheritfromanabstratSTIdentifiatorlass. Duringompilation,identiersareolletedintolists.

(6)

Identiers in alist are heked for uniqueness. When idential namesare found ompilation is stopped and

errorreported. Ifloalidentierhidesaglobalone,theompilerproduesawarning.

The parser generates text sequene of VMASM instrutions for the ode generator. Eah instrution is

represented by a mnemoni followed by operand names. Code generator replaes mnemonis and variable

nameswith appropriatenumberidentiers (indexes). Whileproessingan instrution,the generatorextrats

some information from libraries, e.g. operand size, type and passing method. The number identier an

be interpreted as a pointer to variable or as immediate value. Instrutions resulting from ompilation are

representedby instanes of VMInstrutionlass. Theoperand listVMOperand is also storedasa member of

thislass. Byusinglistsofoperandstypialproblemswithxed-sizeoperandtablesareavoided.

5. Multi-platformvirtual mahine. Binary lewiththeuniversalode andhardwarealloationmap

from the CPCon ongurer are downloaded into the ontroller, to be proessed by virtual mahine. Main

featuresoftheproessingareharaterizedbelow.

a)OperationofVM b)Memoryorganization

Fig.5.1. VirtualMahine

5.1. Operation yle. Virtualmahine isan automatonoperatingaordingto Fig.5.1a. Asindiated

before, the mahine is spei for a partiular proessorand works as an interpreter. The task onsists of

programsexeutedonseutively. Thebinaryodeinvolvesnumberidentiersoftheinstrutionsandaddresses

of operands. The mahine, similarly as a real proessor, maintains program ounter with the addressof

in-strution to be exeuted, and base addressof the data area with operands(speied for eah POU). Given

theinstrution address,the mahine fethes theidentier, deodesit, fethes theoperands,and exeutesthe

instrution. Stak emulationand update of the base addresses permit multiple, onurrentalls of funtions

and funtion bloks. The mahine monitorstime yle ofthe task andsets alarmag if timeoutappears. It

alsotriggersinput/outputproedures responsibleforexternalvariables.

Alloationofsoftwaretomemorysegmentsisshownin Fig.5.1b. Theinstrutionsandtheiroperandsare

in the ode segment (read only). Data segmentontainsglobal, loal and auxiliaryvariables, someof them

withonstantvalues. Thedata segmentanbeaesseddiretly orindiretlybyspeialvirtualregisters. The

mahine's internal memory keepsode of the interpreter, staks and registers. There is no wayof aessing

internalmemoryfromtheprogramlevel. Themahineisableto exeutemultiple instanesofprograms.

As shown in Fig.5.2, thevirtual mahine onsistsof afew universal andplatform-dependentmodules to

simplify implementation. The universalmodules remainunhanged(if one negletsompilation of thesoure

ode for agiven proessor). The platform-dependent modules interfae the mahine to partiular hardware,

exeutingVMrequeststolow-levelproedures. Forinstane,themodule Time&Clokisassoiatedwith

hard-ware,asitemploystimeinterruptstohandleTIMEdata. DATE_AND_TIMEdatarequirereal-timelok(RTC)on

board. I/Ofuntionsprovideinterfaetoanalogandbinaryinputsandoutputs,andtoommuniationeldbus

(7)

Fig.5.2. Universalandplatform-dependentVMsoftwaremodules

The universal part of the virtual mahine hasbeen written in ANSI C, so it an be diretly applied to

dierent proessors. As indiated in Se. 4.1, the number of data types and the way in whih the mahine

instrutions are exeuted are dened by the LCF onguration le. Forexample, one anlimit the number

ofelementarydatatypesor deneasubset ofVMASM instrutionto beused. Aset of generalspeiations

has been developed in CPDev for handling proessor omponents (interrupt system, RTC) and external

in-terfaes(I/O,ommuniations). Thespeiationsare in theform ofprototypesof orrespondingproedures

(names, types of inputs and returned outputs). The prototypes do not depend on proessor and hardware

solutions.

Thelewith theprototypesisompiled togetherwiththeuniversalmodules ofthevirtualmahine. The

ontents(bodies)ofthe speiationproeduresanbepreparedbyhardwaredesignersand, asabinaryle,

onsolidatedwiththeompileduniversalmodules. Thisgivestheompleteodeofthevirtualmahineforgiven

platform. Tillnow,themahinesforAVR,ARM,MCS-51andPCplatformshavebeendeveloped.

We stress that the ontentsof low-level proedures dependent on hardware solutionsmay bewritten by

designersthemselves. ThismakestheCPDevpakageopen inthehardwaresense.

6. User dened funtion bloks. The CPDev environment allowsthe user to dene funtion bloks

bothatPCsideandatontrollerside,i. e. asomponentsofvirtualmahine. ThePCsidebloksarewritten

in ST, whereas theVM side ones are in C. However,the C bloks are still invokedin themain ST program

ompiledanddownloadedfrom PC.So, asfaras invoationsareonerned, thereis nodierene betweenST

andCbloks.

6.1. ST bloks. User libraries are reated in CPDev as typial projets whih may inlude all kinds

of POU units of IEC standard, i. e. programs, funtions and funtion bloks. Delarations VAR_INPUTand

VAR_OUTPUTdetermineinput/outputstrutureoffuntionsandfuntion bloks. Thereisnodierenebetween

programming of a projet diretly for ontroller implementation and programming a library. However, the

libraryprojetissemi-ompiledto VMASMmnemonisand notto binaryform. Sothelast omponentof ST

ompiler,odegenerator(Fig. 4.1),is notneeded. Thele withmnemonis beomesuser-dened libraryand

isexportedtoLibrariesfolder.

Example of user funtion blok FB_PULSE is shown in Fig.6.1. The blok generatessingle pulse at the

outputQaftertimeT,sinerisingedgehasappearedattheinputIN.Theprogramoftheblokmayimplement

FBDdiagramofFig.6.1b,withstandardbloksR_TRIG,RSandTONfromCPDevIEC_61131library(Fig.2.1).

CorrespondingST odeis shownin Fig.6.1,with FB_PULSEbelonging totheprojetPROJ_MY_BLOCK(top of

Fig.6.1). XMLlewithPROJ_MY_BLOCKSsoureodeshouldbesavedforfutureextensionsandmodiations.

Semi-ompilationoftheprojetyields ale withVMASMmnemonis, alled,forinstane, My_Library. This

lemust beexported toLibraries. IfFB_PULSEis needed ina newprojet, bothMy_Libraryand IEC_61131

mustbeimported (thelattertosupporttheformer).

6.2. C-language bloks. Suh bloks are needed at hardware level to handle I/Oand ommuniation

hannels. Inputs andoutputsaredelaredin ST, buttheblokbodyisimplementedin C,atvirtualmahine

side(delarations are also repeated). Diretive (*$HARDWARE_BODY_CALL...*)informsCPDev ompilerthat

theblokisaomponentofVM.

Table6.1presentsinitialpartsoftheodeofGPS_GGAblokwhihprovidesserialommuniationwithaGPS

devieaordingtoNMEAprotool(GGAisaommandinNMEA).IdentierID:0003inthe(*$HARDWARE...)

(8)

a)Timediagram

) STode

b)FBDrealization

Fig.6.1. FuntionblokFB_PULSE

Table6.1

Delaration ofClanguageblokforGPSinterfaing

STdelaration CdelarationinVM

FUNCTION_BLOCK GPS_GGA typedef strut

(*$HARDWARE_BODY_CALL __delspe(align(4))

ID:0003; Align:4 *) tagIO_GPS_GGA

VAR_INPUT {

PORT : BYTE; END_VAR /*inputs*/ VM_BYTE Port;

VAR_OUTPUT /*outputs*/

UTC : TIME_OF_DAY; VM_TIME_OF_DAY Ut;

LAT : LREAL; VM_LREAL Lat;

LON : LREAL; VM_LREAL Lon;

ALT : LREAL; VM_LREAL Alt;

QUALITY : BYTE; END_VAR VM_BYTE Quality;

END_FUNCTION_BLOCK } IO_GPS_GGA, *PIO_GPS_GGA;

Strutureofthebody

swith(ID) {...

ase 0x0003: {

PIO_GPS_GGA arg = (PIO_GPS_GGA)GET_PARAM _POI NTER (); ...} ... }

The blok's PORT input speies ommuniation hannel. The outputs determine UTC time, LATitude,

LONgitudeand ALTitudeofatualposition,togetherwithQUALITYof GPSreading. Westressthat besidesthe

delarationsthereisnobodyinSTomponentoftheblok.

StruturetagIO_GPS_GGAdened atVMsiderepeatsSTdelarationswithalignment,speiestypename

and pointer type. Exeutions of C bloksare implementedby swith(ID)statementwith bodies entered at

suessiveases. SothebodyofGPS_GGAisenteredat ase 0x0003. FuntionGET_PARAM_POINTER()returns

(9)

pointer issavedin argvariable,suientforfurther proessing. OtherClanguagebloksare implementedin

thesameway. Givensuhtemplate,hardwaredesigners anprepareCbloksthemselves.

7. FBD and IL ompiler. The CPDev environment has been extended reently with simple graphi

editor of FBD diagrams and ompiler of IL textual language, mainly for teahing purposes. ST ompiler

remainsbasiplatformoftheenvironment.

7.1. Programmingin FBD. Thegraphieditor, alledBlokers(Fig.7.1),providesbasiediting

fun-tions,i.e. insertingbloksintodiagram,onnetinginputsandoutputsof thebloks,seleting andremoving

objets,zooming,et. ThebloksarehosenfromCPDevlibraries. Globalinput/outputvariablesandonstant

valuesarealso plaedin thediagram. Built-in syntax hekerveriesorretness. Resulting FBDdiagram is

savedin XML textle whosestruture followsreommendationsofPLCopen[13℄. TheXML leis then

on-verted into ST language by means of FBD2CPDev translator. Connetions between the bloks and instanes

of the bloks are representedby automatially reated loal variables of orrespondingtypes. Convention of

variablenamesisbasedontypesof bloksinthediagramandonexeutionorder.

Fig.7.1.FBDdiagramoftheSTART_STOPsystem

Figure7.1showsFBDdiagramoftheSTART_STOPsystemdrawnusingtheBlokerseditor. Numbersinthe

upperleft orners ofthe bloks indiate exeution order. Notiethat in aseof thefuntion bloks TON,TOF

thenumbersmaybeused to distinguishinstanes. Thevariablesplaedin narrowretangles onthe leftand

right areinterpreted asglobal. Equivalent ST ode generatedby FBD2CPDevtranslator is shown in Table 7.1

(ompareFig.3.2).

Table7.1

STprogramonvertedfromFBD

PROGRAM START_STOP

TON10 : TON;

VAR_EXTERNAL TOF11 : TOF;

START : BOOL; END_VAR

STOP : BOOL;

ALARM : BOOL; var_AND6_0 := AND(var_OR7_0,var_NOT9_0 ,va r_NO T8_ 0);

MOTOR : BOOL; var_OR7_0 := OR(var_AND6_0,START);

PUMP : BOOL; var_NOT8_0 := NOT(ALARM);

END_VAR var_NOT9_0 := NOT(STOP);

TON10(IN := var_AND6_0, PT := t#5s);

VAR TOF11(IN := TON10.Q, PT := t#5s);

var_OR7_0 : BOOL; MOTOR := var_AND6_0;

var_NOT9_0 : BOOL; PUMP := TOF11.Q;

var_NOT8_0 : BOOL;

(10)

Itisseenthat:

onnetionsbetweenthebloksare representedbyloal variablesvar_OR7_0to var_AND6_0;nameof

avariable indiatessoureblokofthat variable,

twoinstanesTON10,TOF11arereated,withnamesinvolvingthebloktypeandexeutionorder.

Outputsoftheinstanes,i.e.TON10.QandTOF11.Q,aredenotedin thestandardway(ompareFig.3.2).

7.2. Programming in IL. Sine delarationparts of programswrittenin ST andILare thesame,and

outomeof eahompilation is ale withVMASM ode,the ompilerof ILlanguagehasbeendevelopedby

extendingtheoriginalST ompiler. TheST ompilergeneratestheVMASModefrom expressiontreesbuilt

oftokensaquired from ST ode. Byanalysing asequeneofIL instrutionsoneanreate similartrees and

employtheminsuesivestagesofompilation,inthesamewayaswhileompilingST.Thisgivesmoreeient

VMASModethandiret translationofILinstrutionsintoVMASM,sineVMASM,unlikeIL,doesnotrely

onthenotionofaumulator. Aumulatorisnotneededinexpressiontrees,typialforhigh-levellanguages.

Table7.2

ILprogramforSTART_STOPprojet

PROGRAM PRG_START_STOP

LD START

VAR_EXTERNAL OR MOTOR

START : BOOL; ANDN STOP

STOP : BOOL; ANDN ALARM

ALARM : BOOL; ST MOTOR

MOTOR : BOOL;

PUMP : BOOL; CAL ON_DELAY(IN:=MOTOR, PT:=t#5s)

END_VAR CAL OFF_DELAY(IN:=ON_DELAY. Q, PT:=t#5s)

VAR LD OFF_DELAY.Q

ON_DELAY : TON; ST PUMP

OFF_DELAY: TOF;

END_VAR END_PROGRAM

ThePRG_START_STOPprogramof Fig 3.2is rewrittenin ILin Table7.2. TheinstrutionLD STARTloads

CRregister(CurrentResult;aumulatorinIEC)withthevalueofSTART.NexttheCRisORedwithMOTOR,with

theresultinCR.ThefollowingANDNnegates STOP,ANDsitwithCR,alwayswiththeresultinCR.Similarlyfor

anotherANDN.ST MOTORsavesCRin thevariable MOTOR.CALinstrutionsinvokefuntion bloks.

8. CPDev appliations. TheCPDevpakageisurrentlyappliedforprogrammingnewSMController

from LUMEL, Zielona Góra, Poland. SMC operates as a entral unit in small DCS systems involving

dis-tributedI/Omodules,intelligenttransmitters,PIDontrollers,et.[12℄. Developmentofanotherappliationin

forthomingversionofMINI-GUARDShipControl&PositioningSystemfromPraxisAutomationTehnology,

Leiden,TheNetherlands,isin progress[8℄. ForlabandteahingappliationsPC-basedsoftontrollersanbe

used.

8.1. SMC ontroller. The SMC shown in Fig. 8.1a is based on Atmel AVR 8-bit miroontroller.

Platform-dependent modules of virtual mahine, i. e. interrupts, RTC and ommuniation interfaes, have

beenwritten byLUMELengineers, and sent to theauthorsin binaryformat. Consolidationof universal and

LUMELmoduleshasresultedin aVM-SMCmahinewhih,asSMCrmware,exeutesSTprogramompiled

anddownloadedfromPC.Theontrollerisequippedwithtwoserialports,one(master)fordistributedI/Osand

elddevies,another(slave)forhostPCorHMIpanel. ModbusRTUprotoolisapplied(up to230.4kbaud).

ThirdComplex_blokslibrarytoimplementself-tuningPIDontrolloopsisprovided.

8.2. MINI-GUARD ontrollers. The MINI-GUARD system onsists of seven types of ontrollers

(Fig. 8.1b)involvingNXPARM7 16/32-bitmiroontrollers. The ontrollershaveappliation dediated

fae-plates. VirtualmahineforAtmelARM7hasbeensenttoPraxisA.T.,tobeadaptedfortheNXPARM7. The

softwaretohandleClanguagebloksdesribedinSe6.2hasbeendevelopedespeiallyforMINI-GUARD.The

ontrollersommuniate overEthernet,externaldeviesareonnetedviauniversalserial interfaeorOPC.

8.3. Softontrollers with NI and InTeCo boards. A PC equipped with I/O board and exeuting

(11)

a)SMController b)AlarmPanelofMINI-GUARD

)NI-DAQI/Oboard d)RT-DACI/Oboard

Fig.8.1.AppliationsofCPDevpakage

CPDev.CPCom.ICommDevhasbeendeveloped,withprovisionforothertypes. Softontrollerisonguredintwo

steps. First aboard isseletedfrom menuandI/Ohannelsdened. Thenglobal variablesoftheprojetare

linkedtothehannels. BinaryhannelsbeomeBOOLsandanalogoneREALs. Softontrollersanbeonneted

intoDCS systembymeansofModbusTCPprotool.

9. Conlusions and future work. CPDevenvironmentforprogrammingsmall ontrollersinST, FBD

and ILlanguagesof IEC 61131-3 standardhas been presented. The environmentis onsidered openbeause

ompiledodeanbeexeutedbydierentproessors,low-levelsoftwareomponentsareprovidedbyhardware

designers,andontrol programmersan reatetheirownlibrarieswithreusable programunits. Theompiler

produesuniversalexeutableodeproessedbyruntimevirtualmahineoperatingasinterpreter. Themahine

isanANSICprogramomposedofuniversalandplatform-dependentmodules. ThemahinesforAVR,ARM,

MCS51(ore)andx86proessorshavebeendevelopedsofar. Userfuntion bloksanbeprogrammedin ST

andC. TheSTbloksarekeptin CPDev libraries,whereasCbloksbeome omponentsof virtualmahine.

FBDdiagramistranslatedtoSTandthenompiled. CPDevhasbeenusedforprogrammingontrollersintwo

smallDCSsystemsandforPC-basedsoftontrollerwithI/Oboards.

(12)

simpleFBDeditor should beupgradedto moreprofessional level. Depending onST statementstheompiled

odeislongerorshorter,asintheexpressionx1 AND x2vs. funtionAND(x1, x2). Templatesindiatingmore

eient solutionsare important forthe users. Virtualmahine for FPGAplatform with simplemultitasking

mehanismisurrentlyunderdevelopment.

REFERENCES

[1℄ A.Appel,J.Palsberg,ModernompilerimplementationinJava,CambridgeUniversityPress,Seondedition,(2002).

[2℄ C#LanguageSpeifiation,http://msdn2.mirosoft.o m/en -us /vs harp /aa 3368 09. aspx , (2007).

[3℄ K.Cooper,L.Torzon,EngineeringaCompiler,MorganKaufmann,SanFraniso,(2003).

[4℄ IEC61131-3standard: ProgrammableControllersPart3,ProgrammingLanguages,IEC,(2003).

[5℄ ISaGRAFUser'sGuide,ICSTriplexIn.,(2005).

[6℄ K.H.John, M. Tiegelkamp,IEC61131-3: Programming IndustrialAutomationSystemsBerlinHeidelberg,

Springer-Verlag,(2001).

[7℄ T. Lindholm, F. Yellim, Java Virtual Mahine Speiation - Seond Edition, Java Software, Sun Mirosystems In,

(2004).

[8℄ Mini-GuardShipSystem,PraxisAutomationTehnologyB.V.,http://www.praxis-automati on. om,(2009).

[9℄ D.Rzo«a,J.Sadolewski,A.Ste,Z.‘wider,B.Trybus,L.Trybus,Mini-DCSSystemProgramminginIEC61131-3

StruturedText,Journal ofAutomation,MobileRobotis&IntelligentSystems,Vol.2,No3,(2008).

[10℄ D.Rzo«a,J.Sadolewski, A.Ste,Z.‘wider,B.Trybus,L.Trybus,ProgrammingontrollersinStruturedText

languageofIEC61131-3standard,JournalofAppliedComputerSiene,Vol.16,No1,(2008).

[11℄ E.Tisserant,L. Bessard,M. de Sousa,AnOpenSoureIEC61131-3 Integrated DevelopmentEnvironment,

5

th

Int.

Conf.IndustrialInformatis,Pisataway,NJ,USA,(2007).

[12℄ SMC,LumelS.A.,http://www.lumel.om.pl/ en,(2009).

[13℄ XMLFormatsforIEC61131-3ver.1.01OialRelease,http://www.plopen.org,(2007).

Editedby: JanuszZalewski

Reeived: September30,2009

References

Related documents

7 shows the estimated states of the approximative (cyan) and the exact (blue) multi- target likelihood calculation of a MTB filter with 10000 multi-target particles.. The EM-

stable income streams Market char & coke Geography Commodity Reduce geopolitical risk Mega-energy projects Diversified energy mix- renewable & nuclear Increased coal

(i) indicator 9: antipsychotics in dementia; (j) indicator 10: Parkinson ’ s disease; (k) indicator 11: NSAID in CKD 3 – 5; (l) indicator 12: drugs to avoid in CKD 4 and 5;

Figure 9 illustrates the cost of using the tolled and non-tolled facility from Georgetown to the Austin-Bergstrom Airport during three time periods (i.e., AM peak, PM peak,

What are the driving factors leading companies to request sales tax outsourcing services:. • Complexity of returns at the local level of tax (County

The Career + Professional Development Office is responsible for the review and approval of co-op opportunity postings, but Emily Carr and the Career + Professional Development

L'utilisation de ce travail bénévole (impression, photocopie, transmission) à but non commercial est. autorisé sous réserve de mentionner l'auteur et

Only a particle physicist would phrase all questions about the universe in terms of scattering amplitudes. In general relativity we typically think about the geometry as a whole,