Main Content

Clock resolution

Description

The Clock resolution parameter specifies the clock resolution that the code generator applies in generated code for functions in a model that include blocks that request absolute or elapsed time.

Clock resolution is the smallest increment of a clock value. For example, if a clock increments its value once per second, the clock resolution is 1 second. The parameter setting does not change solver behavior for normal, accelerator, and rapid accelerator mode simulations. However, the parameter setting does influence the data type that Simulink® and the code generator use to represent time values. For example, Simulink uses a specified clock resolution to deduce fixed-point data types, which produces fixed-point simulation and generated code execution output that match.

How the code generator applies a specified clock resolution depends on code interface configured for a model. For models that you configure with a data code interface, the clock resolution that you specify influences the clock tick in generated code. For models that you configure with a service code interface, the clock resolution influences timer service interface calls in the code. When you configure a model to use a service interface, you can specify a clock resolution that aligns with the clock resolution of a target platform. This results in entry-point function code that reads time values that are more accurate and can achieve improved real-time behavior.

For a model configured to use a service code interface, the code generator checks the value of the related Application lifespan (days) parameter. Timer service interfaces support 32-bit clock tick values. If the Application lifespan (days) parameter setting is large enough to result in a clock tick that cannot be stored as a 32-bit value, then an overflow condition results and the code generator returns an error.

Category: Math and Data Types

Settings

Default: -1
scalar

For models simulated in normal, accelerator, or rapid accelerator mode or configured with the System target file parameter set to ert.tlc, you can specify a scalar value, which represents the clock resolution in seconds.

  • Simulink and the code generator use the value to determine the data type for representing time values.

  • The code generator applies that value in generated code for model functions that include blocks that request absolute or elapsed time.

If a model includes a periodic function that includes a block that requests a time value, the value that you specify must divide the sample times used in periodic functions in the model with no remainder. For example, if a model includes periodic functions that use sample times 1, 0.2, and 0.1, then 0.05 is a valid clock resolution setting but value 0.03 is not valid. If the value that you specify for the clock resolution is not a divisor, you must change the clock resolution setting or the offending sample time.

For models configured with a system target file other than ert.tlc, or to get the clock resolution behavior that was provided in previous releases, set Clock resolution to the default value (-1). When the parameter is set to -1, the code generator initializes clock resolutions based on scheduling properties for the model style and type of an entry-point function. For example, the code generator sets the clock resolution for an aperiodic function in an export-function model to the model fixed-step size (fundamental sample time). For periodic functions, the clock resolution is set to the function sample time.

Dependencies

  • To enable this parameter, set the solver parameter Type (SolverType) to Fixed-step.

  • This parameter requires an Embedded Coder® license for generating code.

Command-Line Information

Parameter: ClockResolution
Type: double
Value: scalar
Default: -1

Recommended Settings

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
EfficiencyPositive integer
Safety precaution-1

Related Topics