Vous êtes sur la page 1sur 30

12/14/2015

PLCBasics

PLCBasics
TheMostUnconventionalGuidetoPLCsontheInternet
Sincethelate1960's,theProgrammableLogicController(orPLC)hasbecomeanessentialaspectof
anyautomatedmanufacturingprocess.InrecenttimestherehavebeencontenderstoreplacethePLC
butthepriniciplesandpopularityofthoseearlyPLC'sfunctionsandconceptshavecontinued
unabated.Itisessentialformanypeoplefromthetechniciantotheengineertounderstandthese
essentialpiecesofequipment.
PLCDevhasdevelopedthisinstructionmanual"PLCBasics"inhopesitwillservethebeginnertothe
advanceduser.Ourgoalistomakeitcomprehensiveaspossible,providingnotonlythegeneric
principlesinallPLCs,buttogivepracticalexamplesfrommanydifferentPLCmanufacturers.Tothis
endyouarewelcometocommentoneachsectionbyregisteringasauserandclickingthe"adda
comment"linkatthebottomofthepage.

"I'mwritingabook.I'vegotthepagenumbersdone."StevenWright
PLCBasicsisaworkinprogress.Ifyouwishtobenotifiedofupdatesthenpleaseregisterforan
accountandmakesuretheemailnotificationselectionischecked.

IntroductiontoProgrammableControllers
It'salwaysgoodtogetanoverviewofwheredesignshavebeenandweretheyaregoing.Todothis
it'sessentialtogetabird'seyeviewoftheconceptsandprocessesthatmakethePLCsovaluablein
industrialcontrol.PittingPLCsagainstothercontroltypeswillalsoservetoshowtheprosandcons
fordifferentapplications.

DefinitionofaPLC
WhatisaPLC?
AProgrammableLogicController,orPLCforshort,issimplyaspecialcomputerdeviceusedfor
industrialcontrolsystems.Theyareusedinmanyindustriessuchasoilrefineries,manufacturinglines,
conveyorsystemsandsoon.WhereeverthereisaneedtocontroldevicesthePLCprovidesaflexible
wayto"softwire"thecomponentstogether.
ThebasicunitshaveaCPU(acomputerprocessor)thatisdedicatedtorunoneprogramthatmonitors
aseriesofdifferentinputsandlogicallymanipulatestheoutputsforthedesiredcontrol.Theyare
meanttobeveryflexibleinhowtheycanbeprogrammedwhilealsoprovidingtheadvantagesofhigh
reliability(noprogramcrashesormechanicalfailures),compactandeconomicalovertraditional
controlsystems.
http://www.plcdev.com/book/export/html/9

1/30

12/14/2015

PLCBasics

ASimpleExample
Considersomethingassimpleasaswitchthatturnsonalight.Inthissystemwithaflickoftheswitch
thelightwouldturnonoroff.Beyondthatthoughthereisnomorecontrol.Ifyourbosscamealong
andsaidIwantthatlighttoturnonthirtysecondsaftertheswitchhasbeenflipped,thenyouwould
needtobuyatimeranddosomerewiring.Soitistime,laborandmoneyforanylittlechange.

APLCSavestheDay
NowconsiderthesamedevicewithaPLCinthemiddle.TheswitchisfedasaninputintothePLC
andthelightiscontrolledbyaPLCoutput.Implementingadelayinthissystemiseasysinceallthat
needstobechangedistheprograminthePLCtouseadelaytimer.

Thisisarathersimpleexamplebutinalargersystemwithmanyswitchsandlights(andahostof
otherdevices)allinteractingwitheachotherthiskindofflexibilityisnotonlynicebutimperitive.
Hopefullyalightbulbhasnowturnedonoveryourhead.

HowPLCsWork
Aprogrammablelogiccontrollerisaspecializedcomputerusedtocontrolmachinesandprocesses.It
thereforesharescommontermswithtypicalPCslikecentralprocessingunit,memory,softwareand
communications.UnlikeapersonalcomputerthoughthePLCisdesignedtosurviveinarugged
industrialatmosphereandtobeveryflexibleinhowitinterfaceswithinputsandoutputstothereal
world.
http://www.plcdev.com/book/export/html/9

2/30

12/14/2015

PLCBasics

ThecomponentsthatmakeaPLCworkcanbedividedintothreecoreareas.
Thepowersupplyandrack
Thecentralprocessingunit(CPU)
Theinput/output(I/O)section
PLCscomeinmanyshapesandsizes.Theycanbesosmallastofitinyourshirtpocketwhilemore
involvedcontrolssystemsrequirelargePLCracks.SmallerPLCs(a.k.a.bricks)aretypically
designedwithfixedI/Opoints.Forourconsideration,welllookatthemoremodularrackbased
systems.ItscalledmodularbecausetherackcanacceptmanydifferenttypesofI/Omodulesthat
simplyslideintotherackandplugin.

ThePowerSupplyandRack
SoletsstartoffbyremovingallourmoduleswhichleavesuswithanakedPLCwithonlythepower
http://www.plcdev.com/book/export/html/9

3/30

12/14/2015

PLCBasics

supplyandtherack.

Therackisthecomponentthatholdseverythingtogether.Dependingontheneedsofthecontrol
systemitcanbeorderedindifferentsizestoholdmoremodules.Likeahumanspinetherackhasa
backplaneattherearwhichallowsthecardstocommunicatewiththeCPU.Thepowersupplyplugs
intotherackaswellandsuppliesaregulatedDCpowertoothermodulesthatplugintotherack.The
mostpopularpowersuppliesworkwith120VACor24VDCsources.

TheCPU
ThebrainofthewholePLCistheCPUmodule.Thismoduletypicallylivesintheslotbesidethe
powersupply.ManufacturersofferdifferenttypesofCPUsbasedonthecomplexityneededforthe
system.
TheCPUconsistsofamicroprocessor,memorychipandotherintegratedcircuitstocontrollogic,
monitoringandcommunications.TheCPUhasdifferentoperatingmodes.Inprogrammingmodeit
acceptsthedownloadedlogicfromaPC.TheCPUisthenplacedinrunmodesothatitcanexecute
http://www.plcdev.com/book/export/html/9

4/30

12/14/2015

PLCBasics

theprogramandoperatetheprocess.

SinceaPLCisadedicatedcontrolleritwillonlyprocessthisoneprogramoverandoveragain.One
cyclethroughtheprogramiscalledascantimeandinvolvesreadingtheinputsfromtheother
modules,executingthelogicbasedontheseinputsandthenupdatedtheoutputsaccordingly.The
scantimehappensveryquickly(intherangeof1/1000thofasecond).ThememoryintheCPUstores
theprogramwhilealsoholdingthestatusoftheI/Oandprovidingameanstostorevalues.

http://www.plcdev.com/book/export/html/9

5/30

12/14/2015

PLCBasics

I/OSystem
TheI/OsystemprovidesthephysicalconnectionbetweentheequipmentandthePLC.Openingthe
doorsonanI/Ocardrevealsaterminalstripwherethedevicesconnect.

http://www.plcdev.com/book/export/html/9

6/30

12/14/2015

PLCBasics

TherearemanydifferentkindsofI/Ocardswhichservetoconditionthetypeofinputoroutputsothe
CPUcanuseitforitslogic.It'ssimplyamatterofdeterminingwhatinputsandoutputsareneeded,
fillingtherackwiththeappropriatecardsandthenaddressingthemcorrectlyintheCPUsprogram.

Inputs
Inputdevicescanconsistofdigitaloranalogdevices.Adigitalinputcardhandlesdiscretedevices
whichgiveasignalthatiseitheronoroffsuchasapushbutton,limitswitch,sensorsorselector
switches.Ananaloginputcardconvertsavoltageorcurrent(e.g.asignalthatcanbeanywherefrom
0to20mA)intoadigitallyequivalentnumberthatcanbeunderstoodbytheCPU.Examplesofanalog
devicesarepressuretransducers,flowmetersandthermocouplesfortemperaturereadings
Outputs
http://www.plcdev.com/book/export/html/9

7/30

12/14/2015

PLCBasics

Outputdevicescanalsoconsistofdigitaloranalogtypes.Adigitaloutputcardeitherturnsadevice
onoroffsuchaslights,LEDs,smallmotors,andrelays.Ananalogoutputcardwillconvertadigital
numbersentbytheCPUtoitsrealworldvoltageorcurrent.Typicaloutputssignalscanrangefrom
010VDCor420mAandareusedtodrivemassflowcontrollers,pressureregulatorsandposition
controls.

ProgrammingaPLC
InthesemoderntimesaPCwithspeciallydedicatedsoftwarefromthePLCmanufacturerisusedto
programaPLC.Themostwidelyusedformofprogrammingiscalledladderlogic.Ladderlogicuses
symbols,insteadofwords,toemulatetherealworldrelaylogiccontrol,whichisarelicfromthe
PLC'shistory.Thesesymbolsareinterconnectedbylinestoindicatetheflowofcurrentthroughrelay
likecontactsandcoils.Overtheyearsthenumberofsymbolshasincreasedtoprovideahighlevelof
functionality.
Thecompletedprogramlookslikealadderbutinactualityitrepresentsanelectricalcircuit.Theleft
andrightrailsindicatethepositiveandgroundofapowersupply.Therungsrepresentthewiring
betweenthedifferentcomponentswhichinthecaseofaPLCareallinthevirtualworldoftheCPU.
Soifyoucanunderstandhowbasicelectricalcircuitsworkthenyoucanunderstandladderlogic.
Inthissimplestofexamplesadigitalinput(likeabuttonconnectedtothefirstpositiononthecard)
whenitispressedturnsonanoutputwhichenergizesanindicatorlight.

ThecompletedprogramisdownloadedfromthePCtothePLCusingaspecialcablethatsconnected
tothefrontoftheCPU.TheCPUisthenputintorunmodesothatitcanstartscanningthelogicand
controllingtheoutputs.

TheBirthofthePLC
TheOriginalChallenge
TheearlyhistoryofthePLCisfascinating.Imagineifyouwillafiftyfootlongcabinetfilledwith
relayswhosefunctioninlifeistocontrolamachine.Wiresruninandoutofthesystemastherelays
clickandclacktothelogic.Nowimaginethereisaproblemorasmalldesignchangeandyouhaveto
figureitalloutonpaperandthenshutdownthemachine,movesomewires,addsomerelays,debug
http://www.plcdev.com/book/export/html/9

8/30

12/14/2015

PLCBasics

anddoitalloveragain.Imaginethelaborinvolvedinthesimplestofchanges.Thisistheproblem
thatfacedtheengineersattheHydramaticdivisionofGMmotorsinthelate1960's.
Fortunatelyforthemtheprospectofcomputercontrolwasrapidlybecomingarealityforlarge
corporationsasthemselves.Soin1968theGMengineersdevelopedadesigncriteriafora"standard
machinecontroller".Thisearlymodelsimplyhadtoreplacerelaysbutitalsohadtobe:
Asolidstatesystemthatwasflexiblelikeacomputerbutpricedcompetitivelywithalikekind
relaylogicsystem.
Easilymaintainedandprogrammedinlinewiththeallreadyacceptedrelayladderlogicwayof
doingthings.
Ithadtoworkinanindustrialenvironmentwithallit'sdirt,moisture,electromagnetismand
vibration.
Ithadtobemodularinformtoallowforeasyexchangeofcomponentsandexpandability.

