Chapter 3: Programming a Simple Application

Introduction

Programming is the way of telling the M221 Logic controller how to function. It uses two of the standard IEC61131 programming languages; Ladder Logic and Instruction List. The programming environment also provides tools to help debug the program if it does not perform as expected.

This Chapter Covers These Topics:
i. Languages
ii. The Conveyor Application
iii. Addressing
iv. The Simulator
v. Symbols
vi. Program Structure
vii. Programming Rungs
viii. Timers
ix. Exception Handling
x. Set and Reset Coils
xi. The Operation Block
xii. The Comparison Block

i.Languages

IEC61131
IEC61131 is the international standard for programming PLCs. Its main purpose is to define standard data types and languages. There are many data types that will be discussed later, but there are only five programming languages:

  • Ladder Diagram (LD)
  • Function Block Diagram (FBD)
  • Structured Text (ST)
  • Instruction List (IL)
  • Sequential Function Chart (SFC)

Of these languages, only Ladder Diagram and Instruction List are currently supported by SoMachine Basic although other languages are planned for future releases.

Ladder
Ladder is a popular programming language as it is similar to electrical diagrams and visually, it is very easy to see what the program is doing. With the addition of in-line status display, it is also very easy to debug.

It consists of a series of program lines or rungs, so called because they look like the rungs of a ladder. To the left of the rung are a set of inputs and conditions that must be solved. To the right of the rung is an object (or objects) defining what to do with the result.

A ladder rung may look something like the following:

s1

Put simply, if input %I0.0 is on and input %I0.1 is on then output %Q0.7 will turn on. If either of the inputs is off then the output will also be off.

Ladder does have some limitations though. It cannot perform all functions due to limitations in the programming rules and it must be converted to Instruction List before it is processed by the logic controller.

Instruction List
Instruction List is similar to computer machine code and anyone familiar with that will see many similarities. It uses a working store to load and combine values. This store is then written to an output or memory location called an accumulator.

The commands:
0001| LD %I0.0

0002| AND %I0.1

0003| ST %Q0.7

The three steps are:

Line 1 - Load the value of %I0.0 (0 or 1) into the accumulator.

Line 2 - Perform a logical AND of the accumulator with the value of %I0.1 (0 or 1) and store the result back in the accumulator.

Line3 - Write the result (the contents of the accumulator) to output %Q0.7

This is similar to the way a calculator works. The first number is entered (or loaded) at step 1. A mathematical operator such as plus or minus is pressed and another number is entered at step 2; pressing the equals or another operator stores the result back on the display. The result is transferred from the calculator display to a piece of paper at step 3.

This can be written in ladder as:

s1-1

ii.The Conveyor Application

For the purposes of creating a simple application and program, a simple three- conveyor application will be used. Control will be provided for starting, stopping and fault monitoring.

s2

The start control will simply start all three conveyors at the same time although for better control, timers could be used to feed product in a controlled way or distribute startup current for the motors.

Shutdown is normally timed to allow product to clear the conveyors before each is shutdown. This section will allow the demonstration of timer programming.

Fault monitoring can determine whether there is a problem and take the appropriate action to prevent spillage or damage. A speed monitoring program will also describe the configuration of analog value manipulation and the use of the analog input.

For any application it is important to have a list of the addresses of all I/O and internal registers.

iii.Addressing

Addressing Format
The M221 Logic Controller addressing uses the following format:

s3

An address must always begin with the % character. This tells the Logic Controller that it is an address, not some other piece of information.

This is followed by one of five letters identifying the type of address:

I The address is a physical input on either the controller or an expansion module.
K The address is an internal memory location within the controller. The value is fixed and can NOT be changed by the program.
M The address is an internal memory location within the controller. This value can be changed by the program.
Q The address is a physical output on either the controller or an expansion module.
S Internal system locations that are used to perform various functions and monitor the controller

The type may then be followed by a type identifier which can be one of the following:

(none) The address contains a value that is a single bit having a value of either 0 or 1.
W The address contains a value that is a word and has a value between 0 and 65535.
D The address contains a value that is a double word and has a value between 0 and 4294967295.
F The address contains a value that is in floating point format and has a value between 0 and 65535.

The numeric part of the address contains the location. This location can have one of two formats depending on the address type. The format nnnn is used for internal memory locations. The format x.y is used for inputs and outputs where the first part
(x) identifies the module position in the rack. Slot zero is the left most slot and is the processor.

