You are on page 1of 9

A.

APPENDIX: dSPACE and Real-Time Interface in


SIMULINK
The introduction to the dSPACE software (ControlDesk Next Generation version 4.2.1), the dSPACE DS1104 R&D controller
board, and their use in development and implementation of one-cycle recursive DFT algorithm for phasor estimation is
presented here.

1. System requirements: You can use a ×64-based personal computer as a host PC for your dSPACE applications with the
following specifications:

Host processor: Intel Core 2 Duo/ Intel Core i7 (for desktp PCs) processor at 2 GHz (or equivalent)

Main memory: 8 GB RAM or more (recommended)

Disk space: Up to 22.0 GB of free disk space on the program partition

Dongle licenses: A USB port version 2.0: To install the execution key (dongle)

Required slots: To install a DS1104, you need one free 33 MHz/32-bit 5 V PCI slot

Required MATLAB releases: R2017b (64-bit), R2017a (64-bit), R2016b (64-bit), R2016a (64-bit)

Required compliers: Microtec PowerPC C/C++ Complier version 3.8.6

For processor-in-loop (PIL) simulation, one needs a serial port (RS232) or a free USB port, depending upon type of evaluation
board. The dSPACE products of dSPACE release 2017-B support the following operating systems:

Windows 7 Professional, Ultimate, and Enterprise (64-bit versions) with Service Pack 1.

Windows 10 Professional, Education, and Enterprise (64-bit versions).

2. dSPACE package: To implement a real-time control loop using dSPACE and MATLAB, we need the following items:

1. dSPACE DS1104 R&D controller board (Fig. A.1)

Figure A.1 DS1104 R&D controller board.

2. Dongle licenses on a USB flash disk, as shown in Fig. A.2

© McGraw-Hill Education. All rights reserved. Any use is subject to the Terms of Use, Privacy Notice and copyright information.
Figure A.2 USB flash disk.

3. License.dsp file

4. Keys.dsp file

5. Connector panel CP1104, as shown in Fig. A.3.

Figure A.3 CLP 1104 connector board.

3. Real-time and the structure of a real-time program: Figure A.4 shows the connections between the controller and system
and how to control it with a discrete controller which has sampling time period of T. We need analog-to-digital converters (ADC)
to read the information of the sensors and after processing we need digital-to-analog converters (DAC) to send the output in
digital monitoring device for display.

Figure A.4 Real-time control structure.

The physical system has certain dynamics, which results in a time constant. This time constant will be used to derive a step size
or sample size for the control program. The challenge is not only to use that sample time in the numerical calculations that
make up control algorithm, but also to execute that algorithm within that sample time. This is called real time.

4. Configuration of dSPACE controller with SIMULINK: Use of SIMULINK for controller design and to compile the SIMULINK
model into code that will run on the dSPACE board for real-time implementation of the controller are discussed next. When
MATLAB is started, a message, as shown in Fig. A.5, appears which says that dSPACE RealTime Interface (RTI) is installed for
several hardware platforms; in this case DS1104.

© McGraw-Hill Education. All rights reserved. Any use is subject to the Terms of Use, Privacy Notice and copyright information.
Figure A.5 Step 1.

Next, in order to use DAC/ADC from dSPACE library to the SIMULINK model, one can type rti command in MATLAB command
window. After that the window, as depicted in Fig. A.6, will appear on the computer screen.

Figure A.6 Step 2.

If all of these blocks are double-clicked, the blocks necessary to build the simulation that one needs can be found. The RTI1104
board library as shown in Fig. A.6 is divided into some main sections. The I/O resources of the DS1104 are split between the
two processors on the board, the master PPC (power PC) and the slave DSP F240. By clicking on either one, you will have
access to blocks you can place in your model that provide I/O functionality associated with the respective processor. Here, the
group of blocks contained in the master PPC section are only focused. This window has some of the most commonly used
elements for the controller board, such as ADCs, DACs, encoders, etc.

4.1 Digital-to-analog conversion (DAC) and initialization/termination: The master PPC on the DS1104 controls a D/A
converter. It has the following characteristics:

8 parallel DAC channels (signals DACH1 … DACH8)

16-bit resolution

±10 V output voltage range

© McGraw-Hill Education. All rights reserved. Any use is subject to the Terms of Use, Privacy Notice and copyright information.
±1 mV offset error, 10 V/K offset drift

±0.1% gain error, 25 ppm/K gain drift

> 80 db (at 10 kHz) signal-to-noise ratio (SNR)

After placing a DAC block from rti library to SIMULINK model, double-click on the DAC block to make several settings as shown
in Fig. A.7. First, on the Unit tab, channel numbers need to be selected. Next, under theInitialization/Termination tab, the
initial/final value of the measure parameter has to be entered if applicable.

Figure A.7 Step 3.

