Simulink Equivalent to 'now'?

3 views (last 30 days)
Zachary Santer
Zachary Santer on 30 Nov 2011
I have been declaring 'now' an extrinsic function in an embedded MATLAB function in Simulink. The trouble is, you can't use extrinsic functions in real time applications using Real Time Windows Target. There doesn't seem to be a Simulink block to access the system time.
I feel the need to write a C/C++ S-Function to try and give the same result. I've never written anything in C/C++ and I don't really think I'm going to be able to figure it out soon enough.
Can anybody help me out here? I kind of figured there would be something in the File Exchange, but searches like 'simulink system time' return huge applications that seem to have nothing to do with what I want.
Thanks in advance,
Zack

Answers (1)

Walter Roberson
Walter Roberson on 30 Nov 2011
I would not really expect Simulink to have a block for that, unless it was a target-specific block, as there are a lot of embedded systems that do not have any time-of-day device.
Time-of-day devices need to have a battery backup, as they must keep counting while the system is otherwise turned off. Those batteries run out, making time-of-day devices unsuitable for situations where there is no interface for the user to input the time.
There is not just one way to interface time-of-day devices: some are port-mapped and some are memory-mapped and some involve running special instruction sequences.
  4 Comments
Walter Roberson
Walter Roberson on 30 Nov 2011
The 70 and 71 are hex port numbers -- i.e., 112 and 113 decimal.
Zachary Santer
Zachary Santer on 1 Dec 2011
Thank you for the work you did in finding all that information. I am constantly humbled at what real programmers do. I wouldn't even know where to begin in making a C function to deal with all that.
I ended up just evaluating 'now' in the script that places the needed variables in the workspace, loading that through a Constant block, and adding the simulation time/86400 (seconds in a day) to that value during each simulation step.

Sign in to comment.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!