MATLAB Answers


How do I Interleave Two Different CAN Messages on the Same Channel?

I am looking to send multiple interleaved messages on the same CAN Channel, with one message being sent at some discrete set of times (0, 40, 80, etc.) and another message being interleaved on the same channel, sending at another set of discrete times (20, 60, 100, etc.). I have tried making use of the Periodic Message transmission, but the messages simply send at the same time.
How do I go about interleaving the message in the desired fashion?


No tags entered yet.




1 Answer

Answer by MathWorks Support Team on 22 Apr 2019
Edited by MathWorks Support Team on 22 Apr 2019
 Accepted Answer

I wanted to preface this by mentioning that Vehicle Network Toolbox is not a true real time simulation software. As such, we cannot guarantee that the messages being generated by the CAN Transmit in Simulink will necessarily be perfectly transmitted at the specified rates. For slower sample rates, this is usually not an issue, but for very rapid sampling this can become more apparent. Also since the transmission rate will be tied to the simulation, the more computationally intensive your simulation is, the more likely it is that the messages could lag.
That being said, I have attached an example model that demonstrates how you can interleave messages of different types on the same channel. The model name is "interleavedExample.slx".
Essentially the model works as follows. There are two different messages being sent to the same channel, MathWorks Virtual 1, Channel 1. Each message is packed and transmitted inside one of the enabled subsystem blocks in the model.
Enabled Subsystem Reference:
When each subsystem is enabled, it will be active, packing and sending the data in the form of the specified message type at the sample rate of the signal being fed into the subsystem (0.02 seconds in our case).
Each subsystem is governed by it's own pulse generator block, telling the subsystem when to activate and deactivate.
These pulse generator blocks are what enforce the delay between the subsystems and govern the interleaving. They are configured to alternate every 0.02 seconds, which creates the desired interleave timing for the messages.
One final thing that you need to configure is to set the pacing of the simulation so that it approximates real time. To do this you need to enable Simulation Pacing, found here:
Once this is set then you should be able to run the model and see the counter data being sampled by the alternating messages:


Sign in to comment.