The second part (y) identifies the input or output number on that module.

Thus an address of %I1.2 refers to the third input on the first expansion module (Numbering starts at zero).

I/O List
The following I/O will be used in the application.

Inputs:

Address Description
%I0.2 Conveyor 1 Fault Signal
%I0.3 Conveyor 1 Fault Signal
%I0.4 Conveyor 1 Fault Signal
%I0.6 Stop Button
%I0.7 Start Button

Outputs:

Address Description
%Q0.2 Conveyor 1 Run Control
%Q0.3 Conveyor 2 Run Control
%Q0.4 Conveyor 3 Run Control
%Q0.6 Run Indicator
%Q0.7 Fault Indicator

Analog:

Address Description
%IW0.0 Conveyor Speed

Register List
The following internal registers will be used in the application.

Address Description
%M100 Run Relay
%M101 Conveyor 1 Stop Sequence
%M102 Conveyor 2 Stop Sequence
%M103 Conveyor 3 Stop Sequence
%M104 Not Used
%M105 Conveyor 1 Fault
%M106 Conveyor 2 Fault
%M107 Conveyor 3 Fault
%M108 Not Used
%M109 Stop Sequence Relay
%M110 Remote Start
%M119 Remote Stop
%M120 Variable Speed OK
%M121 Variable Speed High
%M122 Variable Speed Low
Address Description
%MW1 Low Setpoint
%MW2 High Setpoint
%MW3 Scaled Speed

How to Assign Objects to I/O and Memory
When a program is created, the objects used in the program must be assigned to either an I/O or memory address. If this is not done, the program cannot be compiled and downloaded to the Logic Controller.

To assign an object to an I/O or memory address, first double-click the address above the object. An entry field will appear.

s5

Enter the desired address into this entry field.

Note:
The % character is already in the entry box as this identifies the entry as an address.

  • Create a Basic Application

1. Create a new application.

i. Start the SoMachine Basic software using either by double-clicking the icon or the desktop or going to Start » Programs » Schneider Electric » SoMachine Basic » SoMachine Basic.

s6

ii. On the start page click the Create a new project button.

2. Assign a controller.
i. The project will open on the Configuration tab. If the configuration tab is not selected, click to select it.

sc9-1

ii. The right hand side of the screen shows the hardware catalog. In the Logic Controller section, select the logic controller that you have and drag-and-drop it to the centre window. A picture of the logic controller will be shown under the mouse cursor.
iii. If the controller is being changed, a message box will be displayed to confirm the change of controller.

s7
Click the Yes button to replace the controller.

3. Create the first rung.

i. Click the Program tab to enter the programming section of the SoMachine Basic software.

s8

The first ladder rung will have been created ready for programming.

ii. Select the normally open contact from the toolbar and place it in the first row and column of the program.

iii. Select the normally closed contact from the toolbar and place it in the first row second column.

iv. Select the coil from the toolbar and place it on the first row, final column. The program should now look like the following:

s9

4. Assign Inputs and Outputs to the rung.
i. Double-click the word "Address" above the first contact.
s10

ii. In the dialog box that opens, enter the address %I0.7. The % will already be in the dialog box.

The % indicates that it is an address in the Logic Controller, the I means that it will be a physical input and the 0.7 means that it will be the eighth input on the Logic Controller.

iii. Double-click the word "Address" above the second contact and enter the address %I0.6.
This will assign the contact to the sixth input of the Logic Controller.

iv. For the output coil, enter the address %Q0.6.

The Q signifies that this is an output and the 0.6 that this will be the seventh output on the Logic Controller.

The final rung should look similar to the following:

s11

5. Save the application.
i. Click the save button on the toolbar.
ii. Choose the location and enter "Conveyors" for the filename.
iii. Click the Save button to save the application.

iv.The Simulator

Simulating Programs
The simulator is a piece of software supplied with SoMachine Basic that allows programs to be tested without using the controller.

s12

The program is loaded into the controller and the simulated controller inputs to be operated and their effects examined. The outputs can be monitored and the internal program analysed.

Starting the Simulator
The simulator is started using the Launch Simulator button on the Commissioning tab.

s13

This will start the simulator and load the current program. The program can then be tested using the simulator without the need to download to a physical controller.

The Simulator Windows
The simulator window shows information about the simulator and allows control of the inputs for the application. The controller is shown on the left hand side along with, power, run, error and status indicators.

s12-1

