Vous êtes sur la page 1sur 6

Towards a Rapid Control Prototyping Toolbox for the Stellaris LM3S8000

Microcontrollers

Radu Duma
1)
, Petru Dobra
2)
, Mirela Trusca
3)
, Dorin Petreus
4)
and Daniel Moga
5)


1, 2, 3, 5)
Automatic Control Department,
4)
Applied Electronics Department
Technical University of ClujNapoca
(e-mail:
1)
radu.duma@aut.utcluj.ro,
2)
dobra@aut.utcluj.ro,
3)
mirela.trusca@aut.utcluj.ro,
4)
dorin.petreus@ael.utcluj.ro,
5)
daniel.moga@aut.utcluj.ro)
Abstract: The paper presents a Rapid Control Prototyping (RCP) toolbox for Matlab/Simulink, which is
used to generate real-time C code for the Stellaris LM3S800 family of microcontrollers from Texas
Instruments (TI). The toolbox, Target for Stellaris LM3S800, contains Simulink blocks, which implement
drivers and algorithms specific for the Stellaris LM3S800 family of microcontrollers. The paper presents
an ongoing work. For the moment the toolbox contains four libraries: I/O drivers, Digital Motor Control
(DMC), Controller Area Network (CAN) and LM3S8000 Target Preferences. A practical application for a
Computer Numerical Controlled (CNC) machine is presented.
Keywords: rapid control prototyping, microcontroller, closed-loop control, CNC machine, PID control

1. INTRODUCTION
Developing controllers for applications (electrical drive
systems) means large expenditure, when performed with
usual development methods. The workload comprises
development of a mathematical model as well as algorithm
design and implementation, off-line simulation, and
optimization. The whole process has to be restarted on
occurring errors or divergences, which makes the
development process time consuming and costly (Hanselman,
1996). Rapid Control Prototyping (RCP) is a way out of this
situation, especially if the control algorithm is complex and a
lot of iteration steps are necessary.
RCP requires two components: a Computer Aided Control
System Design (CACSD) software and a dedicated hardware,
capable of running tasks in real-time (Fig.1).

Fig. 1. The general architecture of a RCP system.
CACSD tools are extensively used to generate real time code
automatically. The graphical programming approach removes
the need to write software by hand and allows the engineer to
focus instead on improving functionality and performance.
Complete system design is carried out within the simulation
environment.
With the great diversity of applications, a development
environment must be flexible and provide exactly the
functionality necessary for efficient problem solving.
Mathworks' Simulink (Mathworks, 2010) software is such a
graphical modelling tool.
In Fig. 2 is presented the block diagram for the information
flow (from concept to model) and for the data flow (between
PC and the Stellaris LM3S8000 microcontroller) for the
implemented toolbox.

Fig. 2. Block diagram for the information and data flows for
the Target for Stellaris LM3S8000 RCP toolbox.
Control algorithms for the LM3S8000 microcontrollers can
be developed using blocks from the Target for Stellaris
LM3S8000 toolbox and predefined blocks from Simulink or
user defined blocks. After the validation of the model, code
can be generated using Real-Time Workshop. At the end of
the code generation process the Code Composer Studio
(CCS) Integrated Development Environment (IDE) is
automatically started, a new CCS project is created, the
generated code source files are added to the project, the
project is compiled and the binary file is downloaded to the
Preprints of the 18th IFAC World Congress
Milano (Italy) August 28 - September 2, 2011
Copyright by the
International Federation of Automatic Control (IFAC)
1965




