Abstract

Controller area network (CAN) has wide applications in modern industrial control systems. Automobile manufacturers use this communication protocol for vehicle control, which is subject to real-time and high-reliability performance. However, with the increasing actuators gathered in the vehicle, time delay will lead to a serious problem for the vehicle safety and performance control. Thus, the information transmission stability of the CAN message needs to be investigated. In order to find out the delay response time of nonperiodic CAN message in the vehicle bus area, the response of the message transmitted in the CAN bus is modeled based on the GI/G/1 queue theory. The test platform is developed to verify the methodology. In the experimental test, some conditions with different IDs, load ratios, and priorities are investigated. Experimental results are compared with the theoretical results, and the simulation results show that the method is valid and verify the real response delay time of nonperiodic CAN message.

1. Introduction

With the rapid development of the vehicle technology, vehicles are developed as a transportation facility and become more convenient for people. More and more functions are developed for comfort, accessibility, and practicality compared with the past. In order to meet the comfortable and reliability demands of passengers, modern technology has integrated entertainment equipment, personal communication electronic device, wireless connection, and other functions into one car. All these components connected to the network system achieve their function through the electronic control units (ECUs); with the increasing demand for cars, the number of ECUs is growing. There may be more than 100 ECUs to provide all the electronic functions in high-end vehicles [13]. Since the information is exchanged through those ECUs with the interconnected data buses, it is necessary to optimize the communication network to reduce the cost and improve the performance.

Controller area network [46] is designed as a microcontroller in the automotive industry and has become a global standard. Now CAN has been well extensively used in other areas due to its high real-time properties and low cost, such as industrial automation, aircraft industry, industrial control, safety protection, and other fields. No matter in which field, the real-time analysis of CAN bus is still the research; see [79] and the references therein. In [2], Sato and Fukumoto analyzed the response time of CAN with randomly occurring messages based on M/G/1 queuing theory. Lim et al. [10] investigated the signal distortion in a controller area network with flexible data rate, and the presented model-based analysis can closely approximate the size and time response of ringing and the extent of bit time distortion. Mubeen et al. [11] analyzed periodic, sporadic, and mixed transmission of messages in CAN with implementation of priority queues and FIFO queues.

However, for the general CAN bus network communication, due to the message triggered randomly, the real-time property is also related to the random sending messages. In this paper, the nonperiodic CAN bus communication is investigated. Based on the queue theory GI/G/1 and the bit-stuffing mechanism, the delay time can be read clearly at different ratios.

The rest of this paper is organized as follows. Section 2 mainly describes the basics of CAN bus and mathematical queue GI/G/1 model. Section 3 presents the delay model of nonperiodic CAN message which is composed of queue theory about the waiting time and bit-stuffing mechanism about the transmission time. The experimental platform is set up in Section 4. In Section 5, the analysis work about the data compared with the experimental theory is developed. Finally, Section 6 concludes the paper.

2. Theoretical Analysis

CAN is a multimaster serial communication bus, and it is designed not only with high bit rate and high antielectromagnetic interference but also detecting any occurring error. The CAN communication protocol mainly described the ways of information communication between different devices. With the CAN layer and the definition of the open systems interconnection (OSI), all devices can communicate with the same layer. Real communication can be implemented on every equipment between two layers, and information was only interconnected by physical media. Usually, the specification of CAN defines the bottom transmission via two layers: the data link layer and physical layer. CAN communication could use a variety of physical media, such as twisted-pair cable and optical fiber. The most commonly used is twisted-pair wiring. Signals using a differential voltage and two signal lines are referred to as CAN_H and , the static voltage is about 2.5 V, the state is expressed as logic 1, which can also be called a Recessive, and is higher than , which can be presented as logic 0, known as the “dominant”; thus, equals 3.5 V and becomes 1.5 V.

The delay of CAN communication can be divided into four parts: generation delay, queuing delay, transmission delay, and delivery delay [12]. The generation delay refers to the time from receiving the request of sending message from the sending node processor to writing the message data into the cache queue; queuing delay refers to the time from the message frame entering the sending buffer queue to the time when the message frame occupies the bus; the transmission delay refers to the time from the message occupying the bus to leaving the bus; delivery delay refers to the time when a message departs from the bus to the receiving node receiving data and providing it to the target processor. Generally, the generation delay and the delivery delay are generally related to the characteristics of the hardware electrical equipment, and the delay time is small. Therefore, once considering the CAN communication delay, the queuing delay and the transmission delay are considered. This paper mainly discusses these two parts of the CAN delay.

2.1. Transmission Mechanism of CAN Bus

