Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

real time clock in Simulink

1,787 views
Skip to first unread message

Daniel Czarkowski

unread,
Feb 24, 2004, 10:39:11 AM2/24/04
to
Hi folk,

Is there any real time clock in the Simulink? I would like to stop my
simulation after a certain amount of time, e.g. 10 seconds. How to do it?

best regards,
daniel

Stuart McGarrity

unread,
Feb 24, 2004, 11:30:18 AM2/24/04
to
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=3175&objectType=file

"Daniel Czarkowski" <reut...@poczta.onet.pl> wrote in message
news:c1fr16$q3h$1...@news.onet.pl...

Daniel Czarkowski

unread,
Feb 25, 2004, 4:46:07 AM2/25/04
to
Hi folks,

"Stuart McGarrity" <stu...@mathworks.com> wrote in message
news:c1fu6q$6st$1...@fred.mathworks.com...
>
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=3175&objectType=file


Thank you Stuart. The point is that I am looking for something different. In
this Simulink library, the time of simulation equals to real time. I would
like to measure how long the simulation takes in real time. I now that I can
do it in MATLAB
tic
sim('my_model',[0 10],opt)
toc

I am using GA for optimisation and sometimes the simulations in real time
takes to long, so I would like to stop it after e.g. 60 seconds. I found
STOP simulation block, but did not find the real time simulation clock. I
presume that I would have to write an s-function and include (toc). What I
need is just sth like tic and toc function in the Simulink. Anyone came
across with the problem?

Any ideas?


best regards,
daniel


Stuart McGarrity

unread,
Feb 25, 2004, 11:57:13 AM2/25/04
to
One way would be to write an M code S-function that outputs the current time
with the 'now' command. Set it to execute infrequently.

Stuart

"Daniel Czarkowski" <reute...@SPAMpoczta.onet.pl> wrote in message
news:c1hqmj$l9d$1...@news.onet.pl...

Kelvin Hales

unread,
Feb 25, 2004, 12:20:37 PM2/25/04
to

Might there be something in the Humusoft Extended Real-Time Toolbox for MATLAB and
Simulink that could help you? <http://www.humusoft.cz/rt>

Kelvin B. Hales
Kelvin Hales Associates Limited
Consulting Control Engineers
E-mail: kha...@khace.com
Web: www.khace.com

Daniel Czarkowski

unread,
Feb 26, 2004, 3:50:57 AM2/26/04
to

"Stuart McGarrity" <stu...@mathworks.com> wrote in message
news:c1ik59$1p4$1...@fred.mathworks.com...

> One way would be to write an M code S-function that outputs the current
time
> with the 'now' command. Set it to execute infrequently.

It means that this command is not a part of MATLAB/Simulink. I hope in R14
Mathworks will implement that as well.

If someone done it, please send it to
http://www.mathworks.co.uk/matlabcentral/fileexchange/

best regards
daniel


Daniel Czarkowski

unread,
Feb 26, 2004, 3:52:05 AM2/26/04
to
> Might there be something in the Humusoft Extended Real-Time Toolbox for
MATLAB and
> Simulink that could help you? <http://www.humusoft.cz/rt>
As far as I know, they do not have any tic toc block.

thank you
daniel


Steve Amphlett

unread,
Feb 26, 2004, 4:31:01 AM2/26/04
to

One way to limit a simulation's elapsed (wall) time is to:

1) Set up a "Simulation Start Function" callback: t0=clock;

2) Add a MATLAB Fcn block with the function: etime(clock,t0). Ground
the input. The output from this block is now the elapsed time that
the simulation has been running for.

3) Add a relational operator block to compare elapsed time with some
constant (your time limit).

4) Feed the output of the relational operator into a Stop block.
When elapsed time is greater than your limit, the model stops.

If this isn't clear, I can email you my example (for R13).

HTH

- Steve

Kelvin Hales

unread,
Feb 26, 2004, 4:39:29 AM2/26/04
to

To stop your simulation after x-seconds of real time: synchronise the
simulation time with real time and take the output from a Clock block to a
Stop block.

Daniel Czarkowski

unread,
Feb 26, 2004, 6:46:52 AM2/26/04
to
Thank you very much Steve!

daniel


Steve Amphlett

unread,
Feb 26, 2004, 7:37:32 AM2/26/04
to
Daniel Czarkowski wrote:
>
>
> Thank you very much Steve!
>
> daniel

I think your use of the expression "real time" got most posters into
the wrong mindset (RTW, HiL etc). What you really meant (pardon me
for correcting your English) was "wall time" or "elapsed time".

Reza

unread,
Apr 9, 2012, 8:32:12 PM4/9/12
to
Hi
This does not work for me. I am using R2011. I run a "Simulation Start script" calling back: t0=clock; and when I run my simulink file, it would only calculate the elapsed time at the beginning of the simulation and it would be constant through the whole simulation.
I am using SimMechanics too.
Any help would be appreciated.

Thanks,
-Reza
"Steve Amphlett" <Firstname.Lastname@where_I_work.com> wrote in message <eed1...@webx.raydaftYaTP>...

Pramit Biswas

unread,
Apr 24, 2014, 7:14:07 AM4/24/14
to
@Steve Amphlett

Can you please e-mail the simulink file?

my e-mail address: prami...@gmail.com

padmai....@gmail.com

unread,
May 21, 2015, 9:27:35 AM5/21/15
to
Hello Kevin B. Hales,

I am a novice M/S user. I just tried to take the output from a block to a stop block, but how do I synchronize simulation time with real time before doing this?

Cheers
Padma
0 new messages