Simulink - Caspoc Classical Coupling.

In the classical coupling, Caspoc is running in the background and data can be interchanged between Caspoc and Simulink with the use of a S-Function block.

SIMULINK:

In Simulink select a S-Function block from the tree list and place it in your simulink model. Select a MUX-block and place it in front of the S-Function block. Select a DEMUX-block and place it behind the S-Function block

CASPOC:

In Caspoc you use the block ToSLNK block to send data to Simulink. Use the FromSLNK block to read data from Simulink. In the ToSLNK block (first parameter), specify the number of the outputs in the DEMUX block in Simulink. In the FromSLNK block (first parameter), specify the number of the inputs in the MUX block in Simulink.

The number of ToSLNK blocks should equal the width of the DEMUX block in Simulink. Change the width of the DEMUX block by double clicking it with the left mouse button and specify the number of ToSLNK blocks.

The number of FromSLNK blocks should equal the width of the MUX block in Simulink. Change the width of the MUX block by double clicking it with the left mouse button and specify the number of FromSLNK blocks.

For example, if 4 ToSLNK and 3 FromSLNK blocks are specified in Caspoc, the MUX block has 3 inputs and the DEMUX block has 4 outputs.

<br>Click to close the image

 

 

The integration step size, which is specified in Simulink, is also used for the Caspoc simulation. Select a fixed step size at "Solver options".

<br>Click to close the image

The total simulation time is specified at "Stop time:". The integration step size is specified at "Fixed step size". The type of solver can be any as long it supports continuous time steps. Preferred solvers are "ode1" (Euler 1st order) or "ode4" (Runge-Kutta 4th order). If unit delays are used in Simulink, select "Single Tasking" as "Mode".

The selected step size has to be equal to the selected step size in Caspoc. Also in Caspoc a fixed step size has to be selected. In the above figure a step size of 64m s is selected, while the total simulation time equals 1 second

Open the S-functions properties dialog box by double clicking it. Specify the name of the Caspoc2Simulink.dll in the "S-function name" field. Be careful not to include the full path name, since Matlab/Simulink has no idea what to do with it. If Simulink reports an error indicating that the number of input ports is unequal to the number in Simulink, or that there is a general error with the simulink block, please first open the example in Caspoc and select the menu item "Tools" / "Export to Simulink" in Caspoc.

<br>Click to close the image

Before running the simulation in Simulink, first create the netlist in Caspoc by selecting the menu item "Tools" / "Export to Simulink" in Caspoc.

To prevent synchronization problems, never let both the simulations in simulink and Caspoc(started in Caspoc) run at the same time. Therefore be careful to first select the start button in Caspoc and second to select the pause button to stop the simulation. After that Start simulink by selecting "Start" from the "Simulation" menu.

If you have no file opened in Caspoc and selected the start buttton in Caspoc, Simulink will generate an error if you try to attempt to start a simulation.

If the input width of the MUX block in Simulink and the number of FromSLNK blocks are not matching, a warning will be displayed in the "Matlab Command Window". If the output width of the DEMUX block in Simulink and the number of ToSLNK blocks are not matching, a warning will be displayed in the "Matlab Command Window". You can run the simulation, but it is not clearly defined which signals between Caspoc and Simulink are interchanged.

You can directly place a scope in Simulink and connect it to the output from the S-function block "Caspoc2Simulink". All signals from the ToSLNK block in Caspoc are displayed in this scope.

Installation of the coupling between Caspoc and Simulink.

Although it looks very simple you have to take a number of steps to let Matlab/Simulink know where Caspoc is installed.

Start Matlab from the start menu or by double clicking the Matlab-Icon on your desktop and select "File / Set Path ..."

Select the button [Browse...] and select the directory where Caspoc is installed, for example, "c:/Program Files/Caspoc ".

<br>Click to close the image

Select "Path / Add to Path" to include the path.

<br>Click to close the image

Whenever you make a change in the Caspoc model, don’t forget to first export it for Simulink with the menu item "Tools" / "Export to Simulink" in Caspoc.

© 2018 CASPOC, All rights reserved. Home   |   Terms and Conditions   |   Legal   |   Export Compliance   |   Privacy Policy   |   Site Map