target processor. The execution of the code can be monitored
in real-time using the implemented CAN drivers.
2. RELATED WORK
In this section is briefly presented some of the research
literature related to RCP. MathWorks developed toolboxes
for some wildly used targets: Motorola MPC555, Infineon
C166, C2000 and C6000 DSP families from Texas
Instruments. Rebeschiess (Rebeschiess, 1999) developed the
MICROS toolbox for standard 80C166 micrcontrollers. A
DSP based RCP system for engineering education and
research using as CACSD tool Matlab/Simulink is presented
in (Hercog et al., 2006). Duma and Dobra have implemented
a RCP toolbox for the Renesas M32C87 microcontroller
(Duma et al., 2010).
Microchip (Microchip, 2009) developed a Matlab RCP
toolbox for the dsPIC33 Digital Signal Controllers (DSC),
while Kerhuel (Kerhuel, 2009) developed a toolbox which
offers support for several Microchip microcontrollers and
DSCs.
National Instruments LabVIEW graphical code can be used
to develop ARM microcontroller embedded applications for
the Stellaris LM3S88962 using the LabVIEW Embedded
Module for ARM Microcontrollers (National Instruments,
2010).
A free, open source, RCP solution is based on Scilab/Scicos
(Campbell et al., 2009) and Linux-RTAI (Bucher et al.,
2004), which uses the processor of a general purpose
computer for executing real-time tasks. A real-time patch is
applied to the standard Linux kernel. A modified version of
the Scicos code generator, RTAI-Lab, generates hard real-
time code compatible with Linux-RTAI. Acquisition cards
can be directly integrated into the Scicos scheme and into the
generated code using drivers provided by the COMEDI
([Comedi]) project.
Ravn (Ravn, 2006) implemented an adaptive control toolbox,
for Scilab/Scicos, which can be used for RCP. A target
supported in Scilab/Scicos is the Microchip dsPIC DSC
microcontroller. Duma (Duma et al., 2009) presented a
system identification and control RCP toolbox for
Scilab/Scicos.
3. CODE COMPOSER STUDIO
It is important for an RCP toolbox to offer support for a
complete build process. A full post-code generation build
process includes: compilation of generated code, linking of
compiled code and runtime libraries into an executable
program module, downloading the executable to target
hardware with a debugger or other utility, initiating execution
of the downloaded program. Supporting a complete build
process is a complex task, because it involves interfacing to
cross-development tools and utilities that are external to the
Real-Time Workshop software (Mathworks, 2008).
CCS is the integrated development environment for TI's
DSPs, microcontrollers and application processors. CCS is
based on the Eclipse open source software framework and is
a file system based model IDE.
There are command-line utilities that come with CCS to
create, build and import a CCS project. Using these
commands at the end of the code generation process CCS is
automatically started, a new CCS project is created, the
generated code files are copied into the project directory and
the project is build. In the final version of the implemented
RCP toolbox Debug Server Scripting (DSS) will be used for
the automated download of the generated binary file on the
target processor.
4. TARGET FOR STELLARIS LM3S8000
The Simulink library for the Stellaris LM3S8000
microcontrollers is presented in Fig. 3. For the moment the
toolbox contains four libraries: I/O drivers, DMC, CAN and
LM3S8000 Target Preferences.

Fig. 3. The Target for Stellaris LM3S8000 Simulink toolbox.
The target processors for the implemented toolbox are the
Stellaris LM3S8000 family of microcontrollers. The Stellaris
family of microcontrollers - the first ARM Cortex-M3 based
controllers - brings high-performance 32-bit computing to
cost-sensitive embedded microcontroller applications. The
Stellaris LM3S8000 series combines Bosch Controller Area
Network (CAN) technology with both a 10/100 Ethernet
Media Access Control (MAC) and Physical (PHY) layer.
The LM3S8000 microcontrollers are targeted for industrial
applications, including remote monitoring, electronic point-
of-sale machines, test and measurement equipment, network
appliances and switches, factory automation, HVAC and
building control, gaming equipment, motion control, medical
instrumentation and fire and security.
Simulink blocks are defined by two functions: a MEX
function written in the C language and a Target Language
Preprints of the 18th IFAC World Congress
Milano (Italy) August 28 - September 2, 2011
1966




Compiler (TLC) implementation. The MEX function
configures the number of inputs/outputs ports of the block
and transfers the parameters specified in the graphical user
interface of the block in the code generation process. The
TLC implementation initializes the I/O device, computes the
value for the output of the block and terminates the program
by setting the hardware to a neutral state. For each block of
the toolbox the two files were implemented.
In the following sections the libraries of the toolbox are
briefly described.
5. I/O Drivers Library
The I/O drivers (Fig. 4) library contains drivers for the I/O
peripherals of the target processor.

