1.2 THE LANGUAGE

 

• These programs can also coexist with ladder logic programs. This gives the ability to get solutions that are the best of both worlds.

 

• Some general notes about the language are,

- The language can use normal I/O or memory values as well as named variables.

- Separate operators with spaces; when in doubt use spaces. Indents will also make the program more readable.

- Comments will be on lines that start with ‘%’.

- Semicolons are used at the end of instructions - this does not mean every line.

- the instructions can be upper or lower case.

- instructions can be nested.

-

 

• Remember - unlike normal programming languages these programs must run and then stop each ladder logic scan.

 

• Variable names can be anything but those listed below, and the other instruction names.

 

 

• Variables are defined with the following keywords.

 

 

• Examples of variable declarations are given below,

 

 

• Basic numbers are shown below. Note the underline ‘_’ can be ignored, it can be used to break up long numbers, ie. 10_000 = 10000.

 

 

• Character strings are shown below.

 

 

• Basic time duration values are described below.

 

 

• Date values are given below. These are meant to be used to compare to system time and date clocks.

 

 

• Basic math functions include,

 

 

• Functions for logical comparison include,

 

 

• Functions for Boolean algebra and logic include,

 

 

• The precedence of operations are listed below from highest to lowest. As normal expressions that are the most deeply nested between brackets will be solved first. (Note: when in doubt use brackets to ensure you get the sequence you expect.)

 

 

• Language structures include those below,

 

 

• Special instructions include those shown below.

 

 

• Consider the program below to find the average of five values in floating point memory.

 

 

• Consider the program below to find the average of five values in floating point memory.

 

 

• The example below will set different outputs depending upon the stat of an input.

 

 

• The example below will set output bits 00-03 depending upon the value of the integer in N7:0, if the value is not between 0 and 3 the outputs will all go off.

 

 

• The example below accepts a BCD input from (I:000) and will use it to change the delay time for an on delay timer that will examine input I:002/00 drive output O:001/00.

 

 

• Try the example below,

 

 

• Normal ladder logic output functions can be used except for those listed below.

 

 

• The list below gives a most of the IEC1131-3 defined functions with arguments. Some of the functions can be overloaded (for example ADD could have more than two values to add), and others have optional arguments. In most cases the optional arguments are things line preset values for timers. When arguments are left out they default to values, typically 0.

 

 

 

• Try the example below,

 

 

• We can define functions that return single values,

 

 

• Try the example below using a function or subroutine,