The PWR indicator will be green showing that the simulator is running. The RUN indicator will either be flashing to show that the application in the simulator is not running, or solid green to show that the application is running. The ERR and STAT LEDs are not currently used.

The IN column shows the state of the inputs for the controller. These will be numbered from zero up to the total number of inputs supported by the controller. These inputs can also be clicked to change the state of the input, toggling it on or off. When the input turns on it will be coloured green. When the input is off it will be coloured white.

The OUT column shows the state of the outputs for the controller. These will be numbered from zero up to the total number of outputs supported by the controller.

The ANA column shows the values of the analog inputs for the controller. Double- clicking this will open another window allowing the values of the analog inputs to be changed.

s14

The vale can be changed by selecting the analog value and using the slider at the bottom of the window. If a more accurate input is required, the value shown in the change value column can be double-clicked and the value typed in.

Test the Program
1. Start the Simulator.
i. Go to the commissioning tab in SoMachine Basic and click the Start Simulator button.

s13-1

The simulator will be started and the program will be loaded into the simulator.

s12-2

Do not operate anything in the time management window.

The Run indicator in the simulator will be flashing to show that the simulator is stopped.

ii. Click the Run Controller button on the commissioning screen to run the program in the simulator.

s15

A pop-up window will be shown asking to confirm the action.
s16

Click the OK button to confirm and the Run indicator will change to a solid green.

s12-3

2. Test the program.
i. In the simulator window, click the number 7 representing the last input. The input will turn green to show that it is on.

s17

Output 6 should also turn on. This is being controlled by the program. If input 7 is on and input 6 is off, then output 6 should turn on.

ii. If output 6 doesn't not turn on then check the program carefully for any mistakes.

3. Monitor the program.

i. Switch to the programming tab and observe the state of the program. The normally open contact will be coloured green and shown as true, indicating that input 7 is on. The output coil should also be coloured green to show the output being controlled by the program.

s18

Operate the two inputs and observe the effect on the program.

4. Further testing.

i. Ensure that input 7 is off. If not, click input 7 to turn it off. Click input 6 to turn it on. There should be no effect.

ii. Click input 7 to turn it on. This time output 6 should not come on as it is being prevented by the normally closed contact for input 6 which is now true.

Note:
The True/False indication shows the state of the input, not the state of the coil or contact. The green colouring shows the state of the contact. This can be confusing for inverted contacts and coils but a green colour will always signify power or on.

5. Stop the simulator.
i. Go to the Commissioning tab and click the Stop Simulator button to stop the simulator.

v.Symbols

Using Symbols
Symbols are a way of naming objects and making them easier to identify. If an object has an address of %I0.7 it is impossible to determine what that object does without referring to the documentation for the application. If the object is also given the symbol "Start_Button", anyone looking at the program will have a good idea what that object is supposed to do.

Choosing meaningful symbols can help to make the program self-documenting as they will describe what each object does. Usually a good name for the output object will also help to identify what the entire rung does.

How to Add Symbols
In the ladder editor, double-click the word "Symbol" above an object. This will open a dialog box and the symbol can be entered.

s19

The symbol can contain letters numbers and the underscore character. Spaces are not allowed.

Alternatively, the object property box can be displayed at the bottom of the screen by selecting Tools in the Module Programming Tree and selecting the appropriate input or output type.

s20

Double-clicking the Symbol column of the row containing the object will open a dialog box which will also allow the symbol to be entered.

s21

When the symbol has been entered, the Apply button must be clicked to accept the changes. This allows multiple symbols to be entered before accepting the change.

A different method of entering multiple symbols will be explored in the next section

Adding Symbols to Objects

1. Add symbols to the four objects contained in the program.

i. In the ladder editor, double-click the word "Symbol" above the first contact.

s19-1

Enter the symbol START_BUTTON and press Return.

A message will appear asking if you want to associate the symbol "START_BUTTON" with the I/O %I0.7.

s22

Click the Yes button to confirm.

ii. At the bottom of the screen, double-click the Symbol column of the row containing %I0.6.

s21-1

Enter the symbol STOP_BUTTON. Click the Apply button in the bottom right hand corner to accept the change.

iii. In the Module Programming Tree, select the Tools Tab. Under I/O Objects select Digital outputs.

iv. Double-click the Symbol column of the row containing %Q0.6 and enter the symbol "CONVEYORS_RUNNING". Do not click the Apply button.

v. In the Module Programming Tree select another section such as Analog Inputs. The following message will be displayed.

s23

