Development of a CAN bus distributed measurement and control system based on AT89C52 microcontroller
2026-04-06 06:21:34··#1
1. Technical Characteristics of CAN Bus Networks ** Using communication data block encoding, it enables multi-master operation, offers flexible data transmission and reception, and supports various transmission methods such as point-to-point, point-to-multipoint, and global broadcast.** It can distribute the conventional testing and control functions of the host in a DCS structure to various intelligent nodes. Node controllers send the collected data to the bus via CAN adapters or request data from the bus, freeing the host from the previously heavy task of monitoring low-level devices, allowing for higher-level control and management functions, such as fault diagnosis and optimization coordination.** It employs non-destructive priority-based bus arbitration technology, enabling the identification of temporary and permanent faulty nodes and automatic removal of faulty nodes, ensuring uninterrupted communication for other nodes. Simultaneously, CAN features automatic retransmission of erroneous frames, ensuring high reliability. Signal transmission uses a short frame structure (8 bytes), providing good real-time performance. Nodes can be arbitrarily added or removed without shutting down the bus, enhancing system flexibility and scalability. The adoption of unified standards and specifications ensures good interoperability and interchangeability between devices, resulting in good system versatility. The communication medium can be twisted-pair cable, with no special requirements; field wiring and installation are simple, easy to maintain, and economical. In summary, the CAN bus has advantages such as strong real-time performance, high reliability, simple structure, good interoperability, and low price, overcoming the shortcomings of traditional industrial buses and providing an effective solution for building distributed measurement and control systems. 2. System Overall Hardware Design Scheme First, define the function of each node and determine the number, type, and signal characteristics of the detection or control quantities of each node. This is the first step in networking the microcomputer measurement and control system. The principle is to avoid redundant testing as much as possible. Most intelligent node modules are input/output modules, and adjustment loops can be formed across modules. However, considering the safety of the adjustment loop, to ensure that the loop adjustment is not affected in the event of a major fault in the host computer or the entire communication line, modules with adjustment functions, such as isolated, self-tuning PID controllers and isolated temperature controllers, are designed. Their input and output channels are all located in the same module, which boasts powerful underlying software. All input processing, output increment calculation (multiple adjustment algorithms can be selected through configuration, including cascade adjustment), output, and automatic identification of process parameters for the self-tuning module are all implemented within this module, ensuring the safety and reliability of the control loop. Secondly, the controllers for each node and the corresponding CAN adapter components are selected. Since each measurement and control node has a relatively simple function and small data volume, the CPU requirements are greatly reduced; an 8051 series microcontroller suffices. The CAN bus adapter components mainly include: controller interface, bus transceiver, and I/O devices. The Philips 82C200 CAN controller and its matching 82C250 CAN transceiver are used. The 82C200 possesses all the necessary characteristics required to complete a high-performance communication protocol. With its simple bus connection, the 82C200 can perform all functions of the physical layer and data link layer. Finally, the bus medium is selected according to the CAN bus physical layer protocol, a wiring scheme is designed, and the network is connected to form a CAN bus distributed measurement and control network. 3. System Hardware Composition (1) CAN Bus Interface Module ① Microprocessor Currently, there are two main types of widely used CAN bus devices: one is an independent CAN controller, such as 82C200, SJA1000 and Intel 82526/82527; the other is a microcontroller with a built-in CAN chip, such as P8XC582 and 16-bit microcontroller 87C196CA/CB. Based on the actual needs of the current market, development tools and the project, the intelligent nodes of the system all use the ATMEL 8-bit single-chip microcontroller AT89C52 as the microprocessor. ② CAN Controller The CAN controller uses SJA1000 as the controller. SJA1000 is a highly integrated CAN controller. It has a multi-master structure, bus access priority, group and broadcast message functions and hardware filtering functions. The input clock frequency is 16MHz, and the output is programmable. It consists of the following parts: interface management logic, transmit buffer, receive buffer, bit stream processor, bit timing logic, transmit and receive logic, error management logic, controller interface logic, etc. The SJA1000 boasts numerous new features: acceptance and transmission of standard and extended structure messages; a 64-byte receive FIFO; single/dual receive filters for both standard and extended frame formats; an error counter with read/write access; woven error alarm limits; a most recent error code register; an error interrupt generated for every CAN bus error; a lost arbitration interrupt with lost arbitration location functionality; single-transmit mode (no retransmission when the transmitter fails or arbitration is lost); listen-only mode (listening to the CAN bus, no acknowledgment, no error flag); and hot-plug support (interference-free software-driven bit rate monitoring). Therefore, the SJA1000 is selected as the CAN controller for all intelligent nodes in the system. ③ CAN Bus Transceiver: The PCA82C250 is selected as the CAN bus transceiver. The PCA82C250 serves as the interface between the CAN protocol controller and the physical bus. The 82C250 can provide different transmit performance for the bus and different receive performance for the CAN controller. Furthermore, it is fully compatible with the ISO 11898 standard. The PCA82C250 is designed to increase communication distance, improve the system's instantaneous interference immunity, protect the bus, reduce radio frequency interference (RFI), and provide thermal protection. To further enhance interference immunity, an isolation circuit consisting of the high-speed isolation device 6N137 is used between the two CAN devices. The hardware circuit design is not particularly difficult, but several points should be noted: The two 120Ω resistors at both ends of the bus play a crucial role in matching bus interference. Ignoring them will significantly reduce the interference immunity and reliability of data communication, and may even prevent communication altogether. The resistor Rs between pin 8 of the 82C50 and ground is called the slope resistor; its value determines whether the system operates in high-speed mode or slope control mode. Connecting this pin directly to ground will put the system in high-speed operation mode. In this mode, to avoid radio frequency interference, it is recommended to use a shielded cable as the bus. When the baud rate is low and the bus is short, a slope control method is generally used. The rising and falling slopes depend on the resistance value of the pin. Experimental data shows that 15-200kΩ is the ideal range for Rs. In this mode, parallel or twisted-pair cables can be used as the bus. The TX1 pin of the SJA1000 should be left floating, and the potential of the RX1 pin must be maintained at approximately 0.5Vcc; otherwise, the logic level required by the CAN protocol cannot be formed. If the system transmission distance is short and the environmental interference is low, current isolation is not required. In this case, the VREF pin (approximately 0.5Vcc) of the 82C250 can be directly connected to the RX1 pin, thus simplifying the circuit. In the system, the chip select signal of the SJA1000 is generally obtained by decoding the address bus, which determines the address of each register of the CAN controller. In practical applications, P2.7 of the AT89C52 microcontroller is used as the chip select signal. Therefore, the address of SJA1000 is: 7F00~7F32H. When the AT89C52 is powered on and reset, the power-on reset requires a low-to-high level change to activate it, while the RST pin 17 of the SJA1000 is activated, which requires a high-to-low level transition. Therefore, an inverter must be added. (2) Data acquisition module The data acquisition module is used to transmit data from various sensors to the CAN bus. The entire circuit includes: watchdog X5045, microcontroller 89C52, latch 74LS373, A/D converter ADC0809, CAN controller SJA1000 and transceiver 82C250. The working principle of the data acquisition module: After various sensors collect data, they transmit the 0-5V analog quantity to the ADC0809. The 0809 converts the digital quantity to the 89C52. Finally, the microcontroller sends the collected data to the SJA1000 and transmits it to the bus via the CAN bus transceiver 82C250 to complete the data acquisition. (3) The control module is an isolated controller with CAN communication function. This module has one data input point, which can be a command or other signal. It has one analog output for use by control systems where the actuator is continuously changing, such as controlling a stepper motor. There is also a digital output for use by control systems where the actuator is two-position, such as switching equipment. This controller can be used as a regulator because it provides a complete display window and operation buttons. It can set the temperature setpoint, PID adjustment parameters, etc. During operation, it can display the PV value and SV value of the controlled object. This module can automatically adjust according to the set control point and the time of rise and fall. It has a CAN communication port and can communicate with a microcomputer. That is to say, the control module can be connected to the CAN network system. The upper computer sets the upper and lower limits of each control point, PID value, implementation time and other control parameters for the control modules on multiple nodes, and records the measured values of each controller in real time, plotting the change curves for the experimenters to analyze the experimental results. 4 System Software Design (1) CAN Bus Communication Module The communication software of the CAN bus measurement and control system is divided into three parts: CAN initialization, data transmission and data reception. ① CAN Initialization It mainly sets the CAN communication parameters. The registers that need to be initialized are: mode register (Peli CAN mode), time division register, receive code register, mask register, bus timing register, output control register, etc. It should be noted that these registers can only be written to during the reset period. Therefore, before initializing these registers, it must be ensured that the system has entered the reset state, and the initialization words of the bus timing registers of each CAN controller in the system must be the same. ② Data Transmission Each sensor in the field converts and processes the detection signals (digital, analog, switch) of multiple environmental parameters and sends them to the transmission buffer of the CAN controller. Then the CAN controller starts the transmission command. At this time, the CAN controller will automatically send data to the bus without the need for intervention from the sensor's microcontroller. If multiple sensor CAN controllers in the system send data to the bus at the same time, the CAN controllers will arbitrate through the identifier in the information frame. The CAN controller with the smallest identifier value will have priority to use the bus. ③ Data reception When the CAN controller in the entire greenhouse microcomputer monitoring and control system detects data on the bus, it will automatically receive the data on the bus, store it in its receive buffer, and send a receive interrupt to the 89C52 microcontroller to start the interrupt receive service program. The 89C52 reads the data from the CAN controller's receive buffer by executing the interrupt receive service program and performs further processing. (2) The monitoring module integrates all data acquisition, parameter setting, data statistical analysis and other functions. Meanwhile, to enable manual intervention in the production process, such as modifying setpoints, control parameters, and alarm limits, a parameter modification function was added. To establish human-machine communication and display data transmitted from each node graphically, chartably, or dynamically, this system can use any MMI (Man-Machine Interface) software with a DDE (Dynamic Data Exchange) interface. For better data management, a configuration control method was adopted, capable of receiving DDE connection requests from the MMI software and user software, and passing these requests to the communication driver section. The communication driver converts these requests into communication signals, which are then transmitted to the embedded software of the intelligent module via the transmission medium. The module's response is returned to the MMI software and user software as the result of the DDE operation. 5. Conclusion Applying advanced fieldbus technology (CAN BUS) to the intelligent measurement and control system significantly improves system reliability. The independently developed microcontroller-based intelligent node conforming to international standards not only saves substantial funds but also allows for the purchase of similar, universally applicable equipment, saving significant R&D costs. The industrial computer-based host computer provides a user-friendly interface, making operation more convenient and intuitive.