CAN(Controller Area Network) Bus Communication
System Based on Matlab/Simulink
Fang Li, Lifang Wang, Chenglin Liao
The institute of electrical engineering
Chinese Academy of Sciences
Beijing, China
{lifang, wlf, liaocl}@[Link]
Abstract—CAN bus communication system was established In this paper, a CAN bus communication system that built
mainly using SimEvents module in the software of using Matlab/SimulinkTM is given. A case study is employed
Matlab/Simulink. Performance indexes of CAN bus system, to compare the results obtained by Matlab with those obtained
which embraces worst-case response time of messages and bus by theoretical calculation and CANoe experiment seperately.
load, were separately gained by theoretical calculation, The system can offer an efficient and visible environment for
experiments in Matlab and CANoe. The calculation and analyzing CAN bus real-time performance.
experiment results were compared sufficiently, and it concludes
that CAN bus system established in Matlab/Simulink can
efficiently represent the message transfer sequences on the CAN II. CAN BUS PERFORMANCE ANALYSIS
bus, and achieve an exact result of the performance analysis of
the CAN bus system. With CAN bus system established in A. CAN bus Network and Message Model
Matlab/Simulink, test modules for ECU(Electric Control Unit) CAN bus uses CSMA+AMP(Carrier Sense Multiple
testing can conveniently be created, and it is an efficient testing Access with Collision Detection and Arbitration on Message
tool for CAN bus system design. Priority) mechanism. The access technique of CAN bus makes
it rather flexible. However, it also brings some problem when
Keywords - CAN bus; SimEvents; performance analysis; ECU analyzing system performance and guaranteeing predictable
testing
communication, since the communication can not be known in
advance in CAN bus system.
I. INTRODUCTION
The message model assumes a network with n messages
Controller area network (CAN) [1] provides high reliability streams defined as N={S1,S2,ĂSn}. Where Si, i ∈ (1,2,Ăn)
and good real-time performance with very low cost. Due to
defines a message stream i characterized by a unique
this, CAN now is widely used in a wide range of applications,
identifier, and message i can further defines a three element
such as in-vehicle communication, automated manufacturing
stream Si=(Ci Ti Di ). Ci is the longest message transfer time
and distributed process control environments.
during of a stream and Ti is the periodicity of its requests.
In order to guarantee real-time performance and reliability Finally, Di is the relative deadline of a message; that is, the
of CAN networks, it is necessary to analyze system maximum time interval between the instant when the message
performance before it is running practically on the real vehicle. request is placed in the outgoing queue and the instant when
the message is completely transmitted.
There are mainly two methods to analyze the system’s real-
time performance. One is based on mathematical model. The
method [2] applyed processor scheduling analysis to CAN bus, B. CAN bus system performance analysis
the worst case real-time behavior of CAN bus (message Based on message model, system performance analysis is
response time, bus load, etc.) is bounded and can be accurately mainly concerned to calculate message response time and bus
predicted. This method is widely used in the automotive areas, load. The worst-case message response time of a queued
for example, the VNA software of Mentor Graphics Company message, measured from the arrival of the message request to
[3] is based on this method. its complete transmission. And bus load is the total message
transfer time in per time unit. The message stream set
Another method to evaluate the real-time performance of schedulability is guaranteed if every message has a response
CAN bus system is testing or experiment. CAN Bus models are time smaller than its deadline.
established using different tools such as Sate flow and OPNET
[4]. Adriano Carvalho [5] did experiments on the permanent 1˅Response time (Rm) analysis
faults of CAN bus using the Markov tool. But this work is not Rm=tm+Cm ˄1˅
visible, and the paper’s results can hardly be used in the real The term tm represents the worst-case queuing delay – longest
world. time interval between the arrival of the message request and
the start of its transmission.
978-1-4244-2108-4/08/$25.00 © 2008 IEEE 1
Authorized licensed use limited to: COLLEGE OF ENGINEERING - Pune. Downloaded on January 23,2022 at [Link] UTC from IEEE Xplore. Restrictions apply.
§ ª tm + tbit º · messages that should be sent, message ID, and message
t m = Bm + ¨ » × C j ¸¸ ˄2˅
¨ ∀j∈¦ « sending period, can all be configured freely.
© hp ( m ) « T j » ¹
Different from message sending module, message
Where Bm is the worst-case blocking factor, which is equal to receiving module receives messages from controller module,
the longest duration of a lower priority message. and unpacked the signals from messages.
Bm = max {0, Ck } ˄3˅
∀k ∈lp ( m )
B. Controller Module
lp(m) is the set of message streams with lower-priority than
message stream Si; hp(m) is the set of message streams with Controller module makes use of the queuing theory to
implement CAN bus data link. Fig.3 presents the functional
higher-priority than message streams Si; tbit is the duration of
structure of the controller module. In the controller module,
a bit transmission.
message sending and receiving queue is realized by the
2˅Network load analysis “Queue module” in SimEvent Library, they simulate sending
and receiving buffer of CAN controller in the node. Another
§ C · ˄4˅
U = ¨¦ m ¸ two important components - sending and receiving monitor -
© ∀m Tm ¹ in the controller module are used to monitor the messages
being transferred. For example, when a message sending error
III. CAN BUS COMMUNICATION SYSTEM happens, the sending node will retransmits this message, while
In order to implement event-based mechanism of CAN there is an error in the receiving process, the receiving node
bus, SimEvents modules in Simulink are used, which extends will discard the message.
Simulink with a discrete-event simulation model of
computation. Fig.1 shows a functional architecture of CAN
bus communication system, which contains message sending
module, message receiving module, controller module, and
bus arbitration module.
Figure 1. CAN Bus Communication System Figure 3. Controller Module
A. Message Sending and Receiving Modules C. Bus Arbitration Module
Message sending module (Fig.2) sends the packaged Bus arbitration module (Fig.4) emulates the arbitration
message entities to the controller module, which prepares for mechanism of CAN bus. It embraces CSMA/CD module,
the communication process. Message arbitration module, and Replicate module. In the
“CSMA/CD module”, a gate is designed, which is used to
detect the current state of CAN bus. If there is a message
being transferred, it will wait until the bus is free. When there
are multiple messages arriving at the same time, the “Message
arbitration module” will put the message with the highest
priority on the bus, that is, it sends the message to the
“Replicate module”. The “Replicate module” realizes the
broadcast function of CAN bus, which sends one message to
multiple receiving nodes.
Figure 2. Message Sending Module
In message sending module, “Message Generator Module”
in SimEvents Library is used to generate message entities, and
“Set Attribute Module” is also employed to package the
message entities with corresponding attributes, which consist
of message ID, RTR, message data length, message data, etc.
To fulfill different system requirements, the number of
Figure 4. Bus Arbitration Module
978-1-4244-2108-4/08/$25.00 © 2008 IEEE 2
Authorized licensed use limited to: COLLEGE OF ENGINEERING - Pune. Downloaded on January 23,2022 at [Link] UTC from IEEE Xplore. Restrictions apply.
IV. CASE STUDY 2) Bus Load
To validate the correctness of the system established in Similar to the process of message response time, calculate
Matlab/Simulink, experiments have been done and the results theoretical bus load by (4) and record bus load in the
will be compared with the theoretical calculation and CANoe experiment of Matlab under worst case.
experiment seperately. The result shows that bus load in Matlab is 41.5%, less
All the calculation and experiments are done under the than the theoretical value 57.31%. Actually, the worst case
hypothesis that CAN bus baud rate is 250Kbps and there are situation is hard to reach in the real system.
no bus errors. In table 1, the messages [6][7]transferred on the
network are listed. There are 17 messages and message ID are E. Compare with CANoe Experiment
from 1 to 17. DATAi represents data bytes number of CAN In the real situation, the hardware and control algorithm
messages, while Ti and Di represents message period and are different for nodes, thus the clock and active time of the
deadline separately, which have already defined in section II. nodes are not the same. In order to emulate the real situation
and do the comparison between Matlab and CANoe, start time
TABLE I. CAN BUS MESSAGE MODEL of messages that has the periods multiplied each other are
ID DATAi Ti Di ID DATAi Ti Di aparted, so that the confliction is reduced.
(bytes) (ms) (ms) (bytes) (ms) (ms)
1) Message Response Time
1 1 1000 5 10 2 10 10
Record message response time seperately in Matlab and
2 2 5 5 11 1 100 20
CANoe experiment. The response time of two message are
3 1 5 5 12 4 100 100
plotted in Fig.6~Fig.9 (see the APPENDIX). Message 1 and
4 2 5 5 13 1 100 100
message 17 has the highest and lowest priority in the network.
5 1 5 5 14 1 100 100
we can see that:
6 2 5 5 15 3 1000 1000
7 6 10 10 16 1 1000 1000 • In Fig.6 and Fig.7, the maximum response time of
8 1 10 10 17 1 1000 1000 message 1 in Matlab and CANoe are 0.75ms and
9 2 10 10 0.7ms separately.
D. Compare with the Theoretical Calculation • In Fig.8 and Fig.9, the maximum response time of
message 17 in Matlab and CANoe are 2.1ms and
In sectionĊ, CAN bus performance indexes are calculated 2.2ms separately.
under the worst-case situation. Since in Matlab experiment, all
nodes comply with a unified windows clock, which is different 2) Bus Load
from the real system, so if the timers in the nodes used for Fig.10 and Fig.11 (see the APPENDIX) shows the bus
sending messages is not configured properly, for example, the load in Matlab and CANoe experiment, which are 41.5% and
clock deviation is set to zero, it inevitably leads to great 43.53% seperately.
conflict on the bus, this is similar to the worst case situation of
Through the comparison between Matlab and CANoe, it
the theory calculation.
can conclude:
1) Message Response time • In Matlab and CANoe experiment, the maximum
Calculate the theoretical message response time by (1)~(3). response time of most messages and the bus load are
Then do experiment under worst case in Matlab and record the
very close to each other.
minimum and maximum response time of messages.
• Because there are less confliction, the message
Fig.5 plots the results, we can see that the message
response time in Matlab and CANoe experiments are
response time obtained in Matlab is less than or equal to the
deduced dramatically, which are much less than the
theoretical values.
theoretical values.
V. CONCLUSIONS AND FUTURE RESEARCH
CAN bus communication system is designed by the
SimEvent module and other modules in Matlab/SimulinkTM.
Through comparison with the results of theoretical calculation
and CANoe experiment, it concludes that communication
system established in Matlab/SimulinkTM can represent the
message transfer sequences on the CAN bus correctly, and can
be used as an efficient CAN bus analysis or testing tool.
However, there exists some places to be improved, for
example, in the controller module, a bus error counter module
should be designed, and the bus error will be considered in the
Figure 5. The worst case response time of messages in Matlab future system performance analysis.
compared to theoretical values
978-1-4244-2108-4/08/$25.00 © 2008 IEEE 3
Authorized licensed use limited to: COLLEGE OF ENGINEERING - Pune. Downloaded on January 23,2022 at [Link] UTC from IEEE Xplore. Restrictions apply.
ACKNOWLEDGMENT [4] C. Bayilm, [Link]ürk, C. Ceken, etc. “Modeling controller area networks
using discrete event simulation technique”, Complex Computing
The authors would like to thank the anonymous reviewers Networks, vol. 104, Springer Berlin Heidelberg: Germany, 2006, pp.
for their helpful comments. 353-358
[5] Carvalho, A., and Portugal, P., “On dependability evaluation of field
bus networks: a permanent fault analysis”, Proceedings of the 27th
REFERENCES Annual Conference of the IEEE Industrial Electronics Society, Denver,
[1] International Standard Organizaion (ISO). “Road vehicles – Interchange Colombia, USA, 2001, pp. 299-304.
of digital information – Controller area network (CAN) for high-speed [6] [Link], [Link], [Link], “Integrating inaccessibility in response
communication”, ISO 11898, 1993. time analysis of CAN networks.” Proceedings of the IEEE International
[2] Wolfhard Lawrenz, “CAN system engineering from theory to practical Workshop on Factory Communication Systems, Porto, Portugal, 2000,
application”, New York: Spring-Verlag, 1997. pp. 77-84.
[3] Thomas Heurung, “In-Vehicle network design methodology” 㧘 [7] [Link], [Link], [Link], “Calculating controller area network
[Link] (CAN) message response time”, Control Engineering Practice, vol. 3,
, 2002 no.8, pp. 1163-1169, August, 1995.
APPENDIX
Figure 6. The Response time of message 1 in Matlab Figure 7. The Response time of message 1 in CANoe
Figure 8. The Response time of message 17 in Matlab Figure 9. The Response time of message 17 in CANoe
Figure 10. The bus load in Matlab Figure 11. The bus load in CANoe
978-1-4244-2108-4/08/$25.00 © 2008 IEEE 4
Authorized licensed use limited to: COLLEGE OF ENGINEERING - Pune. Downloaded on January 23,2022 at [Link] UTC from IEEE Xplore. Restrictions apply.