Clear Filters
Clear Filters

timer in matlab function

2 views (last 30 days)
Hans Jørgen Jensen
Hans Jørgen Jensen on 16 Jun 2017
Commented: Walter Roberson on 28 Aug 2017
Hi, I have some control code in a Matlab function, and I would like to add a timer, that starts when a pump turns on, and if the pump runs for more than x hours continuously, a flag is to be raised, and the timer reset. I am not sure how to implement a timer, or the requested functionality in a Matlab function. I have read about the timer object, but not sure if that is the way to do it. Any suggestions of how to do this, or where to find info ? Thanks Hans Jensen

Answers (1)

Walter Roberson
Walter Roberson on 16 Jun 2017
Yes, timer objects run their callbacks when they fire.
However, if by "matlab function" you are referring to "MATLAB Function Block" in Simulink, then you would use a different approach completely, as you would need to look at the simulated time rather than the real time.
  2 Comments
Hans Jørgen Jensen
Hans Jørgen Jensen on 28 Aug 2017
Hi, thanks for your reply, and sorry for my slow response. Yes, I am referring to a Matlab Function block
Walter Roberson
Walter Roberson on 28 Aug 2017
Suppose you wanted the flag to be raise after the pump had run for 1 hour. Now, suppose your simulation turns out to be slower than real time, such as if it took 3 minutes real time to simulate each minute of physics: should the flag be raised after 1 hour of real time, or should it be raised after 1 simulated hour? Or perhaps your simulation is faster than life... may it takes only 1 second real time to simulate 6 seconds of pump. Should the flag still be raised after 1 hour of real time, or should it be raised after 1 simulated hour? If you go into the debugger and spend 20 minutes looking around at the state (maybe you went down for coffee while you thought), then should the flag still be raised after 1 real-time hour even if the simulation is paused at the debugger, or should it be after one simulated hour ?

Sign in to comment.

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!