Fig. 4. I/O drivers library.
For the moment the library contains two blocks, one for the
generation of PWM signals and one for input capture. In the
future we plan to implement drivers for the following
peripherals of the microcontroller: analog to digital converter,
digital input, digital output, quadrature encoder interface.
In Fig. 5 is presented the Function Block Parameters window
for setting the parameters of the LM3S000 PWM block. The
window contains several tabs which are described below.
Timer - in this tab the desired PWM generator can be selected
and timer related options can be specified (Up-Down or
Down count mode). The period of the PWM signal can be set
through the dialog (if it is fixed during program execution) or
through input port (if it is variable during program
execution). This option is useful because there are processes
which are controlled using a PWM signal with fixed duty
cycle and a variable frequency.
Output each PWM generator can generate two PWM
signals. In this tab one or both PWM outputs can be enabled,
the duty cycle of the PWM signals can be specified via dialog
or through input port. The PWM outputs can be
enabled/disabled through input ports. This feature is useful
for the control of three phase bridges.

Fig. 5. Function Block Parameters window of the LM3S000
PWM block.
Signal generator in Count-Down mode, there are four
events that can affect the PWM signal: zero, load, match
comparator A down and match comparator B down. In Count-
Up/Down mode, there are two supplementary events that can
affect the PWM signal: match comparator A up and and
match comparator B up. These actions can be used to
generate a pair of PWM signals of various positions and duty
cycles, which do or do not overlap.
Dead band - if dead band is enabled, the second output PWM
signal is the inversion of the first PWM signal with a
programmable delay added between the falling edge and the
rising edge of the PWM signals. This tab allows the
specification of the rising and falling edge delays between the
two PWM signals. The PWM signals with dead band are
used for driving a halfH bridge in order to avoid a short
circuit condition.
Synchronization this tab allows the specification of the
update mode for the timers and for the comparators used to
generate the PWM signals; the update mode for the PWM
generators and the dead band update mode.
ADC trigger specifies the events that generates ADC
trigger.
6. CAN library
Controller Area Network (CAN) is a multicast, shared serial
bus standard for connecting electronic control units. CAN
was specifically designed to be robust in electromagnetically-
noisy environments. Originally created for automotive
purposes, it is also used in many embedded control
applications. Bit rates up to 1Mbps are possible at network
lengths less than 40 meters.
An important feature which should be implemented by an
RCP toolbox is the real-time observation of the code
executed on the embedded processor (Mathworks, 2008).
One industry standard is the use of the CAN bus. For this
Preprints of the 18th IFAC World Congress
Milano (Italy) August 28 - September 2, 2011
1967




purpose the CAN library presented in Fig. 6 was
implemented.

Fig. 6. CAN library.
The library contains three blocks which are used for the
configuration of the CAN module:
CAN Configure the block specifies the CAN module used,
the operating mode and the baud rate.
CAN Transmit the block configures the slot of a CAN
module for the transmission of a message with a certain
identifier.
CAN Receive the block configures the slot of a CAN
module for the reception of a message with a certain
identifier.
7. Digital Motor Control Library
The DMC library (Fig. 7) contains blocks which implement
digital motor control algorithms.

Fig. 7. DMC library.
The implemented algorithms are optimized for the
LM3S8000 microcontrollers, which are fixed point
processors. Only integer variables are declared, and the
single-cycle multiply instruction and the hardware divide
features of Stellaris microcontrollers are used in order to
obtain the lowest sampling rate without breaking the real-
time constrains.
For the moment the library contains only a block which
implements a PID controller with antisaturation. The
structure of the controller is described in detail below. In the
final version of the toolbox the DMC Library will contain
blocks for three phase motor control and for BLDC motor
control.
More than 90% of the control loops are of PI and PID type.
The reason for which the PID controller is so widely used is
its simple structure which has proved to be very robust with
regard to many commonly control problems.
The standard equation of a PID controller is presented below:
|
|
.
|

