dSPACE Online Manual


Setup necessary to use dSPACE MiniBoxes

In order to run programs on the dSPACE hardware you need to add a few things to your .cshrc file and create a new directory. See below:

  1. Create a directory called citfiles in your home directory of your sun account. This is done by typing the following command at the prompt in the root directory:
  2. mkdir citfiles

  3. Copy the needed configuration file, chkerr31.chk to the citfiles directory. This can be done by the following command:
  4. cp /usr/local/dsp_cit/citfiles/chkerr31.cfg citfiles/.

  5. Add the following line to the path statement in the .cshrc file:
  6. /usr/local/dsp_cit/bin /usr/local/c30tools

    For example, if the path statement looked like this:
    set path = (. ~ ~/bin /usr/ucb /usr/bin)

    Add to the path like this: (no line break though)
    set path = (. ~ ~/bin /usr/ucb /usr/bin /usr/local/dsp_cit/bin /usr/local/c30tools)

  7. There are several environment variables that need to be set for the dSPACE software to work. The CITFILES environment variable needs to be set to the path of the directory you created in part 1 above. To get the path of your root directory, type pwd from the prompt in your root directory. It will then display the path of your root directory. This should be substituted where is says root_path below.
  8. The trace software works in Open Windows and X-Windows. To use X-Windows, the OIT_WMGR environment variable needs to be set to OTHER. To use Open Windows, it should be set to OPENLOOK. You can run one or the other but not both unless you change the OIT_WMGR variable! The following lines assume you are using X-Windows.

    Add the following lines to the .cshrc file:

    setenv CITFILES root_path/citfiles
    setenv OIT_PATH /usr/local/dsp_cit/bin
    setenv OIT_WMGR OTHER
    setenv MATLABPATH /usr/local/dsp_cit/matlab/dslib:/usr/local/dsp_cit/matlab/loadsave

    Note:The previous two lines should be on a single line with a space between them in the .cshrc file and there should be NO SPACE after the colon in the previous statement!

    Also, if you already have a MATLABPATH set, just add the above line to it, separating each directory path with a colon like above.

  9. Log off and log back in to make these changes take effect.
  10. The program that downloads to the dSPACE box needs a setup file to work. Do the following to creat this necessary setup file:
  11. Create a directory in your account to hold your dSPACE C program files. A good suggestion is to create a directory called dspace. The following command will do this:
  12. mkdir dspace

  13. There is a sample program that you can copy to the dspace directory if you want. Or you can write your own. Following is the path of this optional sample program:
  14. /usr/local/dsp_cit/demo1102/std/pt2.c

    At this point your account is setup and you are ready to download a program to the dSPACE Minibox.


How to download a program to the dSPACE MiniBox

The shell-script down31 invokes the C compiler, assembler, and linker and then downloads the resulting object module to the DS1102 controller board using the ld31 program loader. This script makes the downloading process very easy.

Following is the command necessary to download a program to the dspace box from the suns:

down31 c_filename -c dspace_name

where:
c_filename is the filename of the c code without an extension
dspace_name is the name of the dSPACE box, e.g. dspace01

If you are unsure of the name of the dSPACE MiniBox you want to use, see the list of dSPACE names and addresses. This list also contains the respective sun workstation names and all the relevant IP addresses.


What is TRACE?

TRACE (trace31) is a utility that runs on the Sun workstation while a program is running on the dSPACE MiniBox. It allows the Sun to have access to the dSPACE memory. The value of variables in the running program can saved in a text or MATLAB format by TRACE. It can also plot the variables versus time as the program is running.


How to run trace31

  1. Add a call to the function service_trace() in the c program where you want to be able to look at the variables.
  2. Use down31 to compile and download the program to the dSPACE MiniBox.
  3. Create a memory map (.trc) file for the program. It needs to include all the variable names and types that you want to look at in trace31. See the example fir.trc file.
  4. To run TRACE type the following:
  5. trace31 -c dspace_name

    where dspace_name is the name of the dSPACE box.

  6. In TRACE, choose File-Open Map File and open the memory map file you created. The variable names should appear in the Signals to Trace box in the lower left corner.
  7. Choose the signal or signals to trace and press the Start Trace button.


How to save data from TRACE and load into MATLAB

  1. Use trace to collect data. See above section.
  2. In trace choose File-Data Format-MATLAB binary
  3. In trace choose File-Save Traced Data. Name the file with a .mat extension.
  4. To load this data into MATLAB run MATLAB and type (or copy):
  5. [x,y,hl,xn,xu,yn,yu] = loadtbd('filename.mat');

    The variables are:

    x = (n,p) matrix with p points of x data
    y = (p,n) matrix with p points of y data
    hl = string vector containing table headlines
    xn = x data array names
    xu = x data array units
    yn = y data array names
    yu = y data array units

    (reference: "Addendum to TRACE for Windows User's Guide", pg.1)


Downloading Simulink models to the dSPACE hardware in real time

MATLAB can be used to directly download a program to the dSPACE minibox. This is accomplished in Simulink. Once you have modeled the system in Simulink, create a new Simulink document and cut and paste the part to be downloaded to this new document. It can contain no output devices such as scopes, etc.

This first figure is a simple Simulink block diagram. It reads a signal on A/D channel (ADC) 1 and outputs the same signal on D/A channel (DAC) 1. Note the times ten amd divide by ten blocks. These are necessary because the DS1102 ADC performs a divide by ten and the DAC performs a multiply by ten internally.

Simulink Block Diagram

The scopes and function generator are Simulink blocks needed to run the simulation. They must be removed before downloading to the dSPACE hardware. When downloaded, these are external connections to the actual hardware. The easiest way to do this is to copy the part to be downloaded and paste it into a new Simulink window. The inputs and outputs are then connected to Simulink "plugs", which tell Simulink that they are external connections. The figure below is all ready to be downloaded.

Simulink Block Diagram

To get the SIMULINK Block Library, in MATLAB type: simulink
To get the dSPACE Board Library, in MATLAB type: dslib

Before downloading the model to the dSPACE minibox, a few parameters must first be set in the Real-Time Options Dialog Box. To get this dialog box, in the open simulink model window, choose Code-Real-time Options... and the box will appear. Make the following changes:

where dspace_name is the name of the dSPACE Minibox you are using.

There are two ways to download the model to the dSPACE Minibox. They both accomplish the same thing so you can use either one:

Your model will be converted to code, compiled, and downloaded to the specified dSPACE Minibox. Simulink will also create the necessary .trc file for use with TRACE so it can be run immediatedly after downloading a file to the dSPACE box.


Lat Updated: 20 July 1996