5. Building the SIMULINK model: Once the model is defined, some parameters in the simulation under configuration
parameter need to be changed, as shown in Fig. A.8. First, in the Solver options, set the Start time to 0 (needed for real-time
applications) and set the Stop time to inf. Next, in the solver section set Type as fixed step, and pick a solver such as Eulers or
Ode5 or choose the automatic solver selection. Note that the more complex solvers you choose, the more computationally
intensive your program will be and thus will require more time to execute. Next, pick the sampling time (here 3.2 kHz) for the
testing that sets the sampling rate for the sensed signals and control updates.

Figure A.8 Configuring parameters.

Sampling rate has to be chosen very carefully specially in the event where controller demands too many computations and that
need to be completed within the sampling period. Inadequate sampling time may encounter an overrun condition and one will
get an error attesting to this upon download of the program to the DS1104.

After this steps, go to Advanced option tab and remove the tick mark from the Block Reduction option as shown in Fig. A.9.

© McGraw-Hill Education. All rights reserved. Any use is subject to the Terms of Use, Privacy Notice and copyright information.
Figure A.9 Advanced Configuration of parameters.

Once the above-mentioned steps have been done, the model is ready to build now. There are two options to build: one short-cut
command CTRL-B (from within the SIMULINK model) or go to Tools > Code Generation>Build Model. C code is generated for
the model, and then this code is compiled and linked by the PPC compiler (since the dSPACE 1104 uses a PPC processor) to
produce a single executable object file with .sdf extension. This executable file is then downloaded to the DS1104 control desk
environment, and the program starts running. If there are any errors during the build process or you run into an overrun
condition, this will be printed in the MATLAB command window, otherwise if all goes well a "successful completion" message
will appear in MATLAB command window.

6. Control desk environment: ControlDesk is the dSPACE experiment software for seamless ECU development. It performs all
the necessary tasks and gives a single working environment, from the start of experimentation right to the end. Therefore, one
should sit in front of host PC with dSPACE software and the DS1104 board and monitor, control, and experience real-time
environment. First, launch the dSPACE ControlDesk 4.2.1 software and follow the step-by-step procedure as mentioned below
and also indicated in Fig. A.10.

Figure A.10 Defining project and experiment.

© McGraw-Hill Education. All rights reserved. Any use is subject to the Terms of Use, Privacy Notice and copyright information.
6.1 Creating a new project+experiment:-

File > New > Project + Experiment

© McGraw-Hill Education. All rights reserved. Any use is subject to the Terms of Use, Privacy Notice and copyright information.
Give the project a name, and set the location for the root directory.

Give the experiment a name.

Check that the "DS1104 R&D controller board" is selected.

Open the .sdf system description file through Import from file... > the folder that the model is saved in > the model name.

Loading a .sdf file will load all the variables created on SIMULINK into dSPACE, where a layout is built for interfacing purposes.
After importing .sdf, a new layout will automatically appear in the screen as shown Fig. A.11.

Figure A.11 Improting .sdf File.

6.2 Map variables: To measure the variable values of a running real-time application, you have to connect an instrument to
the variables. To map the variables from the SIMULINK model to the instruments in the user-interface layout:

Click the plus sign next to Model Root in the bottom left corner (under Variables section) of the dSPACE program, where you will
see all the variables and gain names from SIMULINK model. In the Variables list, select the variable you want to see and then
drag Out1 option to the new layout.

To display or change the properties of the instrument, click on the Plotter, as shown inFig. A.12 (a). The Properties control bar
shows the plotter properties, as depicted in Fig. A.12(b).

© McGraw-Hill Education. All rights reserved. Any use is subject to the Terms of Use, Privacy Notice and copyright information.
Figure A.12 Plotter Functionalities.

6.3 Run the control desk: The program/experiment on the control desk runs as soon as the model is built with the dSPACE
ControlDesk window open. If this is the first time you are building the model and have opened it fresh on the dSPACE
ControlDesk, clicking on the Go Online for the first time starts the program. The Start Measuring button will only initiate the
plotters to start displaying real-time data. The Start Measuring button will switch from blue to grey and the Stop Measuring
button from grey to blue. Now that the program is built and functioning properly, the signal can also be seen on an oscilloscope
via a BNC cable. When you go online and vary the amplitude and frequency, the signal showing on the oscilloscope should look
like the one shown in the plotter array in the user interface.

7. MATLAB SIMULINK model for different test cases: As an example, the following two MATLAB models are shown inFigs.
A.13 and A.14.

1. In presence of odd order harmonics contents in the original signal

2. In presence of decaying DC components (eight cycles) in the original signal

Figure A.13 Odd order harmonics case.

© McGraw-Hill Education. All rights reserved. Any use is subject to the Terms of Use, Privacy Notice and copyright information.
Figure A.14 Decaying DC case.

© McGraw-Hill Education. All rights reserved. Any use is subject to the Terms of Use, Privacy Notice and copyright information.

You might also like