Design and application of CAN bus isolator based on C8051F040

Publisher:WiseSage123Latest update time:2009-12-08 Source: 电子设计工程 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction

CAN (Controller Area Network), or controller area network, is one of the most widely used field buses. CAN bus can be applied to high-speed networks and low-cost line networks with its advantages of strong real-time performance, high reliability, simple structure, good interoperability, and low price. Here, a communication system of CAN bus isolator is proposed, which is applied to the communication network from an aircraft to the ground to achieve speed isolation between the aircraft and the ground, so that the aircraft and the ground can communicate stably and in real time. Based on the analysis of CAN bus 2.0B protocol, the system design adopts a structured method to independently design the communication protocol between the aircraft and the ground. The hardware design of the bottom module is based on the C8051F040 high-speed single-chip microcomputer, which integrates the CAN protocol controller internally. Therefore, only the addition of a CAN transceiver can realize the design of CAN intelligent nodes, which is simpler, more reliable, and easier to operate than the traditional CAN node composed of a single-chip microcomputer and a CAN protocol controller. The CAN bus application layer protocol is defined and written by the user, making it more in line with the system design requirements. At present, the whole system runs well, with stable performance and good communication redundancy, which meets the requirements of industrial field use.

2 Design of CAN intelligent node based on C8051F040

Figure 1 is a schematic diagram of the CAN bus hardware interface based on C8051F040. Through the CAN controller integrated inside the C8051F040, in order to enhance the anti-interference ability of the system, the optocoupler 6N137 is connected between the CAN controller and TJA1040, so as to realize the CAN communication between TJA1040 and the outside world. In fact, the integrated transceiver TJA1040 itself has instantaneous anti-interference ability, which can protect the bus and reduce radio frequency interference to achieve thermal protection function. Therefore, in the application occasions where the interference is not serious, there is no need to increase the optoelectronic isolation so that the system can reach the maximum communication rate or distance. If an optoelectronic isolator is used, a high-speed optoelectronic isolator should be used as much as possible to reduce the delay time of the effective loop signal transmission of the CAN bus. Since the CAN isolator needs to collect the data information of the input and output modules through the CAN bus, the interference is large. For the stability and reliability of the system, an optoelectronic isolator needs to be added. Through the connection communication test of CAN2.0B compatible with CAN2.0A protocol, the photocoupler 6N137 has a rise time of 30 ns (typical value), an isolation voltage of 3 000 V, and supports a maximum frequency value of more than 30 MHz.

CAN bus hardware interface principle circuit diagram based on C8051F040

In order to achieve the stability and reliability of the system, the system design adopts a redundant design, using the dual-channel optocoupler HCPL2631 to isolate and generate control signals to control two single-pole double-throw switches MAX4635, thereby realizing the switching of CAN intelligent nodes.

3 CAN bus isolator design

The CAN bus isolation designed in this system mainly consists of two parts: sending and receiving. Both the sending and receiving parts are composed of three units: data instruction configuration, data processing and data transmission, as shown in Figure 2. In the sending part: after the host computer instruction is configured, it is transmitted to the microcontroller through the FPGA. The microcontroller uses its own CAN bus, which reaches the bus driver after isolation processing, and then outputs data through the CAN bus. The receiving part is just the opposite. The system design sets the aircraft speed to 500 kHz and the ground speed to 50 km/s to better simulate the communication between the aircraft and the ground.

4 Communication protocol between the isolator transmitter and receiver

The bus isolator is divided into two parts: the aircraft high-speed interface and the ground low-speed interface. The isolator is required to pass all data from the ground to the aircraft. The CAN bus of this system adopts the master-slave mode. All bus data uniformly adopts data frames, without remote frames. The maximum data length is 8 bytes and the minimum is 0 bytes. According to the data link layer protocol, the arbitration field standard identifier is 11 bits (ID1O~ID0), and the system determines the priority of data transmission through the identifier. This protocol stipulates that in addition to indicating the priority, the ID is also the data receiving destination node, the data sending source node and the data type. Specifically explain the 11-bit ID: ID[1] (0-3 bits of ID) is the data receiving destination node; ID[2] (4-7 bits of ID) is the data sending source node; ID[3] (8-10 bits of ID) is the data type.

