Development of CAN Bus Distributed Measurement and Control System Based on AT89C52 Single Chip Microcomputer

Publisher:SerendipityGlowLatest update time:2012-09-08 Source: autoooKeywords:AT89C52 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This paper introduces a CAN bus distributed measurement and control system based on the single-chip microcomputer AT89C52. It mainly describes the overall design of the system, as well as the software and hardware design of the control module and the acquisition module. The focus is on the design of the CAN bus interface with the single-chip microcomputer as the core of the system, which solves the problem of using the single-chip microcomputer to store and process the measurement signals obtained by various sensors on site, and then sends the information to the CAN bus through communication with the CAN controller.

1 Technical characteristics of CAN bus network[1][2]

Communication data block encoding can realize multi-master working mode, flexible data transmission and reception mode, and multiple transmission modes such as point-to-point, point-to-multipoint and global broadcast can be realized; the conventional test and control functions of the host in the DCS structure can be dispersed to each intelligent node, and the node controller sends the collected data to the bus through the CAN adapter, or requests data from the bus, so that the host is freed from the original heavy bottom-level equipment monitoring tasks and performs higher-level control and management functions, such as fault diagnosis, optimization and coordination, etc.

Adopting non-destructive priority-based bus arbitration technology, it has the function of distinguishing temporary errors and permanent fault nodes and automatically detaching 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, and has high reliability;

The signal transmission uses a short frame structure (8 bytes) with good real-time performance;

nodes can be connected or removed at will without shutting down the bus, which enhances the flexibility and scalability of the system;

The use of unified standards and specifications ensures good interoperability and interchangeability between devices, and good system versatility;

The communication medium can be twisted pair cable, without special requirements; on-site wiring and installation are simple, easy to maintain, and economical.

In short, the 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 buses and is an effective solution for building distributed measurement and control systems.

2 System Overall Hardware Design

First, define the function of each node, and determine the number, type, and signal characteristics of the detection or control quantity of each node. This is the first step in networking the microcomputer measurement and control system. The principle is to avoid repeated testing as much as possible. Most of the intelligent node modules are input and output modules, and the regulation loop can form a loop across modules. However, considering the safety of the regulation loop, in order to ensure that the loop regulation is not affected when a major failure occurs in the host computer or the entire communication line, modules with regulation functions such as isolated type, self-tuning PID, and isolated temperature regulator are designed. Their input and output channels are all in the same module, and the underlying software is very powerful. All input processing, output increment calculation (a variety of regulation algorithms can be selected through configuration, including cascade regulation), output, and automatic identification of process parameters of the self-tuning module are implemented in this module, ensuring the safety and reliability of the regulation loop.

Secondly, select each node controller and the corresponding CAN adapter components. Since each measurement and control node has relatively simple functions and a small amount of data, the requirements for the CPU are greatly reduced, and the 8051 series microcontroller can meet the requirements. The CAN bus adapter components mainly include: controller interface, bus transceiver and I/O devices. The 82C200 CAN controller produced by Philips and the matching 82C250 CAN transceiver are used. The 82C200 has all the necessary features required to complete the high-performance communication protocol. The 82C200 with a simple bus connection can complete all the functions of the physical layer and the data link layer.

Finally, according to the CAN bus physical layer protocol, the bus medium is selected, the wiring scheme is designed, and the CAN bus distributed measurement and control network is connected, as shown in Figure 1.

58.jpg

3. Hardware composition of the system[3][4][5]

(1) CAN bus interface module

① Microprocessor

There are two major categories of CAN bus devices that are widely used at present: 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 single-chip microcomputer 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 16MHh clock, and the output is programmable. It consists of the following parts: interface management logic, send buffer, receive buffer, bit stream processor, bit timing logic, send and receive logic, error management logic, controller interface logic, etc.

SJA1000 has many new features: receiving and sending 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; programmable error alarm limits: the most recent error code register; each CAN bus error can generate an error interrupt; lost arbitration interrupt with lost arbitration positioning function; single-transmit mode (no retransmission when a master error or lost arbitration is sent); listen-only mode (monitoring the CAN bus, no response, no error flag); support for hot plugging (no interference software-driven bit rate monitoring). Therefore, the system's intelligent nodes all use SJA1000 as CAN controllers.

③ CAN bus transceiver

The CAN bus transceiver uses PCA82C250 as the bus transceiver. 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 the 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-interference ability of the system, protect the bus, reduce radio frequency interference (RFI) and 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.

59.jpg

The design of the hardware circuit is not too difficult, but there are several points that should be noted:

The 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 make communication impossible. (2005-11-28 15:07:00 Readings: 21 ) [page]

The resistor Rs between the 8th pin of 82C50 and the ground is called the slope resistor. Its value determines whether the system is in high-speed working mode or slope control mode. Connecting this pin directly to the ground will put the system in high-speed working mode. In this mode, to avoid radio frequency interference, it is recommended to use shielded cables as the bus. When the baud rate is low and the bus is short, the slope control mode is generally used. The rising and falling slopes depend on the resistance value of the resistor. Experimental data show that 15~200kΩ is the ideal value range of Rs. In this mode, parallel lines 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 cannot be formed. If the system transmission distance is short and the environmental interference is small, current isolation is not required. In this way, the VREF end (about 0.5 Vcc) of 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 the address of each register of the CAN controller is determined from it. 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 power-on reset, the power-on reset of AT89C52 needs a level change from low to high to activate, and the RST pin 17 of SJA1000 is activated, which requires a jump from high level to low level. Therefore, an inverter must be added.

