Fast Development of Controllers with Simulink
Coder
Radim Hýl, Renata Wagnerová
Department of Control Systems and Instrumentation
VŠB – Technical University of Ostrava
Ostrava, Czech Republic
[email protected], [email protected]
Abstract— The aim of this paper is to describe rapid design automatic generation of PLC code has been used, e.g. in [2] or
and realization of a embedded controllers by using MATLAB in [3] is used SIMATIC Automation Designer, which
toolboxes like Simulink Coder. The Simulink Coder generates generates ladder diagrams for industrial robot cells.
and executes C and C++ code from Simulink diagrams, Stateflow The paper is organized as follows. The value of MATLAB
charts, and MATLAB functions. An automatic code generation use in control praxis is mentioned in Section II. Used
enables implementation of Simulink controller models directly to
development environments and tools are defined in Section III.
the PLC without manual coding. The generated source code it is
possible to use for real-time and non-real-time applications,
Section IV deals with methodology of fast controller
including rapid prototyping and hardware-in-the-loop testing. development in Simulink. Section V outlines laboratory stand
The code can be tuned and monitored using Simulink or run and used for experimental tests. Section VI and VII explain two
interact with the code outside MATLAB and Simulink. The approaches of control design for multi-input multi-output
integration of I/O cards in the model enables the simulation of (MIMO) system and implementation of Simulink models to
data acquisition, so that control system can be performed directly Bachmann PLC. The paper concludes by Section VIII, which
from Simulink. The controls deployed to the real-time target can summarizes achieved results.
be used for communication with Simulink using the external
mode, and also can provide data exchange of process variables II. MATLAB IN CONTROL TECHNOLOGY
and block parameters to other applications on the PLC system MATLAB and Simulink provide many advantages
(IEC 61131, C, C++, Java). The controllers’ implementation was especially for developers dealing with the classical or modern
tested with climate unit laboratory model and predictive advanced control technology. Complex control oriented tasks,
controllers and decentralized PID controllers were used. which can normally be performed in the control technology by
installing expensive extensions, can be created, tested and used
Keywords— Laboratory model; Simulink Coder, PLC, Rapid
by applying mathematical models to the PLC like in [1]. The
prototyping
range of functions in MATLAB and Simulink, as well as the
I. INTRODUCTION associated specific toolboxes such as the Control System,
System Identification or Signal Processing, offer solutions for
The product families MATLAB and Simulink from demanding closed-loop control tasks. System identification
MathWorks are in fact worldwide standard for computer functions or advanced controllers (observation structures, fuzzy
simulation and Model-Based Design. Nearly all research control, adaptive systems, MIMO, ...) are already integrated in
departments in industry and at universities benefit from the this software platform. The direct use of these useful functions
advantages these tools provide. for real-time controller programming is actually quite a logical
But in modern automation installations in industry, the step [4]. Target for Simulink makes this possible in shorten
PLC device is the main element of applied control system. time and without any manual coding.
These devices are good adopted for running under hard A. What Is a Target?
conditions on the plants and operate with the almost all types
A target deploys MATLAB and Simulink designs to
of automation tasks. The PLC program itself determinates the
embedded hardware. With a target an application can be
level of automation and processes can be controlled through prototype, verify, and deploy by generating processor-specific
the set of instructions running in PLC. Thus the PLC program code, integrating real-time operating systems and device
becomes a base component for modern manufacturing. drivers, and profiling execution on used embedded hardware
Unfortunately, the manual coding of PLC programs may cause [5].
an extension of commissioning period. Therefore in [1],
automatic generation of PLC programs using rapid modeling B. Targeting Simulink Models to Real-Time Systems
and compiling tools is mentioned like an efficient method to Third-party products enable engineers to target Simulink
reduce the development time. Already several times before an models to a range of real-time platforms. Field Programmable
978-1-5090-4862-5/17/$31.00 ©2017 IEEE
406
Authorized licensed use limited to: COLLEGE OF ENGINEERING - Pune. Downloaded on September 03,2025 at 08:56:46 UTC from IEEE Xplore. Restrictions apply.
Gate Array (FPGA) and DSP developers can generate C code C. Bachmann SolutionCenter
from Simulink models and run their designs on prototyping Bachmann delivers with their PLC devices also the
boards. Additional Simulink libraries help engineers generate engineering tool SolutionCenter which allows configure PLC,
code for microcontroller-based designs, and processor create visualizations in Java or program PLC code in C/C++ or
simulator interfaces provide new testing capabilities. in IEC 61131(CoDeSys) standard. The part of SolutionCenter
Automation engineers can implement and test their models on used for standard programming in C/C++ languages is called
industrial controllers. Special application models for C/C++ Developer. It is based on Eclipse environment and
automotive or other fields in industry can be accelerated by allows import external libraries.
hardware-in-the-loop testing [5].
IV. DEVELOPMENT METHODOLOGY
III. DEVELOPMENT ENVIRONMENT In this research work, automatic generation of PLC code is
A. PLC Bachmann MC210 presented. The tests are carried out in real-time. Mathematical
model created in Simulink is automatically translated in C
The control algorithms were realized on powerful PLC
code and the control implementation to the PLC is done by
MC200 from company Bachmann with 1.6 GHz CPU and 1
GB RAM. The sufficient performance allows computation with using M-Target for Simulink software. In this it is necessary to
large matrices and has enough computational reserve to handle build model with the help of blocks which are available in
with many I/O and other interfaces. One or more applications Bachmann toolbox in a Simulink library. After doing
generated out of Simulink models may run stand-alone or co- configuration settings Simulink models are able to translate
existing with a number of classical PLC applications into a PLC code. The control systems models developed for
(IEC61131) or individual tasks written in C/C++ on the same control of laboratory model are elaborated. To show
controller at the same time. The underlying operating system applicability of methodology, two inputs and two outputs
allows hard real-time functionality. Interfaces are also provided (TITO) model control is described. The following steps have
for exchanging variable values both locally on the same device, to be done during controller deployment:
as well as also via the network.
• Design the controller in MATLAB/Simulink
• Model the complete control system
• Simulate under realistic conditions
• Generate executable code automatically
• Monitor process values in real time
• Verify the model
Fig. 1. Communication between SW modules running on one PLC [4] • Correct deviations
B. M-Target For Simulink • Interactive parameter tuning of controller as it runs on
the embedded hardware
M-Target enables the development of closed-loop controls
and sequential controllers on the modular industrial control • Model deployment for standalone operation
system from Bachmann Electronic GmbH. It is designed as an
additional target for Simulink Coder providing a blocks of I/O Logging of control results are realized by sink blocks in the
cards, as well as variable and parameter interchange blocks. Simulink model. Scope blocks and output ports can be
Simulink controller models are automatically translated to the connected to signals that are wanted to view and analyze once
C/C++ programming language without manual coding and the simulation has completed.
applied into PLC. The integration of I/O cards in the model V. CLIMATE UNIT LABORATORY STAND
enables the simulation of acquisition behavior and hardware-
in-the-loop measurements, so that automation system The research laboratories have two possibilities how to test
engineering can be performed directly from Simulink. new control concepts of real systems. The first option is a
definition of mathematical model of the real process and
Controls deployed to the real-time target are not only simulation of this process in simulation programs, e.g.
enabled for communication with Simulink using the external MATLAB/Simulink. The second way is the use of laboratory
mode, but also can provide data exchange for process variables stand which represents simplified real process. The advantage
and block parameters to other applications on the Bachmann of this solution is the possibility of real hardware application
system (IEC 61131, C, C++, Java). Execution triggers from like in industry together with MATLAB environment. The
hardware signals to latch I/O and position sensors for climate unit laboratory stand (Fig. 2) was used for the
synchronous, hard real-time, multi-axis motion can be used. simulations and tests of proposed control concepts [6].
Standard I/O cards for typical digital (24V) and analog control
signal levels (±1V, ±10V, 0/4..20mA, PT100, PT1000, etc.) are
provided, as well as fieldbus interfaces for PROFINET,
PROFIBUS DP, CAN, DeviceNet, SERCOS, Modbus, etc [4].
407
Authorized licensed use limited to: COLLEGE OF ENGINEERING - Pune. Downloaded on September 03,2025 at 08:56:46 UTC from IEEE Xplore. Restrictions apply.
MV1
MV2
. − −
.
CV1
. +
.
- −
. + CV2
VI. MPC CONTROL STRUCTURE
Most control systems are complex and multi-variable, i.e.
they consist of several measurement signals and control
signals, and there are often complicated couplings between the
Fig. 2. Scheme of climate unit laboratory stand different signals. A typical process control plant may contain
thousands of input and output signals. There are multi-variable
The laboratory stand is a hot air model and consists of the control techniques available today. For example, model-
bulb which is fed by the controllable power voltage. The bulb predictive control (MPC) has gained a lot of interest in recent
represents a heat source and is placed in the covered tunnel, years, both in academia and in industry. Interaction between
inside of which air is being blown through by the ventilator TITO system and MPC can be described like at Fig. 3. DV is
which is connected to the adjustable power voltage as well. For not considered.
measuring of conditions in the tunnel there are three
temperature sensors and one flow meter. In laboratory model CV2
disturbance can be introduced with disturbance ventilator
located in the tunnel next to main controlled ventilator. CV1
This laboratory stand represents MIMO system with two
inputs and two outputs. The first input is connected to the bulb MV1
which is an actuator effecting temperature in the tunnel. The PROCESS
second input is connected to the main ventilator and effects air MPC MV2
flow through the tunnel. The first output is temperature in the (2x2)
tunnel which is measured by one of the thermistors. The
second output is signal from flow meter. All signals were Fig. 3. Direct MPC process interaction
connected to the PLC I/Os. Therefore after identification
process, a transfer function matrix can be defined according the The MPC control structure was designed in Simulink (Fig.
Table I. It is assumed that the treated two-input two-output 4.) and by using Simulink Coder and M-Target for Simulink
(TITO) system is linear square stable non-singular system. In downloaded to the PLC. During our experimental verification
the following, inputs and outputs are referred to MVs the PLC was connected to the controlled laboratory model. The
(manipulated variables) and CVs (controlled variables). DVs chosen sampling period was 1 second. The prediction horizon
stand for disturbance variables and are considered as non- was set up to 50 seconds and the control horizon to 2 seconds.
controllable MVs. The weight vectors with weighting coefficients reflecting the
relative importance of MVs and penalizing changes in CVs
TABLE I. MVS, CVS AND DVS OF THE LABORATORY MODEL were [1 1] and [1 10].
MVs CVs DV
Disturbance
MV1- Bulb Voltage CV1 - Temperature
Ventilator
MV2 - Main Ventilator Voltage CV2 - Air Flow
Voltage
408
Authorized licensed use limited to: COLLEGE OF ENGINEERING - Pune. Downloaded on September 03,2025 at 08:56:46 UTC from IEEE Xplore. Restrictions apply.
Fig. 4. Simulink control scheme with MPC
The Fig. 5 and 6 show courses of set-points (SP1, SP2) and
controlled variables (CV1 - temperature, CV2 – air flow) and
Fig. 7 represents manipulated variables.
Fig. 7. Responses of MVs
VII. DECENTRALISED PID CONTROL STRUCTURE
Fig. 5. Responses of SP1 and CV1
Process control problems are traditionally solved using
single-loop PID controllers that are connected through well-
known couplings such as cascade control, feed-forward
control, ratio control, split-range control, etc. This chapter
presents design of a diagonal PID control of TITO system in
Simulink. When consider the system model defined by Tab. I,
two decentralized PI/PID controllers have to be used. For
autonomous control, also a decoupler had to be introduced
between the decentralized controller and the MIMO process to
eliminate the effect of interactions. In fact that bulb cannot
interact the flowing in the tunnel, only one correction element
had to be added. This correction was realized by transfer
function block according (1).
. . +
=− . = . (1)
. +
.
Fig. 6. Responses of SP2 and CV2
409
Authorized licensed use limited to: COLLEGE OF ENGINEERING - Pune. Downloaded on September 03,2025 at 08:56:46 UTC from IEEE Xplore. Restrictions apply.
The detailed study of the controllers and decouplers second control loop there is used PID controller with
presented here are given in [7] and [9]. parameters 0.49 (proportional), 0.26 (integral) and 0.28
(derivative).
The implemented PID controllers running in PLC got
automatically tuned with the same parameters, which were Due to fact, that second control structure was design in
used in Simulink. Determination of controller parameters in continuous manner, the sampling period used in second
Simulink was realized using PID tuner tool. In the first control example was set to 0.01 seconds. This configuration verifies
loop PI controller is used and its tuneable parameters are as that Simulink models using continuous time can be realized on
follows, proportional part 0.34 and integral part 0.08. In case of PLC.
Fig. 8. Simulink control scheme with two classical controllers
The Fig. 9 and 10 show courses of set-points (SP1, SP2)
and controlled variables (CV1 – temperature, CV2 – air flow)
and Fig. 11 represents manipulated variables.
Fig. 10. Responses of SP2 and CV2
Fig. 9. Responses of SP1 and CV1
410
Authorized licensed use limited to: COLLEGE OF ENGINEERING - Pune. Downloaded on September 03,2025 at 08:56:46 UTC from IEEE Xplore. Restrictions apply.
Due to fact, that second control structure was design in
continuous manner, the use of small sampling period verifies,
that Simulink models using continuous time can be realized on
PLC, too. The achieved results prove that described controller
development methodology can be applied with all benefit in
industry.
Acknowledgement
This research has been elaborated in cooperation with
research company VOIGT+WIPP Industrial Research in the
framework of the project No: SP2017/106 „Advanced Methods
for Machine and Process Control“ supported by the Ministry of
Education, Youth and Sports.
References
Fig. 11. Responses of MVs [1] R. Salunke, P. Vikhe and T. Sarode, “Implementation of automatic PLC
code from MATLAB simulation model using B&R automation target for
simulink,” 2nd International Conference on Control, Communication and
VIII. CONCLUSION Power Engineering, India, 2011.
This paper demonstrated a method for automatically [2] B. Mulman, T. Devinder, and W. Gi-Nam., “Generation of PLC Ladder
generating PLC code and controlling the process through Diagram Using Modular Structure,” International Conference on
simulation model. The methodology combines the high level Computational Intelligence for Modelling, Vienna, pp. 1194- 1198,Oct
2008.
simulation and lower level PLC control. Model-Based Design,
together with automatic code generation creates shorter and [3] P. Falkman, E. Helander and M. Andersson, “Automatic Generation: A
way of Ensuring PLC and HMI Standards,” Aerospace Conference,
more cost efficient design workflows. Above that, this concept IEEE ETFA'2011.
is profitable for control engineers, because it eliminates the [4] Bachmann electronic GmbH, Bachmann info. [Online], available from
differences between high level system modelling and lower http://www.bachmann.info/en/, 2017.
level programming. In advance, an effective MATLAB [5] MathWorks, MathWorks products. [Online], available from
functions can be used for control design and tuning. https://www.mathworks.com/, 2017.
[6] R. Hýl and R. Wagnerová, “Design and Realization of Embedded Model
For example, it is no longer necessary to formulate the Predictive Controller with Software Support,” 17th International
appropriate differential equation of the real controlled system Carpathian Control Conference, ICCC 2016, Slovakia, 2016, pp. 259-
for simulation needs in Simulink. The hardware components 264.
are simply added to the model as graphical blocks and [7] B. Sulc, and M. Vítečková, Theory and Praxis of Control Curcuits
interconnected. Therefore display and change online data Design, Czech Technical University in Prague, 2004, p. 333, ISBN 80-
directly from real-time systems in Simulink is possible. 01-03007-5. (in Czech)
[8] J. Dobeš, M. Kozubková and M. Mahdal, “Identification of the noise
The presented control of the laboratory model approved the using mathematical modelling”, 10th International Conference on
possibility of MPC controller implementation to the lowest Experimental Fluid Mechanics, Czech Republic, 2015.
level of hierarchical control structure. For comparison also [9] J. Macháček, Advanced Process Control Methods, University of
control structure with two decentralized PI/PID controllers was Pardubice, 2015, p. 164, ISBN 978-80-7395-937-1. (in Czech)
presented. From the responses of controlled variables it is [10] J. Skutova and J. Sikora, "Modeling of event-driven model of production
line," 2016 17th International Carpathian Control Conference (ICCC),
evident, that the MPC advantageously uses information about Slovakia, 2016, pp. 679-683.
future reference trajectories and reacts ahead. It leads to the
smooth curves of manipulated variables, which can save
energy in real processes in industry.
411
Authorized licensed use limited to: COLLEGE OF ENGINEERING - Pune. Downloaded on September 03,2025 at 08:56:46 UTC from IEEE Xplore. Restrictions apply.