“This paper introduces a CAN bus distributed measurement and control system based on single chip AT89C52, mainly expounds the overall design of the system, as well as the software and hardware design of the control module and acquisition module, focusing on the single chip in the system with CAN bus interface. The design solves the problem that the measurement signals obtained by the sensors in the field are stored and processed by the single-chip microcomputer, and then the information is sent to the CAN bus through the communication with the CAN controller.
This paper introduces a CAN bus distributed measurement and control system based on single chip AT89C52, mainly expounds the overall design of the system, as well as the software and hardware design of the control module and acquisition module, focusing on the single chip in the system with CAN bus interface. The design solves the problem that the measurement signals obtained by the sensors in the field are stored and processed by the single-chip microcomputer, and then the information is sent to the CAN bus through the communication with the CAN controller.
1. Technical characteristics of CAN bus network
Using communication data block coding, it can realize multi-master working mode, flexible data sending and receiving mode, and can realize point-to-point, point-to-multipoint and global broadcast and other transmission methods; the conventional test and control functions of the host in the DCS structure can be distributed to each Intelligent node, the node controller sends the collected data to the bus through the CAN adapter, or applies for data to the bus, the host is freed from the original heavy monitoring tasks of the underlying equipment, and performs higher-level control and management functions, such as faults. Diagnose, optimize coordination, etc.;
Using non-destructive priority-based bus arbitration technology, it has the function of judging temporary faults and faulty nodes and the automatic detachment function of faulty nodes, so that the communication of other nodes in the system is not affected; at the same time, CAN has the function of automatic retransmission of error frames. High reliability;
Short frame structure (8 bytes) for signal transmission, with good real-time performance;
Nodes can be attached or removed at will without closing the bus, which enhances the flexibility and scalability of the system;
Adopt unified standards and specifications, so that each device has better interoperability and interchangeability, and the system has good versatility;
The communication medium can be twisted pair without special requirements; on-site wiring and installation are simple, easy to maintain, and economical.
In a word, CAN bus has the advantages of strong real-time performance, high reliability, simple structure, good interoperability and low price. It overcomes the defects of traditional industrial bus and is an effective solution for building a distributed measurement and control system.
2. Overall hardware design scheme of the system
First, define the function of each node, and determine the number, type, and signal characteristics of each node’s detection or control variables. This is the first step to network the computer measurement and control system. The principle is to try to avoid repeated testing. Most of the intelligent node modules are input and output modules, and the adjustment loop can form a loop across the modules. However, considering the safety of the adjustment loop, in order to ensure that the loop adjustment will not be affected when a major fault occurs in the host computer or the entire communication line, modules with adjustment functions such as isolation type, self-tuning PID, and isolation type temperature regulator are designed. Their input and output channels are all in the same module, and their underlying software has strong functions. All input processing, output increment calculation (multiple adjustment algorithms can be selected through configuration, including cascade adjustment), output, including automatic The automatic identification of the process parameters of the tuning module is realized in this module, which ensures the safety and reliability of the regulating loop.
Next, select each node controller and the corresponding CAN adapter element. Because the function of each measurement and control node is relatively single and the amount of data is small, the requirements for the CPU are greatly reduced, and the 8051 series of single-chip microcomputers can meet the requirements. CAN bus adapter devices mainly include: controller interface, bus transceiver and I/O devices. Adopt the 82C200CAN controller produced by Philips and the 82C250CAN transceiver that is matched with it. The 82C200 has all the necessary features required to implement high performance communication protocols. The 82C200 with a simple bus connection can perform all functions of the physical layer and the data link layer.
Select the bus medium according to the CAN bus physical layer protocol, design the wiring scheme, and connect it into a CAN bus distributed measurement and control network. As shown in Figure 1.
Design of Distributed Static Measurement System Using 8051 Series Single Chip Computer
3. The hardware composition of the system
(1) CAN bus interface module
There are two broad categories of CAN bus devices: one is an independent CAN controller, such as 82C200, SJA1000 and Intel 82526/82527, etc.; the other is a microcontroller with chip CAN, such as P8XC582 and 16-bit Microcontroller 87C196CA/CB, etc. According to the actual needs of the current market, development tools and subjects, the intelligent nodes of the system all use ATMEL 8-bit microcontroller AT89C52 as the microprocessor.
② CAN controller
CAN controller selects SJA1000 as controller. SJA1000 is a highly integrated CAN controller. It has multi-master structure, bus access priority, group and broadcast message function and hardware filtering function. The input clock frequency is 16MHh clock, and the output is programmable. It consists of the following parts: interface management logic, transmit buffer, receive buffer, bit stream processor, bit timing logic, transceiver logic, error management logic, controller interface logic, etc.
The SJA1000 has many new features: reception and transmission of standard and extended structure messages; 64-byte receive FIFO; single/dual receive filters for both standard and extended frame formats; error counters with read/write access; Braided error alarm limit: nearest error code register; error interrupt can be generated for each CAN bus error; lost arbitration interrupt with lost arbitration positioning function; Listen-only mode (listen to CAN bus, no response, no error flag); support hot swap (no interference software-driven bit rate monitoring). Therefore, the intelligent nodes of the system select SJA1000 as the CAN controller.
③ CAN bus transceiver
CAN bus transceiver selects PCA82C250 as bus transceiver. The PCA82C250 is the interface between the CAN protocol controller and the physical bus. 82C250 can provide different transmission performance for the bus and different reception performance for CAN controller. And it is fully compatible with the “ISO 11898” standard. The purpose of PCA82C250 is to increase the communication distance, improve the instantaneous anti-jamming capability of the system, protect the bus, and reduce radio frequency interference (RFI) to achieve thermal protection. In order to further improve the anti-interference measures, an isolation circuit composed of a high-speed isolation device 6N137 is used between the two CAN devices. The hardware connection between the CAN device and the microprocessor is shown in Figure 2.
The design of the hardware circuit is not too difficult, but a few points should be noted:
Two 120Ω resistors at both ends of the bus play a very important role in matching the bus interference. Ignoring them will greatly reduce the anti-interference and reliability of data communication, or even fail to communicate.
The resistance Rs between the 8th pin of 82C50 and the ground is called the slope resistance, and its value determines whether the system is in the high-speed working mode or the slope control mode. Connect this pin directly to the ground, and the system will work in high-speed mode. In this mode, in order to avoid radio frequency interference, it is recommended to use a shielded cable as the bus; and when the baud rate is low and the bus is short, the slope is generally used. Control mode, the slope of rising and falling depends on the resistance value of the people. The experimental data shows that 15 “200kΩ is the ideal value range of Rs. In this mode, parallel wires or twisted pairs can be used as the bus.
The TX1 pin of SJA1000 is suspended, and the potential of the RX1 pin must be maintained at about 0.5Vcc, otherwise, the level logic required by the CAN protocol will not be formed. If the transmission distance of the system is short and the environmental interference is small, galvanic isolation is not required. In this way, the VREF terminal (about 0.5 Vcc) of the 82C250 can be directly connected to the RX1 pin, thereby simplifying the circuit.
In the system, the chip select signal of SJA1000 is generally obtained by decoding the address bus, and thus determines the address of each register of the CAN controller. In practical application, P2.7 of the single chip AT89C52 is used as the chip selection signal. So, the address of SJA1000 is: 7F00″7F32H.
When the power-on reset is performed, the power-on reset of the AT89C52 needs to be activated by a low-to-high level change, while the 17-pin RST of the SJA1000 is activated, and a transition from a high level to a low level needs to occur. Therefore, This must add an inverter.
(2) Data acquisition module
The data acquisition module is used to transmit the data of various sensors to the CAN bus. The whole circuit includes: watchdog X5045, microcontroller 89C52, latch 74LS373, A/D converter ADC0809, CAN controller SJA1000 and transceiver 82C250. The circuit board is shown in Figure 3.
The working principle of the data acquisition module: after all kinds of sensors collect the data, the 0-5V analog quantity is transmitted to the ADC0809, the 0809 transmits the converted digital quantity to the 89C52, and the single-chip microcomputer sends the collected data to the SJA1000 through the CAN bus transceiver 82C250 uploads the bus to complete the data acquisition.
(3) Control module
It is an isolated controller with CAN communication function. The module has a data input point, which can be a command or other signal, and an analog output, which is used by a control system whose output actuator is continuously changing, such as controlling a stepper motor; there is also a digital output for the actuator. It is used for two-position control systems, such as switchgear. This controller can be used as a regulator alone, because a complete Display window and operation buttons are provided on the module, which can set the temperature set value, PID adjustment parameters, etc. During operation, the PV value of the controlled object and SV value.
The module can realize automatic adjustment according to the set control point and the time of rising and falling. With CAN communication port, it can communicate with the microcomputer, that is to say, the control module can be connected to the CAN network system. The upper and lower limit control points, PID values, realization time and other control parameters of each control point are set for the control modules on multiple nodes through the host computer, and the measured values of each controller are recorded in real time, and the change curve is drawn for the experimenter. Analyze the experimental results. As shown in Figure 4.
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 is mainly to set the communication parameters of CAN. 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 and accessed during reset. 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 the detection signals (digital quantity, analog quantity, switch quantity) of environmental multi-parameters, and sends it to the sending buffer of the CAN controller, and then starts the sending command of the CAN controller. At this time, the CAN controller Data is automatically sent to the bus without the need for the sensor’s microcontroller to intervene. If there are multiple sensor CAN controllers in the system sending data to the bus at the same time, the CAN controller will arbitrate through the identifier in the information frame, and the CAN controller with the identifier value has the priority to use the bus.
③ Data reception
When the CAN controller in the whole greenhouse microcomputer measurement and control system detects that there is data on the bus, it will automatically receive the data on the bus, store it in its receive buffer, send a receive interrupt to the 89C52 microcontroller, and start the interrupt receiving service program. Execute the interrupt receiving service routine, read the data from the receiving buffer of the CAN controller, and perform further processing work on it.
(2) Monitoring module
It integrates all data acquisition, parameter setting, data statistical analysis and other functions. At the same time, in order to realize the manual intervention of the operator in the production process, such as modifying the given value, control parameters and alarm limits, the parameter modification function is added; in order to establish the human-machine information connection, and the data transmitted from each node can be Graphics, charts or other dynamic ways to display, the system can use any MMI (Man-Machine interface) software with DDE (Dynamic Data Exchange) interface; in order to better manage various data, the configuration control method is adopted, which can Receive the DDE connection request from MMI software and user software, and transmit the request to the communication drive part, and the communication drive converts it into a communication signal and transmits it to the firmware of the intelligent module through the transmission medium. And return the response of the module to the MMI software and user software as the result of the DDE operation.
The advanced field bus technology (CAN BUS) is applied to the intelligent measurement and control system, which greatly improves the reliability of the system; independently developed the intelligent node based on the single-chip microcomputer that conforms to international standards, which not only saves a lot of money, but also can purchase common equipment of the same kind , which can save a lot of research and development costs; the host computer based on the industrial computer provides a good man-machine interface, making the operation more convenient and intuitive.
The Links: 1MBI200SA-120B NL12880BC20-02D