Configurations
A configuration describes how the programs of a project are executed. It declares tasks, which run at fixed intervals or when a boolean signal changes from FALSE to TRUE, and assigns program instances to those tasks. Configurations are optional. Without a configuration, the SoftPLC creates one instance of each program, named after the program, and runs every program once per scan.
Contents
Declaring a Configuration
A configuration is declared between CONFIGURATION and END_CONFIGURATION, in any Structured Text file. It contains tasks, program instances and global variables. These can optionally be grouped into resources, which represent the processing units of a PLC.
CONFIGURATION Cell
TASK Fast(INTERVAL := T#10ms, PRIORITY := 0);
TASK Slow(INTERVAL := T#100ms, PRIORITY := 1);
PROGRAM Motion WITH Fast : MotionControl;
PROGRAM Supervisor WITH Slow : Supervision;
END_CONFIGURATIONA larger configuration can be split into resources, each with its own tasks, program instances and global variables. The name after ON identifies the type of processing unit, and is not used by the SoftPLC.
CONFIGURATION Cell
VAR_GLOBAL
LineSpeed : LREAL; // Shared by every resource.
END_VAR
RESOURCE MotionController ON PLC
TASK Fast(INTERVAL := T#10ms, PRIORITY := 0);
PROGRAM Axes WITH Fast : Motion;
END_RESOURCE
RESOURCE CellController ON PLC
VAR_GLOBAL
Alarms : INT; // Only accessible within CellController.
END_VAR
TASK Slow(INTERVAL := T#100ms, PRIORITY := 1);
PROGRAM Monitor WITH Slow : Supervision;
END_RESOURCE
END_CONFIGURATIONOn a physical PLC, resources often run on separate processors at the same time. The SoftPLC runs every resource sequentially, and orders the tasks by priority across all resources.
A configuration represents one PLC, so a project can only contain one configuration. Declaring a second configuration is a compile error.
Tasks
A task is declared with a name and its properties:
- INTERVAL: The time between executions of a cyclic task. The interval must be a multiple of the simulation timestep, which is 10 ms by default.
- SINGLE: A boolean signal, which triggers an event task. The task runs once each time the signal changes from
FALSEtoTRUE. The signal can be a global variable, an output of a program instance, or a direct address such as%IX0.0. - PRIORITY: The priority of the task, where 0 is the highest priority. When several tasks are due in the same scan, they run in order of priority.
TASK Cyclic(INTERVAL := T#20ms, PRIORITY := 1);
TASK OnTrigger(SINGLE := Trigger, PRIORITY := 2);Tasks never run in parallel. Within each scan, the due tasks are executed sequentially, and the programs assigned to the same task run in the order they are declared. A program instance without a task runs every scan cycle.
A physical PLC can start an event task as soon as its signal changes, for example through a hardware interrupt. The SoftPLC instead checks the SINGLE signal once per scan, so an event task starts in the scan in which its signal is first found to be TRUE. A signal that becomes TRUE and returns to FALSE between two checks is not detected, so the signal must remain TRUE for at least one timestep. A task with both SINGLE and INTERVAL runs periodically while its signal is FALSE, and once each time the signal changes to TRUE.
Program Instances
A program instance is declared with PROGRAM, followed by the instance name, an optional task, and the program type. The same program can be instantiated several times, for example once for each identical station of a machine. Each instance has its own variables.
The inputs and outputs of a program can be connected to global variables in the instance declaration, using := for inputs and => for outputs:
PROGRAM Station
VAR_INPUT
Start : BOOL;
END_VAR
VAR_OUTPUT
Running : BOOL;
END_VAR
Running := Start;
END_PROGRAM
CONFIGURATION Cell
VAR_GLOBAL
StartButton AT %IX0.0 : BOOL;
RunningLamp AT %QX0.0 : BOOL;
END_VAR
TASK Main(INTERVAL := T#10ms, PRIORITY := 1);
PROGRAM Left WITH Main : Station(Start := StartButton, Running => RunningLamp);
END_CONFIGURATIONIn this example, tags may be imported for the global variables Cell.StartButton and Cell.RunningLamp. The located variables of a program instance are named by the configuration, the resource (if any) and the instance. For example, a variable Sensor of the instance Left would be imported as the tag Cell.Left.Sensor, or Cell.Station.Left.Sensor when the instance is declared in a resource named Station.
Global Variables
Global variables can be declared in a configuration or a resource. A global variable of a configuration is accessible to every program instance in the configuration, including those in its resources. A global variable of a resource is only accessible to the program instances in that resource. Program instances access global variables by declaring them with VAR_EXTERNAL.
The tags of global variables are named by their scope. In the example above, the tags are Cell.LineSpeed and Cell.CellController.Alarms.
Configuring Variables
A VAR_CONFIG section assigns addresses to variables that are declared with a partly specified address (%I*, %Q* or %M*). This allows each instance of a program, or each instance of a function block within a program, to use different inputs and outputs.
PROGRAM Station
VAR
Sensor AT %I* : BOOL;
Lamp AT %Q* : BOOL;
END_VAR
Lamp := Sensor;
END_PROGRAM
CONFIGURATION Cell
TASK Main(INTERVAL := T#10ms, PRIORITY := 1);
PROGRAM Left WITH Main : Station;
PROGRAM Right WITH Main : Station;
VAR_CONFIG
Left.Sensor AT %IX0.0 : BOOL;
Left.Lamp AT %QX0.0 : BOOL;
Right.Sensor AT %IX0.1 : BOOL;
Right.Lamp AT %QX0.1 : BOOL;
END_VAR
END_CONFIGURATIONEvery partly specified address must be assigned in a VAR_CONFIG section. The path can include function block instances, for example Left.Clamp.Valve.