(2) Data acquisition module

The data acquisition module is used to transmit the data of 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 circuit board is shown in Figure 3.

60.jpg

The working principle of the data acquisition module: After collecting data, various sensors transmit the 0-5V analog quantity to ADC0809, 0809 transmits the converted digital quantity to 89C52, and finally the microcontroller sends the collected data to SJA1000 and transmits it to the bus through the CAN bus transceiver 82C250 to complete the data collection work.

(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, an analog output for control systems with continuously changing output actuators, such as controlling stepper motors; and a digital output for control systems with two-position actuators, 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, and the PV and SV values ​​of the controlled object can be displayed during operation. The module can realize automatic adjustment according to the set control point and the time of rise and fall. With a CAN communication port, it can communicate with a microcomputer, that is, the control module can be connected to the CAN network system. The upper and lower control points, PID values, implementation time and other control parameters of each control point can be set for the control modules on multiple nodes through the host computer, and the measured values ​​of each controller can be recorded in real time, and the change curve can be drawn for the experimenter to analyze the experimental results. As shown in Figure 4.

61.jpg

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 sending and data receiving.

① CAN initialization

It is mainly used 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 during reset. Therefore, before initializing these registers, it is necessary to ensure 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 on site converts and processes the detection signals (digital, analog, and switch) of multiple environmental parameters, and sends them to the send buffer of the CAN controller, and then starts the send command of the CAN controller. At this time, the CAN controller will automatically send data to the bus without the intervention of the sensor's microcontroller. 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 smallest identifier value has priority use of the bus.

③ Data Reception

When the CAN controller in the entire 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 receiving buffer, and send a receiving interrupt to the 89C52 microcontroller to start the interrupt receiving service program. The 89C52 reads the data from the receiving buffer of the CAN controller by executing the interrupt receiving service program and further processes it.

(2) Monitoring module

It integrates all functions such as data acquisition, parameter setting, and data statistical analysis. At the same time, in order to realize the operator's manual intervention 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 human-machine information connection and display the data transmitted from each node in graphics, charts, or other dynamic ways, this system can use any MMI (Man-Machine interface) software with a DDE (Dynamic Data Exchange) interface; in order to better manage various data, a configuration control method is adopted, which can receive DDE connection requests from MMI software and user software, and pass the request to the communication driver part, which is converted by the communication driver into a communication signal and passed to the intelligent module's fixed software through the transmission media. And the module's response is returned to the MMI software and user software as the result of the DDE operation.

5 Conclusion

The application of advanced field bus technology (CAN BUS) to the intelligent measurement and control system has greatly improved the reliability of the system; the independent development of intelligent nodes based on single-chip microcomputers that meet international standards has not only saved a lot of money, but also enabled the purchase of common similar equipment, saving a lot of R&D costs; the upper computer based on the industrial computer provides a good human-machine interface, making the operation more convenient and intuitive.

References:
[1] Lin Qiang, Yang Xianhui, et al. Fieldbus and its network integration. Measurement and Control Technology, 1999, 18 (5): 24-26

[2] Gu Hongjun et al. Industrial enterprise network and fieldbus technology and application. Beijing: People's Post and Telecommunications Press, 2002.4.265-416
[3] Xiao Hairong, Zhou Fengyu. Design of intelligent node of CAN bus system based on SJA1000 [J]. Computer Automatic Measurement and Control, 2001,9(2)
[4] Wu Kuanming. CAN bus principle and application system design [M]. Beijing University of Aeronautics and Astronautics Press
[5] Application of independent CAN device SJA1000 [J]. Journal of Nanjing Institute of Technology, March 2002

Keywords:AT89C52 Reference address:Development of CAN Bus Distributed Measurement and Control System Based on AT89C52 Single Chip Microcomputer

Previous article:The production of kitchen timer based on AT89C2051 single chip microcomputer
Next article:Various patterns of water lights c51 program

Recommended ReadingLatest update time:2024-11-16 17:38

Design of signal generator based on AT89C52 single chip microcomputer and DAC0832 D/A converter chip
    Signal generator is a commonly used signal source, widely used in electronic circuits , automatic control systems and teaching experiments. Signals can be generated by analog circuits, dedicated hardware and software. Using analog circuits to build a function signal generator can generate square waves, triangle wa
[Microcontroller]
Design of signal generator based on AT89C52 single chip microcomputer and DAC0832 D/A converter chip
AT89C52 MCU + AT24C02 + 1602 password lock
      This is a C language source program schematic diagram of a password lock composed of AT89C52 single-chip microcomputer + AT24C02 + 1602. The keyboard consists of 16 key switches and a 6-digit password. The password can be saved when the power is off and can be modified at any time. The circuit is simple and easy
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号