
CAN channel loop-back demo on a single RT Box
•CAN1 baud rate specifies the baud rate for CAN transmission. Note that all devices on a CAN
bus must be configured to use the same baud rate. Here in this demo the default value of 500 kHz
is used.
•CAN1 tx/rx pin specifies which I/Os to use for CAN communication. The option Internal CAN in-
terface is available on all RT Box versions except RT Box 1 with hardware revision earlier than
1.2. For older revisions the digital in and out pins 26/27 can be used to set up a CAN interface.
Please note that an external CAN transceiver chip needs to be added by the user.
• If the Internal CAN interface is chosen above, a new field Termination for CAN1 will appear.
Each end of a CAN Bus should have a termination resistance of 120 Ωbetween CAN-Hi and CAN-
Low. As this example discusses a direct point-to-point connection, the termination resistance should
be enabled for both CAN interfaces.
Build the “RT Box” model onto the RT Box. Once the model is uploaded, from the External Mode
tab of the Coder options... window, Connect to the RT Box and Activate autotriggering. The real-
time simulation results are shown in Fig. 6.
• The first signal received in an unsigned integer with a value of 10. By changing the Constant value
in front of the CAN Pack block to another value (for example: from 10 to 20) during run-time, one
should see the change reflected on the first received signal of the Scope in Fig. 6 immediately.
• The second received signal is a 1 Hz, 0.5 duty cycle digital pulse alternating between 0 and 1.
• The third signal is a 5 Hz Triangular waveform with duty cycle of 0.5 changing between -5 and +5.
• The fourth signal is a 5 Hz Sine waveform with amplitude of 1.
• The fifth signal shows the valid flag asserted when new valid data arrives
One can also see in the last two signals that the 10 ms staircase effect of quantization correctly reflects
the Sample time setting in the CAN Transmit block. The “v” port signal of the CAN Receive block
goes high only when new data arrived. The signal can be used to trigger potentially time consuming
calculations implemented in a triggered/enabled subsystem. This demonstration uses a simple setup
where the first two signals are added and the last two signals are multiplied.
4 Conclusion
This RT Box demo model demonstrates a loop-back test using the integrated CAN interface on the
RT Box. It shows how to set up the CAN interface in the Coder settings and how CAN messages are
formed in a PLECS model using CAN Pack and Unpack blocks. The demo model runs in both offline
and in real-time simulation.
www.plexim.com 5