How to get system time into simulink (under Real-time windows target)?
14 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Jan Houska
2014-11-28
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 个评论
Jan Houska
2014-12-1
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Target Computer Setup 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!