Difference between revisions of "User:DukeEgr93/DSPACE2"
Line 18: | Line 18: | ||
# Using the Simulink Library Browser, drag the following blocks into the <code>OutputDemoModel</code> window: | # Using the Simulink Library Browser, drag the following blocks into the <code>OutputDemoModel</code> window: | ||
#* Source->Sine Wave | #* Source->Sine Wave | ||
+ | #* Sink->Out1 | ||
+ | #*: This block will provide a convenient way for the ControlDesk to access the value sent to the DAC; it does not serve any other purpose in the model. | ||
#* Math Operations->Gain | #* Math Operations->Gain | ||
#* dSPACE RTI1104->DS1104 MASTER PPC->DS1104DAC_C1 | #* dSPACE RTI1104->DS1104 MASTER PPC->DS1104DAC_C1 | ||
− | # | + | #: Once these blocks are in place, connect the Sine Wave to the Gain, connect the Gain to the DAC, and connect the Out1 to the wire between the Sine Wave and the Gain. Your model should resemble: |
− | # | + | #:<center>[[Image:OutputDemoModelPic1.png]]</center> |
− | #: | + | # The gain block is in place because the DAC block accepts inputs between -1 and 1 which relate to voltages between -10 and 10 V. In order for the signal you want to be properly generated by the dSPACE card, you should set the Gain block to 0.1. The Out1 block is ''before'' the gain, so it should ''also'' represent the value you want to set. Once you change the value of the gain, you may need to make the Gain block a little bigger to see the value within it. Do that, then save the model. It should now resemble: |
+ | #:<center>[[Image:OutputDemoModelPic2.png]]</center> | ||
+ | # Each block has other options worth looking at. | ||
+ | #* In the Sine Wave block, you can set (among other things) the Amplitude, Bias, Frequency, Phase, and Sample time. For this demonstration, leave everything as the default case except change the frequency to <code>2*pi*10</code> to set it to 20<math>\pi</math> rad/s or 10 Hz. | ||
+ | #* The Gain block has already been set to 0.1 to compensate for the scaling factor in the DAQ block. | ||
+ | #* The Out1 block has several parameters, none of which will be changed here. | ||
+ | #* The DAC block has three tabs. The '''Unit''' tab which allows the user to specify which channel is being used, the '''Initialization''' tab which determines the voltage value when the dSPACE card first runs the model, and the '''Termination''' tab which determine the voltage value to set the channel at when the program terminates. This third tab should generally be checked and set to 0 volts. | ||
+ | |||
+ | That concludes perparing a model for controlling one output channel. The model will generate a signal (here with the Sine Wave block) and send it two places - an Out1 block so that ControlDesk can read it and a combination of a Gain block and a DAQ block so that the signal is scaled and sent to the appropriate digital to analog conversion channel. | ||
+ | |||
+ | === Running The Model === | ||
+ | To run the model, make sure the dSPACE ControlDesk is running. Then, in the Simulink model window, either type '''CTRL-B''' or go to Tools->Real-time Workshop->Build Model. At this point, you can watch the MATLAB Command Window print out information about compiling and loading the model. When it is finished, the compiled program will be running on the dSPACE card. Note at this point that MATLAB is ''not'' running the program - the digital signal processing card inside the dSPACE box is. In this case, if you want to see if the program is working, you need to attach the output of DACH1 to an oscilloscope or a data acquisition card running softscope. |
Revision as of 20:05, 23 July 2008
Building a Basic Model
Building a basic Simulink model and running it on the dSPACE cards is fairly straightforward:
- Start the dSPACE ControlDesk.
- Start MATLAB - note that on a PC, the first time MATLAB is run after the PC has been turned on may take quite a bit of time to start.
- MATLAB must run a configuration script to communicate with dSPACE. In Hudson 149, the script is already set to run. If that is not the case,
dspacerc.m
must be run. That script is provided with the dSPACE card and software.
- MATLAB must run a configuration script to communicate with dSPACE. In Hudson 149, the script is already set to run. If that is not the case,
- In MATLAB, start Simulink.
- The block library should already include the dSPACE blocksets, though the individual blocks may need to be loaded. To load them, simply expand the
dSPACE RTI1104
blockset. - In the Simulink Library Browser, go to File->New->Model; when the model comes up, save it inside the folder you chose when creating the experiment. For this demo, it will be called
OutputDemoModel
. - The model needs to know the properties of the DSP card in order to compile the model properly. To set these properties, go to 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"
- Once done, you can save the model.
- The block library should already include the dSPACE blocksets, though the individual blocks may need to be loaded. To load them, simply expand the
Generating Output Signals
There are several methods in Simulink for generating a signal. Most of these methods can be dynamically adjusted via the ControlDesk once the Simulink model is built and once an appropriate Layout is constructed in ControlDesk. For this documentation, a simple sinusoidal input will be used.
- Using the Simulink Library Browser, drag the following blocks into the
OutputDemoModel
window:- Source->Sine Wave
- Sink->Out1
- This block will provide a convenient way for the ControlDesk to access the value sent to the DAC; it does not serve any other purpose in the model.
- Math Operations->Gain
- dSPACE RTI1104->DS1104 MASTER PPC->DS1104DAC_C1
- The gain block is in place because the DAC block accepts inputs between -1 and 1 which relate to voltages between -10 and 10 V. In order for the signal you want to be properly generated by the dSPACE card, you should set the Gain block to 0.1. The Out1 block is before the gain, so it should also represent the value you want to set. Once you change the value of the gain, you may need to make the Gain block a little bigger to see the value within it. Do that, then save the model. It should now resemble:
- Each block has other options worth looking at.
- In the Sine Wave block, you can set (among other things) the Amplitude, Bias, Frequency, Phase, and Sample time. For this demonstration, leave everything as the default case except change the frequency to
2*pi*10
to set it to 20\(\pi\) rad/s or 10 Hz. - The Gain block has already been set to 0.1 to compensate for the scaling factor in the DAQ block.
- The Out1 block has several parameters, none of which will be changed here.
- The DAC block has three tabs. The Unit tab which allows the user to specify which channel is being used, the Initialization tab which determines the voltage value when the dSPACE card first runs the model, and the Termination tab which determine the voltage value to set the channel at when the program terminates. This third tab should generally be checked and set to 0 volts.
- In the Sine Wave block, you can set (among other things) the Amplitude, Bias, Frequency, Phase, and Sample time. For this demonstration, leave everything as the default case except change the frequency to
That concludes perparing a model for controlling one output channel. The model will generate a signal (here with the Sine Wave block) and send it two places - an Out1 block so that ControlDesk can read it and a combination of a Gain block and a DAQ block so that the signal is scaled and sent to the appropriate digital to analog conversion channel.
Running The Model
To run the model, make sure the dSPACE ControlDesk is running. Then, in the Simulink model window, either type CTRL-B or go to Tools->Real-time Workshop->Build Model. At this point, you can watch the MATLAB Command Window print out information about compiling and loading the model. When it is finished, the compiled program will be running on the dSPACE card. Note at this point that MATLAB is not running the program - the digital signal processing card inside the dSPACE box is. In this case, if you want to see if the program is working, you need to attach the output of DACH1 to an oscilloscope or a data acquisition card running softscope.