Advertisement
Responsive Ad Slot (Vector Toolchains & Embedded Certifications)
🚗 Automotive System Focus: Powertrain Gateway & Network Scheduler

Bus Jitter, Transmission Latency & Cycle Drift Analysis

In automotive networks, periodic messages must maintain strict cycle times. An engine status message specified at 20ms must not arrive at 15ms or 25ms due to bus arbitration delays or buffer congestion. CAPL timing scripts analyze arrival deltas and compute jitter statistics in real time.

Overview & Key Concepts

CAN Signals & Message Timing in CAPL (CAN Access Programming Language) Scripting

CAPL (CAN Access Programming Language) is a high-level programming language used for automotive and embedded system applications, particularly for CAN bus communication. In CAPL, signals and message timing play a crucial role in simulating and testing CAN communication systems.

Here, we will explain CAN Signals, Messages, and Timing in CAPL, followed by detailed examples.

CAN Signals and Messages in CAPL

A CAN signal represents a specific piece of data within a CAN message, while a CAN message is the entire frame of data that is transmitted over the CAN bus. CAPL allows you to interact with both signals and messages to simulate, test, or analyze the behavior of the CAN network.

A CAN message consists of several parts

Identifier (ID): The ID of the message, which determines the priority of the message.

Data: The actual data sent, represented as signals.

CRC: The cyclic redundancy check for error detection.

Control Information: Includes stuff bits, acknowledgement, etc.

For example, a CAN message in CAPL might look like this

cpp

CAPL CAPL - For example, a CAN message in CAPL might look like this
message CanMessage1 {
// Message identifier (ID)
id = 0x123;
// Data length (8 bytes max for CAN 2.0)
dlc = 8;
// Signal 1 (e.g., temperature)
signal Temperature : int32;
// Signal 2 (e.g., pressure)
signal Pressure : float;
}

This message can represent a frame with two signals: Temperature and Pressure.

Signals in CAPL

Signals in CAPL are associated with a CAN message, and they define the data type and size. A signal is typically extracted from or assigned to a message. A signal's value can be changed or read during simulation or test.

Example of signal definition

cpp

CAPL CAPL - Example of signal definition
variables
{
message CanMessage1 msg;  // Define a message object
}
on message CanMessage1  // Event triggered on receiving the message
{
int32 temperature = msg.Temperature;  // Accessing the signal
float pressure = msg.Pressure;        // Accessing the signal
write("Received Temperature: %d, Pressure: %f", temperature, pressure);
}
In the above example:
CanMessage1 is a message type.
Temperature and Pressure are signals within that message.

When CanMessage1 is received, the on message event handler accesses the signal values.

Message Timing in CAPL

Message timing is critical for simulating and controlling how often messages are transmitted, how they interact, and how synchronization between different modules is achieved. CAPL offers various mechanisms to work with timing, including timers, event handling, and signal changes.

Example of Timing with Timer

cpp

CAPL CAPL - Example of Timing with Timer
variables
{
msTimer messageTimer;  // Define a timer
}
on start
{
setTimer(messageTimer, 1000);  // Set a timer to trigger after 1000ms (1 second)
}
on timer messageTimer
{
// Send a message periodically every second
output(CanMessage1);  // Transmit CanMessage1 message
setTimer(messageTimer, 1000);  // Reset the timer for the next period
}
In this example:

A timer named messageTimer is set to trigger every 1000 milliseconds (1 second).

When the timer triggers (on timer), it sends the message CanMessage1.

After sending the message, the timer is reset, causing the message to be sent every second.

Sending Messages at Specific Time Intervals

CAPL allows you to schedule the transmission of messages based on timing events, such as periodic signals from ECUs or timed requests.

cpp

CAPL CAPL - Sending Messages at Specific Time Intervals
variables
{
message CanMessage1 msg;
}
on start
{
setTimer(messageTimer, 500);  // Send message every 500ms (0.5 second)
}
on timer messageTimer
{
msg.Temperature = getTemperatureSensorData();  // Set a signal value
msg.Pressure = getPressureSensorData();        // Set another signal value
output(msg);  // Send the message with the updated signal values
setTimer(messageTimer, 500);  // Reset timer for next message
}
In this example:

A message with signals (Temperature and Pressure) is transmitted every 500ms.

The signals are updated with sensor data and sent out via output(msg).

Signal-based Timing

Sometimes, you need to trigger actions based on signal values or signal changes over time. For instance, you might want to monitor when a signal exceeds a threshold and then trigger a message or some event.

cpp

CAPL CAPL - Signal-based Timing
variables
{
message CanMessage1 msg;
}
on signal Temperature  // Trigger event when Temperature signal changes
{
if (Temperature > 100)  // Check if temperature exceeds a threshold
{
msg.Alert = 1;  // Set an alert signal
output(msg);    // Send the message with the alert
}
}
In this example:

When the Temperature signal changes, it checks if the value exceeds a threshold (100).

If the threshold is exceeded, an alert signal (Alert) is set in the message and transmitted.

Using CAN Timing Functions

CAPL also offers several timing functions to manage CAN message reception and time delays effectively:

msleep(time): Sleep for time milliseconds before executing the next command.

setTimer(timer, time): Set a timer to trigger after time milliseconds.

