Sie sind auf Seite 1von 22

dSPACE and Real-Time

Interface in Simulink






Azad Ghaffari






San Diego State University
Department of ECE
San Diego
CA 92182-1309
12/20/2012
This document provides a tutorial introduction to the dSPACE
software (ControlDesk Next Generation version !"!#$% the
dSPACE DS##& '(D controller )oard% and their use in
development and implementation of maximum power point
trackin* (+PPT$ for a sin*le photovoltaic (P,$ module usin*
extremum seekin* (ES$ in Simulink software! -t is intended for
use as a .uick/start *uide to dSPACE hardware0software for a
universit1 course! 2ull details on the dSPACE hardware and
software can )e found in the dSPACE documentation! This
presentation is prepared )ased on the followin* packa*e3
+AT4A5 ,ersion 6!#"('"&##a$% Simulink ,ersion 6!6
('"&##a$% and dSPACE D,D 'elease 6!7 ("&#"$!

1
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU
Contents
#! S1stem 'e.uirements !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "
"! dSPACE Packa*e !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "
7! 'eal/Time and the Structure of a 'eal/Time Pro*ram !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 7
! Photovoltaic +odule and +aximum Power Point Trackin* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8! Controller Desi*n and -mplementation in Simulink !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 6
8!# Analo* to Di*ital Conversion (ADC$ and Si*nal Scalin* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #&
8!" Di*ital to Analo* Conversion (DAC$ and -nitiali9ation 0Termination!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ##
8!7 5uildin* the Simulink +odel !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #"
:! Control Desk Environment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #
6! ;ow to Prepare the Tutorial Pro<ect !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #8
6!# ;ow to +easure ,aria)le ,alues !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #6
=! Experimental 'esults !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "&
>! 'eferences !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! "#


2
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU
1. System Requirements

You can use an x8-com!ati"le !ersonal com!uter as a host PC for #our dSPACE a!!lications
$ith follo$in% s!ecifications&

'ost !rocessor& Pentium ( at ) G'z *or e+ui,alent-
.ain memor#& ) G/ RA. or more *recommended-
0isk s!ace& 121 G/ on the !ro%ram !artition for com!lete installation of the 030
0on%le licenses& A 4S/ !ort& To install the execution ke# *don%le-
Re+uired slots& To install a 0S556(7 #ou need one free 88 .'z98)-"it 1 3 PCI slot

Control0esk :ext Generation ,ersion (2)25 $hich is a !art of dSPACE 030 Release ;28 su!!orts
follo$in% o!eratin% s#stem&

<indo$s =P Professional *8)-"it ,ersion- $ith Ser,ice Pack 8
<indo$s 3ista /usiness7 4ltimate7 and Enter!rise *8)-"it ,ersion- $ith Ser,ice Pack )
<indo$s ; Professional7 4ltimate7 and Enter!rise *8)-"it or (-"it ,ersions- $ith Ser,ice Pack 5

(-"it .AT>A/ ,ersions are not su!!orted2 Real-Time Interface to Simulink $hich is a !art of
?RCP and 'I> soft$are? *Ra!id Control Protot#!in% and 'ard$are-in the->oo! soft$are-
su!!orts the follo$in% ,ersions of .AT>A/& R)65)a7 R)655"7 R)655a7 R)656"SP57 R)656a7
R)66@"SP52
2. dSPACE Package

To implement a real-time control loop using dSPACE and MATLAB we need following items.

52 dSPACE 0S556( RA0 Controller /oard


)2 0on%le licenses on a 4S/ flash disk