This ensures that any unsaved changes will not be lost if you forget to apply the changes and try to navigate away from the page.

vi. Click the Yes button to apply the changes the change.
vii. Save the application.

Exporting and Importing
Exporting and importing provide an easy way of editing symbol names and descriptions outside SoMachine Basic.

The symbols can be exported to a .csv file; either comma separated or semi-colon separated. This file can then be opened in Microsoft Excel and edited, allowing all the features of Microsoft Excel to be used to edit the list.

s29

When the editing is complete, the file can be saved to .csv format and imported back into SoMachine Basic. The Import will check whether the symbol already exists and if not, import the symbol into the application. If the symbol already exists then it will be ignored. The description however, will be replaced if it already exists. A report will show the actions carried out by the import process.

s30

How to Export Symbols
To export a list of symbols, click the Export button. The following dialog box will appear: If the export options are not shown, click the down-arrow button to the left of Export options.

s31

Enter the path and filename and choose the export options:

 Whether to include headers and comments
 Whether to use a semicolon or comma separator
 Whether to use Unicode or ASCII

How to Import Symbols
To import a list of symbols, click the Import button. The following dialog box will appear:

s32

Enter the path and filename and choose the import options:

 Whether to create a backup first
 Whether to import only changes or import all items
 Whether to use a semicolon or comma separator
 Whether to use Unicode or ASCII

Exercise - Exporting and Importing Symbols

1. Export the symbols to a .csv file

i. In the Module Programming Tree, under Software Objects select Symbols List. A list of the currently configured symbols will be displayed.

s33

ii. Click the Export button above the list of symbols. The following dialog box will be displayed. If the Export options are not displayed, there will be a Down Arrow button to the left of "Export options". Click this down arrow button to display them.

s31-1

iii. Click the ellipsis button to the right of the File Path entry box and choose the desktop.
iv. Enter Conveyor Control for the filename.
v. Click the Export button to export the file.

2. Edit the exported symbols file in Excel.
i. Start Excel and open the symbols file that is on the desktop. If the file was saved to a different location in the previous step, open it from there. The import wizard will be automatically displayed.

s34

Click the Next button to go to page 2.

ii. On page 2 of the wizard, ensure that the Semicolon tickbox is selected.

s35

Click the Finish button to complete the import process.

iii. Excel will display the symbols in three columns of the spreadsheet;
Symbol, Address and Comment

s36

iv. Edit the spreadsheet to contain the following entries:
s37

v. Save the spreadsheet as a .csv file called Conveyor Control Symbols.

If a message is displayed about compatible features, click the Yes
button to save the file.

3. Import the .csv file into SoMachine Basic.
i. In the SoMachine Basic Symbols List view, click the Import Button.

The project must be saved before the symbols file can be imported. If the following message is displayed, the project has not been saved.

Click the OK button, save the project and then click the Import button again.

s32-1

ii. Click the ellipsis button to the right of the File Path and navigate to the desktop. Select the file called Conveyor Control Symbols.csv. If the file was saved to a different location in the previous step, open it from there.

iii.If the Import Options are not displayed, there will be a Down Arrow button to the left of "Import Options". Click this down arrow button to display them. Drop down the Separator selection box and choose Comma.

s38

(Excel will use the comma separator by default unless a different separator has been chosen in the Excel options)

iv. Click the Import button to begin the import process.

v. When the import has completed, a window will open showing the report for the import. Review the report for any errors.

s39

vi.Program Structure

POUs
Program Operation Units (POUs) are a way of organising code into sections, making it easier to find were certain control functions are located.

Although there is a Search function in SoMachine Basic, grouping sections of code in this way can help to see how rungs interact with each other.

For example, the conveyor application has three POUs

 Control
 Fault Handling
 Speed Monitoring

Thus if a programmer wanted to look at setpoints for the speed control, it makes sense for the program code handling that to be in the Speed Monitoring POU. If they wanted to find out why the running light wasn't coming on, they would look in the Control Section (although perhaps the first task would be to check the bulb).

Adding POUs and Rungs
To create a new POU, right click the Master Task and from the menu select Add POU.

s40

To create a new rung, right click the POU and from the menu select Add Rung.

s41

Renaming POUs and Rungs
POUs and Rungs can also be renamed. Right click the POU or Rung and select
Rename POU or Rename Rung.
s42
s43

This renaming helps to self-document the program.

