How to get system time into simulink (under Real-time windows target)?

14 Ansichten (letzte 30 Tage)
Kareem Abdelgawad
Kareem Abdelgawad am 24 Nov. 2014
Kommentiert: Jan Houska am 1 Dez. 2014
For the purpose of time stamping, I would like to read system time, i.e., PC clock, in Simulink under 'Real-time windows target'. Any ideas how to do this?

Antworten (1)

Jan Houska
Jan Houska am 28 Nov. 2014
In Normal mode, you can use any method you would use in Simulink. For example, a MATLAB Function block that returns the output of the clock function.
However, this wouldn't work in External Mode. Although there are ways to achieve the goal in External Mode, their usability depends on what you are trying to timestamp, what accuracy you need, etc. For example, I think I would be able to suggest a setup that would generate timestamps that would be highly accurate relative to each other but their absolute accuracy would be limited (the whole timestamp series may be somewhat shifted in time). Please let me know if you are interested.
  2 Kommentare
Kareem Abdelgawad
Kareem Abdelgawad am 28 Nov. 2014
Thank you Jan for your answer and readiness to help. I may need an accuracy of milliseconds. More would be also desirable as it would allow me to widen the spectrum of applications that I could serve. However, if you have any endeavours/ideas/ways to read PC clock (under Real-time windows target) as you mentioned, with any accuracy (whatever just to start) or if you have a method to generate time stamps in general, I would be very deeply grateful.
Jan Houska
Jan Houska am 1 Dez. 2014
Getting an absolute accuracy in order of milliseconds will be a real challenge. This would require to have your PC clock running exactly to a millisecond which is rarely the case and is itself difficult to achieve.
Anyway, I'm attaching a model that attempts to do what you need. It uses simulation time to get relative offset for timestamps and then reads the system time in a callback to Initial time offset block and adds it to the relative time. Because there is some delay between the execution of the callback and actual start of the model, additional offset is added by the Time offset tuning that can be fine-tuned to compensate for that.
Using this model, you should be able to get sub-millisecond relative accuracy of the timestamps (one vs. another), and absolute accuracy to hundreds or maybe even tens of milliseconds.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by