PLC programming languages – Ladder Logic and Advanced Functions

In our last article I mentioned Sequential Function Charts SFC programming language. In this post I will cover advanced functions of ladder logic which allow storage and recovery of bits and words and are useful when implementing buffered and queued systems.

Advanced function are:
  • Arrays
  • Shift registers
  • Stacks
  • Sequencers
  • Branching, looping, subroutines,
  • Temporary ends and one shots
  • Block Transfers
  • Interrupts; timed, fault and input driven
Examples are based on Allen Bradley RSLogix5000

Arrays Functions
Arrays allow us to store multiple data values in sequential series of numbers.
For example, we want to measure average temperature and store it in floating point memory starting at temp[0]. Data will be store in temp[0],temp[1] …[9] because we want to calculate an average of 10 measures
RSLogix5000 average instruction

Array array tag name[]
Dimension to vary [0,1,2] DINT which dimension to use array[0,1,2]
Destination tag result of the operation
Control tag control structure for the operation
Length Number of elements of the array to average
Position Current element in the array initial value is typically 0

Shift Registers

Shift registers are oriented to single data bits. A shift register can only hold so many bits, so when a new bit is put in, one must be removed. In CompactLogix PLC we have BSLbit shift left and BSRbit shift right
When enabled, the BSL instruction starts at bit 0 in array_dint[0]. The instruction unloads array_dint[0].9 into the .UL bit, shifts the remaining bits, and loads input_1 into array_dint[0].0. The remaining bits (10-31) are invalid.
RSLogix5000 shift registers

Stacks FIFO and LIFO

There are two types of stacks; first-on-first-out (FIFO) and last-in-first-out (LIFO). Stacks store integer words in a two ended buffer. As words are pushed on the stack it gets larger, when words are pulled off it gets smaller. When you retrieve a word from a LIFO stack you get the word that is the entry end of the stack. But, when you get a word from a FIFO stack you get the word from the exit end of the stack.
FIFO first in First Out


A sequencer in PLC controller uses a list of words in memory. It recalls the words one at a time and moves the words to another memory location or to outputs. When the end of the list is reached the sequencer will return to the first word and the process begins again.
Allen Bradley RSLogix5000 SQO sequencer

Above we have SQO Output Sequencer which can be used to control traffic lights. Pattern is stored in switch_pattern[0] array. Mask in hex 16#003F allows only to change first 6 bits ( 0000 0011 1111 ) so our pattern looks like this one below:
SQO sequencer pattern

This pattern will be moved to PLC Outputs for traffic light control Lights_ON_Outputs[0] when next_step_bit is executed.

Popular posts from this blog

Pengertian Kartu ATM dan Kartu Debit ( Cirrus dan Maestro Logo )

Free OPC Software

Siemens WinCC Flexible 2008 SP1 Download