Copying POUs and Rungs
POUs and Rungs can also be copied. Right click the POU or Rung to be copied and select Copy POU or Copy selected rung.

s42

s43

When a POU has been copied it can be pasted into the Master Task. Right-click the Master Task and select Paste POU from the menu.

s44

When a Rung has been copied it can be pasted into any POU. Right-click the required POU and select Paste Rung from the menu.

Copying Objects in Rungs

Individual items within rungs can also be copied. Select the items to be copied. The Windows shortcut keys will allow multiple items to be selected - click and
click. a can also be used to select all items in the rung.

Right-click the green area to the left of the rung and select Copy from the menu.

s45

Select the rung where the items are to placed, right-click the green area to the left of the rung and select Paste from the menu.

The options to add, rename, copy and paste rungs are also here along with options to insert a rung and edit lines, columns and items within the rung.

Exercise - Create a Program Structure
1. Create new rungs for the program.
i. Right-click the rung Rung_0 and from the menu select Rename Rung.

s43

ii. Change the name of the rung to Start Control.

iii. Right-click the POU POU_0 and from the menu select Add Rung.

s42

iv. Change the name of the rung to Stop Control.

v. Add new rungs to the program and give them the following names:

  • Conv 1
  • Conv 2
  • Conv 3
  • Running
  • Stop 1
  • Stop 2
  • Stop 3
    i. Right-click the POU and rename it to Control.

2. Create new POUs for the program
i. Right-click the Master Task and from the menu select Add POU.

s44

ii. Rename this POU Fault Handling.
iii. Add another POU and call it Speed Monitoring.

3. Save the application

vii.Programming Rungs

Links
Links are often created automatically when objects are placed in a rung. The link is usually correctly placed but there will be times when the link must be changed.

s46

For example, when the output coil is drawn in the above rung, the link between the last contact and the coil is drawn automatically.

There are two modes when placing a contact, normal mode and branching mode. Normal mode will simply place the object in the rung; branching mode will place the object in the rung and attempt to draw the links to existing contacts.

Automatic Links
If Branching Mode sa is selected, any contact drawn on the screen adjacent to another contact already in the rung, will be linked to that existing contact.

s46

For example, if a new contact is placed under the normally open contact in the above rung, the links will be drawn automatically.

s47

If the contact is not placed adjacent to another contact, the branches will have to be drawn manually. Links will also have to be redrawn manually if they are incorrectly placed by the automatic process.

Manually Drawing Links
There are two tools to allow links to be drawn or erased. These are the draw line tool and the erase line tool.

The Erase Line tool sb will allow lines or links to be erased anywhere in the rung, except where another object has been placed. They are erased by dragging over the line or link to be erased. The line will appear red as it is being erased.

s48

The Draw Line tool sc will allow lines or links to be drawn anywhere in the rung, except where another object has been placed. The line will appear green as it is being drawn.

s49

Power Flow

A way of analysing ladder logic is to imagine power flowing through the contacts. If a contact is closed then power will flow through it and on to the next contact or coil.

In the following example, the normally closed contact will allow power to flow through but this does not answer the question of whether the output coil will turn on. Imagining power flow along the rung allows the rung to be analysed.

s46-1

If the first contact is closed, ie input %I0.7 is true, then power will be applied to the left hand side of the normally closed contact. If the second contact is closed, ie input %I0.6 is false, then the power will be applied to the left hand side of the coil allowing it to turn on.

More complex rungs require more complex analysis but this concept of power flow and whether there is power at a certain point in the rung, remains the same. Thus any rung can be "solved" to see whether the output will turn on.

If the first contact is closed, ie input %I0.7 is true, then power will be applied to the left hand side of the normally closed contact. If the second contact is closed, ie input %I0.6 is false, then the power will be applied to the left hand side of the coil allowing it to turn on.

More complex rungs require more complex analysis but this concept of power flow and whether there is power at a certain point in the rung, remains the same. Thus any rung can be "solved" to see whether the output will turn on.

Reverse Power Flow
In the following example, there is a point in the middle of the rung where power flows from right to left instead of from left to right. This is known as Reverse Power Flow. The following shows an example of reverse power flow where power must flow back to the start of the second row of contacts.

s50

Some programming packages allow reverse power flow when a rung is configured. However SoMachine Basic does not allow reverse power flow so care must be taken to avoid this when configuring a rung.

Program errors will be present if this is configured in SoMachine Basic.

Start Control
The first section of the program will be responsible for Start Control. The start control will simply start all three conveyors at the same time.

