I compiled this S function to form dll file for a simulink block.
Now when I used two such instances of this block in parallel, I found
that the variable 'm' is considered to be the same in the two blocks
i.e suppose 'm' is changed to some value in one of the blocks then
that change is also tranparent to the other block too or 'm' is
changed for the other block too. Someone Please suggest some method
to make these blocks independent with Global variables still in use.
greatful for any help,
Zia
Using work vectors should help out.
From 'Writing S-Functions':
"If your S-function needs persistent memory storage, use S-function
work vectors instead of static or global variables. If you use static
or global variables, they are used by multiple instances of your
S-function. This occurs when you have multiple S-Function blocks in a
Simulink model and the same S-function C MEX-file has been specified.
The ability to keep track of multiple instances of an S-function is
called reentrancy.
You can create an S-function that is reentrant by using work vectors.
These are persistent storage locations that Simulink manages for an
S-function. Integer, floating-point (real), pointer, and general data
types are supported. The number of elements in each vector can be
specified dynamically as a function of the number of inputs to the
S-function."
Hope this helps.
Ted
I typically use work vectors as 'storage bins', so to speak, in order
to use them persistantly. The key value of using work vectors you
are concerned with (I think) is reentrancy.
Work vectors act very similarly to global or static variables, in the
sense that they are accessable everywhere within a specific instance
of your S-function.
Reentrancy allows you to use multiple instances of your S-function
without things getting 'muddled up' with each other.
Conversly, using global or static variables DOES NOT provide
reentrancy. This means the global or static variable 'X' in one
S-function instance is no different (in memory) than the variable 'X'
in another instance of the SAME S-function. Using work vectors
avoids this 'confusion'.
I suggest <http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/sfg/sfun.html>
s a starting point.
Ted