programming controllers- c vs. relay ladder logic

2
WHITE paper PROGRAMMING CONTROLLERS: C VS. RELAY LADDER LOGIC By G. Young, Customer Support Manager T he World of program- mable controllers has become more sophis- ticated if not more complicated. No longer is it sufficient for a machine to endlessly perform the same series of actions. Systems now, in addition to performing repetitive tasks, must optimize procedures in order to maximize production while keeping basic statistics (a requirement of quality assurance). Moreover, many systems must interact with one or more third-party devices with interfaces that are alien to the controlling Programmable Logic Controller (PLC). Some systems must also interface with at least one enterprise-wide network that provides management with up-to- the-minute information. Relay Ladder Logic (RLL) was designed to provide more flexible software simulation that would replace the relays, timers, and counters common to control systems of the 1960s and 1970s. RLL has been successful in not only achieving, but in surpassing its modest goals. RLL is a power- ful tool when applied to an application that performs specific tasks. However, RLL cannot meet the multiple challenges of todays PLCs even though some RLLs have been retrofitted with features to handle more complicated application demands. At best, these enhancements are awkward and slow and are either difficult or nearly impossible to use. RLL is simply not suited for todays more complicated industrial problems. C, on the other hand, was designed to be a general purpose programming language. Not only does C dominate the development of applications for personal and corporate computing, it dominates the development of embedded systems. Therefore, C is used to program everything from word processors and databases to microwaves and TVs. In essence, C is everywhere. The reason for Cs popularity is its general-purpose nature. Because C makes no assumptions about its environment or what types of tasks it will perform, programs written in C use re- sources much more efficiently than equivalent RLL systems. Most PLCs provide the user with a fixed number of devices such as auxiliary relays, registers, and timers. Eventually, every RLL programmer encounters a situa- tion where a fixed allocation of assets is not acceptable for an application. For example, a particular application may only require a few auxiliary relays and timers, but requires more registers than an RLL application can make available. The most aggravating aspect of this scenario is that the PLC often has the needed memory, but has allocated that memory to unneeded auxiliary relays and timers. When pro- gramming in C, allocating memory is not a problem because the programmer is in control of how resources are allocated. As long as a programmer does not attempt to allocate more resources than available, C allows the programmer to decide how to use resources. When programming in C, allocating memory is not a problem because the programmer is in control of how resources are allocated. This paper examines two methods of programming embedded controllers and describes the benefits of using C-Language in industrial control applications. Z-World White Paper No. 100 Part No. 022-0022 Rev. B ELECTROMATE Toll Free Phone (877) SERVO98 Toll Free Fax (877) SERV099 www.electromate.com [email protected]

Upload: anonymous-fampalxj

Post on 13-Dec-2015

217 views

Category:

Documents


2 download

DESCRIPTION

PLC Programming logic ladder diagram programming language

TRANSCRIPT

Page 1: Programming Controllers- C vs. Relay Ladder Logic

WHITEp a p e r

PROGRAMMING CONTROLLERS: C VS. RELAY LADDER LOGICBy G. Young, Customer Support Manager

The World of program-mable controllers hasbecome more sophis-

ticated if not more complicated.No longer is it sufficient for amachine to endlessly perform thesame series of actions. Systemsnow, in addition to performingrepetitive tasks, must optimizeprocedures in order to maximizeproduction while keeping basicstatistics (a requirement of qualityassurance). Moreover, manysystems must interact with one ormore third-party devices withinterfaces that are alien to thecontrolling Programmable LogicController (PLC). Some systemsmust also interface with at leastone enterprise-wide network thatprovides management with up-to-the-minute information.

Relay Ladder Logic (RLL)was designed to provide moreflexible software simulation thatwould replace the relays, timers,and counters common to controlsystems of the 1960s and 1970s.

RLL has been successful in notonly achieving, but in surpassingits modest goals. RLL is a power-ful tool when applied to anapplication that performs specifictasks. However, RLL cannot meetthe multiple challenges of today�sPLCs even though some RLLshave been retrofitted with featuresto handle more complicatedapplication demands. At best,these enhancements are awkwardand slow and are either difficult ornearly impossible to use. RLL issimply not suited for today�s morecomplicated industrial problems.

