How to get system time into simulink (under Real-time windows target)?
조회 수: 21 (최근 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!