In practice timers are often used to provide a staggered start to space out product and prevent current surges. Timed control of the conveyors will be performed as part of the stop control where it is much more important to clear product from the conveyors.

Exercise - Create the Start Control Program

1. Modify the start control rung.
i. Click the descriptor for the coil and change the address from %Q0.6 to %M100. Similarly, change the descriptor for the latching contact to %M100

s51

ii. Delete the Stop contact - this will be implemented in a different way as a controlled shutdown is required.
iii. Add two normally open contacts on the second row of the rung.
iv. Select the line drawing tool.
v. Click and hold at the right hand side of the contact at row 2 column 2 and drag the line up to join the top row. The completed rung should look like the following picture

s52

This will complete the change to the start control rung.

2. Create the code for conveyor 1.
i. In the rung "Conv 1" add a contact and a coil.
ii. Enter the address %M100 for the contact and %Q0.2 for the coil.

s53

3. Create the code for conveyor 2.
i. Delete the existing Conv 2 rung
ii. Select the Conv 1 rung.
iii. Right-click the green area of the rung and select Copy selected rung from the menu.
iv. Right-click the empty area below the rung and select Paste rung
from the menu.
v. Click the address above the coil and change it to %Q0.3.

4. Create the code for conveyor 3.
i. Select the contact and coil from the Conv 1 rung.
ii. Right-click the green area of the rung and select Copy from the menu.
iii. Right-click the green area on the left of the Conv 3 rung and select Paste from the menu.
iv. Change the address of the contact to %Q0.4.

5. Create the code for the running indicator lamp.
i. Program the "Running" rung with the following objects

s54

6. Save the application.

viii.Timers

Stop Control
Stop control will perform a controlled stop of the conveyors.

Timers will be used to ensure product has travelled down the conveyor before each is stopped. This approach ensures that the conveyor stops and no product is left on the conveyor.

Each conveyor will have a separate timer which will accommodate different conveyor lengths and speeds.

How to Create a Timer
Clicking the Functions button on the Ladder Editor menu will open a drop-down menu of special functions. The first of these is the Timer function.

s55

Select the Timer object and when the cursor is moved over the ladder rung a timer will be displayed underneath it.

s56

Place the timer at the desired location.

How to Configure Timer Parameters
Parameters must also be configured for the timer to set the type of timer and time value. This is done in the Timer Properties section.

Either double-click the timer function block in the ladder editor or go to the Module Programming Tree, select the Tools tab then under Software Objects select Timers.

s57

The Timer Parameter configuration will be displayed at the bottom of the page.

s58

To change the type or base, double-click the column on the row containing the required timer. A drop-down box will appear allowing the type or timebase to be selected.

To change the symbol or preset, double-click the column on the row containing the required timer. A dialog box will open allowing the required information to be entered.

Exercise - Create the Stop Control Program

1. Create the stop sequence ladder rung.
i. Add the following objects to the Stop Control rung:

s59

2. Create timer for the first conveyor.
i. In the Stop 1 ladder rung, place a normally open contact at the start of the rung. Click the Symbol text above the contact and enter Stop. A list of the previously entered symbols that contain "STOP" will appear.

s60

ii. Select the "STOP_RELAY" symbol.
This is an alternative way of assigning an address to an object.

iii. In the functions menu bar, drop down the functions sub-menu and select the timer object.

s55-1

iv. Place the timer next to the contact

s61

3. Modify the parameters for the timer.
i. In the Module Programming Tree, select the Tools tab. Under Software Objects, select Timers.

s57-1

ii. Double-click the base column on the row containing %TM0. A drop- down box will appear allowing the timebase to be selected. Choose the 1s (1 second) timebase.

s62

iii. Double-click the Preset column on the row containing %TM0 and enter a preset value of 2. This will set the timer to 2 seconds.

iv. Apply the changes.

4. Complete the rung.
i. Add a contact to the end of the rung and assign it to address %M101.

5. Create the code to stop the other conveyors.
i. Copy the objects from the Stop 1 rung and paste them into the Stop 2 rung.
ii. Change the address of the coil to %M102.
iii. Double-click the timer address to change the timer number.

s63

iv. Change the address of the timer to %TM1.
v. Paste the objects into the Stop 3 rung.
vi. Change the timer to %TM3 and the output coil to address %M103.

6. Modify the parameters for the other timers.
i. Open the timer configuration and enter the following parameters for the timers.

s64

ii. Accept the changes.

