Missed CAN Rx Data in Mathworks Example As-is

35 views (last 30 days)
Corey
Corey on 8 Jan 2026 at 19:36
Edited: Corey on 15 Jan 2026 at 21:10
Attempting to run CAN send/receive example in Simulink 2024b:
openExample('vnt/GetStartedWithCANCommunicationInSimulinkExample')
If I simply open this example and run the model, the solver auto settings cause missing CAN rx data contrary to the documentation. The solver settings are set to Variable Step initially:
It is ALSO the case that the plotted results change between clicking run multiple times, without changing anything:
Then, if I change the solver to Fixed Step and speed up the sample time to 0.0001sec, I begin to get less dropped data:
Only if I speed all the way up to 0.000001sec sample time do I get all of the transmitted CAN data in the result:
The example makes no mention of this so I believe it to be an unintentional error. Moreover, I am trying to understand why it requires such a fast sample time to receive all of the data. The example is creating a sine wave input with sample time 0.01sec which gets transmitted as a 64-bit signal in a single CAN message. The CAN Receive block is set to sample time of 0.01sec by default. So in my thinking, the model should be transmitting new data every 0.01sec based on the sine wave input sample time. And then receiving/unpacking the updated data every 0.01sec as well. With everything set to 0.01sec nothing should be missing. Why do we have to run the model at multiple magnitudes faster to receive everything properly?
  1 Comment
Corey
Corey on 15 Jan 2026 at 21:08
Edited: Corey on 15 Jan 2026 at 21:10
I opened a MW support case about this issue and learned a bit. It turns out that virtual CAN transmission works on wall-clock time, while CAN receive works on simulation step time. So the tx/rx are not synced. The reason that speeding up the simulation timestep "worked" was that it literally slowed down the simulation, meaning it became closer to wall-clock time, which brought the Receive side closer to the transmission side.
There is apparently no way to force virtual CAN tx to synchronize with simulation time. The best that can be done is to use simulation pacing, to artificially slow down simulation time.
I had hoped to build simulation test harnesses for CAN communication using these virtual CAN blocks. If anyone has a way to synchronize the transmission with simulation time, please let me know.

Sign in to comment.

Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!