cancelTimer(timer): Cancel a running timer.

These functions allow you to simulate real-time behaviors and delays in CAN communication. Here's an example of msleep():

cpp

CAPL CAPL - Using CAN Timing Functions
on start
{
output(CanMessage1);   // Send the message
msleep(1000);          // Wait for 1 second
output(CanMessage2);   // Send another message after 1 second delay
}

In CAPL scripting

Signals represent individual data elements in a CAN message and can be accessed or modified as part of the CAN message structure.

Message Timing is managed through setTimer(), msleep(), and other timing functions, allowing messages to be sent at specific intervals or after certain delays.

Signal-based Timing allows you to trigger events based on signal values or changes, such as generating alerts or sending data when certain thresholds are met.

These features enable effective simulation and testing of CAN systems, including real-time communication and time-dependent behavior in embedded automotive applications.

⚠️ Common Pitfalls & CANoe Troubleshooting Tips
  • Remember that `this.time` resolution depends on the hardware channel configuration (standard is 10 microseconds per unit, or 1 microsecond in high-precision setups).
  • Be aware that timer interrupts in the Windows operating system introduce small software scheduling variations; use hardware timestamps (`this.time`) for rigorous bus jitter verification.
📝 Concept Mastery Assessment
12 Questions Score: 0 / 0

Select your answer for each question below to receive immediate correctness evaluation and in-depth technical rationale.

Question 1 of 12
What is the 'Cycle Time' of a periodic CAN message?
Explanation
Cycle Time is the regular periodic repetition rate defined for that frame in the network database (DBC).
Question 2 of 12
What is Message Jitter in automotive CAN communication?
Explanation
Jitter measures timing irregularity caused by CAN bus arbitration delays, task scheduling latency, or CPU load.
Question 3 of 12
What is a 'Debounce Time' (Minimum Send Time) attribute in a CAN database?
Explanation
Debounce time enforces a minimum spacing between bursty event frames, preventing high-priority messages from starving the bus.
Question 4 of 12
What transmission mode is used when a CAN frame is transmitted both periodically AND immediately upon signal value change?
Explanation
Hybrid transmission sends frames cyclically (heartbeat) while also transmitting immediately whenever a critical signal changes.
Question 5 of 12
How do you detect a message timeout (missing ECU heartbeat) using CAPL in an automated test?
Explanation
Watchdog timers scaled to 1.5x - 2.5x nominal cycle time detect absent messages, validating ECU fail-safe behavior.
Question 6 of 12
What is End-to-End (E2E) protection in automotive safety-critical CAN communication?
Explanation
AUTOSAR E2E protection detects data corruption, stale frames, and dropped messages using sequence counters and CRCs.
Question 7 of 12
How does an Alive Counter (Sequence Counter) work in a safety-critical CAN message?
Explanation
Rolling sequence counters (0, 1, 2... 15, 0) enable receivers to detect dropped frames, duplicate transmissions, and frozen ECUs.
Question 8 of 12
What is the CAN bus load (utilization percentage)?
Explanation
Bus load measures bus bandwidth saturation. Automotive standards recommend keeping average bus load below 60-70%.
Question 9 of 12
What function in CANoe retrieves the current bus load percentage of a CAN channel?
Explanation
CANoe provides system variables and API functions (@sysvar::CAN::Busload) reporting live bus utilization.
Question 10 of 12
Why does high CAN bus load increase transmission jitter for lower-priority messages?
Explanation
Dominant arbitration favors lower IDs. When bus load is high, lower-priority frames must wait, introducing timing jitter.
Question 11 of 12
What is the standard tolerance window for message cycle time verification in automotive OEM test specifications?
Explanation
Most automotive OEM test specifications require message cycle times to stay within +/- 5% to +/- 10% of nominal.
Question 12 of 12
How do you verify in CAPL that an ECU transmits its first startup message within 100 ms of vehicle ignition switch ON?
Explanation
Timestamping the ignition event and calculating delta to the first CAN frame arrival verifies startup latency.
0 / 0 (0%)
Great job! Review the questions above and proceed when ready.
🛠️ Hands-on Automotive Challenge: CAN Message Cycle Jitter Monitor

Write an `on message 0x150` handler that computes the elapsed time since the previous arrival. Assuming a nominal 20ms cycle (2000 units in 10us resolution), calculate the jitter (measured - nominal). If absolute jitter exceeds ±2ms (200 units), log a timing violation.

Verified CAPL implementation:

CAPL Solution - CAN Message Cycle Jitter Monitor
variables {
  dword gLastMsgTime = 0;
  const dword NOMINAL_CYCLE = 2000; // 20ms in 10us units
}

on message 0x150 {
  if (gLastMsgTime != 0)
  {
    long delta = this.time - gLastMsgTime;
    long jitter = delta - NOMINAL_CYCLE;

    if (jitter > 200 || jitter < -200) // Exceeds +/- 2ms
    {
      writeLineEx(0, 2, "JITTER VIOLATION: Msg 0x150 cycle was %.2f ms (Jitter: %+.2f ms)", 
                  delta / 100.0, jitter / 100.0);
    }
  }
  gLastMsgTime = this.time;
}
Advertisement
Responsive Ad Slot (Automotive Embedded Systems Career Resources)