Difference between revisions of "User:DukeEgr93/DSPACE2"

From PrattWiki
Jump to navigation Jump to search
Line 46: Line 46:
 
# For this document, you will be adding a gauge to track the current value being sent to the Out1 block.  In the Virtual Instruments section of the Instrument Selector, click on the '''Gauge''' option, go into the layout, and draw a box.  The size of the box will be the size of the gauge, so make it about 15 blocks wide and 15 blocks tall (based on the grid size of the layout).  The layout should now resemble:
 
# For this document, you will be adding a gauge to track the current value being sent to the Out1 block.  In the Virtual Instruments section of the Instrument Selector, click on the '''Gauge''' option, go into the layout, and draw a box.  The size of the box will be the size of the gauge, so make it about 15 blocks wide and 15 blocks tall (based on the grid size of the layout).  The layout should now resemble:
 
#: <center>[[Image:LayoutPic1.PNG]]</center>
 
#: <center>[[Image:LayoutPic1.PNG]]</center>
 +
# Next you need to tell ControlDesk which variable to monitor with this gauge.  The easiest way to do that is to drag the variable from the bottom right window (it should still be the '''In1''' variable from the '''Out1''' block) and place it on top of the gauge.  The name of the gauge will change to indicate that it is now monitoring '''Out1/In1''' - the default title for an item is the block name followed by the variable name.
 +
# You can change gauge parameters by double-clicking the gauge.  In this case, you may want to change the Range, which is in the Gauge tab, as well as the Text, which is in the Captions.  Go ahead and set the range to be between -10 and 10 and set the text to "DACH1 Output" - once you have done that your layout should resemble:

Revision as of 20:36, 23 July 2008

Building a Basic Model

Building a basic Simulink model and running it on the dSPACE cards is fairly straightforward:

  1. Start the dSPACE ControlDesk.
  2. 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.
  3. 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.

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.

  1. 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
    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:
    OutputDemoModelPic1.png
  2. 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:
    OutputDemoModelPic2.png
  3. 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.

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.

Monitoring With ControlDesk

When the Real-Time Workshop builds a model, it generates a .SDF file containing information about the variables associated with each block. These varaibles may be monitored (and sometimes changed) in ControlDesk using a Layout. To see this, go to the ControlDesk, stop the card by clicking the red square in the navigation bar. To set things up properly:

  1. In the bottom of the ControlDesk, there are various tabs. Once a Simulink model is built and sent to the dSPACE cards, one of the tabs should be the SDF tab for that particular model. Go ahead and select it. The window just above the tabs should now show a "tree" with the model name at the top (using all lower-case letters) followed by Model Root, Labels, and Task Info.
  2. Expand the Model Root and the entries below it will be the blocks from the Simulink model, plus an extra RTI Data block that MATLAB added automatically.
  3. Click on the Out1 entry and the right-side window will now indicate that there is a Variable called In1 associated with it. That means ControlDesk has access to the input of that block.
  4. To monitor a variable, you will need to create a layout. Just above the variable explorer window is a set of four tabs. The second one, marked by a yellow rectangle above a blue square and red rectangle, is the Instrumentation tab. Select that. The window above it will indicate "No layouts open!"
  5. Double-click the "No layouts open!" and a new layout, layout1 will appear. This are is where you can add gauges, graphs, and other monitoring and instrumentation. To see what objects are available, go to the View menu and select Controlbars->Instrument Selector. The Instrument Selector should now be on the left side of the screen.
  6. For this document, you will be adding a gauge to track the current value being sent to the Out1 block. In the Virtual Instruments section of the Instrument Selector, click on the Gauge option, go into the layout, and draw a box. The size of the box will be the size of the gauge, so make it about 15 blocks wide and 15 blocks tall (based on the grid size of the layout). The layout should now resemble:
    LayoutPic1.PNG
  7. Next you need to tell ControlDesk which variable to monitor with this gauge. The easiest way to do that is to drag the variable from the bottom right window (it should still be the In1 variable from the Out1 block) and place it on top of the gauge. The name of the gauge will change to indicate that it is now monitoring Out1/In1 - the default title for an item is the block name followed by the variable name.
  8. You can change gauge parameters by double-clicking the gauge. In this case, you may want to change the Range, which is in the Gauge tab, as well as the Text, which is in the Captions. Go ahead and set the range to be between -10 and 10 and set the text to "DACH1 Output" - once you have done that your layout should resemble: