This example uses MathWorks Virtual CAN FD channels to set up transmission and reception of CAN FD messages, using Simulink®. The Virtual channels are connected in a loopback configuration.
Vehicle Network Toolbox™ provides Simulink blocks for transmitting and receiving live messages via Simulink models over networks utilizing the Controller Area Network Flexible Data (CAN FD) format. This example uses the CAN FD Configuration, CAN FD Pack, CAN FD Transmit, CAN FD Receive and CAN FD Unpack blocks to perform data transfer over a CAN FD bus. These blocks operate similarly to the existing CAN blocks, but are intended for use only on networks or devices that support the CAN FD protocol.
Create a model to transmit and receive a CAN FD message carrying a sine wave data signal. The model transmits a single message per timestep. A CAN database file (.dbc) defines the message and signal used in the model.
The CAN FD Receive block generates a function-call trigger if it receives a new message at any particular timestep. This indicates to other blocks in the model that a message is available for decoding activities. Signal decoding and processing is performed inside the function-triggered subsystem.
Plot the sine wave values before and after transmission. The X-axis corresponds to the simulation timestep and the Y-axis corresponds to the value of the signal. Note that the phase shift in the two plots. This represents the propagation delay as the signal travels across the network.
MathWorks CAN FD Virtual channels were used for this example. You can however connect your models to other supported hardware. You can also modify the model to transmit at periodic rates.