> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/rt-lab/configure-ios/communication-protocol-ios/can/canfd-four-channels-example.md).

# CANFD Four Channels Example

## Description <a href="#description" id="description"></a>

The **CANFD\_4\_channels** example can be created by starting a new RT‑LAB project. From the menu bar, select **File > New > RT‑LAB Project**. Enter a name and location for your project, then click **Next**. From the available templates list, navigate to **IO > Generic > CAN > Kvaser** and select **CANFD\_4\_channels**, then click **Finish**. This example demonstrates how to use the **CAN interface** to exchange CAN messages between multiple CAN channels using a **physical loopback configuration**. The example illustrates message transmission and reception, cyclic and non‑cyclic messages, dynamic CAN identifiers, and CAN FD operation.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-87b53f9874010e750b2038768d27921ff2036e00%2FDR-rtlab-can-ex7.png?alt=media" alt="" width="383"><figcaption></figcaption></figure>

Four CAN channels are used in this example. Channels are connected in loopback pairs to allow messages transmitted on one channel to be received on another channel within the same simulator.

## Requirements

The simulator must be equipped with a **Kvaser PCIe CAN interface card (**[**OP3411**](https://www.opal-rt.com/docs/pcie-cards-and-connector-kits/pcie-cards/op3411-kvaser-pcie-can-bus-kits.md)**)** providing **four CAN channels**. Physical CAN **loopback connections** must be installed between:

* **Channel 1 and Channel 2**

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-ca8dca8c143626db3c231ad33609be0255e0c496%2FDR-rtlab-can-ex2.jpg?alt=media" alt=""><figcaption></figcaption></figure>

* **Channel 3 and Channel 4**

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-6bd7eda8afe2c5bf6cadd66c65e6d83cd640c8c7%2FDR-rtlab-can-ex8.jpg?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
The CAN loopback cables shown above include **internal 120 Ω termination resistors at both ends**, providing proper bus termination for loopback operation.
{% endhint %}

[Verify that an active RT-LAB license](https://www.opal-rt.com/docs/rt-lab/licensing-reference/simulator-license.md) with the following features is installed on the simulator:

<table><thead><tr><th width="245">Feature Name</th><th width="175">Required Status</th><th width="320">Description</th></tr></thead><tbody><tr><td>CAN</td><td>enabled</td><td>Enables CAN</td></tr><tr><td>CAN_CHANNEL_NB</td><td>4 enabled (or more)</td><td>Number of activated CAN channels</td></tr></tbody></table>

## Detailed explanation

All four CAN channels are configured to operate at a **bit rate of 1 Mbps** with **CAN FD enabled**, allowing payloads of up to **64 bytes**. Silent mode, extended mode, and promiscuous mode are disabled on all channels.

Each channel transmits one CAN message with the **Dynamic ID** option enabled, allowing the CAN identifier to be modified at runtime from the Simulink console. Channels 1 and 2 transmit **non‑cyclic messages**, and require an explicit enable signal to be transmitted at each model time step. Channels 3 and 4 transmit **cyclic messages**, and also require an explicit enable signal to be transmitted at their configured transmit rates.

Messages transmitted on Channel 1 are received on Channel 2, and vice versa. Similarly, messages transmitted on Channel 3 are received on Channel 4, and vice versa, validating bidirectional CAN communication through physical loopback.

### Model preparation and configuration

1. Review and adjust CAN interface parameters such as bit rate, CAN FD mode, or message configuration as desired.
2. Build the CANFD\_4\_channels model.
3. Load the model and verify that all CAN interface connections are correctly established.
4. Execute the model.

## Simulation and results

Once the simulation is running, the CAN channels begin exchanging messages through the physical loopback connections.

The **Console subsystem** allows runtime interaction with the CAN interface, including modifying dynamic CAN IDs, updating transmitted data, enabling or disabling message transmission and reception, and monitoring received data and status information. Data transmitted on one channel can be observed as received on its paired channel, confirming correct CAN configuration and operation.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-05f575e10e2f6e92f8a09856c1eb635c43b45924%2FDR-rtlab-can-ex9.jpg?alt=media" alt=""><figcaption></figcaption></figure>

Successful execution of this example validates correct CAN channel configuration, message timing, dynamic identifier handling, and CAN FD communication using RT‑LAB.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/rt-lab/configure-ios/communication-protocol-ios/can/canfd-four-channels-example.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