Data in CAN bus is divided into two types: one is the standard frame, and the other is extended frames. The main difference between these is the length of identifier ID. The schematic diagram of the standard frames is shown in Figure 1.

The main difference of two CAN types between standard frame and extended frame is the length of message. The standard frame has an 11-bit identifier and the extended one has 29-bit identifier. The identifier must be unique, which means that the message derived from different sources must have different identifiers.

Once the bus is at least 6 recessive bits, it is called idle, and all nodes join in the bus with pending messages ready to transmit from the identifier field. According to the arbitration mechanism, a node will not transmit a message if it sent a recessive bit, and the bus level is dominant. Only when the node level is the same as the bus level through whole ID field will the node be allowed to transmit messages. That means the message ID is used for the arbitration mechanism: the smaller the ID, the higher the priority. Thus, the identifier has two purposes: (1) the priority of the frame and (2) making the receivers able to filter frames. It should be noted that the data transmit in the bus will only have 0∼8 bytes and each byte of message occupies 8 bits in data field, and the data field has 0∼64 bits. For more details about other fields in the frame, the reader is referred to [2, 9].

CAN uses NRZ (non-return-to-zero) encoding mode for bit synchronization. In CAN bus, it will be seen as an error flag when the bus has 6 consecutive same polarity bits (000000 or 111111). To avoid those special bit patterns, once a send node has successively transmitted 5 same polarity bits (00000 or 11111), it will additionally add one opposite polarity bit (as a stuff bit). When the receive node has detected 5 same polarity bits, it will remove the stuff bit. This process is called bit-stuffing mechanism.

2.2. Queue Mode Modeling

Queuing is a normal phenomenon in daily life; for example, people queue to register in the hospital and line up in the store and cars on the highway queue to toll station. The queue system [1315] consists of two parts: one needs to be served and the other provides the services. Those people or things that need to be served are called customers and service for customers is called service counter. The queuing service system can be seen as the customers and the service counter. The GI/G/1 queue [16, 17] model is usually described as follows: the customers arrived at time , , …; arrival time interval sequence , where (n = 1,2, …,  = 0) are independent from each other and follow the same distribution function ; , and ; here is a constant. The service time sequence of customers needed is independent and follows the general distribution , and is taken as the average service time. The system follows the FIFO (first-in-first-out) mechanism and only has one service counter.

In GI/G/1 queue system, can be seen as the customer arriving in the system at time , and can be seen as the waiting time of customer . Customer arriving in the system will meet two statuses: one is that the service counter is busy and the other is that the service counter is idle. The two statuses are shown in Figures 2(a) and 2(b). The process can be formulated as

Here, is the customer’s waiting time when it arrives in the system, and thereby could be greater than 0 or equal to 0. could be shown as

Let , and equation (2) can be described as

According to equation (3), we can know that

According to [18], the upper boundary of the average waiting time for the mean waiting time of the GI/G/1 system is adopted. In this paper, when , there will be

Here, is the variance of service time, is the variance of arrive interval time, and indicates the load level or intensity of the system. Thereby, the inequation can be deduced into two parts.

In equation (6), the first part on the right can be seen as the waiting time of customers in the queue when a new message arrived, and the second part is the average service time of the current customer served by service counter when a new message arrived. That means if denotes the current customer-rest service time when a new customer arrives, we can get

The average staying time of a message can be obtained by the total time of the average service time and average waiting time, and the expression is

3. Delay Analysis for Nonperiodic CAN Message

Based on the knowledge of queue theory, if messages occupy the bus and transmitted data was considered as service, then the nodes in the CAN bus need to occupy the bus in the messages transmission process which can be regarded as customer, and the CAN bus provides the physical media to transmit the messages by arbitration and managing the message transmission; the bus can be called service counter.

Generally, the messages in the CAN bus system are sent continuously; the total number of customers is infinite, and let the arrival interval time of customer follow general independent distribution. The CAN bus employs the Carrier Sense Multiple Access (CSMA) protocol to arbitrate the messages. This means that if the low-priority message is sent, the higher-priority message needs to wait to be sent until the low-priority messages are sent completely, and if the higher-priority messages are sent, the priority message cannot be sent. This process accords with the service protocol of nonpreemptive discrimination of priorities. The status of transmission finish for a message in CAN bus is only when all the bits were sent completely. Thus, we could consider the transmission time as the service time. Due to the fact that the CAN bus transmission time followed a probability distribution according to the difference of stuffing bit, the service time followed the general probability distribution. There are many nodes in a CAN bus but only one node can send message transmitted on the bus at a moment, which means that there is only one service counter. On the basis of these features of the CAN bus transmission mechanism, we adopt the GI/G/1 queue theory [12, 19, 20] to model the delay of nonperiodic CAN messages.

