You are on page 1of 3

Acounterisasimpledeviceintendedtodoonesimplethingcount.

Usingthem,however,cansometimesbea
challengebecauseeverymanufacturer(forwhateverreason)seemstousethemadifferentway.Restassuredthat
thefollowinginformationwillletyousimplyandeasilyprogramanybody'scounters.
Whatkindsofcountersarethere?Well,thereareupcounters(theyonlycountup1,2,3...).ThesearecalledCTU,
(countup)CNT,C,orCTR.Therearedowncounters(theyonlycountdown9,8,7,...).ThesearetypicallycalledCTD
(countdown)whentheyareaseparateinstruction.Therearealsoupdowncounters(theycountupand/ordown
1,2,3,4,3,2,3,4,5,...)ThesearetypicallycalledUDC(updowncounter)whentheyareseparateinstructions.
Manymanufacturershaveonlyoneortwotypesofcountersbuttheycanbeusedtocountup,downor
both.Confusedyet?Canyousay"nostandardization"?Don'tworry,thetheoryisallthesameregardlessofwhatthe
manufacturerscallthem.Acounterisacounterisacounter...
Tofurtherconfusetheissue,mostmanufacturersalsoincludealimitednumberofhighspeedcounters.Theseare
commonlycalledHSC(highspeedcounter),CTH(CounTerHighspeed?)orwhatever.
Typicallyahighspeedcounterisa"hardware"device.Thenormalcounterslistedabovearetypically"software"
counters.Inotherwordstheydon'tphysicallyexistintheplcbutrathertheyaresimulatedinsoftware.Hardware
countersdoexistintheplcandtheyarenotdependentonscantime.
Agoodruleofthumbissimplytoalwaysusethenormal(software)countersunlessthepulsesyouarecounting
willarrivefasterthan2Xthescantime.(i.e.ifthescantimeis2msandpulseswillbearrivingforcountingevery
4msorlongerthenuseasoftwarecounter.Iftheyarrivefasterthanevery4ms(3msforexample)thenusethe
hardware(highspeed)counters.(2xscantime=2x2ms=4ms)
Tousethemwemustknow3things:

1.Wherethepulsesthatwewanttocountarecomingfrom.Typicallythisisfromoneoftheinputs.(asensor
connectedtoinput0000forexample)

2.Howmanypulseswewanttocountbeforewereact.Let'scount5widgetsbeforeweboxthem,forexample.
3.When/howwewillresetthecountersoitcancountagain.Afterwecount5widgetsletsresetthecounter,for
example.
Whentheprogramisrunningontheplctheprogramtypicallydisplaysthecurrentor"accumulated"valueforusso
wecanseethecurrentcountvalue.
Typicallycounterscancountfrom0to9999,32,768to+32,767or0to65535.Whytheweirdnumbers?Because
mostPLCshave16bitcounters.We'llgetintowhatthismeansinalaterchapterbutfornowsufficeittosaythat0
9999is16bitBCD(binarycodeddecimal)andthat32,768to32767and0to65535is16bitbinary.
Herearesomeoftheinstructionsymbolswewillencounter(dependingonwhichmanufacturerwechoose)andhow
tousethem.Rememberthatwhiletheymaylookdifferenttheyareallusedbasicallythesameway.Ifwecansetup
onewecansetupanyofthem.

Inthiscounterweneed2inputs.
Onegoesbeforetheresetline.Whenthisinputturnsonthecurrent(accumulated)countvaluewillreturntozero.
Thesecondinputistheaddresswherethepulseswearecountingarecomingfrom.
Forexample,ifwearecountinghowmanywidgetspassinfrontofthesensorthatisphysicallyconnectedtoinput
0001thenwewouldputnormallyopencontactswiththeaddress0001infrontofthepulseline.
Cxxxisthenameofthecounter.Ifwewanttocallitcounter000thenwewouldput"C000"here.

yyyyyisthenumberofpulseswewanttocountbeforedoingsomething.Ifwewanttocount5widgetsbeforeturning
onaphysicaloutputtoboxthemwewouldput5here.Ifwewantedtocount100widgetsthenwewouldput100
here,etc.Whenthecounterisfinished(i.ewecountedyyyyywidgets)itwillturnonaseparatesetofcontactsthat
wealsolabelCxxx.
NotethatthecounteraccumulatedvalueONLYchangesattheofftoontransitionofthepulseinput.

Here'sthesymbolonaladdershowinghowwesetupacounter(we'llnameitcounter000)tocount100widgetsfrom
input0001beforeturningonoutput500.Sensor0002resetsthecounter.
Belowisonesymbolwemayencounterforanupdowncounter.We'llusethesameabbreviationaswedidforthe
exampleabove.(i.e.UDCxxxandyyyyy)

Inthisupdowncounterweneedtoassign3inputs.Theresetinputhasthesamefunctionasabove.However,
insteadofhavingonlyoneinputforthepulsecountingwenowhave2.Oneisforcountingupandtheotherisfor
countingdown.InthisexamplewewillcallthecounterUDC000andwewillgiveitapresetvalueof1000.(we'll
count1000totalpulses)Forinputswe'lluseasensorwhichwillturnoninput0001whenitseesatargetandanother
sensoratinput0003willalsoturnonwhenitseesatarget.Wheninput0001turnsonwecountupandwheninput
0003turnsonwecountdown.Whenwereach1000pulseswewillturnonoutput500.Againnotethatthecounter
accumulatedvalueONLYchangesattheofftoontransitionofthepulseinput.Theladderdiagramisshownbelow.

Clickhere

andviewtheanimationtoreallylearn!

Oneimportantthingtonoteisthatcountersandtimerscan'thavethesamename(inmostPLCs).Thisisbecause
theytypicallyusethesameregisters.Wehaven'tlearnedabouttimersyetbutyoumightmakeanoteofthisfor
futurereferencebecauseit'sprettyimportant.
Well,thecountersabovemightseemdifficulttounderstandbutthey'reactuallyquiteeasyoncewegetusedto
usingthem.Theycertainlyareanessentialtool.Theyarealsooneoftheleast"standardized"basicinstructionsthat
wewillsee.However,alwaysrememberthatthetheoryisthesamefrommanufacturertomanufacturer!

You might also like