TheRaceisOn
Thiswasatallorderin1968butfourcompaniestookonthechallenge.
1. InformationInstruments,Inc.(fullyownedbyAllenBradleyayearlater).
2. DigitalEquipmentCorp.(DEC)
3. CenturyDetroit
4. BedfordAssociates
BedfordAssociates,runbyRichardMorley,wonthecontractandquicklyformedanewcompany
aroundthetechnologycalledMODICONafterModularDigitalControl.ByJuneof1969theywere
sellingthefirstviableProgrammableControllerthe"084"(their84thproject)whichsoldoverone
thousandunits.Theseearlyexperiencesgavebirthtotheirnextmodelthe"184"in1973whichset
Modiconastheearlyleaderinprogrammablecontrollers.
Nottobeoutdone,thepowerhouseAllenBradley(allreadyknownforit'srheostats,relaysandmotor
controls)purchasedInformationInstrumentsin1969andbegandevelopmentonthisnewtechnology.
Theearlymodels(PDQIIandPMC)weredeemedtobetoolargeandcomplex.By1971OdoStruger
andErnstDummermuthhadbeguntodevelopanewconceptknownastheBulletin1774PLCwhich
wouldmakethemsuccessfulforyearstocome.AllenBradleytermedtheirnewdevicethe
"ProgrammableLogicController"(patent#3,942,158)overthethenacceptedterm"Programmable
Controller".ThePLCterminologybecametheindustrystandardespeciallywhenPCbecame
associatedwithpersonalcomputers.

Numbers,CodesandaLittleLogic
Attheheartofanycomputersystemarethenumberingsystemsanddigitalcodesusedforinstructions
andmemorystorage.Besidestheonesandzerositisimportanttounderstandhowthesebitsare
packagedintocodeslikeBCDandGraycodes.Understandingtheseconceptsenablestheprogrammer
tomanipulatethePLCatit'smostbasiclevel.Don'tyouwanttofeelthepoweratyourfingertips!?
Nowforthemostpartthesetypesofconceptswillbetransparentwhenprogrammingbuttherewillbe
occasionswhenyou'llbegladyoureadthis.

http://www.plcdev.com/book/export/html/9

9/30

12/14/2015

PLCBasics

Whenthecavemenfirststartedcountingtheysataroundlookingattheirfingersand
stoppedatten.Ittookmanalittlelongertofigureouttheconceptofzerobut
nobodyisperfect.Sowe'veendedupwithacommonwayofcountingby10's
whichintechjargonisreferedtoasbase10orradix10.Baseorradixreferstothe
numberofsymbolsyouhaveavailabletocount.We'llseethatcomputersmakeit
moredifficultforuslazyhumansbecausetheyliketocountbybase2(binary).In
acompromisewithcomputersushumanshavedevelopedthebase8(octal)orbase
16(hexadecimal)systems.

BinaryPeople:Learningyour1'sand0's
Introduction
"Thereare10typesofpeopleintheworld:Thosewhounderstandbinary,andthosewhodon't."
Ifyoudon'tgetthisjokethenhopefullybytheendofthechapteryou'llgetachuckleoutofit.You
see,inthebinarynumbersystem10=2.How?Considerifyouhadnochoicebuttocountwithonlya
zerooraone.Pretendthattheevilgoblinofnumbersnatchershadtakeneverynumberfromtwoto
nine.Howwouldyoucountanything?You'dhavetodoitlike0,1,10,11,100,101,110,111andso
on.Yougetthepoint?Therefore,ifyouhadthreeapplesthenthethirdapplewouldbedesignatedas
10wheninrealityyouonlyhavethreeapplestoeat.
WhenitcomestocomputersandthereforePLCstheycanonlystoreinmemorya0ora1.That'sthe
beautyofourdigitalage,it'seither"on"orit's"off".Thosememorychipsincomputersareactually
madeofrowsuponrowsofcircuitsthatareeitheronatsomevoltageoroffatsomevoltage.
Thereforeacomputeratit'sverybasiclevelcanonlycountusinga0(off)ora1(on).
That'swhyit'scalledbinarybecausethereareonlytwonumberslikethereareonlytwowheelsona
bicycle.Thenumbersystemweareusedtousingiscalleddecimal(dec=10)andthereforewegetto
usetennumbersfrom0to9.Whenyouthinkaboutit,it'strulyarbitraryhowwecount.Youcould
alsouseanoctalsystem(by8)orhexidecimal(by16)numberingsystemwhichwe'lltalkaboutalittle
later.

Base10:AnOldFamiliarFriend
Let'sstartoffbylookingcloseratouralltoofamiliarbase10decimalsystemandthencompareitto
binary.Decimal,likealltheseothernumbersystems,isbasedonplacevaluesystem.Thismeansthat
thevalueofadigitdependsbothonthedigititselfandit'spositionwithinthenumber.Thefollowing
figureshowstheweightsofadecimalnumberbrokendownintocolumns.

http://www.plcdev.com/book/export/html/9

10/30

12/14/2015

PLCBasics

Thatmuchisobviousright?Sowithanumberlike9876weaddituplikethis:

Thevalueofthenumberiscomputedbymultiplyingeachdigitbytheweightofitspositionand
addinguptheresults.

NowforBinaryPeople:Learningyour1sand0s.">Binary
Rememberthatforabase10systemtheweightsare1,10,100,1000andsoon.Forabinarysystem
theweightsare1,2,4,8,16,32,64,etc.

Tofigureoutthevalueofabinarysystemwedothesameaswiththedecimalbutwithdifferent
weights.

http://www.plcdev.com/book/export/html/9

11/30

12/14/2015

PLCBasics

Thebaseofthenumberisusuallyexpressedinasubscriptsothatinourexamples111112=3110and
101012=2110.Itsureisalittlecumbersometocountinbinarybutatleastit'seasierthenRoman
numerals Laughing .

Word,ByteandBit
Whatdoyoucallagroupofbinarydigits?Thegeekswhofirstthoughtthisstuffupdecidedtocalla
binarydigitabit(binarydigit).ThisisnottobeconfusedwithTimbits.Aftersometimethey
decidedthatitwouldbegoodtocallagroupof8bitsabyte.Funnybunchofgeeksthattheywerethe
termnibblebecameusedfor4bitsbeingasubsetofbyte.Finally,agroupof16bitsarereferredtoas
aword.Here'sapicturetodrivehomethepoint.

CheatingwithaCalculator
Unlessyou'reagluttonforpunishmentastandardscientificcalculatorswitchesbetweenthedifferent
numberformatswithease.Infactthere'sonebuiltintotheWindowsoperatingsystemthattypically
livesundertheStartbutton|AllPrograms|Accessories.PulldowntheViewmenuandselect
"Scientific".I'vehighlightedtheareabelowwhereyoucanswitchbetweenhexadecimal,decimal,
octalandbinary.Veryhandyevenfordoingmathandlogicalfunctions(i.e.AND,OR,etc.).

http://www.plcdev.com/book/export/html/9

12/30

12/14/2015

PLCBasics

Octal?WhattheHex?
"Donotworryaboutyourproblemswithmathematics,Iassureyouminearefargreater."Albert
Einstein
You'rethrobbingheadisprobablyallreadytellingyouthatbinarynumbersarenoteasytoread.Asa
compromisebetweenhumansandcomputerstheoctal(base8)andhexadecimal(base16)areused.

Octal
Whileoctalisnotascommonasit'scousinhexadecimalitisstillusedinvariousPLCssoit's
importanttograsptheconcept.Forinstance,whenprogramminganAutomationDirectPLCthe
memoryaddressesareinoctal.Octal,likeanoctopus'eightlegs,meanseightandthereforethereare
eightnumberstousefromzerotoseven.Thecolumnweightsare1,8,64,512,etc.Theweightsare
derivedbytakingthebasenumbertothepowerofthecolumn,80=1,81=8,82=64,83=512,etc.Now
wecandothesameexerciseasinthelastchaptertoconvertanoctalnumbertodecimal.

http://www.plcdev.com/book/export/html/9

13/30

12/14/2015

PLCBasics

Iknowthisisn'thelpfulsofar.Whereitreallycomesinhandyiscovertingfrombinarytooctal
becauseallyouhavetodoisbreakdownthebinarynumberintochunksofthree.Thisisbecause8is
23.

Mostprogrammablecontrollershaveinputsandoutputcardsgroupedin8or16(andhighdensityof
32and64).Thereasonforthisisthewaycomputersliketohavethingsinpowersof2,4,8,16andso
on.Soifitisnotinoctalitistypicallyinhexadecimal.

Hexadecimal
Hexadecimalisalittlemoretrickybecauseitisbase16andthereforeweneedsomethingbeyond0
through9forsymbolsandthisisdonebyusingtheletters'A'through'F'.Hexadecimalisusedforthe
samereasonsasoctalsothatwecanrepresentbinaryinacondensedformandmakeiteasierfor
conversion.Whereoctalused3bitsthehexadecimalsystemused4bitstorepresentonenumber.

Ifyou'regoingtobeprogrammingsomethinglikeaMitsubishiPLCthenyoubettergetusedto
hexadecimal.
http://www.plcdev.com/book/export/html/9

14/30

12/14/2015

PLCBasics

Conclusion
Towrapthingsuphere'satablebelowshowingtheequivalentsforeachnumberingsystem.

Binary
People:
Decimal
Learning
your1sand
0s.">Binary

Octal

Hex

00000

00001

00010

00011

00100

00101

00110

00111

01000

10

01001

11

10

01010

12

11

01011

13

12

01100

14

13

01101

15

14

01110

16

15

01111

17

16

10000

20

10

17

10001

21

11

18

10010

22

12

19

10011

23

13

andsoonandsoon...
http://www.plcdev.com/book/export/html/9

15/30

12/14/2015

PLCBasics

WhenBeingNegativeisaComplement
Let'sdelvedeeperintoPLCprogrammingbyconsideringagainourcommonwordmadeof16bits.If
itwasallfilledupwithone'sthenthedecimalvaluewouldbe65535.Soarangefrom0to65535
couldberepresented.Addingbinarynumberstogetherwouldbeverysimilartoadditionindecimal.
Forexample0+1=1and1+1=10(carrytheone).
Theproblemcomeswhenyouneedtosubtract.Howdoyourepresentanegativenumberwhenyou
can'tjustputaminussigninfrontofitandsayit'sgood?Rememberthatthecomputercanonlydoa
0ora1.Toourrescuecomesaconceptcalledtakingthecomplement.Complement'sareapretty
cooltrickandyoucanlearnmoreaboutthematWikipedia.We'llkeepitsimplehereandtalkabout
two'scomplementwhichisthemostcommonincomputersandPLCs.
Signedbinarynumbersareachievedbystealingthe16thbitinaword(themostsignificantbit)and
usingthatasasignbitwhere0ispositiveand1isnegative.

Bydoingthiswehaveshiftedtherangeofvaluesfrom0to65535to32767to+32767.Sothehigh
endofourvalueisdecreasedbutwe'vemadeitawholeloteasiertoindicateanegativenumberanddo
subtraction.Here'showitworks.Let'stakeanumberlike30andperformthetwo'scomplementto
get30.
Thenumber30is

0000000000011110

Thefirststepistoinvert(orflip)thebits 1111111111100001
Thesecondstepistoaddone

1111111111100010

InthePLCthenthevalueof30willberespresentedas1111111111100010.Maybenotwhatyou
wouldexpect?Thebeautyofthisisthatnowalltheprocessorhastoworryaboutisaddingthetwo
numberstogetthecorrectvalue.Seehowthismagicallyworksinthetablebelow(I'mjustgoingto
use8bitsnowtosimplifythingsbutitworksjustthesamewithhowevermanybitsyouwant).
http://www.plcdev.com/book/export/html/9

16/30

12/14/2015

PLCBasics

Decimal

SignedBinary
People:
Learningyour
1sand
0s.">Binary

57

00111001

+30

+00011110

=87

01010111

57

00111001

+(30)

+11100010

=27

00011011

57

11000111

+30

+00011110

=27

11100101

57

11000111

+(30)

+11100010

=87

10101001

Forthemostpartthiswillallworkseamlesslyinthebackgroundwhileyouprogramaway.It'sjust
thateveryonceinawhileyou'llneedthisknowledgetoovercomeanylimitationsinthesystem.
Dealingwithnegativenumberscanbeprettytrickybutwithcomplementslikethisyoubetternotletit
gotoyourhead.

GettingthePointaboutFloatingPointNumbers
TheFreedomofFloatingPoint
http://www.plcdev.com/book/export/html/9

17/30

12/14/2015

PLCBasics

Floatingpointnumbers(alsoknownas'realnumbers')giveacertainfreedominbeingabletorepresent
bothverylargeandverysmallnumbersintheconfinesofa32bitword(that'sadoublewordinour
PLCs).Upuntilthispointtherangeofnumberswewereabletorepresentwithadoublewordwould
befrom0to4,294,967,295.Floatingpointontheotherhandallowsarepresentationof
0.0000000000000001aswellas+/1,000,000,000,000.Itallowsforsuchlargenumbersthatwecan
evenkeeptrackoftheUSnationaldebt.
Floatingpointgivesusaneasywaytodealwithfractions.Before,awordcouldonlyrepresentan
integer,thatis,awholenumber.We'dhavetousesometrickstomaybeimplyadecimalpoint.For
instance,anumberlike2300inawordcouldbetakentorepresent23.00ifthedecimalpointis
"implied"tobeinthe1/100thplace.Thismightbeallweneedbutitcangetabittrickywhenit
comestomathwherewewanttoretainaremainder.Thetrickistogetsomesortofformatwherethe
decimalpointcan"float"aroundthenumber.

RealNumbersintheRealWorld
Atthispointlet'sdealwithanexample.Inthiscasewe'reusinganAutomationDirectDL250PLC
whichconvenientlyhastheabilitytohandlerealnumbers(floatingpoint).OurPLCisreadinga
pressuretransducerinputwhosemaxreadingis250psi.InourPLCthemaxnumberisrepresentedby
4095(FFFinhex).Soessentiallytogetourrealworldreadingwewouldneedtodivide4095by
16.38(4095reading/250maxpressure).Thisiseasilydonewithrealnumbersbutourreadingisin
decimal.SotheBTORinstructionisusedtoconvertthedecimalnumbertoarealnumberformat.
ThenweusethespecialDIVRinstructiontodivideitwitharealnumberandgetourreading.The
resultingladderlogicwouldlooklikebelow.

Ifyou'reacompletenewbieatthisanddon'tunderstandtheladderlogicthendon'tworryaboutthat.
We'llgetintoladderlatter.Justunderstandthatwhenyouneedtodealinfractionsyou'llmostlikely
wanttoturntorealnumberformatsinthePLCinstructionset.
Ifyou'restillstayingafloatinalltheseconceptsandwanttounderstandmorethenreadon...

SinkingDeeperintoFloatingPointNumbers
http://www.plcdev.com/book/export/html/9

18/30

12/14/2015

PLCBasics

Floatingpointisbasicallyarepresentationofscientificnotation.Ohyeah?What'sscientific
notation?Scientificnotationrepresentsnumbersasabasenumberandanexponent.Forexample,
123.456wouldbe1.23456x102.That10withalittle2aboveistellingustomovethedecimaltwo
spacestotherighttogettherealnumber.Anotherexample,0.0123wouldbe1.23x102.Thatlittle
2indicateswemovethedecimalpointintheoppositedirectiontotheleft.(Justaheadsup,inthe
PLCyoumaybeabletousescientificnotationbutinadifferentformlike1.23456E2whichisthe
sameasafirstexample.)Thenumber10heremeanswe'redealingindecimal.Wecouldjustaseasily
doscientificnotationinhexadecimal(123.ABCx162)orevenbinary(1.0101x22,thisbinaryone
becomesimportantlateron).

TheFormat
Atsomepointinhistoryabunchofgeeksgottogetherandagreeduponacertainformatorlayoutfora
32bitfloatingpointnumber.Duetoalackoforiginality,itofficiallybecamecalled"IEEEStandard
754".Hereitisinallit'sglory.

Firstthereisthesignbit.Itdoesn'tgetanyeasierthenthis.Ifthebitis0thenthenumberispositive
butifitisa1thenitisnegative.Flipthebitandyouchangethesignofthenumber.Whatpower.
Theexponentisthesameasourlittlenumberabovethe10inscientificnotation.Ittellsuswhichway
thedecimalshouldgosoitneedstobepositive(gototheright)ornegative(gototheleft).Herewe
areagaintryingtodealwithnegativenumbersbutinthiscasethegeeksdecidedtousewhat'scalleda
biasoroffsetof127.Basicallythismeansthatatavalueof127theexponentis0.Anynumberbelow
127willcauseanegativeexponent.Anynumberabove127willbeapositiveexponent.Soastored
valueof200indicatesanexponentof73(200127).
Themantissa(orsignificand,ifthatisanyeasiertosay)representtheprecisionbitsofthenumber.In
ourexampleaboveitwasthe1.23456partofthescientificnotation.
Thefinalnomenclatureinscientificnotationwouldbe:(sign)mantissaxbaseexponent
Normallythebasewouldbe10butinthiscaseitwillbe2sinceweareonlydealinginbinary.Since
it'sinbase2(orbinary)there'salittleoptimizationtrickthatcanbedonetosaveonebit.Wastenot,
wantnot,youknow.Thetrickcomesaboutbyrealizingthatscientificnotationallowsustowrite
numbersinmanydifferentway.Considerhowthenumberfivecanbe
5.00x100
http://www.plcdev.com/book/export/html/9

19/30

12/14/2015

PLCBasics

0.05x102
5000x103
Theseareallthesamenumber.Floatingpointnumbersaretypicallyinanormalizedformwithone
digittotheleftofthedecimal(i.e.5.00x100or4.0x103).Theexponentisalwaysadjustedtomake
thishappen.Intermsofusingbinarywe'llalwayshavea1infront(i.e.1.0x23).Youwouldn'thave
0.1x24asitwouldn'tbenormalized.Sointhiscaseit'salwayssafetoassumethattheleadingdigitis
a1andthereforewedon'thavetostoreit.Thatmakesthemantissaactually24bitslongwhenallwe
haveare23bitsofstorage.Ah,whatwedotosaveonebit.

WARNING:It'sNotaPerfectWorld
Withallthispowerusingfloatingpointyouareprobablythinking,"I'lljustuseitallthetime".There's
aproblemthoughasthismethodcanactuallylosesomeprecision.Inmanycasesitwillbenegligible
andthereforewellworthittouserealnumbers.Inothercasesthoughitcouldcausesignificanterrors.
Sobeware.
Considerwhatwouldhappenifthemantissapartofthefloatingpointformatwasactuallylongerthen
24bits?Somethinghastogiveandwhathappensistheendistruncated,thatis,itiscutofftheend
andlost.
Here'sanexampleofa32bitnumber
11110000110011001010101000001111whichwouldbe4039944719indecimal
Infloatingpointwithonly24bitsitwouldhavetobe
1.11100001100110010101010x231whichwhencovertedbackwouldbe
11110000110011001010101000000000andtherefore4039944704indecimal.
That'sadifferenceof15.Duringnormalmaththismightnotbeofconcernbutifyouare
accumulatingandtotalizingvaluesthenthatkindoferrorcouldreallymakethebeancountersmad.
Thisissimplyacaseofknowingyourlimitations.

GluttonforPunishment:FurtherReading
There'smoreonthissubjectconcerningthingslikedoubleprecision,overflow,zeroand'notanumber'
whichyoucanreadaboutintheseexcellentarticles.
WhatEveryComputerScientistShouldKnowAboutFloatingPointArithmetic
IEEEStandard754FloatingPointNumbers
IntroductiontoFloatingpointcalculationsandIEEE754standard

ASCII...andyeshallreceive
http://www.plcdev.com/book/export/html/9

20/30

12/14/2015

PLCBasics

ASCIIChart">ASCIIisanacronymforAmericanStandardCodeforInformationInterchange.You
canseenowwhytheyshorteneditdowntoASCIIwhichispronouncedas'askey'byusgeeks.Thisis
themostcommoncodefortheexchangeoflettersandcontrolcharactersbetweencomputersandtheir
peripheraldeviceslikeprinters.Itisastandardthatprovidesaneasywayforthelettersonour
monitorstogetintoabinaryformatthatacomputercanunderstand.Thusitalsofindsitswayintoour
everydayPLClivesinformofserialtransmissiontoadisplayorprinter.
AlltheassignedASCIIcodescanberepresentedwith7bits.Rememberfromourbinarychapterthat
7bitsofbinaryrepresent128indecimal.TypicalPLCsthoughhave8bitsofdataandthereforethe
leftoverbitisusedforparitycheckingjusttomakesureeverythingistransmittingcorrectly.The
followingchartshowsalltheassignedletters,numbersandcontrolcharacterswiththecomputer
numberontheleftandthesymbolontheright.Someoftheselookweirdbecausethisstuffgoesway
backtothedayswhenyouhadtocontrolteletypesandphonelines.ThesedaysI'mtypicallyonly
concernedwith10(linefeed),13(carriagereturn)and32through126.

ASCIIChartinWordformatavailablefordownload

InternationalCodes
InalotofwaysASCIIisveryrestrictivebecausetheAstandsforAmericanandsoitbasicallyserves
onlyEnglish.Untilrecentlythecomputerworldhasbeentryingtocatchuptothemanydifferent
languagesintheworldandtheneedforcomputerstobeabletousethemall.Thustherearemany
differentcharactersetsforotherlanguages.TheAlphabetSoupisagreatresourcetolocatea
languageandit'scorrespondingcharacterset.Therealadvancethoughhascomewiththeadventof
Unicodewhichisonestandardrepresentingallthelanguagesoftheworld.Unicodehasandwill
continuetosupersedealltheseothertypesofalphanumericcodesbecauseitsimplifiestheuseof
multiplelanguages.ThelistofpossibilitiesisendlesssoifyoueverneedtoprograminUgariticthen
yougotit.

TheABCsofBCD
http://www.plcdev.com/book/export/html/9

21/30

12/14/2015

PLCBasics

BinaryCodedDecimal(BCD)isanumbercodethatmakesallthose1sand0sinthecomputereasier
forhumanstoread.InBCDthedigits0through9arestoredas4bits(a.k.a.anibble).Thusina16bit
wordyoucanhavefourdigits(16bitword/4BCDbits=4digits).Thefigurebelow
demonstrateshowtoconvertabinarynumbertoit'sBCDequivalent.

Theastutestudentwillseethatthisisalotlikeconvertingfrombinarytohexadecimal.Inthis
casethoughtherearenoletterslikeAthroughFwhichispartofmakingiteasiertoread.Ina
purebinarysensethe16bitwordcanhaveavalueof0to65535butBCDlimitsusfrom0to9999.

WhatisBCDgoodfor?
MostmoderncontrolsystemcomponentslikePLCsandHMIs(forexampleAutomationDirect)make
theuseofBCDseamless.Thatis,youusethemlikeyouwoulddecimalnumberswithout
knowingthedifference.Therecomesatimethoughwhenyou'llneedtoknowthedifference(for
instancewhensettingupanI/Ocard).
TherealuseofBCDcomesinoldertypesofcontrolslikethumbwheelswitches,7segmentdata
displaysandabsoluteencoders.Forexample,thethumbwheelswitchwillhave(atleast)four
outputsforonedigitwhichrepresentthebinarynumbersofthatdigit.Gangingthethumbwheel
switchestogetherthenmakesawordinBCDformat.

TheBlackandWhiteofGrayCode
Graycode(namedafterit'sinventorFrankGray)isasequenceofbinarynumberswhereonlyonebit
http://www.plcdev.com/book/export/html/9

22/30

12/14/2015

PLCBasics

changesatatime.Marchingthroughtheintegersequencethenonlyrequiresflippingonebitatatime
whichincertainapplicationsdrasticallyreducesanyerrors.Instandardbinarymanydigitscanchange
atonce,forinstantwhengoingfrom7to8(0111to1000)therearefourbitschangingstate.
It'safactoflifethataPLCinputcanturnONquickerthenitcanturnOFF.We'retalking
millisecondsherebutwithequallyfastscantimesitcangenerateawrongreadingwhenusingnormal
binarymethods.WithGraycodeyoucanbeassuredthatonlyonebitisgoingtochange.Anymore
thenthatonebitchangingandthereissomethingwrong.
Theproblemisdemonstratedinthefigurebelow.Forexample,let'ssayittakesaninputsignal300
millisecondstocomeONbutittakes500millisecondstogoOFF.Inbinarythenwhengoingfrom7
to8theONbitwillcomeonfirstbutthebitsthatareONarestillONandthereforethedecimalvalue
is15.Ittakesanother200millisecondsfortheONbitstogoOFFandachieveourproperreadingof
eight.Ontheotherhand,withGraycodenoticethatonlyonebitischangingfromOFFtoONand
thereforethereisnoerror.

Here'showthesequenceinGraycodestartsandyoucancomparehowdifferentitistostandardbinary
code.I'vemadeiteasybyemphasizingthebitsthatarechanging.

Decimal BinaryPeople:Learningyour1sand0s.">Binary GrayCode


0

0000

0000

0001

0001

0010

0011

0011

0010

0100

0110

0101

0111

0110

0101

http://www.plcdev.com/book/export/html/9

23/30

12/14/2015

PLCBasics

0111

0100

1000

1100

1001

1101

10

1010

1111

11

1011

1110

12

1100

1010

13

1101

1011

14

1110

1001

15

1111

1000

Anotherneattrickisyou'llnoticethatgoingfrom15to0stillpreservesourGraycodeofonly
changingonebit.Prettyneat,eh?Thisiswhytheycallitacycliccodebecauseitcangoaroundin
circles.

WhatisGrayCodegoodfor?
Inautomationit'sparticularlygoodforpositiontransducersusedtomeasuretheangleofashaft.This
applicationbenefitsfromthecyclicnatureofGraycodes,becausethefirstandlastvaluesofthe
sequencearedifferentbyonlyonebit.Thatis,ifyoufeellikegoingroundandroundincircles.
InanopticalabsoluteencoderthereisadiskwithaGraycodepatternlikeso...

Abeamoflight,LEDorlaser,isshotthroughthediskandthelightispickedupontheothersidebya
gangofphototransistors.ThislightisconvertedintoelectricalsignalswhichcanbereadasGraycode
http://www.plcdev.com/book/export/html/9

24/30

12/14/2015

PLCBasics

orconvertedtoBCD.Astheshaft(andthereforethedisk)rotatethelightcomingthroughtheholes
changesbutonlyslightlybasedontheGraycode.Thusthecontrollerreadingthephototransistors
knowstheexactpositionoftheshaft.

Illustration:ExampleofanabsoluteencoderconvertinglighttoaGraycode.

AdvancedTopic:UsingLadderLogicforGraycodeconversion

TheDecisionMakers:AND,ORandNOT
Lifeisfullofdecisions.WhatistrueforusisalsotrueofPLCs.Wegatherinformation(input)and
basedonthatwemakechoicesthatdetermineouroutput.AllthoughI'vealwaysfoundcomputersto
bequiteabitmorelogicalthenhumanbeings.
Foranexampleofhowweuselogicineverydaylifeconsiderthesestatements:
IfTommyORBobwanttoplaybasketballthenI'llplaytoo.
It's6o'clockANDI'mNOThungrythereforeI'mgoingtokeepplaying.
IfMomcomesoutANDordersmeinsideORitget'sdarkthenI'llstopplaying.
Nowtheseareprettysimpledecisionsespeciallyifyou'reatenyearoldboy.You'llnoticethattheyall
involvethreetypesofcomparisions:AND,ORandNOT.Nowwecouldgetmorecomplexbutall
thatwe'dbedoingisusingthesesimplebuildingblocks.
IntheworldofautomationthesetypesofTRUEorFALSEconditionscomedowntoadevicebeing
ONorOFF,CLOSEDorOPEN,PRESENTorABSENT,24VOLTSor0VOLTS.InthePLCitall
boilsdowntoournowfamiliarbinarysystemofa1ora0.TypicallyhavingabitONrepresentsa
TRUEconditionwhileOFFisFALSE.Thisisabitrarythoughasitmaymakemoresensetousewhat
iscalledfailsafelogicandhaveanONbitasaFALSEcondition.
http://www.plcdev.com/book/export/html/9

25/30

12/14/2015

PLCBasics

Let'sturnagaintosomesimplestatementsbutthistimeusingautomationexamples.
WhenthebuttonispressedANDthedoorisclosedthenturnonthemotor.
IftheprocessisdoneORtheemergencystopbuttonsignalisNOTonthenturnoffthemotor.
(Thisisanexampleofafailsafeoperationastheemergencystopbuttoncouldbepressedorthe
wirehasbeendisconnected.Ineithercasewewanttocheckthisforsafetyreasons.Relyingon
asignaltoturnonwhenawirehasfallenofflongagomaycauseanawkwardmomentwhenwe
trulyhavetostopthemachineinanemergency.)
IfthetankisfullORthebuttonispressedANDtherearenoalarmsthenstarttheprocess.
Itwouldbenicetoprogramlikethisbutcomputersliketobealittlebitmorestructured.Aseriesof
graphicalobjectshavebeenusedforyearstorepresenttheselogicelementsandtheycanbeeasily
convertedtoacommonladderlogicequivalent.Thesefunctionsarealsocalledgatesastheyactlike
gatekeepersfordifferentlogic.

TheNOTfunction
ThesimplestofalllogicfunctionsistheNOTgate.

It'ssolefunctioninlifeistoinvertofflipthelogicstate.Soaninputof1willcomeoutasa0andvisa
versa.Shownbelowisatruthtable(itdoesn'tlie)showingallpossibleinputsandtheresultinglogical
output.

InputA Output
0

TheladderlogicequivalentforaNOTfunctionlookslikeanormalcontactbutwithaslashthroughit.

TheANDfunction
TheANDgateisassociatedwiththefollowingsymbolthatcanhaveanynumberofinputsbutonly
oneoutput.

http://www.plcdev.com/book/export/html/9

26/30

12/14/2015

PLCBasics

Thetruthtablebelowshowsthattheoutputisonlyturnedonwhenalltheinputsaretrue(1).Aneasy
waytorememberthisisANDworkslikemultiplication.

InputA InputB Output


0

TheladderlogicequivalentforanANDfunctionlooksliketwonormalcontactssidebyside.

TheORfunction
LastbutnotleasttheORgateisassociatedwiththefollowingsymbolthatalsocanhaveanynumber
ofinputsbutonlyoneoutput.

Thetruthtablebelowshowsthattheoutputisturnedon(1)whenanyoftheinputsaretrue(1).An
easywaytorememberthisisORworkslikeaddition.

InputA InputB Output


0

TheladderlogicequivalentforanORfunctionlooksliketwonormalcontactsontopofeachother.
http://www.plcdev.com/book/export/html/9

27/30

12/14/2015

PLCBasics

CombiningANDorORwithNOT
TheNOTgatemightnotlooklikemuchhelpifyouhaven'tprogrammedmuchbutyou'llfindyourself
actuallyusingitfrequently.It'sverycommontouseitincombinationwithANDandOR.Sothe
engineeringgodsdecidedtomakesomesymbolsforthesecombinations.
PuttingtheNOTandANDgatestogetherformstheNANDgate.Thetruthtablebelowshowsthatitis
simplyaninvertedoutputoftheANDgate.

InputA InputB Output


0

Alittlecircle(orifyoulike,abubble)attheendofaANDgateisusedtosignifytheNANDfunction.
It'ssymbolandcorrespondingladderlogicareshownbelow.Nowpaycloseattentiontotheladder
logicbecausethecontactsareinparallelandnotinseriesliketheANDfunction.

PuttingtheNOTandORgatestogetherforms...yougotit...theNORgate.Thetruthtablebelow
showsthatitissimplyaninvertedoutputoftheORgate.

InputA InputB Output


0

http://www.plcdev.com/book/export/html/9

1
28/30

12/14/2015

PLCBasics

AgainalittlecircleisplacedattheendofanORgatetosignifytheNORfunction.It'ssymboland
correspondingladderlogicareshownbelow.TheladderlogicisverydifferentfromtheregularOR
gate.

Butwait!Don'torderyet...theXORgate.
Sofarwithourlogicgateswe'vecoveredalmostallpossiblecombinationsexceptforoneshownby
thetruthtablebelow.

InputA InputB Output


0

ThelogictoproducethisoutputiscalledanExclusiveORgateotherwiseknownastheXORgate.It's
aspecializedformoftheORgate.Soifeitheroneoftheinputsareonthentheoutputistrue,
otherwiseyou'reoutofluck.ThesymbolfortheXORgateisshownbyaddedacurvedlinetotheOR
gatesymbol.

TheladderlogictoimplementanXORgateisalittlemorecomplexthentheothers.

http://www.plcdev.com/book/export/html/9

29/30

12/14/2015

PLCBasics

HowusefulistheXORlogic?YouprobablyusetheXORgateeverydaywithoutthinkingaboutitif
youhavearoomwithalightthatworksofftwoswitches.Ifbothswitchesareinthesameposition
thenthelightwillbeoff.Thereforejustflippingoneswitchwillturnthelighton.InthePLCprogram
thiscanbeextremelyusefulforprogrammingalternatingactionsorgraycodes.
Ok,thereisonemorelogicgatebutIpromiseitisthelastone.ItmakessensethatthereisaXNOR
gatewhichisthecombinationoftheNOTandXORlogic.ItsimplyinvertstheoutputoftheXOR
function.

InputA InputB Output


0

ThesymbolfortheXNORgateisshownbelowalongwithit'sladderlogicequivalent.

HopefortheFuture
WhilethesetermsandsymbolsmayseemabitesotericforthePLCbeginnertheyareimportantinthe
longrun.AgoodgraspoftheseessentialswillmakePLCprogrammingeasier,simplierandsave
memory.ThenextlessonwillmakethisclearerwhenweconsiderBooleanalgebra.

http://www.plcdev.com/book/export/html/9

30/30

Vous aimerez peut-être aussi