\
|
+ + =
}
t
d
i
p
dt
t d
T d
T
t K t u
0
) (
) (
1
) ( ) (
c
t t c c

where ) ( ) ( ) ( t y t y t
sp
= c is the error signal,
sp
y is the
set point and y is the output of the process.
The discrete equations used for the implementation of the
PID algorithm are described below:
)) ( ) ( ( ) ( n y n y K n P
sp p
= |
)) ( ) 1 ( ( ) 1 ( ) ( n y n y n D n D
d d
+ = | o (1)
) ( ) ( ) ( ) ( n D n I n P n v + + =
)) ( ) ( ( )) ( ) ( ( ) ( ) 1 ( n v n u n y n y n I n I
t sp i
+ + = + | |
where ( ) Nh T T
d d d
+ = o , ( ) ( ) Nh T N T K
d d p d
+ = | ,
i s p i
T T K = | and
t s t
T T = | .
Equations (1) were used for TLC implementation of the
LM3S8000 PID block.
For the PID controller the following parameters have to be
chosen: K
p
, proportional gain; T
i,
integration time; T
d
,
derivative time; , fraction of command signal; N, high
frequency limiter of derivative action; u
min
, minimum
saturation value; u
max
, maximum saturation value; and T
s
,
sampling time. The block has two input ports: the reference
and the feedback signal and one output: the command signal
for the controlled process.
8. APPLICATION EXAMPLE
In order to test the implemented toolbox a practical
application for a Computer Numerical Controlled (CNC)
machine was implemented. The stepper motors of an old
CNC machine are replaced with Brushless Direct Current
(BLDC) motors, in order to obtain higher positioning
accuracy. For BLDC motor control, three PWM signals and
three activation signals are needed. Unlike a DC motor, the
Preprints of the 18th IFAC World Congress
Milano (Italy) August 28 - September 2, 2011
1968




BLDC motor must be commutated electronically. In order to
simplify the control of the BLDC motor, a control logic
circuit was implemented. Using this control logic circuit, a
BLDC motor can be controlled similarly to a DC motor. A
single PWM signal and a single feedback signal are needed.
The description of the control logic circuit is out of the scope
of this paper.
A Stellaris LM3S8962 Ethernet+CAN evaluation kit,
equipped with a LM3S8962 microcontroller is used as target
processor. The motor which is controlled is a Hurst-Emerson
BLDC motor ([Emerson]). In order to communicate between
the embedded processor and the PC, an USB to CAN
converter produced by Systec-Electronic ([SystecElectronic])
is used. The test setup is presented in Fig. 8.







Fig. 8. The test setup.
The closed loop Simulink model for the control of an axis of
the CNC machine is presented in Fig. 9. The model of the

control algorithm implements a cascade control topology. For
the position loop a PI controller is used and for the speed
loop a P controller is used. The parameters of the controllers
are computed using the method introduced by Kessler
(Kessler, 1958). The position reference is a rectangular
signal, which is applied on the reference port of a LM3S8000
PID bock. The output of the position controller sets the
reference of the speed controller. The speed controller
computes the duty cycle of the PWM signal which is used for
the control of the BLDC motor of the axis of the CNC
machine.
A configuration LM3S8000 CAN Configure block is added to
the model. It does not connect to any other blocks, but stands
alone to configure the selected CAN module.The reference
position, the measured position and the speed are
concatenated into an array and are sent over the CAN bus
using a LM3S8000 CAN Transmit block.
A target preference block has to be added to the model. The
LM3S8000 Target block does not connect to any other
blocks, but stands alone to set the target preferences for the
model. After the validation of the model the code generation
process is invoked, and the generated executable file is
downloaded to the LM3S8962 processor
The positioning of the axis of the CNC machine is shown in
Fig. 10 and the speed in Fig 11.
9. CONCLUSIONS
A contribution of the paper is the implementation of a RCP
toolbox for the Stellaris LM3S8000 family of
microcontrollers, using as CACSD tool Matlab/Simulink.
Until now, for these microcontrollers there was not a RCP
toolbox. The RCP approach removes the need to write
software by hand and allows the engineer to focus instead on
improving the performance of the control algorithm.

Fig. 9 Simulink block diagram for the control of an axis of the CNC machine.
CNC axis LM3S8000 Evaluation Kit USB-CAN Converter Driver Control Logic
Preprints of the 18th IFAC World Congress
Milano (Italy) August 28 - September 2, 2011
1969





Fig. 10. The positing of the axis of the CNC machine.

Fig. 11. Speed profile of the axis of the CNC machine.
In our opinion, the Traget for Stellaris LM3S8000 RCP
toolbox has some advantages over the code generation
solution offered by NI. First, the toolbox is targeted for all
the microcontrollers of the LM3S8000 family of ARM
microcontrollers, while in LabView only the LM3S8962
microcontroller is supported. Second, the developed RCP
toolbox is dedicated for the LM3S8000 processors, which
makes the graphical programming approach much easier than
in LabView, which offers support for several ARM
microcontrollers, among which the Stellaris LM3S8962
microcontroller.
The Stellaris microcontrollers are suited for motor control
and communication applications because motion plus
connectivity is possible only with a deterministic architecture
like ARM Cortex-M3. In the selection of the target processor
it is recommended to choose a widely available evaluation
board. The LM3S8962 Ethernet+CAN Evaluation Kit used in
the practical application presented is such an evaluation
board.
ACKNOWLEDGMENT
This paper was supported by the project Progress and
development through post-doctoral research and innovation
in engineering and applied sciences PRiDE - Contract no.
POSDRU/89/1.5/S/57083", project co-funded from European
Social Fund through Sectorial Operational Program Human
Resources 2007-2013.
REFERENCES
Bucher, R., Dozio L. and Mantegazza P. (2004). Rapid
control prototyping with Scilab/Scicos and Linux RTAI.
Scilab Conference.
Campbell, S. L., Chancelier, J.-P., and Nikoukhah, R. (2009).
Modeling and simulation in Scilab/Scicos with ScicosLab
4.4, Springer.
Duma, R., Dobra, P., Trusca, M., Dumitrache, D., and Sita, I.
V. (2009). Rapid control prototyping educational
toolbox for Scilab/Scicos, in Proc. of European Control
Conference 2009, pp. 4611-4616.
Duma, R., Trusca, M., and Dobra, P. (2010). BLDC Motor
Control using Rapid Control Prototyping, in Journal of
Control Engineering and Applied Informatics, vol. 12,
nr. 1.
Hanselman, H. (1996). Automotive control: from concept to
experiment to product, Proc. IEEE International
Symposium on Computer-Aided Control System Design,
pp. 129-134, Sept. 15-18.
Hercog, D., Curkovic, M., and Jezernik, K. (2006). DSP
Based Rapid Control Prototyping Systems for
Engineering Education and Research, Proceedings of
the 2006 IEEE Conference on computer Aided Control
Systems Design, Munich, Germany, October 4-6.
Kerhuel, L. (2009). Simulink - Embedded Target for PIC.
Kessler, C. (1958) Das symmetriche optimum.
Regelungstetechnik, 6, 395-400 , 432-436.
Mathworks (2008), Real-Time Workshop Embedded Coder 5
Developing Embedded Targets.
Mathworks (2010), Simulink users guide.
Microchip (2009), MATLAB/Simulink device blocksets for
dsPIC DSCs.
National Instruments (2010). Getting started with the NI
LabVIEW embedded module for ARM microcontrollers.
Ravn, O. (2006). Adaptive control using the adaptive
toolbox-TAT for Scilab/Scicos, 14th IFAC Symposium
on System Identification, Newcastle, Australia.
Rebeschiess, S. (1999).MIRCOS- microcontroller-based real
time control system toolbox for use with
Matlab/Simulink. Proc. IEEE Int. Symp.Computer
Aided Control System Design, pp. 267-272.
([Comedi]) Comedi. URL http://www.comedi.org.
([Emerson]) Emerson. URL http://www.emersonmotors.com.
([SystecElectronic]) SystecElectronic. URL
http://www.systec.com

Preprints of the 18th IFAC World Congress
Milano (Italy) August 28 - September 2, 2011
1970

Vous aimerez peut-être aussi