PLC Basics: Ladder Logic Common Functions

Updated on April 5, 2019
LiamBee profile image

Automation Software Engineer with 10+ years experience in automation, instrumentation and software programming.

Introduction To Ladder

Ladder logic is a staple of PLC programming, it is more often than not the most used language in a PLC program. It's used because it's easy to read, easy to use and lends itself to logical processes, especially where digital logic (relay logic) is concerned.

In this article, we'll be looking at basic ladder code that are the building blocks for any size project

Logic Latch

Latching signals are common place in automation, especially in factories and process plants. Take a look at the image above, this ladder rung is a classic "Hold On" latch where the coil (the furthest right) variable is used again to hold itself on.

When "ON" is set to TRUE, and "OFF" is set to FALSE, the "Latch" is set to TRUE.

This then "holds its self on" through the "Latch" contact and stays on until the "OFF" is set to TRUE as seen below

Branches

Making a logic branch is simple, think of it as an OR command. In the above image you can see that there is a "fork" in the logic path after "Signal_1". If "Override" is TRUE, the logic bypasses Signals 2,3,4,5 and sets the "Output" to TRUE.

This logic is not just limited to overrides either, imagine if "Output" was actually a fault indication. The above logic would now be:

IF Signals 1,2,3,4,5 are all true OR Signal 1 and Override are TRUE then Output = True.

This would give "Override" a higher priority over all other signals when it comes to driving the fault indication.

Set & Reset Latches

Personally, I don't like this approach because I feel a coil (output) should only ever be written to in one place so you can see what is happening clearly. This design can leave the door open to the latch staying on unnoticed if you have a lot going on.

In the example above, the Latch has already been set by "Signal_1" momentarily becoming TRUE. Notice the "S" inside the coil for "Latch", this is the SET command. Once set, "Latch" will not return to FALSE until the RESET instruction is given (seen on the last line of the logic).

When "Signal_3" becomes TRUE, the "Latch" will become false and therefore "Output" will also become FALSE.

!!! This is not always the case though !!!

What happens when "Signal_1" AND "Signal_3" are both TRUE?

The "Output" is TRUE, even though "Latch" is FALSE?

This is because of the PLC scan. The PLC scans top to bottom and in this case, the SET is TRUE on line 1, therefore on line 2 "Latch" is TRUE and allows "Output" to become TRUE. However on line 3, "Signal_3" is driving the RESET and setting "Latch" to FALSE.

The reason it is displayed incorrectly is because most PLCs only update their views at the beginning or end of the scan. This would be the same if you were monitoring "Latch" when connected to a PLC too, you wouldn't see it flicking between 0 and 1, it would most likely just sit at 0 even though it IS driving an output. This is why I don't like using this method.

Basic Sequencing

Its not uncommon to want to run a PLC as a sequencer, especially for conveyor like systems. The above example shows a very basic sequencer. Imagine that this was controlling a conveyor belt.

  • Step 0 - Wait for a bottle to appear in front of a sensor (Signal_1)
  • Step 1 - Wait for a completed signal of a process filling the bottle (Signal_2)
  • Step 2 - Wait for a signal to show the bottle was in a position to be picked up by an employee ready to pack it (Signal_3)
  • Step 3 - Wait 10 seconds before restarting the process

This is a very crude example, but you get the idea.

Lines 1 and 3 have a "Run" coil assigned, these drive the "Output" signal to TRUE on the last line. As "Output" is the signal to run the conveyor system, this means that the bottles on the conveyor can only be moved on step 0 and step 2.

Some more experienced readers may notice "Run.0" and "Run.1". This is because "Run" is declared as a BYTE and not a BOOL, this simply allows me to use the variable "RUN" as a group of signals, like an array (Not all PLCs let you do this!)

Self Resetting Timer

The above image shows a Timer (TON) function that immediately resets itself, leaving the "Q" output TRUE for only 1 PLC scan.

When Timer.Q is TRUE, the "ADD" function is enabled and increments the "Count" value.

This logic has so many different uses it would be impossible to list them all, it's definitely one worth knowing!

Wrapping Up

The above examples are literally just that, examples, but when put together and applied to a solution will get you much further than you expect. These functions serve as basic building blocks for a variety of different functions.

Get experimenting! On that note, the above images were made with CoDeSys, a free PLC tool. Take a look at it, its very good for beginners to get to grips with things!

Questions & Answers

    Comments

      0 of 8192 characters used
      Post Comment

      No comments yet.

      working

      This website uses cookies

      As a user in the EEA, your approval is needed on a few things. To provide a better website experience, owlcation.com uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

      For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: https://owlcation.com/privacy-policy#gdpr

      Show Details
      Necessary
      HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
      LoginThis is necessary to sign in to the HubPages Service.
      Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
      AkismetThis is used to detect comment spam. (Privacy Policy)
      HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
      HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
      Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
      CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
      Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the googleapis.com or gstatic.com domains, for performance and efficiency reasons. (Privacy Policy)
      Features
      Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
      Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
      Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
      Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
      Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
      VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
      PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
      Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
      MavenThis supports the Maven widget and search functionality. (Privacy Policy)
      Marketing
      Google AdSenseThis is an ad network. (Privacy Policy)
      Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
      Index ExchangeThis is an ad network. (Privacy Policy)
      SovrnThis is an ad network. (Privacy Policy)
      Facebook AdsThis is an ad network. (Privacy Policy)
      Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
      AppNexusThis is an ad network. (Privacy Policy)
      OpenxThis is an ad network. (Privacy Policy)
      Rubicon ProjectThis is an ad network. (Privacy Policy)
      TripleLiftThis is an ad network. (Privacy Policy)
      Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
      Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
      Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
      Statistics
      Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
      ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
      Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
      ClickscoThis is a data management platform studying reader behavior (Privacy Policy)