Skip to content

§ 1.6. Clock Generator

A clock is an ordinary signal in the one global time line (§ 1.1 Events and the simulator): the clock generator toggles it at a fixed half period.

Component Description Structural Behavioral
ClockGenerator A square wave with a fixed half period Yes No

The structural form is the leaf itself.

1.6.1. ClockGenerator

ClockGenerator drives a square wave on one output. In the catalog it is the contract timing.clock with the parameter half_period, in ticks.

IO pins

Pin Direction Width Description
CLK_OUT Output 1 The clock

Behavior

The clock starts low. When it is started at time t₀ (startClock), it rises at t₀ and then toggles every half period: high at t₀, low at t₀ + h, high at t₀ + 2h, and so on, for a period of 2h. Until it is started it drives nothing. The clock's own logic takes no time; only the half period separates the edges.

C++ example

#include <cstdint>

// The clock level at time t, started at t0 with half period h (t >= t0).
bool clock_ref(uint64_t t, uint64_t t0, uint64_t h) {
    return ((t - t0) / h) % 2 == 0;
}

This binary function describes the driven level. It is not a registered implementation.

Unknown inputs

There are no inputs. The output is never X or Z once the clock has started.

Implementation

Structural implementation

A leaf with no children. Each evaluation inverts the level, publishes it with zero delay and schedules the next evaluation one half period later. The certified clock periods of the cores are in § 1.2 Clocks.

Examples

ClockGeneratorTest starts a clock with a half period of 5 ticks at time 0 and checks its edges: high at 0, low at 5, high at 10, and so on. It has no inputs, so it has no example table; the simulation below shows the waveform.

Embedded simulation

The clock scenario runs ClockGeneratorTest.

Open ClockGenerator in the simulator

Source and tests

Test Coverage
ClockGeneratorTest Half period 5: high at 0, low at 5, high at 10, low at 15, high at 20