You are on page 1of 21

CPU and RTOS PLC Programming – Learn the basics with CoDeSys

CPU and RTOS


CPU and RTOS PLC Programming – Learn the basics with CoDeSys

PLC

Input Output

CPU
Boards Boards

I O
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

User Software Download

CPU
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Operating System

CPU
Operating System (OS)
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Operating System
Main Functions of an Operating System

• System’s resources management


• Device management
• Process execution and resources allocation
• User Interface (UI) Management
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Operating System
Main Functions of an Operating System

• System’s resources management


• Device management
• Process execution and resources allocation
• User Interface Management
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Operating System
Process Management in a standard PC
• Large number of tasks (e.g Task
Manager on Windows)

• «Pseudosimultaneous» execution
(Round Robin)
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Operating System
Process Management in a standard PC
• Large number of tasks (e.g Task
Manager on Windows)

• «Pseudosimultaneous» execution
(Round Robin)

• Very fast and frequent process


switches to create a
simultaneousness illusian

• Execution time is not a crucial


aspect
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Operating System

CPU REAL TIME

Within guaranteed time


Real-Time Operating System constraints
(RTOS)
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Real-Time Operating System


Funzioni principali di un Sistema Operativo

• System’s resources management


• Device management
• Process execution and resources allocation
• User Interface Management (NOT PRESENT ON PLCS)
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Real-Time Operating System


Process Management in a standard PC
• Few processes

• Static Priority Assignement

• Execution Time is a Crucial Aspect (Real Time)


CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Cyclic Task Scheduling


PLCs often use a Cyclic Task Scheduling

TASK
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Cyclic Task Scheduling


PLCs often use a Cyclic Task Scheduling

Important Tasks→ High Priority→ Small Cycle Times

Less Important Tasks→ Low Priority→ Large Cycle Times

Typically, as a rule of thumb, priority should be inversely proportional with


respect to cycle time
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Cyclic Task Scheduling


Example:

TASK Priority * Cycle Time


TASK_MachineControl
TASK_ExternalDeviceCommunication
TASK_HMI
TASK_Logging

*Codesys Notation: LOW INDEX → HIGH PRIORITY


CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Cyclic Task Scheduling


Example:

TASK Priority * Cycle Time


TASK_MachineControl 1
TASK_ExternalDeviceCommunication 2
TASK_HMI 3
TASK_Logging 4

*Codesys Notation: LOW INDEX → HIGH PRIORITY


CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Cyclic Task Scheduling


Example:

TASK Priority * Cycle Time


TASK_MachineControl 1 1 ms
TASK_ExternalDeviceCommunication 2 10 ms
TASK_HMI 3 100 ms
TASK_Logging 4 200 ms

*Codesys Notation: LOW INDEX → HIGH PRIORITY


CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Process - Task

Computational Load

Cycle Time
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Process - Task

T1 T1

T2
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Process - Task

T1 T1

T2
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Process - Task

T1 T1

T2

Missed Deadline
• In a standard PC, it may lead to a slowdown in operations
• In a PLC, it may lead to serious damage to the plant and
people
CPU and RTOS PLC Programming – Learn the basics with CoDeSys

Watchdog
Internal PLC mechanism, used to stop the CPU, whenever certain
«missed deadline» condition arise, in order to ensure the safety of the
plant.

You might also like