7. Complete the stop control.
i. On the Conv 1 ladder rung add a normally closed contact and assign it to address %M101.

s65

ii. On the Conv 1 ladder rung add a normally closed contact and assign it to address %M102.

iii. On the Conv 1 ladder rung add a normally closed contact and assign it to address %M103.

8. Save the application.
9 Download the application to the controller and test it.

i. When the start input, %I0.7, is operated. All the conveyor outputs will come on at the same time; %Q0.2, %Q0.3 and %Q0.4.

ii. When the Stop input is operated, the outputs will turn off in a timed sequence:

%Q0.2 will turn off after two seconds.

%Q0.3 will turn off after five seconds

%Q0.4 will turn off after nine seconds.

If the program does not work as expected, carefully check the programming for any mistakes, resolve them and try again.

ix.Exception Handling

Exceptions
Exception handling is an important part of any application. If a problem condition can be identified and correctly handled it can prevent damage to equipment or loss of production.

Typical exception handling may be written for the following:

 Equipment being turned on but not running, such as a conveyor jam
 Motors not running at the correct speed
 Insufficient product
 No bottles or caps for a bottling machine
 Storage container overfill (if a high level probe fails)
 Product backup on conveyor

The last of these for example, may cause product to spill on the floor if there is not enough room on the conveyor and it is not stopped.

The following exercises will add code to handle the first two of these.

Note:
If any of these physical exceptions occur they are often referred to by engineers as faults. The fault is not part of the control system but with the process itself and if programmed correctly, the control system can handle the fault in a controlled way.

Exception Indication
As well as handling the exception, the program should also provide some kind of indication to the operator so they can take the appropriate action to resolve it. This can be in the form of indicator lights, horns and/or alarm displays. An output will be provided for lights/horns and the program must be written to operate these outputs under the appropriate circumstances.

Alarm displays are usually implemented using a graphic or text display and data connection to the controller. In most cases there must be some programming in the controller to accommodate this.

Conveyor Application
For this section of program, inputs %I0.2, %I0.3 and %I0.4 will simulate conveyor faults. A settling time will be provided for each conveyor and if the input is activated after this time then an exception will be generated.

The appropriate conveyor will be stopped along with all preceding conveyors to prevent product from being fed to the conveyor that has stopped.

The speed of a conveyor will also be monitored. This speed will be represented by an analog value on input %IW0.0. A low and high setpoint will be configured and if the speed of the conveyor is outside the range of the setpoints then an indication will be made to the operator. No other automation control is required.

A fault Indicator output will be provided on %Q0.7: It will be flashing for a conveyor speed error and permanently on for a conveyor fault.

x.Set and Reset Coils
Set and Reset coils work slightly differently to normal coils.

When the preceding logic resolves to true a Set coil will turn the output on. The output will then stay on, even if the preceding logic changes state and resolves to false. The coil must be reset using a reset coil.

When the preceding logic resolves to true a Reset coil will turn the output off. If the preceding logic resolves to false, the Reset coil will not change the state of the output.

s66

These usually operate independently in separate ladder rungs; the only link between them is that they operate on the same output.

Note:
If the same object appears later in the program as a normal coil, the logic of this rung will determine the state of the object. The Set and Reset will be ignored.

Exercise - Create an Exception Handling Program
1. Create new rungs for the exception handling.

i. Add five new rungs to the Fault Handling POU and give them the following names:

Conv 1 Flt

Conv 2 Flt

Conv 3 Flt Reset Fault Light

2. Program the settling timers.
i. Program the following objects for the settling timer and fault for conveyor 1.

s67

Notice the use of the Set Coil not a normal coil. This will have to be placed using the Set Coil tool on the toolbar.

ii. Configure the following parameters for the settling timer.

s68

iii. Configure the other two fault rungs and settling timers similarly.

Try to work out which contacts and coils are required and program them before turning the page.

s69

3. Add code to reset the faults.
i. For each set coil, there must be a reset coil. These will be programmed into a single rung and will reset the circuits when all the faults have been removed and the start button is pressed.

s70

4. Add code for the fault light.
i. Finally add the program for the fault light which will come on when there is a fault on any of the conveyors.

s71

5. Save the application

xi.The Operation Block

Setting Numeric Values
The setpoints for speed handling need to be set by the program at startup. SoMachine Basic provides a function for setting numeric values. It is called the Operation Block.

The Operation Block is used to perform a calculation or other operation and write the result to a register.

