Thread Subject: simulink sample times with mdlGetTimeOfNextVarHit

Subject: simulink sample times with mdlGetTimeOfNextVarHit

From: David

Date: 12 May, 2008 18:41:03

Message: 1 of 3

I am working with a model that has 2 s-functions. Matlab
7.0.4.365 (r14) sp2, in case that matters.

s-function 1 is continuous sample time and reads data out
of a shared memory type buffer that is filled at 10hz.
The data is put in there by another s-function that is
called in a triggered subsystem. I have shown that the
data is in there at 10hz on an even tick.. say at 2.5
sec. an output of this functions feeds an input port of s-
function 2.

s-function 2 is set as variable sample time and sets its
next sample time with mdlGetTimeOfNextVarHit based on
external information, but it wants to read data at
2.5sec. It gets called but doesn't see the data in in the
s-function 1 output. if i put a print statement in the
mdlOutputs of s-function 1 it doesn't get called until
2.502+ sec... how can i make sure that s-function 1 gets
called to fill its output before s-function 2 tries to
read it?? is it something to do with priorities, or
inherited sample times??

Subject: simulink sample times with mdlGetTimeOfNextVarHit

From: David

Date: 12 May, 2008 19:05:06

Message: 2 of 3

"David " <dave@bigcompany.com> wrote in message
<g0a2vv$4tk$1@fred.mathworks.com>...
> I am working with a model that has 2 s-functions.
Matlab
> 7.0.4.365 (r14) sp2, in case that matters.
>
> s-function 1 is continuous sample time and reads data
out
> of a shared memory type buffer that is filled at 10hz.
> The data is put in there by another s-function that is
> called in a triggered subsystem. I have shown that the
> data is in there at 10hz on an even tick.. say at 2.5
> sec. an output of this functions feeds an input port of
s-
> function 2.
>
> s-function 2 is set as variable sample time and sets its
> next sample time with mdlGetTimeOfNextVarHit based on
> external information, but it wants to read data at
> 2.5sec. It gets called but doesn't see the data in in
the
> s-function 1 output. if i put a print statement in the
> mdlOutputs of s-function 1 it doesn't get called until
> 2.502+ sec... how can i make sure that s-function 1 gets
> called to fill its output before s-function 2 tries to
> read it?? is it something to do with priorities, or
> inherited sample times??

unfortunately i don't own all these pieces... doing some
more prints to trace the execution it looks now like the
continuous s-function 1 that is feeding s-function 2 is
getting called at the 2.5 sec time before s-function 2
runs... but the data isn't in the buffer yet. this data
is created by a triggered subsystem in another part of the
model that runs at 2.5 sec, it will be a while to prove it
but i am guessing that the triggered subsystem isn't
running until after the s-function 1 and 2 have run. does
that make any sense?? Could this still be a priority
issue or is there something different with handling
scheduling that has to be done with mixing up timing
models like this???

Subject: simulink sample times with mdlGetTimeOfNextVarHit

From: riccardo

Date: 13 May, 2008 07:47:04

Message: 3 of 3

"David " <dave@bigcompany.com> wrote in message <g0a4d2
$slm$1@fred.mathworks.com>...
> "David " <dave@bigcompany.com> wrote in message
> <g0a2vv$4tk$1@fred.mathworks.com>...
> > I am working with a model that has 2 s-functions.
> Matlab
> > 7.0.4.365 (r14) sp2, in case that matters.
> >
> > s-function 1 is continuous sample time and reads data
> out
> > of a shared memory type buffer that is filled at 10hz.
> > The data is put in there by another s-function that is
> > called in a triggered subsystem. I have shown that the
> > data is in there at 10hz on an even tick.. say at 2.5
> > sec. an output of this functions feeds an input port
of
> s-
> > function 2.
> >
> > s-function 2 is set as variable sample time and sets
its
> > next sample time with mdlGetTimeOfNextVarHit based on
> > external information, but it wants to read data at
> > 2.5sec. It gets called but doesn't see the data in in
> the
> > s-function 1 output. if i put a print statement in the
> > mdlOutputs of s-function 1 it doesn't get called until
> > 2.502+ sec... how can i make sure that s-function 1
gets
> > called to fill its output before s-function 2 tries to
> > read it?? is it something to do with priorities, or
> > inherited sample times??
>
> unfortunately i don't own all these pieces... doing some
> more prints to trace the execution it looks now like the
> continuous s-function 1 that is feeding s-function 2 is
> getting called at the 2.5 sec time before s-function 2
> runs... but the data isn't in the buffer yet. this data
> is created by a triggered subsystem in another part of
the
> model that runs at 2.5 sec, it will be a while to prove
it
> but i am guessing that the triggered subsystem isn't
> running until after the s-function 1 and 2 have run.
does
> that make any sense?? Could this still be a priority
> issue or is there something different with handling
> scheduling that has to be done with mixing up timing
> models like this???

Yes, that can happen.
You'll have to implement some sort of logic to make sure
the data is available when required.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
mdlgettimeofnextvarhit David 12 May, 2008 14:45:08
simulink David 12 May, 2008 14:45:08
sample times David 12 May, 2008 14:45:08
priorities David 12 May, 2008 14:45:08
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com