3
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU
82 >icense2ds! file
(2 Be#s2ds! file
12 Connector !anel CP556(

3. Real-Time and the Structure o a Real-Time Program

Su!!ose $e ha,e a continuous s#stem and $e $ant to control it $ith a discrete controller $hich
has sam!lin% time !eriod of T2 The follo$in% fi%ure sho$s the connections "et$een the s#stem
and its controller2 <e need analo%-to-di%ital con,erters *A0C- to read the information of the
sensors2 Also to a!!l# the control commands $e need di%ital-to-analo% con,erters *0AC-2

Fig. 1: Real-time control structure

/ecause this s#stem or o"Cect has certain d#namics associated $ith it7 #ou ha,e to control it
"ased on those d#namics2 Therefore $e sa# that the !h#sical s#stem $ill ha,e a time constant7
from $hich #ou $ill deri,e a ste! size or sam!le time for #our control !ro%ram2 The challen%e is
to not onl# use that sam!le time in the numerical calculations that make u! #our control
al%orithm7 "ut also to execute that al%orithm $ithin that sam!le time2 You ha,e to start each
Dste!E of #our !ro%ram exactl# one sam!le time or ste! size a!art7 and thus ha,e to finish the
"
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU
com!utation of each ste! $ithin the sam!le time7 i2e2 "efore the next ste! starts2 This is real-time2
Please see the dia%ram "elo$2


Fig.2: Real-time control timing

If the sam!le time of our !ro%ram is T7 #ou can see that the !ro%ram is executed at distinct !oints
in time that are one sam!le time a!art2 You $ill also note that each ste! of the !ro%ram finishes
executin% "efore the next ste! is due to startF thus this !ro%ram is runnin% in real-time2 If
ho$e,er the com!utational demands of the !ro%ram cause the !rocessor to take more time than
the sam!le time then $e ha,e an o,errun condition7 and our !ro%ram cannot run in real-time2
The o,erall structure of a real-time !ro%ram can "e sim!lified for ex!lanation !ur!oses into
three main sections& Initialization7 the real-time task or tasks7 and the "ack%round2 The
initialization section is code that is executed onl# once at the start of execution7 u!on do$nload
of the !ro%ram2 In this section #ou $ill ha,e functions that7 for initialization of the s#stem7 are
onl# needed to run once2 The next !art of the !ro%ram is the real-time !art7 the task7 re!resented
"# the %ra# sections in the dia%ram a"o,e2 This is $hat is executed !eriodicall# "ased on the
sam!le time2 This !art is the heart of the control !ro%ramF for this7 #ou read in!uts *e2%27 from an
A0C-7 com!ute #our control si%nals7 and $rite out!uts *e2%27 $ith a 0AC-2 :ote that de!endin% on
$hat #our control a!!lication is #ou ma# ha,e multi!le tasks in #our model2 Ginall#7 the last
section is the "ack%roundF this is code executed in the DidleE time "et$een the end of
com!utation of a ste! and the start of the next ste!2

!. Photo"oltaic #odule and #a$imum Po%er Point Tracking

The P3 cell is modeled as an ideal current source of ,alue i
s
in !arallel $ith an ideal diode $ith
,olta%e v
d
2 Electrical losses and contactor resistance are accounted for "# the inclusion of the
!arallel and series resistances R
s
and R
p
7 res!ecti,el#2 The amount of %enerated current i
s
is
de!endent on the solar irradiance S and the tem!erature T.


Fig. 3: PV module electrical equivalent circuit
#
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU

As is clear from follo$in% fi%ure the !o$er-,olta%e *PH3- characteristic has a uni+ue "ut (T, S)
de!endent !eak2

Fig. 4: Power and current variations of a PV module for different solar irradiance an environmental temperature

It is the Co" of the .PPT al%orithm to automaticall# track this !eak2 In man# %rid-tied P3 s#stems
*includin% our current $ork-7 this is done "# means of a se!arate 0C90C !o$er electronics sta%e2
'ere $e use a 0C90C "uck con,erter as follo$s2


Fig. 5: DC-DC Buck converter to harvest power from a PV module

The a,era%ed model of the "uck con,erter in Continuous Conduction .ode *CC.- is descri"ed as

v =
v
dc
u


$
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU
$here u is the !ulse duration a!!lied from !ulse-$idth modulation unit to the %ate of the s$itch2
3ariation of the !o$er ,ersus !ulse duration for a P3 module $ith P
m
= 12<7 I
oc
= 21.6 37
I
sc
= 8uu mA7 I
m
= 17.237 and I
m
= 7uumA under standard test conditions is sho$n in the next
fi%ure2

Fig. 6: Power versus duty cycle

<hen !o$er is less than maximum ,alue and the dut# c#cle is less than o!timal dut# c#cle the
cur,e has a !ositi,e slo!e and increasin% the !ulse duration results in hi%her !o$er %eneration2
<hen the dut# c#cle is lar%er than the o!timal dut# c#cle the !o$er cur,e has a ne%ati,e cure
and decreasin% the !ulse duration %enerates more !o$er2 At the !eak !oint the slo!e of the
cur,e is zero and there is no need to chan%e the !ulse duration2 /ased on this information $e
em!lo# extremum seekin% al%orithm to estimate the %radient of the cost function and to
im!lement the %radient descent o!timization scheme2 The !ro!osed scheme is sho$n follo$in%2



Fig. 7: Extremum seeking algorithm for Maximum Power Point Tracking of a PV module

Su!!ose $e ha,e the estimate of the !ulse duration7 u
`
2 If this ,alue is less than o!timal dut#
c#cle7 the !o$er ,aries in !hase $ith the !ertur"ation in!ut2 If the estimate of !ulse duration is
%reater than the o!timal dut# c#cle the !o$er chan%e is out of !hase $ith the !ertur"ation in!ut2
This causes the estimate of the %radient7 g7 "e !ositi,e or ne%ati,e7 res!ecti,el#2 The hi%h-!ass
filter remo,es the 0C !art of the !o$er and the lo$-!ass filter is used to remo,e the oscillator#
%
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU
!arts of the estimate of the %radient2 <e use the Po$er-!ole circuit "oard to construct the 0C90C
"uck con,erter2

Fig. 8: Power-pole board used as a buck converter.

&. Controller 'esign and (m)lementation in Simulink

In this section $e $ill discuss ho$ to use Simulink for controller desi%n and ho$ to com!ile the
Simulink model into code that $ill run on the dSPACE "oard for real-time im!lementation of the
controller2 <hen $e start .AT>A/ follo$in% messa%e a!!ears7 $hich sa#s that dSPACE Real-
Time Interface *RTI- is installed for se,eral hard$are !latforms7 in this case 0S556(2 To sto!
sho$in% this messa%e $hen .AT>A/ starts #ou can check the "ox2




The closed-loo! s#stem is sho$n as follo$s2 <e need to measure the !o$er %enerated "# the P3
module2 Gor this !ur!ose $e measure the current and ,olta%e of the 0C "us usin% the A0C in!uts
8
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

of 0S556(2 The command %enerated "# the extremum seekin% is
a!!lies to the in!ut of the P<. %enerator2

Su!!ose that #ou "uild a maximum !o$er !oint trackin% "ased on extremum seekin%
Simulink as sho$n "elo$2 Sa,e #our !roCect in
need to sense7 current and ,olta%e7
the Simulink model of the controller sho$n "elo$&


The construction of this "lock dia%ram $ill "e discussed in more detail "elo$2 Gor
ho$ $e create the soft$are interface "et$een the controller and the !lant
%enerates control in!uts and read sensor ,alues-2 The di%ital to
are !ro,ided in Simulink $hen the dSPACE soft$are is
sho$n a"o,e to %enerate the control in!ut to
see the dSPACE "locks one can t#!e
follo$in% $indo$ is sho$n&

Time Interface in Simulink
D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g
of 0S556(2 The command %enerated "# the extremum seekin% is the !ulse duration $hich
P<. %enerator2
maximum !o$er !oint trackin% "ased on extremum seekin%
2 Sa,e #our !roCect in E:\Work2 :o$ that $e ha,e the si%nals that $e
7 current and ,olta%e7 and actuate7 dut# c#cle7 $e can consider the de,elo!ment of
the Simulink model of the controller sho$n "elo$&
The construction of this "lock dia%ram $ill "e discussed in more detail "elo$2 Gor
ft$are interface "et$een the controller and the !lant *i2e27 the interface that
%enerates control in!uts and read sensor ,alues-2 The di%ital to analo% con,ersion *0AC- "locks
are !ro,ided in Simulink $hen the dSPACE soft$are is a,aila"le2 'ence7 $e use a
sho$n a"o,e to %enerate the control in!ut to the !lant and an A0C "lock to read the
t#!e rti from the .AT>A/ command $indo$2 If #ou do that the
SDSU
ulse duration $hich

maximum !o$er !oint trackin% "ased on extremum seekin% in
:o$ that $e ha,e the si%nals that $e
$e can consider the de,elo!ment of

The construction of this "lock dia%ram $ill "e discussed in more detail "elo$2 Gor no$7 focus on
*i2e27 the interface that
analo% con,ersion *0AC- "locks
a,aila"le2 'ence7 $e use a 0AC "lock as
the !lant and an A0C "lock to read the si%nal2 To
command $indo$2 If #ou do that the
9
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU


If #ou dou"le-click on each of these "locks7 #ou are %oin% to find the "locks necessar# to "uild the
simulation that #ou need2 :ote that there are Demos that ma# "e useful to #ou2 Also7 note that
there is a Help "utton #ou ma# find useful2 :ext7 $e $ill discuss interface issues2

The RTI556( /oard >i"rar# seen a"o,e is di,ided into some main sections2 The I9I resources of
the 0S556( are s!lit "et$een the t$o !rocessors on the "oard7 the .aster PPC *Po$er PC- and
the Sla,e 0SP G)(62 /# clickin% on either one #ou $ill ha,e access to "locks #ou can !lace in #our
model that !ro,ide I9I functionalit# associated $ith the res!ecti,e !rocessor2 Gor this tutorial
$e $ill focus on the %rou! of "locks contained in the .aster PPC section2 If #ou dou"le-click on
this #ou $ill %et the follo$in% $indo$&



As #ou see7 this $indo$ has some of the most commonl# used elements for the controller "oard7
such as A0Cs7 0ACs7 Encoders7 etc2 If #ou dou"le-click on an# of these I9I "locks #ou $ill %et its
10
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU
res!ecti,e confi%uration dialo% "ox7 and one of the "uttons #ou $ill see in this dialo% "ox is
Help2 Clickin% on this $ill launch the dSPACE 'el!0esk exactl# at the !a%e referencin% that
!articular "lock2 'ere7 $e clicked on dSPACE 'el! and do$nloaded the rele,ant information on
the A0C and 0AC that $e need for the tem!erature control !ro"lem2 You can also launch the
dSPACE 'el!0esk from the JStart>All Programs>dSPACE ControlDesk 4..!>dSPACE HelpDesk
"ControlDesk 4..!#7 or if #ou are usin% Control0esk :G #ou can launch it from the 'el! menu or
sim!l# "# hittin% the $! ke#2

&.1 Analog to 'igital Con"ersion *A'C+ and Signal Scaling

The master PPC on the 0S556( controls an A0C unit featurin% t$o different t#!es of A90
con,erters&
Ine A90 con,erter *A0C5- multi!lexed to four channels *si%nals A0C'5 K A0C'(-2The in!ut
si%nals of the con,erter are selected "# a (&5 in!ut multi!lexer2 The A90 con,erters ha,e the
follo$in% characteristics&
o 5-"it resolution
o L56 3 in!ut ,olta%e ran%e
o L 1 m3 offset error
o L 62)1M %ain error
o N86 d/ *at 56 k'z- si%nal-to-noise ratio *S:R-
Gour !arallel A90 con,erters *A0C) K A0C1- $ith one channel each *si%nals A0C'1 K
A0C'8-2 The A90 con,erters ha,e the follo$in% characteristics&
o 5)-"it resolution
o L56 3 in!ut ,olta%e ran%e
o L 1 m3 offset error
o L 621M %ain error
o N ;6 d/ si%nal-to-noise ratio *S:R-

To confi%ure the soft$are so that it can %et this si%nal into the controller $e click on ADC in the
u!!er left corner *note the la"el on the "ottom of that "utton-2 In the $indo$ that comes u!
there is a 'el! "utton2 If #ou click it7 #ou $ill see&


11
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU

'ere7 $hen #ou !lace an A0C "lock in a Simulink model *"# dra% and dro!- and then dou"le click
it7 all #ou need to select is the C%annel n&m'er. :ext7 it is im!ortant to understand the s(al)ng
that occurs in ac+uirin% the si%nal2 The !h#sical in!ut si%nal in!ut ran%e is H563 to O5632 dSPACE
al$a#s scales this "# a factor of 625 *multi!lies "# this num"er- to !lace the ,alue on a ran%e of H
53 to O532 <e need to take the A0C si%nal and multi!l# "# 56 to remo,e the scale factor2



&.2 'igital to Analog Con"ersion *'AC+ and (nitiali,ation -Termination

The master PPC on the 0S556( controls a 09A con,erter2 It has the follo$in% characteristics&
o 8 !arallel 0AC channels *si%nals 0AC'5 K 0AC'8-
o 5-"it resolution
o L56 3 out!ut ,olta%e ran%e
o L 5 m3 offset error7 56 P39B offset drift
o L 625M %ain error7 )1 !!m9B %ain drift
o N86 d/ *at 56 k'z- si%nal-to-noise ratio *S:R-
o Trans!arent and latched mode

To confi%ure the soft$are to %enerate the out!ut si%nals $e click on DAC on the left side7 third
"lock do$n *note the la"el on the "ottom of that "utton-2 In the $indo$ that comes u! there is a
'el! "utton2 If #ou click it7 #ou $ill see&



12
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

'ere7 note that if #ou !lace a 0AC "lock in #our Simulink model and dou"le click it there are
se,eral settin%s that need to "e made *note the ta"s near the to! of the $indo$-2 Girst7 on the
*n)t ta" #ou need to select the channel num"erF here it is channel 5 *0AC'57 !in P5A 85-2 :ext7
under the +n)t)al),at)on "-erm)nat)on
on $hich ex!eriment #ou hook u!7 the choice of these ,alues can dictate smooth and safe
o!eration of the ex!eriment *e2%27 so that #ou do not hurt the ex!erimental e+ui!ment-2


Gor instance7 if the initial ,alue for some mechanical s#stem
to s!innin% a motor at its maximum rotational s!eed2 :ote that in %eneral these ,alues should "e
,ie$ed as the ones that are in!ut to the !lant immediatel# "efore and after the actual control
s#stem o!erates2 'ence7 for exam!le7 if #ou initialize the out!ut to "e zero there ma# "e a shar!
chan%e at the first sam!lin% instant $hen the controller ma# !ut out a different ,alue *analo%ous
comments hold for termination-2
:ote that such a shar! chan%e is somethin% that #ou ma#
im!lementation since it can ha,e effects on the transient res!onse *e2%27 for some ex!eriments
#ou ma# $ant to make sure that the initial transients due to such effects ha,e died out "efore
#ou test the res!onse of the s#stem to a ste! set !oint chan%e-2
&.3 .uilding the Simulink #odel

Ince $e define the model7 $e ha,e to chan%e some !arameters in the simulation2 To do this7 in
the Simulink model7 use DS)m&lat)on > Con.)g&rat)on Parameters
$indo$2

Time Interface in Simulink
D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g
'ere7 note that if #ou !lace a 0AC "lock in #our Simulink model and dou"le click it there are
to "e made *note the ta"s near the to! of the $indo$-2 Girst7 on the
ta" #ou need to select the channel num"erF here it is channel 5 *0AC'57 !in P5A 85-2 :ext7
"-erm)nat)on- ta" #ou !ick the initial *final- ,olta%e ,alu
on $hich ex!eriment #ou hook u!7 the choice of these ,alues can dictate smooth and safe
o!eration of the ex!eriment *e2%27 so that #ou do not hurt the ex!erimental e+ui!ment-2
Gor instance7 if the initial ,alue for some mechanical s#stem $ere 5637 then this ma# corres!ond
to s!innin% a motor at its maximum rotational s!eed2 :ote that in %eneral these ,alues should "e
,ie$ed as the ones that are in!ut to the !lant immediatel# "efore and after the actual control
exam!le7 if #ou initialize the out!ut to "e zero there ma# "e a shar!
chan%e at the first sam!lin% instant $hen the controller ma# !ut out a different ,alue *analo%ous

:ote that such a shar! chan%e is somethin% that #ou ma# ha,e to !a# attention to in an actual
im!lementation since it can ha,e effects on the transient res!onse *e2%27 for some ex!eriments
#ou ma# $ant to make sure that the initial transients due to such effects ha,e died out "efore
s#stem to a ste! set !oint chan%e-2
.uilding the Simulink #odel
Ince $e define the model7 $e ha,e to chan%e some !arameters in the simulation2 To do this7 in
S)m&lat)on > Con.)g&rat)on Parameters and #ou $ill see the follo$in%
SDSU
'ere7 note that if #ou !lace a 0AC "lock in #our Simulink model and dou"le click it there are
to "e made *note the ta"s near the to! of the $indo$-2 Girst7 on the
ta" #ou need to select the channel num"erF here it is channel 5 *0AC'57 !in P5A 85-2 :ext7
- ta" #ou !ick the initial *final- ,olta%e ,alue2 0e!endin%
on $hich ex!eriment #ou hook u!7 the choice of these ,alues can dictate smooth and safe
o!eration of the ex!eriment *e2%27 so that #ou do not hurt the ex!erimental e+ui!ment-2

$ere 5637 then this ma# corres!ond
to s!innin% a motor at its maximum rotational s!eed2 :ote that in %eneral these ,alues should "e
,ie$ed as the ones that are in!ut to the !lant immediatel# "efore and after the actual control
exam!le7 if #ou initialize the out!ut to "e zero there ma# "e a shar!
chan%e at the first sam!lin% instant $hen the controller ma# !ut out a different ,alue *analo%ous
ha,e to !a# attention to in an actual
im!lementation since it can ha,e effects on the transient res!onse *e2%27 for some ex!eriments
#ou ma# $ant to make sure that the initial transients due to such effects ha,e died out "efore
Ince $e define the model7 $e ha,e to chan%e some !arameters in the simulation2 To do this7 in
and #ou $ill see the follo$in%

13
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g


Girst7 in the Sol/er o!tions *see ta"- set the
The Stop t)me can "e set accordin% to ho$ #ou $ant the ex!eriment to run2 If #ou set it as
it $ill %o fore,er7 "ut if #ou set it to )6
to a Gixed-ste! o!tion7 and !ick a sol,er such as
com!lex sol,ers #ou choose the more com!utationall# intensi,e #our !ro%ram $ill "e and thus
$ill re+uire more time to execute2 :ext7 !ick the sam!lin% time for the ex!eriment2 This is the
sam!lin% rate7 $hich is t#!icall# denoted "# DTE in di%ital control "ooks7 and it sets the sam!lin%
rate for the sensed si%nals and control u!dates2 If #ou ha,e a contr
com!utations $ithin the sam!lin% !eriod such that the# cannot "e com!leted in time7 then #ou
$ill encounter an o,errun condition and #ou $ill %et an error attestin% to this u!on do$nload of
the !ro%ram to the 0S556(7 and #ou $il

After #ou chan%e this7 %o to the Ad/an(ed
o!tion 0..1 so do that to o"tain the next fi%ure&


Ince #ou follo$ed these ste!s7 #ou are read# to "uild the model2 Yo
short-cut command C-2345 *from $ithin the Simulink model- or %o to
> 5&)ld 6odel2 C code is %enerated for the model and then this code is com!iled and linked "#
the Po$er PC com!iler *since the 0S55
executa"le o"Cect file $ith a .pp(
and the !ro%ram starts runnin% *i2e27 executin% the controller-2 If there are an# errors durin% the
"uild !rocess or #ou run into an o,errun condition this $ill "e !rinted in the
$indo$7 other$ise if all %oes $ell #ou $ill see the messa%e
You can sto! the !ro%ram on the 0S556( in the Control0esk7 on the
click on 0S556( and click on
sto!!in% the $hole !ro%ram7 thus the real
$a# $ill not execute or ena"le functions associated
Time Interface in Simulink
D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g
o!tions *see ta"- set the Start t)me to 6 *needed for real-
can "e set accordin% to ho$ #ou $ant the ex!eriment to run2 If #ou set it as
it $ill %o fore,er7 "ut if #ou set it to )6 it $ill run the ex!eriment for )6 sec2 :ext7 set the DT#!eE
ste! o!tion7 and !ick a sol,er such as E&ler or !erha!s ode7. :ote that the more
com!lex sol,ers #ou choose the more com!utationall# intensi,e #our !ro%ram $ill "e and thus
uire more time to execute2 :ext7 !ick the sam!lin% time for the ex!eriment2 This is the
sam!lin% rate7 $hich is t#!icall# denoted "# DTE in di%ital control "ooks7 and it sets the sam!lin%
rate for the sensed si%nals and control u!dates2 If #ou ha,e a controller that demands too man#
com!utations $ithin the sam!lin% !eriod such that the# cannot "e com!leted in time7 then #ou
$ill encounter an o,errun condition and #ou $ill %et an error attestin% to this u!on do$nload of
the !ro%ram to the 0S556(7 and #ou $ill ha,e to raise the sam!lin% rate2
Ad/an(ed o!tion ta"7 and #ou should ha,e the
so do that to o"tain the next fi%ure&
Ince #ou follo$ed these ste!s7 #ou are read# to "uild the model2 You ha,e t$o o!tions& the
*from $ithin the Simulink model- or %o to -ools > Code 8enerat)on
C code is %enerated for the model and then this code is com!iled and linked "#
the Po$er PC com!iler *since the 0S556( uses a Po$er PC !rocessor- to !roduce a sin%le
.pp( extension2 This executa"le is then do$nloaded to the 0S556(
and the !ro%ram starts runnin% *i2e27 executin% the controller-2 If there are an# errors durin% the
rocess or #ou run into an o,errun condition this $ill "e !rinted in the .AT>A/
$indo$7 other$ise if all %oes $ell #ou $ill see the messa%e S&((ess.&l (omplet)on
You can sto! the !ro%ram on the 0S556( in the Control0esk7 on the Plat.orm9De/)(e
Stop 2-P2 :ote that sto!!in% the !ro%ram this $a# means
sto!!in% the $hole !ro%ram7 thus the real-time task and the "ack%round routine7 and that this
$a# $ill not execute or ena"le functions associated $ith the termination state7 such as the
SDSU
-time a!!lications-2
can "e set accordin% to ho$ #ou $ant the ex!eriment to run2 If #ou set it as )n.
it $ill run the ex!eriment for )6 sec2 :ext7 set the DT#!eE
:ote that the more
com!lex sol,ers #ou choose the more com!utationall# intensi,e #our !ro%ram $ill "e and thus
uire more time to execute2 :ext7 !ick the sam!lin% time for the ex!eriment2 This is the
sam!lin% rate7 $hich is t#!icall# denoted "# DTE in di%ital control "ooks7 and it sets the sam!lin%
oller that demands too man#
com!utations $ithin the sam!lin% !eriod such that the# cannot "e com!leted in time7 then #ou
$ill encounter an o,errun condition and #ou $ill %et an error attestin% to this u!on do$nload of
o!tion ta"7 and #ou should ha,e the J5lo(k red&(t)on

u ha,e t$o o!tions& the
-ools > Code 8enerat)on
C code is %enerated for the model and then this code is com!iled and linked "#
6( uses a Po$er PC !rocessor- to !roduce a sin%le
extension2 This executa"le is then do$nloaded to the 0S556(
and the !ro%ram starts runnin% *i2e27 executin% the controller-2 If there are an# errors durin% the
.AT>A/ command
S&((ess.&l (omplet)on in .AT>A/2
rm9De/)(e ta" ri%ht
2 :ote that sto!!in% the !ro%ram this $a# means
time task and the "ack%round routine7 and that this
$ith the termination state7 such as the
1"
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU
termination ,alues for the 0AC channel2 To ena"le the termination condition or state #ou ha,e to
sto! onl# the real-time task7 and chan%in% a certain ,aria"le in the !ro%ram does this2
/. Control 'esk En"ironment

You should sit in front of a com!uter $ith dSPACE soft$are and the 0S556( "oard2 Iur intent in
this first section is to lead #ou throu%h ho$ to start u! the soft$are and understand its main
functions2 In the next section $e $ill sho$ ho$ to use the soft$are and hard$are to im!lement a
,er# sim!le control s#stem2
Girst7 from the PC o!eratin% s#stem7 the follo$in% shortcut ena"les access to the dSPACE
Control0esk en,ironment2 If the shortcut does not exist on the deskto! !lease launch
Control0esk from the dSPACE ControlDesk 4..! folder under Start\All Programs2 Either $a#7
once #ou access it7 #ou $ill find the follo$in% $arnin% messa%e2 /# checkin% the "ox and
selectin% JQAcce!tQQ "utton #ou $ill not see this messa%e in the future launches2




The follo$in% illustration dis!la#s Control0eskRs user interface and sho$s the control"ars #ou
$ill use in this tutorial.

1#
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU

Control0esk is a user-interface2 The 0S556( "oard is considered a !latform on $hich a
simulation is run7 Cust as .AT>A/ is also a !latform to run non-real-time simulations on2 Grom
this en,ironment7 #ou $ill "e a"le to do$nload a!!lications to the 0S556(7 confi%ure ,irtual
instrumentation that #ou can use to control7 monitor and automate ex!eriments7 and de,elo!
controllers2 :otice that in the ,ie$ sho$n a"o,e *default $indo$ settin%s for the Control0esk-
#ou see different re%ions2 Plat.orm ta" sho$s the different simulation !latforms that
Control0esk can interface to2 In the re%ion on the "ottom *Tool <indo$-7 $hen #ou select the
3og :)e;er ta"7 #ou are !ro,ided $ith error and $arnin% messa%es2 The Pro<e(t 6anager ta"
!resents #ou $ith ,ie$ similar to <indo$s Ex!lorer as it allo$s #ou to "ro$se throu%h the file
s#stem of the PC7 and choose and do$nload a!!lications $ith a dra% and dro! action2 The
*P#thon- +nterpreter ta" *$hich uses the DP#thonE !ro%rammin% lan%ua%e- handles P#thon
commands and scri!ts for Control0esk Automation and TestAutomation2 Ither ta"s $ill a!!ear
de!endin% on $hat #ou do in the Control0esk *e2%27 $hen #ou com!ile a model as discussed
"elo$-2 The lar%e %ra# re%ion in the u!!er middle !ortion of the screen is a %eneral $ork area2 In
this area #ou can create and dis!la# la#outs7 as $ell as "rin% u! an editor to $rite text files7
P#thon scri!ts or c code2 Grom JQ:)e;>Control'ars #ou can hide or sho$ control "ars


0. 1o% to Pre)are the Tutorial Pro2ect

Grom the JQ$)le men&7 select JQ=e; 4 Pro<e(t>E?per)ment2 Control0esk o!ens the JQDe.)ne a
Pro<e(t dialo%2 In the :ame of the !roCect edit field7 enter JQ8rad)entS(alarES2

1$
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU

Click JQ=e?t2 Control0esk o!ens the JQDe.)ne an E?per)ment dialo%2 In the :ame of the
ex!eriment edit field7 enter JQ6PP-s)ngleP:2


Click JQ=e?t2 Control0esk o!ens the JQAdd Plat.orm9De/)(e dialo%2 Select JQDS!!@4 2AD Control
'oard2



Click Im!ort to na,i%ate to the JQE:\Work .older $here #ou ha,e #our Simulink files and select
the s)nglegrades.sd. ,aria"le descri!tion file for #our real-time hard$are from the2



Click JQ$)n)s%2 In the JQPro<e(t 6anager7 #ou can see the !roCect structure #ou ha,e created so far2
1%
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU


You can define a !roCect $ith t$o or more ex!eriments that access the same real-time !latform2
See JQ6eas&rement and 2e(ord)ng -&tor)al document2

0.1 1o% to #easure 3aria4le 3alues
To measure the ,aria"le ,alues of a runnin% real-time a!!lication7 #ou ha,e to connect an
instrument to the ,aria"les2 A successful measurement also confirms that #our Control0esk :ext
Generation installation is $orkin% correctl#2 In the tree ,ie$ of the JQ3aria"le /ro$serQQ7 na,i%ate
to s)nglegrades.sd. > 6odel 2oot2 In the :ar)a'le l)st7 select the 8rad > 0&t! ,aria"le and dra%
it to the ne$ la#out2 In the +nstr&ment -Bpe list click Plotter2

To dis!la# or chan%e the !ro!erties of the instrument click on the Plotter2 The JPropert)es
control "ar sho$s the Plotter !ro!erties2
18
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU

To add another ,aria"le to #our measurement7 chan%e to the R.S !o$er ,aria"le %rou! in the
tree ,ie$ of the 3aria"le /ro$ser and select the Iut5 ,aria"le in the 3aria"le list2 0ra% it to the
Plotter2 You can add other ,aria"les like JQd > 0&t! to the Plotter in the same $a#2 Each
measurement is sho$n in a different color2 Grom the tool"ar7 select JQStart 6eas&r)ng or !ress $7
to measure the ,aria"le ,alues2
To ex!and the time frame sho$n on the !lotter7 %o to JQ6eas&rement Con.)g&rat)on > -r)ggers >
D&rat)on -r)gger! and chan%e JQD&rat)on to 56s2



You can chan%e minimum and maximum of the Y-axis from JQPropert)es ta" of the !lotter2 Go to
Propert)es > A?es and click on the "ottom in front of JQA?es line2 To ha,e a fixed axis $ido$
select JQ$)?ed from JQS(al)ng mode then #ou can chan%e max and min of the rele,ant axis2

19
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU


To ca!ture the measurements on the com!uter hard disk7 %o to 6eas&rement > :)e;
6eas&rement Con.)g&rat)on or click C-23>62 In the 6eas&rement Con.)g&rat)on ta" %o to
2e(orders2 Ri%ht click on the 2e(orders then select Create =e; 2e(order2 <e name the
recorder 6PP-re(oder2 Also $e can add the ,aria"les to the recorder2 0ra% and dro! the
desired ,aria"les from the :ar)a'le ta" to the 6PP-re(order ta"2

You can ex!ort the recorded data to #our destination folder $ith JQ.mat extension for future
.AT>A/ uses2

20
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU
Prior to re"uildin% the model in .AT>A" or Simulink #ou shoud sto! the online cali"ration "#
!ushin% C-23>$C2 After #ou "uild the ne$ model7 %o to Pro<e(t > Hard;are Con.)g&rat)ons
and ri%ht click on JQs)nglegrades.sd. and click on 2eload :ar)a'le Des(r)pt)on2

5. E$)erimental Results
Gollo$in% fi%ures sho$ the results of .aximum Po$er Point Trackin% for a P3 module usin%
Extremum Seekin% and the 0C-0C "uck con,erter2

Fig. 9: Power maximization for two different initial conditions. The convergence rate is different on different sides of the
power curve of PV module as shown in Fig. 6.
0 5 10 15 20 25 30 35
0
0.5
1
1.5
2
2.5
3
3.5
4
P
o
w
e
r
(
W
)
Time (s)


d
0
= 37%
d
0
= 80%
21
dSPACE and Real-Time Interface in Simulink


D e p a r t m e n t o f E l e c t r i c a l a n C o m p ! t e r E n g i n e e r i n g

SDSU

Fig. 10: Variation of duty cycle versus time.

Fig. 11: Variation of the gradient versus time.
6. Reerences
S5T :icanor UuiCano7 Be,in Passino7 Santhosh Vo%i7 A -&tor)al +ntrod&(t)on to Control SBstems
De/elopment and+mplementat)on ;)t% dSPACE1 0e!t2 of Electrical En%ineerin%7 The Ihio
State 4ni,ersit#7 )66)
S)T dSPACE 'el!0esk *Control0esk (2)25-7 dSPACE 030 Release )65)
0 5 10 15 20 25 30 35
30
35
40
45
50
55
60
65
70
75
80
D
u
t
y
c
y
c
l
e
(
%
)
Time (s)


d
0
= 37%
d
0
= 80%
0 5 10 15 20 25 30 35
5
0
5
10
15
20
25
G
r
a
d
i
e
n
t
Time (s)


d
0
= 37%
d
0
= 80%