3.1. Queue Theory and the Waiting Time

The model of CAN bus queue and service is shown in Figure 3. The following can be summarized based on the figure:(1)N nodes in CAN bus represent n customer’s arrival interval time sequence, and they share one bus.(2)The customers have priority; the range of the priority from high to low was 1, 2, …, n, respectively. Service mechanism employs the nonpreemptive discrimination of priorities.(3)The speeds of arrivals are , , …, .(4)The customer’s service time followed the general distribution, and, in different levels, the average service time is , , …, .

On the basis of the message priority from high to low, the first high-priority message is called class 1, the higher-priority message is class 2, and the lowest-priority message is class n. For the class 1 message, its average waiting time is expressed as below. When a class 1 message arrives, the remaining transmission time (the average rest service time) of the messages that are transmitting through the bus is , and the average waiting time is supposed to be

From equation (7), the average rest service time is supposed to be

Here, represents the kinds of messages, represents the speed of class i message arrivals, is the variance of transmission time, and is the variance of arrive interval time. For the class 2 message, its average waiting time is expressed as follows:(1) is the remaining transmission time (the average rest service time) of the messages that are transmitting through the bus.(2)When class 2 message arrives, the total transmission time of remaining class 1 message in the queue is supposed to be(3)When class 2 message arrives and during its waiting period, a new class 1 message arrives, and the total transmission time of new higher-priority (class 1) message is supposed to be

According to equations (9), (11), and (12), the average waiting time of class 2 message can be deduced:

For the class i message, its average waiting time is expressed as follows:(1) is the remaining transmission time (the average rest service time) of the messages that are transmitting through the bus.(2)When class i message arrives, the total transmission time of remaining higher priority than i messages in the queue is supposed to be(3)When class i message arrives and during its waiting period, a new higher-priority message arrives, and the total transmission time of new higher-priority messages is supposed to be

According to equations (14) and (15), the message average waiting time of class i can be deduced:

3.2. Bit-Stuffing Mechanism and the Transmission Time

The transmission time is regarded as service time, so we need to figure out the transmission time. As mentioned above for the bit-stuffing mechanism, it will make the real transmitted message bits be greater than original bits.

According to the CAN standard, before the bit-stuffing mechanism, the total number of bits in a CAN frame is

Here, is the number of bits of the data in messages, ; is the number of control bits in CAN frame, and, for standard frame, ; and, for extended frame, . The total number of bits exposed to bit-stuffing is 8 + ; the remainder including Cyclic Redundancy Check (CRC) delimiter bit, ACK field, EOF, and Int, all 13 bits, are without bit-stuffing.

After bit-stuffing, the total number of bits of a message iswhere T is the total number of stuffed bits.

In the worst situation, an opposite polarity bit every 4 bits will be inserted, as shown in Figure 4. Due to exposure to bit-stuffing only having 8 +  bits, the maximum of T is

The transmission time of a message in the worst situation will bewhere represents the time taken to transmit a bit on bus.

In fact, the message’s stuffing bits are always less than the worst-case scenario; the value of T is less than the maximum , and the real transmission time is less than the value as shown in equation (20); the relationship between transmission time and stuffing bits T satisfies the equation

Due to the bits having different arrangements, the transmission time changes randomly. In [9], after bit-stuffing, the real probabilities of having a certain frame length can be calculated. If we transmit a message with 7 bytes, before bit-stuffing, the length of a frame can be at most 103 bits and among them 90 bits are exposed to bit-stuffing. In this 90-bit probabilities model, the following will be assumed: (1) equal probability of bit values 0 and 1 and (2) no dependency among bits. According to the bit-stuffing probability distribution, the mean and variance of transmission time can be calculated by using equation (21). The mean and variance of transmission time for standard format messages with 7 bytes are 106.48104 t and 2.0078405 , respectively.

As mentioned above, according to the waiting time and the transmission time, the online delay of nonperiodic CAN message can be derived from equations (8), (16), and (21).where represents the average service time and represents the average waiting time.

4. Experimental Test

Actually, the nonperiodic CAN messages transmission is a triggering process. In real condition, the CAN nodes get a send request which is random and then the message is sent. Therefore, we use the random sequence as the messages arrival interval time in this experiment through the random interval sequence to send CAN messages in send nodes and use the oscilloscope to detect the received messages in the receiving node and save the datum.