How to Create an Operation Block
The Operation block tool is located on the toolbar next to the Other Items button. It is a rectangle with three dots inside.

s72

To create an Operation block select the tool and place the object on the right hand side of the rung.

Double-click the Operation Expression above the block to open an entry box and enter the required expression.

s73

Note:
Operation blocks can only be placed on the right hand side of a ladder rung.

Conveyor Application
The speed of a conveyor will also be monitored. This speed will be represented by an analog value on input %IW0.0. A low and high setpoint will be configured and if the speed of the conveyor is outside the range of the setpoints then an indication will be made to the operator. No other automation control is required.

Exercise - Creating Setpoints

1. Create the ladder rung.
i. In the Speed Monitoring POU, create a rung and name it "Setpoints".

2. Create the programming for the rung.
i. Select the Operation Block toola1 and place the block at the right hand end of the rung. Place a second Operate block beneath it.

ii. Click the Operation Expression above the first block and an entry box will open.

s73-1

Enter the expression %MW1 := 625

Notice that this is colon-equals, not just equals.

iii. Configure the second Operation block with the expression %MW2 := 400

Note:
Although this will perform the correct function and load the setpoints with the values, this will happen each time the logic is processed.


Sometimes the setpoints will need changing depending on the state of the process so it is better to load the setpoints once when the program starts up. The setpoints can then be changed without being overwritten by the program.

The system bit %S13 provides a single pulse when the program starts and remains off after that. This can be used for any initialisation in the program.

3. Change the rung so that the values are loaded once when the program starts.
i. Place a normally open contact at the start of the rung and assign it to address %S13. The completed rung should look like the following.

s74

4. Save the application.

xii.The Comparison Block

Comparing Numeric Values
Sometimes it is necessary to compare values to see if a value is above or below another. For example, consider a storage silo weighing 200Kg and that silo can contain 100 Kg of product. If the silo is fitted with a load cell then the weight can be measured. If the weight exceeds 290 Kg then the storage silo can be considered full and the control system can ensure that no more product is put into that silo.

Comparing numeric values in SoMachine Basic is achieved using the Comparison block.

How to Create a Comparison Block
The Comparison Block tool is located on the toolbar next to the XOR and Functions. It is a rectangle with a left chevron (<) inside.

s75

To create a Comparison Block select the tool and place the object on the rung in any position except the right hand side of the rung.

Double-click the Comparison Expression above the block to open an entry box and enter the required expression.

Conveyor Application
The speed of a conveyor is represented by an analog value on input %IW0.0 and will be compared with the low and high setpoints that were configured previously. If the speed of the conveyor is outside the range of the setpoints then an indication will be made to the operator. No other automation control is required.

Exercise - Comparing With the Setpoints

1. Create the rungs for comparing the analog value.
i. Create two new rungs in the Speed Monitoring POU.
ii. Rename these rungs VS High and VS Low.

2. Program the rung to compare with the high setpoint

i. Place a contact at the start of the rung and assign it to address %M100.

The comparison only needs to be done when the conveyor is running.

ii. Select the Comparison Block tool a2 and place the block next to the contact.

iii. Click the Operation Expression above the Operation block and enter the expression %IW0.0 > %MW1.

iv. Add a coil to the rung and assign it to address %M121.

The completed rung should look like this

s76

3. Program the rung to compare the low setpoint.
i. Program the Low SP rung with the following objects and the expression %IW0.0 < %MW2

s77

4. Save the application.

Linking the Program Parts

Completing the application
In this final exercise the programs in the separate POUs will be linked together by adding contacts to rungs that were previously created. This linking is typical of the way a program is developed with new functionality and is sometimes called hooking in to the existing application.

The speed errors will be amalgamated into a single contact and that contact will be used to make the fault light flash. The fault relays will also be used to stop the conveyors.

Exercise - Complete the Program

1. Add a rung to indicate that the variable speed is OK.

i. Create a new rung in the Speed Monitor POU and rename it VS OK
ii. Add the following objects.

s78

2. Modify the fault light rung to make the light flash when the speed is not within the range of the setpoints.

i. Modify the Fault Light rung to the following
s79

Note:
This contains a contact using the address %S6, This is a system bit which turns on and off with a 1 second interval. It is often used to create cyclic actions such as flashing a light.

3. Modify the conveyor run rungs to make the conveyors stop when a fault occurs.

i. Modify the conveyor rungs to the following.

s80

4. Save the application