Documentation Home Page HYPERSIM Home Page
Pour la documentation en FRANÇAIS, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

Example | CAN 4 channels


Location

This example model can be found in the software under the category "IO Interfaces" with the file name "CAN_4_Channels.ecf".

Description

This example model permits to test the CAN communication capability of the simulator.
It requires a CAN Kvaser 4-channel card, with channels 0 and 1 connected in loopback, and channels 2 and 3 connected in loopback. The network also requires a termination resistor.
Messages exchanged on channels 0 and 1 have manually built data frames, whereas messages on channels 2 and 3 have data frame definitions imported from a DBC file.

All 4 channels are configured with a bit rate of 1Mbps. Silent, extended and promiscuous modes are disabled. Each channel transmits 1 message with the dynamic ID option enabled. This means that the CAN ID of the message can be changed during the model's execution. Channel 0 receives messages sent by channel 1, and vice-versa; channel 2 receives messages sent by channel 3 and vice-versa.

The message to be transmitted from channel 0 (Bus_0/Node_0/Message_0) and that from channel 1 (Bus_0/Node_1/Message_1) are non-cyclical which means they have to be enabled (a connection to Enable Message exists for that purpose) for them to be transmitted every time step. The messages to be transmitted from channel 2 (Bus_Dbc/MCU_1/MCU_1_PARKING_CAMERA) and from channel 3 (Bus_Dbc/MCU_2/MCU_2_DOOR_LOCK) are cyclical and have a transmit rate of 10ms and 5ms respectively. To make a message cyclical, check the Enable Cyclic Transmission box and set a Transmit Rate. Cyclical messages have no Enable Message connection point and are transmitted at a rate specified by the Transmit Rate parameter.

All channels are configured with the FD (CAN with Flexible Data-Rate) feature enabled. This means that the payload of the messages exchanged is 64 bytes instead of the usual 8 bytes.

Flags and statuses for each channel can be monitored in ScopeView. 

It is possible to clear the transmission and reception buffers, as well as setting the MSG_STD and MSG_RTR bits of transmitted messages.

Setup

Prerequisites

Kvaser 4 channel card, with channels 0 and 1 connected in loopback and channels 2 and 3 connected in loopback, everything terminated with a termination resistor.

Configuration

Hardware

  • Ensure that the simulator has a Kvaser 4-channel card (check the delivery binder).

  • The card is connected to its breakout cable.

  • The cable has the connectors for channels 0 and 1 in a loopback.

  • The cable has the connectors for channels 2 and 3 in a loopback.

  • The cable has a termination resistor installed.

Simulation and Results

In order for data to be exchanged between channels 0 and 1, the following blocks need to have their value set to 1:

  • Ch0_Tx_Enable

  • Ch0_Rx_Enable

  • Ch1_Tx_Enable

  • Ch1_Rx_Enable

This is not necessary for channels 2 and 3, where the reception is already enabled and the transmission does not need any manipulation as the exchange is cyclical.

The user can change the values of the data sent as necessary by modifying the values of the blocks ChY_Tx_DataZ, where Y is the channel (0, 1, 2 or 3) and Z is the data (0, 1, 2, 3, 4, 5, 6 or 7).

Next, ScopeView can be used to validate that the loopback is functional by loading the template CAN_4_Channels.svt present alongside the model. The image below shows the result for channel 0, that all values sent match with those received:

 

The tabs Flags and Statuses permit monitoring information pertaining to the data exchange on the CAN bus. This can prove to be useful in case there is a failure to establish a successful loopback.

 

 

 

 

OPAL-RT TECHNOLOGIES, Inc. | 1751, rue Richardson, bureau 1060 | Montréal, Québec Canada H3K 1G6 | opal-rt.com | +1 514-935-2323
Follow OPAL-RT: LinkedIn | Facebook | YouTube | X/Twitter