The experimental platform includes two parts: the hardware network nodes system and the data collecting system. The hardware devices adopt the Freescale MC9S12X series single chip which is built-in CAN module. This nodes system totally has five nodes, which are consistent with three built-in CAN modules and two CAN analyzer device named CANalyst as four send nodes and one receive node. In more detail, one built-in CAN module acts as a receiving node, the other built-in module acts as the sending node, and the test built-in CAN module and two CAN analyzer act as the interrupt nodes to change the bus load ratio and compete the bus with the sending node. The test and save system was the digital oscilloscope; it could give intuitive level changes and could save the delay datum about the sending and receiving moment. The whole platform is shown in Figure 5. Numbers 1, 2, and 5 are the CAN module embedded in the Freescale 16-bit MC9S12X series single chip. Number 1 is the sending node in CAN bus, number 2 is the interrupting node in CAN bus, and number 5 is a receiving node in CAN bus; numbers 3 and 4 are the CAN analyzers as two interrupting nodes in the CAN bus; number 6 is a high-accuracy digital oscilloscope, as the delay time data save system; number 7 is the computer, mainly for the CANalyst sent data through a software interface on the computer.

In the experimental platform, the delay of nonperiodic CAN messages with different bus load ratios at different IDs and different priorities is tested and saved in an actual CAN communication process.

4.1. Nonperiodic CAN Test Results

The experiment is implemented and the data are handled, respectively, in ID1, ID2, ID3, and ID4 with ratios of 9.84%, 12.208%, 15.168%, and 18.974%. In each test, 50 time intervals are set, 51 messages are sent at one time, and 10 times data are saved for the data of every ID with every bus load ratio. Then, the time difference between receiving and sending is adopted to be the response time, and the value obtained is the average of 10 test data. The following are the detailed data for the nonperiodic CAN messages’ response time.

In the first experiment, ID1 is set as the send node, and the nonperiodic CAN messages transmitted from the send node to receive node are tested. Then, deal with the datum to get the difference between receiving moment and sending moment and the other operations. In the second experiment, ID1 is set as the send node and, like the first experiment, the third and fourth experiments are similar to the above; the response times of nonperiodic CAN messages are obtained in Table 1.

5. Comparative Analysis

As discussed above, we can calculate the theory value of the upper boundary of response time with different ratios and different priorities as shown in Table 2. According to the experiment, the ratios of 9.84%, 12.208%, 15.168%, and 18.974% are chosen. Due to the fact that the bus baud rate is 250 kb/s, the value of is . It is worth mentioning that the ID also means the priority, and the lowest ID has the highest priority which is already mentioned in Section 3.

Table 2 shows the response time trend with different priorities in ratios of 9.84%, 12.208%, 15.168%, and 18.974%, respectively. Figure 6(a) shows the priority increase in a certain bus load ratio, and the upper boundary of response time is increased. Figure 6(b) shows the bus load ratio increase in a certain priority; the upper boundary of response time is increased, and when the priority is the lowest, the trend of response time increases more quickly than the others, and the highest one is stable.

The experimental data are processed in the same ways as in the theory part. From Table 2, the trend about the response time with different priorities in ratios of 9.84%, 12.208%, 15.168%, and 18.974% is obtained and it is shown in Figures 7(a) and 7(b).

From Figure 7(a), we can draw the conclusion that, with the priority decrease in a certain bus load ratio, the upper boundary of response time is increasing; and, from Figure 7(b), it is shown that, with the bus load ratio increase in a certain priority, the upper boundary of response time is increasing and when the priority is lower, the response time is higher than the higher priority.

Comparing the test and theory data, Figures 8(a)8(d) represent the relationship between the test delay time of nonperiodic CAN messages and the theory in different bus load ratios; the results show that the theory analysis about the experimental data of the nonperiodic CAN message delay time is under the upper boundary of theory response time in GI/G/1queue system; and the trend of experimental change curve is similar to the theory.

6. Conclusions

This paper adopts the GI/G/1 queue system model to analyze the nonperiodic CAN messages time delay performance with nonpreemptive discrimination of priorities, and the experimental data reflect the reliability of the upper boundary of waiting time and the service time obtained by the bit-stuffing mechanism. The similarity between mathematical theory and the experiment about the trends of delay time in different ratios with different priorities also shows that the mathematical theory of the GI/G/1 queue system is feasible. Using the upper boundary of response time, the new model for the worse scenario of response time to handle the case of messages transmit in CAN bus will be investigated in the future.

Data Availability

The research data used to support the findings of this study are available from the corresponding author upon request.

Conflicts of Interest

The authors declare that they have no conflicts of interest.

Acknowledgments

This work was partially supported by the National Natural Science Foundation of China under Grant 51505276.