In this protocol, both the aircraft system and the ground system have three nodes, and the node numbers and ID numbers are shown in Table 1.

Node number and ID number

5 CAN isolator software design

5.1 CAN bus initialization

CAN bus initialization includes: I/O configuration, external crystal oscillator configuration, CAN bus opening and closing, sending and receiving initialization. The initialization procedure is as follows:

void initial_can(unsigned char MsgNum,unsignedl int id)
{SFRPAGE=CONFIG_PAGE;

Initialization Procedure

5.2 Sending and receiving procedures

CAN message transmission is automatically completed by the CAN controller. The user only needs to transfer the corresponding data to the transmission buffer register according to the identifier of the received data frame, and then write the encoding of this message object into the command request register to start the transmission. The transmission is completed by hardware. Here, the data in the message object is updated regularly. The data transmission is automatically completed by the controller. When a data frame is received, the data frame with the same identifier can be sent out. The transmission program code is as follows:

Send program code

The reception of CAN messages is the same as the transmission, which is automatically completed by the CAN controller. The receiving program only needs to read the received data from the receiving buffer and then process it accordingly. The method is basically the same as the sending program, so I will not repeat it here.

6 Key Technology Design Analysis

6.1 Redundancy Design

The conditions on industrial control sites are complex. The cable contact failure rate caused by external forces is much higher than the node failure rate. Once a cable fails, the bus will lose its communication capability and cause the system to crash, posing a threat to the robustness of the industrial control system. The simplest and most effective way to solve this problem is to design redundancy for physical media with a high failure rate. That is, use two bus cables and two CAN bus transceivers, but only one bus controller. The arbitration circuit automatically monitors the bus status and adaptively selects a normal cable to complete the communication task. When a cable failure occurs, the device automatically alarms to remind the staff to perform maintenance. During the maintenance process, the device continues to work using the spare cable. The cable redundancy design can achieve code-level compatibility with the usual CAN bus communication system. The arbitration circuit is set between the bus controller and the two bus transceivers to monitor the CAN bus cable status and achieve adaptive switching and alarm. When the device sends a message to other nodes, the bus controller sends the same message to the two buses at the same time; when receiving a message, the arbitration circuit always uses bus 1 (main bus) to receive the message when there is no cable failure. If bus 2 (slave bus) fails, the fault monitoring circuit will send an interrupt signal to the main control computer to report the fault, while bus 1 in normal state will still undertake normal communication tasks; if bus 1 fails, the fault monitoring circuit will automatically switch to bus 2 while sending an interrupt signal to the main control computer to ensure the normal operation of the equipment. The bus switching action will only occur when the cable in use fails, which can improve the stability of communication and reduce the probability of response failure.

6.2 Implementation of ID non-filtering when receiving data

In the receiving process of the CAN bus, the method of matching the sending ID and the receiving ID is generally implemented, that is, the receiving party needs to receive and filter the ID. However, this design implements any receiving method. As long as there is data, it starts receiving without filtering the ID number. This allows for better testing. For example, the ID number carried by a certain device does not match the ID received by the receiving party due to various reasons. In this way, it can be determined that the sending device may be interfered with, or there is a problem with the sending device itself. This method of not filtering the ID number is mainly implemented by setting the command request register, message mask register, arbitration register, message control register and command mask register of the receiving device. The implementation procedure is as follows:

Implementation Procedure

7 Conclusion

This paper proposes a solution for implementing a CAN bus isolator. The C8051F series microcontroller with a CAN bus controller is used to implement a CAN intelligent node, increase the redundancy design of the CAN node, improve the stability of communication, and reduce the probability of response failure; the unfiltered CAN data reception can better test the reliability and monitoring function of the system. When a message is received that is not sent by a known device, the location of the device failure can be accurately located. The CAN bus isolator implemented by this solution has been successfully applied to a ground test bench for a certain type of aircraft. After testing and debugging, the system works stably and meets the design requirements. And because of the use of an embedded CAN bus controller, a lot of space can be reserved for future system upgrades.

Reference address:Design and application of CAN bus isolator based on C8051F040

Previous article:Oilfield power indicator parameter monitoring system based on ZigBee technology
Next article:Design of Power Quality Parameter Monitoring System for Electrified Railway

Latest Industrial Control Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号