CAPL Script

Measure One CAN Message Period in CAPL

Define which interval you want

The time between any two frames on a busy CAN channel is not the period of one message. For this walkthrough select CAN1, standard ID 0x200, received data frames, and one continuous recording. A change of channel, direction, ID or frame type changes the population being measured.

Use the timestamp attached to the message event. Reading the current execution time inside a handler answers a different question and can include when your processing happened. The TIME selector is expressed in 10-microsecond units; TIME_NS uses nanoseconds and an int64 value in the available reference. Nanosecond units do not establish the hardware's measurement accuracy. Check selector support in your installed CANoe version.

Observe matching frames

Use a separate observer node and the sender from messages and periodic timers. This complete illustrative source records the difference between consecutive matching events. It has not been compiled or run in your environment.

variables
{
  int havePrevious;
  int64 previousNs;
}

on start
{
  havePrevious = 0;
  previousNs = 0;
}

on message CAN1.0x200
{
  int64 currentNs;
  float intervalMs;

  if (this.DIR != Rx || this.RTR != 0) return;
  currentNs = this.TIME_NS;
  if (!havePrevious)
  {
    previousNs = currentNs;
    havePrevious = 1;
    write("First matching frame: no interval yet");
    return;
  }
  if (currentNs < previousNs)
  {
    write("Timestamp moved backwards; starting a new interval segment");
    previousNs = currentNs;
    return;
  }
  intervalMs = (currentNs - previousNs) / 1000000.0;
  previousNs = currentNs;
  if (intervalMs == 0)
  {
    write("Repeated timestamp: inspect the original trace");
  }
  write("CAN1 0x200 interval: %.6f ms", intervalMs);
}

The first timestamp establishes a baseline even when it is exactly zero. A separate havePrevious flag prevents the common mistake of treating zero as “no previous frame.” An equal timestamp yields a zero interval and a warning. A decreasing timestamp ends the current comparison segment; the following frame is compared with the new baseline. No sorting hides the discontinuity.

Units you can check by hand

Input representation Example difference Difference in milliseconds
TIME_NS 100,000,000 nanoseconds Divide by 1,000,000: 100 ms
TIME 10,000 ticks of 10 microseconds Divide by 100: 100 ms
Exported seconds 0.100 seconds Multiply by 1,000: 100 ms

The calculation subtracts integer timestamps before converting the difference to a floating-point millisecond value. This avoids unnecessarily rounding two large absolute values first. For long runs, also check the representation's range; do not silently combine recordings when clocks reset.

Export the same stream to the analyzer

  1. Filter the original Trace using the same channel, ID, direction and data-frame criteria. Do not export unrelated IDs between matching frames.
  2. Export or copy only the timestamp column, in original order, using a documented unit. Use elapsed timestamps from the recording origin rather than calendar dates.
  3. Open the message interval analyzer, choose that unit, and supply a target/tolerance from the test requirement. The two comparison values always use milliseconds.
  4. Compare a few hand-calculated pairs with the CAPL output. Then inspect median, maximum, P95, duplicate and reversal counts. A single mean can hide short and long intervals that balance.

For a synthetic input of 0, 0.100, 0.200 and 0.310 seconds, expect 100, 100 and 110 ms. This is arithmetic demonstration data, not measured CANoe output. The calculator preserves all rows and flags backwards intervals instead of joining across them; the observer prints a new-segment warning at the same discontinuity.

Interpret and troubleshoot

Symptom First check What you cannot conclude yet
Approximately half the expected period Mixed IDs, channels or directions That the sender doubled its rate
A gap near twice the target Trace continuity, filtering and sender state That exactly one frame was lost
Repeated timestamps Export duplication and timestamp resolution Two truly simultaneous physical transmissions
CAPL and CSV disagree Same stream, clock and unit; matching row pair A defect in either calculator without aligning inputs

Per-frame Write output is useful for a short debugging run but adds work. For longer observation use the original recording and offline analysis instead of printing every payload byte. Message count per second is an observation rate, not CAN bus utilization; estimating utilization needs additional frame and bus information. The reciprocal of one gap is not a stable average frequency either.

This page provides an inspection method, not a root-cause diagnosis or timing certification. Record the CANoe version, channel mapping, capture origin, unit, selected stream and test requirement when sharing results. See sources and validation limits.