LC001 - Release
LC001 - Release
Liam Bee
ALVEARE LEARNING
Alveare Learning LC001 Liam Bee
Contents
LC001 - The Basics Of Programming With Codesys............................................. 3
Course Outline ........................................................................................................ 3
Story Board ............................................................................................................. 4
C-B-0001 - Introduction To CODESYS .................................................................... 5
About CODESYS .................................................................................................... 5
Versions.................................................................................................................. 5
Downloading CODESYS ........................................................................................ 5
Why Choose CODESYS?....................................................................................... 6
C-B-0002 - CODESYS Environment ........................................................................ 7
CODESYS Environment Overview ......................................................................... 7
Key Areas ............................................................................................................... 8
Additional Tools ...................................................................................................... 9
X-B-0001 - PLC Fundamentals .............................................................................. 11
IO Hardware Isn't Always Needed! ....................................................................... 12
PLC Data Types ................................................................................................... 12
Program Organisation........................................................................................... 18
C-B-0003 - CODESYS Hardware Setup ................................................................. 19
Setting Up Hardware ............................................................................................ 19
Adding A PLC ....................................................................................................... 19
Device Setup ........................................................................................................ 21
Configuration Of Sub-Devices / Fieldbus Networks .............................................. 21
Adding IO.............................................................................................................. 22
Installing New Devices.......................................................................................... 23
C-B-0004 - CODESYS POUs .................................................................................. 24
POU Overview ...................................................................................................... 24
Creating A POU .................................................................................................... 24
Configuring A New POU ....................................................................................... 25
POU Properties..................................................................................................... 26
Key Properties ...................................................................................................... 26
C-B-0005 - CODESYS Tasks .................................................................................. 27
What Is A “Task”? ................................................................................................. 27
Adding A Task To Projects ................................................................................... 27
Configuration Of Tasks ......................................................................................... 28
X-B-0002 - Ladder Logic Introduction .................................................................. 29
What Is Ladder Logic (LAD/LD)? .......................................................................... 29
Key Points ............................................................................................................ 29
Strengths .............................................................................................................. 30
Weaknesses ......................................................................................................... 30
Common Instructions & Functions ........................................................................ 31
X-B-0003 - Structured Text Introduction .............................................................. 34
What Is Structured Text (ST/SCL)? ...................................................................... 34
Key Points ............................................................................................................ 34
Strengths .............................................................................................................. 35
Weaknesses ......................................................................................................... 35
Common Instructions & Functions ........................................................................ 35
X-B-0004 - Function Block Diagram Introduction ................................................ 37
What Is Function Block Diagram (FBD)? .............................................................. 37
Key Points ............................................................................................................ 38
Strengths .............................................................................................................. 38
Weaknesses ......................................................................................................... 38
Common Instructions & Functions ........................................................................ 39
C-B-0006 - Sequential Function Chart – CODESYS............................................. 40
What Is Sequential Function Chart (SFC)?........................................................... 40
Key Points ............................................................................................................ 41
Methods ................................................................................................................ 41
Strengths .............................................................................................................. 42
Weaknesses ......................................................................................................... 42
Things To Note ..................................................................................................... 42
C-B-0007 - Continuous Function Chart – CODESYS ........................................... 43
What Is Continuous Function Chart (CFC)? ......................................................... 43
Key Points ............................................................................................................ 44
Modes ................................................................................................................... 44
Strengths .............................................................................................................. 45
Weaknesses ......................................................................................................... 45
Common Instructions & Functions ........................................................................ 46
Course Outline
LC001 - The Basics Of PLC Programming With Codesys takes a student through the
basic principles of a PLC, CODESYS as a development platform and then looks at
key components to get started with such as POUs, Tasks and adding a Soft PLC to
a project to work with.
This course also features a simulated section where the course will explore multiple
languages that all control a simulated chemical make-up system.
Story Board
When this material is taught live, the below story board outlays the lesson plan
About CODESYS
CODESYS is a “Free” development platform for a multitude of different devices.
Although CODESYS has been around for quite some time, it is still yet to receive the
recognition it deserves as a serious development platform, despite being the choice
platform for plenty of companies (some major companies too such as Schneider &
ABB)
Versions
CODESYS has two different major releases, version 2.3 and version 3.5. The
differences between these two versions are quite substantial and 3.5 vastly improved
on its previous version.
CODESYS as we see it now is version 3.5 + any service packs that are installed.
Most of the courses supplied by Alveare Learning will be built on Version 3.5 +
SP16
Downloading CODESYS
Codesys can be downloaded by visiting the 3S CODESYS market place -
https://store.codesys.com/
Key Areas
Below details the key areas of the development environment
Legend
Additional Tools
CODESYS is packed full of different tools and utilities, however, there are some that
aren’t immediately obvious that shouldn’t be overlooked
Simulation Mode
o Located in the Online menu
The Simulation mode is a great way to simply get started without any hardware.
Once simulation is on, you’ll see a simulation icon on the bottom status bar of the
CODESYS Editor that looks like this
Note
The version Of CODESYS documented here is CODESYS 3.5 + SP16 + Patch 2
There is an important difference between Simulation Mode and the built in Soft
PLC. The biggest difference is that the Soft PLC is network capable, meaning
protocols such as Modbus and Profinet can be tested. This is not the case for
Simulation Mode
Communication Settings
o This is accessible via double clicking the Device from the Project
Explorer (Area 1 above)
o Once in this view, you can connect to different PLC / Devices that fit
your application configuration
o You’ll need to do this if you ever connect to physical hardware for a
live project, or if you want to connect to the Soft PLC in windows.
A PLC needs to acquire data, process that data and then respond via it's defined
logic. Above we can see that in action. The CPU is on the left, followed by an Input
Card and then an Output Card.
This type of setup is a modular setup, meaning more cards can be added, in
different orders, or even no cards can be included if the inputs /outputs are coming
from a network for example.
The above diagram shows that the PLC is receiving data from the two valves and the
pump. This data could be feedback in for form of Digital signals to say when the
pump is running and the valves are closed / open.
Once the Input Card processes the signal received, it is passed to the CPU where we
can interact with it via our logical program.
The logic is stored and executed in the CPU (most commonly referred to as "The
PLC"). The CPU is the brains of the operation, receiving data, processing that data
and passing outputs back to the Output Cards.
When the Output Cards receive a command from the CPU, they close relays /
transistors to create electrical signals that are then used to signal to valves / pumps
to operate correctly.
In this example, no I/O cards are required because the information is relayed to the
CPU directly via the Ethernet Network that the VSDs are connected to.
A data type is as simple as the name suggests, its a Type that tells the PLC program
what sort of information will be stored in the Variable. These different types have
different Lengths and consume more memory. Some Types take up different
amounts of memory depending on what they are placed between. Some Types can
even be converted into other Types too.
These Data Types are the bread and butter of programming, you'll get nothing done
without them!
Each Data Type has a specified size and also a "Common" use, although this can vary
depending on the project and what you are actually doing with the data.
The "Boolean" Data Type is probably the most common type that gets used, you'll
use these for all of your TRUE / FALSE conditions. They're as simple as a data type
typically gets, however the memory they consume can be a little complicated to get
your head around
The above tells us that the only options we have for this Type is "True or False". The
little numbered squares show how many "Bits" in a "Byte" of memory the "Boolean"
Type uses. In this case, it uses 1 Bit of the Byte.
However, if we had two Booleans next to each other, our memory consumption
would still be 1 Byte, but 2 Bits in that Byte would be used. This continues until we've
filled all Bits in our Byte. This means that 8 Booleans = 1 Byte and also anything
between 1 and 8 still equals 1 Byte when they are not consecutively followed by
more Booleans!. So be careful if you are scattering Booleans between other Types as
this can increase the memory consumption quite considerably!
Byte (Hexadecimal)
The "Byte" Data Type is also a heavily used Data Type, especially useful for things
such as Statuses and collective "bit" data. This is because a "Byte" is a numerical
value that directly represents the bits that are turned on.
A Byte cannot be anything else other than a Byte, two next to each other would
simply be 2 Bytes next to each other and nothing else.
A Byte is made up of 8 bits and when these bits are switched on and off, there are up
to 256 combinations using Binary. This means that a Byte has an applicable
numerical range of 0 - 255.
Bytes, due to the nature of the Data Type, can be easily converted between
individual Booleans and a complete byte. For example, in the PLC you may have a
Byte named as "MyByte1", but you want to access the 6th bit of that Byte as you are
storing Boolean values packed together in a Byte. You can do this by using
MyByte1.%X6 (Siemens). In other editors, you should be able to access with
MyByte1.6
The approach of addressing Boolean Values in a Byte Type is not a new concept, its
exactly how I/O Cards work, you'll notice that IO nearly always comes with channels
that are in multiples of 8, and in nearly all cases you can address an entire 8 channel
IO card with a single Byte (however, for simplicity and ease of use, I don't actually
recommend that this is done)
Word (Hexadecimal)
The "Word" Data Type is simply an extended version of a Byte. It is double the
length, so holds 16 bits of data
Just like the Byte, this Data Type is typically used for statuses and Boolean
compacting into "Words". You'll often see in documentation for VSD drives (and
other networked devices) the terminology "Status Word" and "Control Word".
These Words refer to the fact that they are Word Types and all of the current states
are stored in these 16 bits. In modern and newer applications, the "Control Word"
may contain more than just one Word, but this is where the name comes from.
Note that due to the longer length of the Data Type, the numerical range has
increased to 65535, which is the number of available patterns that can be made with
16 bits (2 Bytes)
DWord (Hexadecimal)
The "DWord" Data Type is an extension again of the Word, meaning that 4 Bytes are
used, or 2 Words to create a "Double Word".
This is the largest Data Type in the Hexadecimal range for a 32-bit PLC. Once again,
it follows the same theme for usage as the Byte and Word.
The "Representative Value" is the amount that Bit is worth when it is turned ON
(True). So if the following Byte value was 155, the bits would have to look like this:
The summated "Bits" correspond to the current value, so when Bits 7, 4, 3, 1 & 0 are
all True, the representative value for this = 155.
This also works the other way around, because the value is 155, we know that Bits 7,
4, 3, 1 & 0 are True, meaning we don't need to test all 5 as Boolean variables, we can
simply check the value as a direct Byte by checking if the Byte = 155.
The "Sint" and "USint" Data Types are the smallest numerical Data Types available.
They are the same size as a Byte and therefore can only hold 8 bits of information.
The key difference between the two is that the "U" in USint stands for "Unsigned",
this means the number can only be positive, where as the Sint Data Type is "Signed"
and can be negative.
Notice how the USint data type has exactly the same numerical range as the Byte
data type, but the Sint data type has the same spread, but different start and end
ranges. This is because "Signed" types use the last Bit to determine if a value is
positive or negative. If the last bit is TRUE (Bit 7 in this case), then the value is
negative.
The same principles apply for Int & UInt as they do for SInt & USInt. The Int / UInt
data type is 2 Bytes long, like the Word type.
The above shows us the same setup that we've seen already with SInt, the last Bit
(15) is used for signage and therefore reduces the maximum available positive value
so that the negative range is also accessible.
You'll also notice that the Unsigned range is the same as the Word Data Type, this is
because they use the same amount of Bits.
Just as we've seen with the Double Word, its a 4 Byte Type and capable of a much
higher value range
Again, the last Bit of the Data for the DInt is used to show signage.
The "Real" Data Type is a special and commonly used type. You'll see and use this
type often when working with things such as Scaled Values, as a degree of accuracy
is required.
Unlike the above Data Types, the Real Type is a little more complicated under the
hood. Whilst it uses 4 Bytes, the degree of accuracy can change depending the
values being worked with.
The range of a Real is enormous due a system that's used by the PLC to represent
additional value against Bits. In the above image, the Blue Bits are used to hold
decimal information and the Yellow Bits are used to hold the Integer part.
At this point, a Wiki on floating point does a much better job of explaining how this
type works than I can - You can find it here
However, one thing that you should consider is that Reals are subject to rounding in
almost 100% of cases, not all numbers are actually obtainable and as numbers get
further away from 0, the accuracy drops away exponentially. These traits can cause
issues with logic if you are not careful.
One thing to realise is that between the above data types, every type that is used
in any other Type is referenced above. Every single type, custom or standard must
consist of Bytes, Words or DWords. In essence, every type is made up of Bytes.
Program Organisation
Almost every PLC has some form of Task Management. There are two common
types of this in two different forms, but they both share a commonality - Objects.
1. Task Management
a. Some PLCs use Tasks to organise the execution of code. These are Tasks
that manage Entry Points into a program. Once the Entry Point has
started, it continues until the code is finished. The Task may then call the
same, or a different Entry Point depending on what is happening.
a. A Parent Object (or program block) is predefined within the editor and
acts as an Entry Point. This then calls Child Objects as and when they
are scanned in the Parent’s logic. Different Parent Objects can be utilized
(together or independently) to create interrupts and segregated tasks
In both of the above scenarios, the Entry Points will still call other Objects such as
Function Blocks, Functions and other technical objects that your PLC program may
be using
Once all of these aspects come together, this forms the PLC programs we use to
control our physical assets.
Adding A PLC
Win V3 PLC
In the Examples below, we’re adding a Win V3 PLC. This is the Soft PLC used by
Codesys that allows you to test your program functionality with a generic PLC
that’s simulated inside your Windows Computer.
1. Right-click your project from the Devices pane on the left of CODESYS
(Sometimes referred to as the Project Explorer)
2. Choose Add Device
Note: There may be more in your list if you’ve installed more PLCs in the Device
Repository
4. Click Add Device and the device will be added to your project.
Multiple Devices
More than one device, even of the same type, can be added to a project. Just
remember though, only 1 can be simulated at any one time
Device Setup
You can access the device setup, where you can configure items such as the
communication settings, Backup settings, PLC Settings and more, by simply double
clicking the Device in the left-hand side Device pane
Adding IO
If you have added a PLC with configurable / expandable IO, you can add IO modules
into the virtual chassis that appears under the compatible device:
If you right-click on the <Empty> module slots and choose Plug Device, you can
pop-up the familiar window that allows you to choose a device.
Once you add the device to the module slot, you are then able to access the devices
mapping facilities by double clicking the module you’ve added your device to as
shown below
Win V3 PLC
You can’t add IO to a Soft PLC
Missing Libraries
Once you’ve added hardware via Device Descriptions, you may have errors about
missing libraries. If you do, double click the error in the information pane at the
bottom of the CODESYS screen. You’ll be taken to the Library Manager where
you can then click the Download Missing Libraries button and finish off your
install
Creating A POU
1. In the Devices Pane (Project Explorer) on the left hand side, right-click in on
any folder or on the Application Icon
2. Choose Add Object
3. Choose POU…
Once a new POU has been added, a new dialogue will appear. This is then used to
configure what type of POU is required
There are a few areas to consider
Name
o The name you want to give your POU
o Try to keep names meaningful QUARTER_TURN_VALVE_MANAGER
means a lot more than VALVE
Type
o Program
This is an Entry Point into your project / solution. Programs are
linked to Tasks and are called cyclically or by other means to
execute their program requirements
o Function Block
The most common type of re-usable code
Allows for Instances of the same code, allowing two Function
Blocks to behave the same, but with different data
Capable of retaining data between Program Cycles
CODESYS is capable of “OOP” when using function blocks,
this is configured using the additional options when
selecting a Function Block. This is advanced
o Function
Re-usable code block
Does not have any memory, it “forgets” values every time it is
used
Implementation Language
o The language that the POU is written in
POU Properties
By right-clicking on a POU and choosing Properties, you can configure some
additional options
Advanced Options
Some of the options in the Properties dialog are advanced and can fundamentally
change the way the POU behaves. Its highly unlikely that at this stage all options
would be required
Key Properties
Build
o Exclude From Build
This is extremely handy for testing purposes. By checking this
box you can exclude the POU from being compiled and
downloaded to the PLC. It’s highlighted green once this is
selected so indication is given that its not being included
o External Implementation - Advanced
This allows the POU to skip the compiling process and the PLC
links the POU to the process during runtime. This is advanced
and is sometimes required when dynamic information that is
created in Runtime is not available in development time and
causes compilation of the POU to fail
CFC Execution Order
o This is useful if the POU being developed (which needs to use CFC as
the language) needs to have an explicit flow of data. The Execution
Order can be modified to suit the POUs needs, it can also be applied
to all POUs of this implementation language
Access Control - Advanced
o Using the CODESYS Administration Utilities, the POU can be
protected against unwanted user interaction
Bitmap
o Create your own image associated with the object
This can be useful if many different libraries or POUs are in use. Also
helpful for standardisation of POUs from a visual perspective
Siemens
For people familiar with Siemens, a Task in CODESYS is the equivalent of using
the appropriate OB#
Note: This may already exist when some devices are added / Projects are
created
2. Right-Click on the Task Configuration and choose
Add Object → Task
3. A new Task will be created underneath the parent Task Configuration
4. Drag a POU that is a Program (PRG) type onto the Task to add it to the
Task’s execution responsibilities
Configuration Of Tasks
By double-clicking on a Task, the Task Configuration will open and options
presented that allow configuration of how the Task operates
Priority
o Tasks can have different priorities. This means that if a Task is
triggered at the same time as other Task, the one with the lowest
priority will execute first (the lower the number the higher the priority)
Type
o Cyclic
Run the attached POU’s cyclically at a declared interval period
o Event
When a Variable that is specified becomes True, the POU will
execute once. The variable must go False before the POU can
run again
o Freewheeling
The POU’s specified will run again as soon as all are complete
o Status
The POU’s specified will run in the same manner as
Freewheeling, but only when the specified Variable is True
Watchdog
o The Watchdog allows the Task to be given a finite amount of time to
finish a complete execution. This is helpful for safety sensitive
applications.
o Time
The time required before a Watchdog condition is deemed
erroneous
o Sensitivity
Essentially the amount of consecutive exceptions of the
watchdog are allowed before an actual watchdog fault occurs.
Ladder Logic is probably the most common language used in PLC programming,
however that is slowly changing as PLCs become more and more powerful.
Ladder has become so popular due to its reliability, ease of use and its ability to suit
most types of application. It gets its name from the “Ladder” like view it has, although
most development environments no longer join the right hand vertical rail.
Key Points
Left → Right then Up → Down scan cycle
Left most vertical rail is the Power Rail - a constant TRUE signal
Logic is applied along the horizontal “Rung”, ending with a Coil or Instruction
When monitored, logic flows from the Power Rail to the coils through
instructions and contacts
Areas of code are segmented into “Networks” or “Rungs”
Networks usually must start with an instruction or comparator, however some
environments allow exceptions
Some configurations of Instructions may not be allowed, such as branching
around Timers or Function Blocks, however this changes depending on what
environment the development is in
Strengths
Weaknesses
Poor portability between different environments
Difficult to handle mathematical equations and other numerical scenarios
Tendency to always be used over other languages for “Familiarity” purposes
Unable to iterate over loops without JUMP instructions, which can lead to
poorly organised code
Comments / Documentation usually limited in some fashion due to size of
Network
o Contact
Test for a TRUE value
o Negated Contact
Test for a FALSE value
o Coil
Writes the value of the preceding logic to the variable assigned
If preceding logic results in a TRUE the coil value is also TRUE
If preceding logic results in a FALSE the coil value is also
FALSE
o Set Coil
If preceding logic results in a TRUE the coil variable is set to
TRUE and remains set to TRUE until a Reset Coil sets the
variable value to FALSE
o Reset Coil
If preceding logic results in a TRUE the coil variable is set to
FALSE
Comparators
o EQ - Equal
OUTPUT is TRUE when INPUT 1 and INPUT 2 are equal
o NE - NOT Equal
OUTPUT is TRUE when INPUT 1 and INPUT 2 are NOT equal
o LT - Less Than (<)
OUTPUT is TRUE when INPUT 1 is less than INPUT 2
o GT - Greater Than (>)
OUTPUT is TRUE when INPUT 1 is greater than INPUT 2
o LE - Less Than Or Equal To (<=)
OUTPUT is TRUE when INPUT 1 is less than or equal to
INPUT 2
o GE - Greater Than Or Equal To (>=)
OUTPUT is TRUE when INPUT 1 is greater than or equal to
INPUT 2
Math Functions
Unlike other languages, Structured Text is a purely Text Based language. This
means it can be written in any text editor, easily transported between different
development environments.
Structured Text is quickly becoming a popular language to develop PLC logic with.
This is mainly because of the fact it’s so similar to other text based languages and
also because of the advantages it holds with Loops.
Key Points
Top → Down Scan Cycle
Unlike most other PLC Languages, outputs appear before the conditions that
set them
Does not require intermediate variables in order to process multi-conditional
statements
Extremely useful with Arrays due to Loop capabilities
Comments can be much more in depth thanks to free-text comments
Can be copied and pasted into other editors with relative ease
Strengths
Weaknesses
Difficult to read unless a format is adopted such as the use of comments and
regions
Prone to user-error and mistyping
Lack of support from lower end PLCs and older development platforms
Monitoring is ugly in nearly all editors
Basic Instructions
o Setting A Value
Bool1 := True;
Bool1 := False;
o Notice the :=, this means Set Value, whereas = only means EQ
o Reading A Value
Value := Bool1;
o Note the ;, this must be present at the end of any code that sets a
variable or calls a function.
//Calling A Function
Result := MyFunction(In_1:= Var_1, In_2:= Var_2);
o The => denotes an Output, whereas the := denotes an Input (or InOut)
Calling A Loop
//Loop Through Array And Check If Any Values Are True
FOR i := 0 TO 9 BY 1 DO
IF Result = FALSE THEN
Result := VarArray[i];
END_IF
END_FOR
Math Functions
Result := ((Var_1 + Var_2) / Var_3) * Var_4;
More ST
There are a lot more ST examples and instructions that can be given and
explained. It warrants an entire course rather than a simple module
Key Points
All Block Inputs → Block Outputs Scan Cycle
Areas of code are segmented into “Networks” or “Rungs”
All “Instructions” are Function Blocks / Functions (or are at least represented
in that manner)
Strengths
Weaknesses
Lines cannot be crossed, resulting in variables being used to “bridge the
gaps” (as seen above with OSR.Q)
Some unnecessary & functions are required sometimes due to the inability to
cross lines
Networks can become massive and long vertically if a lot of & / OR blocks are
used in one network
Conversion To Ladder
Some PLC environments can convert freely between Ladder and Function Block
Diagram as their representation always compiles to the same base code.
Other Aspects
Nearly all other instructions / functions in FBD are the same as Ladder Logic. The
only difference is how it is graphically represented
Sequential Function Chart is different from other languages, in that it isn’t really a
“Language” in its own right. SFC is still capable of controlling basic functions such as
setting a Boolean value to TRUE or FALSE, but it falls short in being able to do much
else without employing some special measures.
SFC is best at one very particular type of logic control… Sequences. The sequence
flow employed by SFC is simple, STEP TRANSITION JUMP. Steps must be
preceded by a transition and followed by a transition. Transitions must be Boolean
results, of which a TRUE result “opens the gate” and allows the sequence to
transition to the next step.
A Jump will be at the end of the sequence, returning to a known step so that the
sequence can start again. Jumps can also be utilised elsewhere to jump transitions
to other steps.
Key Points
Top → Down Scan Cycle
Very structured sequence pattern of Steps & Transitions
Capable of basic Boolean control by using Action Associations
Steps are capable of calling Entry, Exit and Active Step Logic, in any
language as an Action
o This particular feature makes CODESYS' implementation of SFC
extremely powerful
Methods
There are two different methods to using SFC, they can be used in tandem or one
can be picked over the other
1. Action Associations
2. Step Actions
a. Step actions allow the Parent SFC Object to create child Actions that
are then associated with a step. These actions can be implemented in
any language and share the variables from their parent. The available
action types are:
b. Entry Action - When entering the step, the assigned action will run
once (shown by an E in the bottom left of the step)
c. Step Action - When the step is active, the assigned action will run
once per scan until the step is no longer active (shown by a “folded
corner” in the top right of the step)
d. Exit Action - When exiting the step, the assigned action will run once
(shown by an X in the bottom right of the step)
Strengths
Built for sequences
Steps able to call any implementation language
Actions for Steps act as encapsulation, ensuring simplicity in sequence
Graphical and easy to follow
Weaknesses
Transitions can become long, which causes long sideways scrolling
Jumps from parallel branches can cause strange behaviour if not properly
controlled
Large sequences end up with many child Actions, which can become
confusing without a proper naming convention
Online edits of the code need to be carefully managed, much more so than
other languages as more elements are involved at once
Different editors employ different design principles, how CODESYS works
does not necessarily translate to other platforms
Things To Note
Logic Pattern
The SFC design for logic must be Initial Block → Transition (Sequence Start) →
Step → Transition … Jump (End Of Sequence)
CFC is an adaption of Sequential Function Chart that allows the developer a little
more free-reign in where objects are located and how objects interact with each
other.
Rather than using Transition gates, CFC uses Wires or Flows to move information
around the POU. Inputs and Outputs are assigned using dedicated elements.
There are two view modes in CFC:
Page Oriented
Non-Page Oriented
CFC in CODESYS is more popular amongst users who have migrated from
platforms such as PCS7
Key Points
Scan Cycle determined by Flow of POU
Two types of modes - Page driven and non-page driven
Flow mode can be auto or explicitly defined
Highly visual, great for high-level print outs
Offers some functionality that is not available in other languages such as
“breaking out” of structures and variable lists into easy to use, on the fly
interfaces
Modes
When a POU is being added and the implementation language is being selected,
CFC has two options
Page Oriented
When using the CFC (page oriented), inputs are placed on the left and
outputs are placed on the right
This gives the appearance and feel of creating an interface for the logic in the
center
This also makes things easier to read
Pages are listed on the left of the development pane. Each page can be given
a name
Variables are shared between pages, allowing data to be passed between
pages from the Output of page 1 to the input of page 2 for examples.
Non-Page Oriented
Strengths
Very visual, useful for offline viewing / printing
Great for high-level flow control
Useful for I/O to Variable mapping where I/O is conditioned
Weaknesses
Tedious to work with due to lines automatically routing
Slow to program due to Input / Output Elements needing placing all the time
and “Click & Drag” style linking
Can become extremely messy easily
If “Flow Mode” is set to explicit and is not monitored carefully, the execution of
blocks may not be in the order expected and lead to unexpected results.
Composer / Selector
o The above is the Selector which allows a data type or Variable List to
be wired to it and then each element in that data set will appear as an
output of the Selector. This is great for providing on the fly interfaces
to parts of data sets. In other languages this can be tedious.
o The Composer is simply the reverse of the above, where many input
elements are brought together and placed in an output defined as a
data type.
Note: the Composer requires the connected output to be instantiated,
this means Global Variable Lists cannot be used, but a UDT (User
Defined Type) inside a Global Variable List can be used as it’s
instantiated in the variable list.