Clock
Display and provide simulation time
Libraries:
Simulink /
Sources
Description
The Clock block outputs the current simulation time at each simulation step. This block is useful for other blocks that need the simulation time.
When you need the current time within a discrete system, use the Digital Clock block.
Examples
Calculate and Display Simulation Step Size using Memory and Clock Blocks
This example shows how to use the Memory and Clock blocks to calculate and display the step size in a simulation. The Sum block subtracts the time at the previous time step, which the Memory block generates, from the current time, which the Clock block generates.
Because Inherit sample time is not selected for the Memory block, the block sample time depends on the type of solver for simulating the model. In this case, the model uses a fixed-step solver. Therefore, the sample time of the Memory block is the solver step size, or 1.
If you replace the Memory block with a Unit Delay block, you get the same results. The Unit Delay block inherits a discrete sample time of 1.
Extended Examples
Inverted Pendulum with Animation
Use Simulink® to model and animate an inverted pendulum system. An inverted pendulum has its center of mass above its pivot point. To stably maintain this position, the system implements control logic to move the pivot point below the center-of mass as the pendulum starts to fall. The inverted pendulum is a classic dynamics problem used to test control strategies.
Accurate Zero-Crossing Detection
How zero-crossing detection works in Simulink®. Simulink uses zero-crossing detection to accurately simulate an abrupt model change or discontinuity without decreasing the solver time steps. For more information, see Zero-Crossing Detection.
Ports
Output
Port_1 — Sample time
scalar
Sample time, specified as the current simulation time at each simulation time step.
Data Types: double
Parameters
Display time — Display simulation time on block icon
off
(default) | on
Select this check box to display the simulation time as part of the Clock block icon. When you clear this check box, the simulation time does not appear on the block icon.
Programmatic Use
Block Parameter:
DisplayTime
|
Type: character vector |
Values:
'off' | 'on' |
Default:
'off'
|
Decimation — Interval at which to update block icon
10
(default) | positive integer
Specify the interval at which Simulink® updates the Clock icon as a positive integer.
Suppose that the decimation is 1000. For a fixed integration step of 1 millisecond, the Clock icon updates at 1 second, 2 seconds, and so on.
Dependencies
To display the simulation time on the block icon, you must select the Display time check box.
Programmatic Use
Block Parameter:
Decimation
|
Type: character vector |
Value: scalar |
Default:
'10'
|
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Not recommended for production code. Relates to resource limits and restrictions on speed and memory often found in embedded systems. Generated code can contain dynamic allocation and freeing of memory, recursion, additional memory overhead, and widely-varying execution times. While the code is functionally valid and generally acceptable in resource-rich environments, smaller embedded targets often cannot support such code. Usually, blocks evolve toward being suitable for production code. Thus, blocks suitable for production code remain suitable.
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)