User:DukeEgr93/DSPACE
This is a personal sandbox for using the dSpace systems in Hudson 149. Several parts of it will move to the main site eventually.
Contents
General Startup
The following describes how to begin an experiment from scratch. More information will be provided later on how to reload an already-completed experiment.
- Start dSpace ControlDesk (CD)
- In CD, go to File->New Experiment
- Give the experiment a name, decide where you want all the files to go for the Working root, add author information and a description; when completed, the Experiment tab will have the name of the experiment as well as a .cdd link.
- Click on the Platform tab, right click Simulink, and Open Matlab - the first time MATLAB is started on a computer it will take quite some time to start up. When ready, the Simulink logo in the Platform window will be in color
- Within the new MATLAB window, type
simulink
- In Simulink, go to File->New->Model; when the model comes up, save it inside the folder you chose when creating the experiment
- In the model's window, go to Simulation->Configuration Parameters
- Solver: make sure to use a fixed-step solver; change the Fixed-step size if need be
- Hardware Implementation: choose the following:
- Device type: "Custom"
- Byte ordering: "Big Endian"
- Signed integer division rounds to: "zero"
- Back in the ControlDesk, the left window should still be Platform (if not, pick the Platform tab). At the bottom of the CD window, pick File Selector and find the Simulink model you have saved. Drag its name to the Simulink platform - the icon will change from the Matlab logo to a small red box with a green arrow, blue rectangle, and pink clock.
- Create the model (this must be done before variables can be generated in the next step; more information below about different models)
- In ControlDesk, right click the Simulink platform and select Build Variable Description File. Save the model if need be; at the bottom of the ControlDesk, a new tab for the "sdf" file will appear
- In the Simulink model window, type CTRL-B or go to Tools->Real-Time Workshop->Build model - this will compile the model, send it to the dSpace card, and start the process. Note that any time you change the model, you will need to save the model, go back to the Simulink platform and Build Variable
Resuming an Experiment
To resume work on a saved experiment;
- Start ControlDesk
- Go to File->Open Experiment and find your experiment
- Go to the Platform tab, right-click on Simulink and Open Matlab
- Drag the model you want to use from the File Selector onto the Simulink platform
- Right click the Simulink platform and select Build Variable Description File. Save the model if need be
- Now if you want to compile and run the model, just type CTRL-B or go to Tools->Real-Time Workshop->Build model - this will compile the model, send it to the dSpace card, and start the process. Note that any time you change the model, you will need to save the model, go back to the Simulink platform and Build Variable
Generate a Signal
Go through the steps in General Startup, stopping at "Create the model..." Then:
- Generate the signal - this is easily done by importing a Sources->Clocck and a User-Defined Functions->Fcn block. Connect the clock to the Fcn block, then put the function you want in the Fcn block.
- Tell dSpace to take data - go to the dSpace RTI1104 blockset in the Simulink library, expand it and click the DS1104 MASTER PPC set within it. Drag a DS1104DAC_C1 block into your model
- In the model, double-click the DS1104DAC_C1 block to set properties:
- Unit: pick the channel (for this document, we will use DACH1)
- Initialization: should already be set to 0 V
- Termination: make sure the block will set the output to 0 volts on termination
- Connect the Fcn block to the DAC block
- Save the model
- In ControlDesk, right click the Simulink platform and select Build Variable File. Save the model if need be; at the bottom of the ControlDesk, a new tab for the "sdf" file will appear
- In the model window in Simulink, type CTRL-B or go to Tools->Real-Time Workshop->Build model - this will compile the model, send it to the dSpace card, and start the process. Note: the process will continue until you stop the dSpace card in ControlDesk by selecting the ds1104 platform and then hitting the stop button in the menu bar.
- Another way of stopping the process is to put a stop in the Simulink diagram that is triggered by a particular condition. The easiest way to do this is to add another User-Defined Functions->Fcn block and a Sinks->Stop block. Connect the clock to this new function block, but in a logical operator that is true when you want the simulation to stop (for example,
u[1]>3
for a 3 second simulation), then connect this to the Stop block.
- Another way of stopping the process is to put a stop in the Simulink diagram that is triggered by a particular condition. The easiest way to do this is to add another User-Defined Functions->Fcn block and a Sinks->Stop block. Connect the clock to this new function block, but in a logical operator that is true when you want the simulation to stop (for example,
Accessing Experiment Values
If you want dSpace to save variables and dump them into MATLAB for analysis, you will use the Sinks->To Workspace blocks. Just drag a block onto your model, double-click it, set the name of the variable you want, and change the Save format to Array (unless you want it to be a Structure). Connect it to the line you want to measure. Then:
- Save the model
- In ControlDesk, right click the Simulink platform and select Build Variable File. Save the model if need be; at the bottom of the ControlDesk, a new tab for the "sdf" file will appear
- In the model window in Simulink, type CTRL-B or go to Tools->Real-Time Workshop->Build model