C, on the other hand, wasdesigned to be a general purposeprogramming language. Not onlydoes C dominate the developmentof applications for personal andcorporate computing, it dominatesthe development of embeddedsystems. Therefore, C is used toprogram everything from wordprocessors and databases tomicrowaves and TVs. In essence,C is everywhere.

The reason for C�s popularityis its general-purpose nature.Because C makes no assumptionsabout its environment or whattypes of tasks it will perform,programs written in C use re-sources much more efficientlythan equivalent RLL systems.

Most PLCs provide the user witha fixed number of devices such asauxiliary relays, registers, andtimers. Eventually, every RLLprogrammer encounters a situa-tion where a fixed allocation ofassets is not acceptable for anapplication. For example, aparticular application may onlyrequire a few auxiliary relays andtimers, but requires more registersthan an RLL application can makeavailable.

The most aggravatingaspect of this scenario is that thePLC often has the neededmemory, but has allocated thatmemory to unneeded auxiliaryrelays and timers. When pro-gramming in C, allocatingmemory is not a problem becausethe programmer is in control ofhow resources are allocated. Aslong as a programmer does notattempt to allocate more resourcesthan available, C allows theprogrammer to decide how to useresources.

When programming in C, allocating memory is not a

problem because theprogrammer is in control

of how resources areallocated.

This paper examines two methodsof programming embeddedcontrollers and describes thebenefits of using C-Language inindustrial control applications.

Z-World White Paper No. 100 Part No. 022-0022 Rev. B

ELECTROMATEToll Free Phone (877) SERVO98

Toll Free Fax (877) SERV099www.electromate.com

[email protected]

Sold & Serviced By:

Page 2: Programming Controllers- C vs. Relay Ladder Logic

C can solve mostprogramming problemsand is supported on all

major programmingplatforms.

Another important advantageof C is its execution focus. RLLwas written to simulatehardware�s inherently paralleloperation. Parallel operation isaccomplished by executing every�rung� of the RLL program oneach scan. While this achievesthe desired results, it has onemajor drawback: scan timesincrease as the size and complex-ity of the program increases.When attempting to use RLL toperform complex tasks, scantimes, which can increase tomore than 10 milliseconds, aregenerally too slow for mostapplications.

C, however, has a programcounter that starts at the function

main (the first function executedin any C program). The program-mer counter works its waythrough the code, directed by flowcontrol statements written by theprogrammer. A processor runninga C program is executing only onesequence of instructions at a time.

While one sequence of instruc-tions is executed, the rest of theprogram is idle, waiting to ex-ecute the next set of instructions.This single execution focus gives

the programmer incredible powerto decide which aspects of theapplication need the most intenseattention and which only need tobe checked periodically. Withoutthis control, handling high-speedevents (such as deployment of anairbag) would be impossible.

In today�s more sophisticatedrealm of programmable control-lers, it is well worth the timeinvested to become a proficient Cprogrammer. C can solve mostprogramming problems and issupported on all major program-ming platforms. Ultimately, agood C programmer can writeprograms that out perform thoseof an equally competent program-mer using RLL.

C and RLL Characteristics

C Programming Language

� Programming flexibility provides manymeans to solve a problem. So many, in fact,that a novice often gets overwhelmed by thepossibilities.

� Ability to focus execution on a small sectionof code. Important for applications wherecertain functions are not done often enough orare skipped entirely.

� Less intuitive for beginners and a little harderto learn than RLL.

� A useful set of basics can be learned quickly,but the more complicated aspects of thelanguage can be quite confusing even toprogrammers with moderate experience.

� Designed to perform a single task, andperforms that task well.

Relay Ladder Logic

� So restrictive that the simplest problems oftenseem to solve themselves.

� Executes every section with every scan. Thereis no chance of code not executing.

� Can be learned relatively quickly.

http://www.zworld.com

Z-World White Paper No. 100 Page 2 of 2

Part No. 022-0022 Rev. B

Z-World, Inc. � 2900 Spafford Street, Davis, California 95616 U.S.A. � 530.757.3737 Fax: 530.753.5141

ELECTROMATEToll Free Phone (877) SERVO98

Toll Free Fax (877) SERV099www.electromate.com

[email protected]

Sold & Serviced By: