【问题标题】:TwinCAT - How to measure program execution time?TwinCAT - 如何测量程序执行时间?
【发布时间】:2021-08-08 10:50:59
【问题描述】:

我想测量结构化文本 (ST) 程序的执行时间。与程序关联的任务以 10 毫秒运行。

如何衡量执行时间?

【问题讨论】:

  • 目前不是很有用,但 Beckhoff 将来某个时候会推出 Profiler 产品。我认为它会附带 4026。它使您能够将 Profiler 项目添加到 PLC 项目中。然后 Profiler 将向您显示执行时间,直至各个功能/功能块。
  • Profiler 在2021 Automation update presentation中被提及

标签: plc twincat


【解决方案1】:

您可以使用免费的 TwinCAT 库 Tc2_Utilities,它有一个功能块 Profiler。

https://infosys.beckhoff.com/english.php?content=../content/1033/tcplclib_tc2_utilities/35053195.html&id=1344160655692967299

“Profiler”功能块可用于测量PLC代码的执行时间。

Infosys 页面也有一个示例代码:

VAR
    Profiler1     : PROFILER;
END_VAR


Profiler1(START := TRUE, RESET := TRUE);

//Do something here

Profiler1(START := FALSE);
//Now Profiler1.Data has the execution time

【讨论】:

  • 我的版本是 4024。我认为它没有分析器选项。我使用 LTIME 来获得 ns 的差异。
  • Profiler 功能块从 TwinCAT 2 开始就可用
【解决方案2】:

当然,您可以使用 Profiler,但仅出于演示目的,您可以像这样测量执行时间。

PROGRAM PLC_PRG
    VAR
        tStart: TIME; (* Time program start *)
        tWork : TIME; (* Execution time *)
    END_VAR

    (* First line of main program *)
    tStart := TIME();

    // Your program here

    (* Last line of your program *)
    tWork := TIME() - tStart;
END_PROGRAM

【讨论】:

  • 这是我的第一个想法。但是我的时间差是 ns 并且 TIME() 无法在该范围内进行测量。
猜你喜欢
  • 2011-02-16
  • 2020-03-07
  • 2021-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-28
  • 2019-10-03
相关资源
最近更新 更多