Documentation

Absolute and Elapsed Time Computation

关于计时器

某些块需要任何一个的值absolutetime (that is, the time from the start of program execution to the present time) or过去time (for example, the time elapsed between two trigger events). Targets that support the real-time model (rtmodel) data structure provide efficient time computation services to blocks that request absolute or elapsed time. Absolute and elapsed timer features include

  • 计时器在生成的代码中作为未签名的整数实现。

  • 在多次模型中,最多一个计时器是每个速率分配的。如果没有以给定速率执行的块需要计时器,则未分配计时器。这可以最大程度地减少分配的计时器内存,并大大减少与维护计时器有关的高架。

  • 分配过去time counters for use of blocks within triggered subsystems is minimized, further reducing memory usage and overhead.

  • S-function and TLC APIs let your S-functions access timers, in simulation and code generation.

  • The word size of the timers is determined by a user-specified maximum counter value,申请寿命(天)(Simulink). If you specify this value, timers will not overflow. For more information, seeControl Memory Allocation for Time Counters.

SeeAbsolute Time Limitationsfor more information about absolute time and the restrictions that it imposes.

定期和异步任务的计时器

Timing services provided for blocks execute withinperiodictasks (that is, tasks running at the model base rate or subrates).

The code generator also provides timer support for blocks whose execution is异步with respect to the periodic timing source of the model. See the following topics:

计时器的分配

If you create or maintain an S-Function block that requires absolute or elapsed time data, it must register the requirement (seeAccess Timers Programmatically)。在多次模型中,计时器以每速率分配。例如,考虑一个构造如下的模型:

  • There are three rates, A, B, and C, in the model.

  • 不blocks running at rate B require absolute or elapsed time.

  • Two blocks running at rate C register a requirement for absolute time.

  • One block running at rate A registers a requirement for absolute time.

In this case, two timers are generated, running at rates A and C respectively. The timing engine updates the timers as the tasks associated with rates A and C execute. Blocks executing at rates A and C obtain time data from the timers associated with rates A and C.

Integer Timers in Generated Code

在生成的代码中,绝对和经过的时间的计时器将作为无符号整数实现。默认大小为64位。如果指定一个值的值,这是计时器分配的内存量inf为了申请寿命(天)(Simulink) parameter. For an application with a sample rate of 1000 MHz, a 64-bit counter will not overflow for more than 500 years. SeeTimers in Asynchronous TasksControl Memory Allocation for Time Countersfor more information.

Elapsed Time Counters in Triggered Subsystems

Some blocks, such as the Discrete-Time Integrator block, perform computations requiring the elapsed time (delta T) since the previous block execution. Blocks requiring elapsed time data must register the requirement (seeAccess Timers Programmatically)。触发的子系统,然后根据需要分配并维护单个经过的时间计数器。该计时器在子系统级别,而不是在单个块级别上起作用。如果触发子系统(或触发子系统中的无条件执行的子系统)包含一个或多个需要经过的时间数据的块,则会生成计时器。

不te

If you are using simplified initialization mode, elapsed time is reset on first execution after becoming enabled, whether or not the subsystem is configured to reset on enable. For more information, seeUnderspecified initialization detection(Simulink).

相关话题

Was this topic helpful?