Design and implementation of CAN bus intelligent nodes
2026-04-06 06:39:16··#1
Abstract: This paper introduces the basic characteristics of the CAN bus and the design and implementation of intelligent node digital and switching input/output, and gives the software development method. Keywords: CAN bus; SJA1000; intelligent node 1Introduction With the development of computer science and the increasingly in-depth application of 4C technologies (computer technology, automatic control technology, communication technology, and CRT display technology) to various aspects of industrial production, the structure of automation systems has been optimized and transformed, gradually forming a control system based on network integrated automation. Fieldbus has developed in response to this trend. With the continuous development of fieldbus technology and the continuous technological investment of many large companies around the world, fieldbus control systems (FCS) have made breakthrough progress in the real-time performance and accuracy of data exchange. This article, based on the author's practice, describes the design of a general CAN bus intelligent node, which is a subsystem distributed in the field of the fieldbus system. It can realize data acquisition and closed-loop control, and can also realize intelligent control after adding appropriate algorithms as needed. 2 Overview of CAN Bus CAN (Control Area Network) bus is a serial communication local area network that supports distributed real-time control systems. Due to its advantages such as high performance, high reliability, and real-time performance, it has been widely used in data communication between detection and actuators in control systems. It has the following technical characteristics: (1) multi-master mode operation, non-destructive priority-based bus arbitration technology; (2) multi-address frame transmission with the help of receiving filtering; (3) data adopts short frame structure, low interference rate, CRC check of data frame information and other error detection measures; (4) frames lost during transmission or broken due to errors can be automatically retransmitted; (5) automatic bus shutdown function for serious errors, so that other bus operations are not affected. The CAN bus conforms to the ISO11898 standard, with a maximum transmission rate of 1MB/s (maximum transmission distance of 40m) and a maximum transmission distance of 10km (transmission rate of approximately 5K). The transmission medium can be twisted-pair cable, coaxial cable, etc. As a promising fieldbus, the CAN bus has gained support from many large international companies. Its hardware interface is simple, programming is convenient, and system integration is easy. Based on these characteristics, the CAN bus is particularly suitable for situations where systems are geographically dispersed, real-time requirements are high, and field environments are subject to significant interference. 3. System Composition Using CAN Intelligent Nodes Since the CAN bus operates in a multi-master mode, it can support up to 110 nodes. The control system consists of a computer and intelligent nodes, as shown in Figure 1. Unlike the DCS control system, its topology is different. Not all lower-level machines are centered around the host computer; instead, all nodes (including the host computer) are connected to the bus as "equal entities." [align=center] Figure 1 CAN Bus System Structure Diagram[/align] Intelligent nodes can collect field data and send it to the CAN bus based on received commands or by actively sending data. By pre-setting acceptance codes and acceptance mask codes, the data or commands that the intelligent node receives from the bus can be controlled. If some data requires further complex processing, the host computer can receive the data from the bus. When the host computer needs to apply control actions to a node, it can communicate with that node in a point-to-point manner; when it needs to apply control actions to all nodes simultaneously, it can broadcast the commands to the bus. In this way, the host computer can operate normally without the participation of the host computer. This greatly reduces the amount of data transmission and improves the real-time performance and reliability of the system. 4 Hardware Design of Intelligent Nodes The CAN intelligent measurement and control node has field data acquisition, control, and CAN bus communication functions. It can transmit various parameters with the monitoring station and other CAN intelligent measurement and control nodes, and receive commands and data from the monitoring station to adjust and change the control state. Therefore, in the embedded ARM control system based on CAN fieldbus, the control node directly contacts the controlled object and plays a key role in the system. The intelligent node requires 3 pulse inputs, 5 switch inputs, 7 switch outputs, 2 analog inputs, and 2 analog outputs. The structural diagram is shown in Figure 2. To achieve the detection and control of on-site switching quantities, this node is designed with switching I/O channels, enabling 4-channel switching input and 4-channel switching output. The 4-channel switching input is isolated by an optocoupler before being input to the microcontroller's I/O port. The 4-channel switching output is output from the pins of port P1, driven by relays, providing passive switching control signals. Analog input is amplified and converted from analog to digital before being input to the microcontroller. The control output from the microcontroller is converted from digital to analog and then amplified to control the corresponding actuator. [align=center] Figure 2 Schematic diagram of the intelligent node structure[/align] The structural principle diagram of the CAN intelligent node is shown in Figure 3: The core components of the node are the CAN controller (SJA1000) and CAN driver (PCA82C250) manufactured by PHILIPS, as well as the microcontroller. The SJA1000 is an integrated independent CAN controller (fully compatible with PHILIPS' earlier CAN controller PCA82C200), responsible for completing the physical layer and data link layer functions of the CAN bus communication protocol. For a microprocessor, it is equivalent to a memory I/O image device. The SJA1000 has on-chip control registers, command registers, status registers, interrupt registers, and transmit/receive registers, etc. [align=center]Figure 3 Schematic diagram of intelligent node circuit[/align] The microcontroller controls the SJA1000 by reading and writing these registers; the TX0, TX1, RX0, and RX1 pins of the chip are used for interfacing with the CAN bus. The PCA82C250 is a 9-pin chip specifically designed for CAN bus transmit/receive driving. The TXD and RXD pins receive and transmit the driven signals, respectively; the twisted pair (coaxial cable) transmission medium is connected to the CANH and CANL pins, respectively. It is important to note that a 120Ω terminating resistor must be added between CANH and CANL. Considering various interferences in the field, a high-speed optocoupler isolation device (6N137) was added between the CAN controller and the driver. Since both the CAN controller and the microcontroller have their own internal clock generation circuits, an external crystal oscillator was added to the CAN controller as the system clock to ensure coordination between them. The clock output of the CAN controller was used as the clock input of the microcontroller. The interrupt output signal /INT of the SJA1000 was connected to the INT1 interrupt of the microcontroller. Communication between the microcontroller and the CAN controller was achieved through interrupts. Simultaneously, a manual reset circuit was added to ensure that the CAN controller and the microcontroller could be reliably reset simultaneously. 5. Node Software Design The software design of the intelligent node can be broadly divided into two parts: initialization, including the initialization of the microcontroller and the CAN controller; and the actual data acquisition and actuator control functions that the node needs to perform. After initialization, the node can operate. However, to complete the actual tasks, application layer software also needs to be designed. A fuzzy control algorithm was adopted, the control structure is shown in Figure 4, and the software flow is shown in Figure 5. [align=center]Figure 4. Structure Diagram of Fuzzy Control System[/align] The functions implemented by the system software are as follows: Sample the A/D conversion output value at time n, compare it with the system setpoint and the previous sampled value e(n-1) to obtain the deviation e(n) at time n; and the deviation change rate ec(n); select appropriate quantization factors ke and kc, and obtain fuzzy values E(n) and EC(n) according to the corresponding fuzzification rules; analyze the changing trends of E(n) and EC(n) to determine whether to add an integral term. Then, based on the values of E(n) and EC(n), directly look up the fuzzy control table in the program memory or perform integral calculations to obtain the fuzzy control increment. Finally, for the fuzzy control increment to be added or not added, use the maximum membership principle to make a fuzzy decision, select an appropriate scaling factor ku to obtain the control increment Δu, calculate the value of Δu+u(n-1), and obtain the control quantity at time n. This value can be transmitted to other intelligent units via the CAN bus, and after D/A conversion, it can control field devices or the host computer for further processing to coordinate the normal and effective operation of each control unit in the entire system. While handling the above tasks, the intelligent control unit also needs to complete data communication with the CAN bus and display and alarm the status of field devices. The fuzzy control master table calculated offline can be directly written into the chip's internal program memory in matrix form. Its software design flow is shown in Figure 5. [align=center] Figure 5 Flowchart of the fuzzy control implementation program of the intelligent unit[/align] The results of practical debugging show that the design and implementation of this intelligent node are successful. It can reliably operate and complete the required tasks. Control information is processed on-site, while the management layer is implemented in the host computer. This reflects the high performance and high reliability characteristics of the CAN bus. References: [1] Guo Sumin, Xiang Fenghong Design of intelligent data acquisition system based on CAN bus Journal of Kunming University of Science and Technology [2] Chi Dongming, Si Dongsen. Application of CAN bus in intelligent control system of parking lot lighting [J]. Microcomputer Information, 2005, 2: 46-47 [3] Lu Qianfeng, Liu Bo, Chen Mingzhao Design of intelligent control system based on CAN bus of SJA1000 Instrumentation [4] Wu Kuanming CAN bus principle and application system design [M] Beijing: Beijing University of Aeronautics and Astronautics Press [5] PHILIPS SJA1000 Stand-alone CAN controller DATA SHEET [Z] 2000