Design of an Electrical Engineering Experiment Guidance System Based on CAN Bus
2026-04-06 03:48:28··#1
Introduction In production site control systems, the installation, commissioning, and maintenance of intelligent equipment and conventional electrical equipment require a considerable number of electrical technicians. How to efficiently, efficiently, and systematically train advanced electrical operators is a pressing issue for educational equipment manufacturers. This necessitates that equipment possess communication capabilities, allowing instructors to monitor dynamic indicators during training, understand students' actual experimental progress, control the experimental process, and provide categorized guidance. This paper, through research on the CAN (Controller Area Network) protocol and its applications, utilizes CAN communication controllers, CAN transceivers, and enhanced microcontrollers to develop a CAN bus-based application system—an electrical engineering experiment guidance system. This system enables networked experimental teaching courses in electrical engineering laboratories, overcoming the shortcomings of conventional teaching methods. Students can complete their experimental tasks more autonomously and flexibly, and can extend their experiments according to their own needs. This lays a solid foundation for establishing open experimental training facilities and allows students to experience the practical value of network experiments and understand the basic knowledge of CAN bus control technology. 1. CAN Bus Network Communication Layer Model and Protocol Different application specifications can be selected for different application areas. For general applications, a "command-response" communication protocol can achieve a reliable and efficient "master-slave" communication network. For CAN networks requiring large-scale data exchange or flexible communication methods, standard multi-master communication protocols, such as the Hilon B protocol, or the remote frame definition in the CAN 2.0 protocol can be used. In the automotive electronics field, standards such as J1939 are typically referenced or directly adopted. In the power communication design field, the DeviceNET V2.0 specification is commonly used, which has been adopted as a national standard in China. In the intelligent building communication field, the Modbus protocol or the RS-485 "master-slave" protocol is generally used. In establishing the actual CAN bus communication network, this system uses the CAN underlying hardware to control the physical layer and data link layer. The communication error detection mechanism specified in the CAN 2.0A/B protocol ensures the reliability of the CAN bus communication network. A user protocol layer communication protocol is established, and the communication data stream on the network is interpreted and managed. Its user protocol layer (application layer) communication protocol is implemented by defining data frames and remote frame formats, belonging to a "master-slave" structure. 2. Hardware System Composition and Module Hardware Design The hardware of the fieldbus-based electrical experiment guidance system mainly consists of a host, an interface card, and intelligent nodes (slave devices). The host contains application programs and database files; the interface card serves as the bridge for CAN communication and also acts as a node in the network; the intelligent node consists of a data acquisition and transmission module based on fieldbus and microcontroller technology, as well as practical operation wiring devices. The node can provide intelligent guidance for students' electrical experiments under computer control. 2.1 Design of Data Acquisition and Transmission Module The data acquisition and transmission module can be divided into five main parts: a host unit composed of an AT89S52 microcontroller; a CAN bus control and interface unit composed of an SJA1000, PCA82C250, and opto-isolation circuit; a power supply and display unit composed of a +5V reference voltage source, driver transistors, LED indicators, and digital tubes; a data conversion and acquisition unit composed of four 8255 chips as I/O ports and the back-end interface circuit of the operating station; and the actual operating station. The AT89S52 microcontroller acts as the host, responsible for initializing the SJA1000, controlling the SJA1000 to achieve data reception and transmission, and implementing experimental data acquisition. The P1 port is used to control dynamic scanning display and guide experimental data. A 74LS138 is used as the address latch, and a 74LS138 is used for chip selection of the 8255 and SJA1000. 2.1.1 CAN Bus Control and Interface Section During the operation of the slave unit, the master CPU needs to complete multiple tasks. While requiring a certain degree of flexibility, the system also needs to have a certain degree of scalability. Therefore, the Philips SJA1000 is selected as the CAN controller in the slave unit. The PCA82C250 is selected as the CAN bus transceiver. It also serves as the interface between the CAN protocol controller and the physical layer, possessing transient immunity, radio frequency immunity, and electromagnetic interference immunity. Its internal current-limiting circuit protects the transmission output stage in case of a short circuit. An optocoupler circuit is added between the node (workstation) and the medium. That is, the TX0 and RX0 pins of the SJA1000 are not directly connected to the TXD and RXD pins of the 82C250, but are connected to the 82C250 through a high-speed optocoupler 6N137. The 6N137 is a high-speed optical isolator used to isolate external lines from the system. Two fully isolated power supplies, VCC and VDD, power the two parts of the optocoupler circuitry respectively, achieving complete signal isolation. This effectively improves the system's anti-interference capability and internal system security. The SJA1000's ADO~AD7 pins are connected to the AT89S52's P0 port, and CS is connected to the 74LS138's Y4 port. When Y4 is 0, the CPU can select the SJA1000 from its external memory address. The CPU can perform corresponding read and write operations on the SJA1000 through these addresses. The SJA1000's RD, WR, and ALE pins are connected to the corresponding pins of the AT89S52. INT can be connected to the AT89S52's INT0 or INT1. The AT89S52 can access the SJA1000 via interrupt or polling. Alternatively, INT can be connected to other ports of the AT89S52 for polling access. The interface circuit is shown in Figure 1. 2.1.2 Data Conversion and Acquisition Section 1) Data Conversion Circuit Design Based on the analysis and research of electrical control principles, a relatively universal wiring method was optimized. This allows the corresponding points to sequentially provide a +5V level to the CPU's I/O port according to the operation sequence, thus completing sampling and digital conversion. The front of the student operating station has the actual terminal block sockets, and the back has the signal lines connected to them. The other end of the signal lines is connected to a fixed port of the 8255. 2) Sampling Circuit Design The operating station uses four 8255 chips as I/O port expansions, connected to the corresponding terminals at the rear of the operating station via 20 kΩ pull-down resistors. During 8255 initialization, it is set to normal read mode. If a terminal is high, a high level can be acquired at the corresponding 8255 I/O port. If all terminals are high, the total current will approach the maximum output current of the 7805. Therefore, a phase-by-phase, circuit-by-circuit method is needed for experimental guidance to complete the experimental instruction task. 2.1.3 Addresses Accessed by the Microcontroller to Various Parts of the Hardware Circuit After the hardware circuit schematic is designed, its access addresses can be determined according to the specific situation. This paper uses P2.5~2.7 ports to control the 74LS138, and performs chip selection and access on four 8255 and SJA1000 chips respectively. The access addresses are shown in Table 1. 3 CAN Bus Electrical Experiment System Node Software 3.1 Implementation of Data Acquisition and Display in the Node This paper uses the AT89S52 microcontroller as the core of the workstation (node) system for control, data acquisition, and display, and uses the Keil uVision2 integrated development environment for software development and debugging. Since the slave device needs to complete display, data acquisition, and transmission functions, at least two interrupt sources are required for program control, namely INT0 and T0. INT0 is used to indicate external interrupts for processes such as CAN bus data reception and transmission; T0 controls the display scanning clock, etc. The data sampling process is divided into two cases: one is automatic initial sampling during initialization; the other is automatic sampling during program execution when a data frame is received. 1) Function and Process Analysis of the Display Section: The display circuit has three functions: displaying successful initialization, error information, and indicating experimental steps for students. These information can be defined by the user according to the hardware structure and software requirements. This paper uses a 74LS47 decoder driver integrated circuit for driving and display control. Through software operation, the P1 port controls the on/off state of the common anode terminals of the six digital tubes. Simultaneously, the P0 port provides data to the 74LS47 decoder driver circuit, realizing dynamic scanning control of the display. When initialization is normal, the custom display is 004321. During normal operation, it displays the project number, phase number, wiring step number, or, in case of an error, the error flag number. 2) Principle and Process Analysis of Data Acquisition: The principle of data acquisition is as follows: The CPU controls the corresponding pins of its P2 port to provide a +5V level to the corresponding phase start terminal. The remaining contacts are connected by signal lines according to certain rules, resulting in a 0V or high-level signal on each terminal. The state of the corresponding terminal can be read through the 8255. That is, when wiring is done in a certain order, different sampled data can be read from the corresponding 8255 port. Each port of the 8255 can read an 8-bit binary number (1 byte). These data are associated with experimental operation steps, so that different data is obtained for each operation. This system requires 4 8255 chips, and 12 8-bit binary numbers can be obtained in one sampling. A 20-byte array is set in the RAM space of the microcontroller as the storage space for the collected data. During power-on reset, the 8255 chips are initialized to normal read mode, and initialization data is written into the array. After normal operation, data is collected once for each data frame received. The collected data is directly updated in the array according to the frame format of CAN bus communication for reading and uploading. The storage address and content of the collected data are shown in Table 2. 3.2 Communication Software Design In this paper, the master station uses the PC15121 interface card as the interface device. After the communication method and protocol are determined, the communication between the master station and the slave station can be realized by calling the interface function of this product. The control software of the slave station (workstation) CAN node adopts a modular design method. There are five main modules: SJA1000 initialization module, SJA1000 data receiving module, SJA1000 data sending module, SJA1000 error handling module; and other task modules of the system. 3.3 Operation of the intelligent node program The main functions of the slave device are hardware initialization, entering normal display, waiting for interrupt events, receiving data frames, data processing and display, waiting to receive remote frames and returning the required data frames, and data acquisition, etc. Its main program flow is shown in Figure 2. The external interrupt service program flow is shown in Figure 3. In the host program design, the interface program and data processing algorithm design are key. Among them, the host interface card can be used as an intelligent node, and the data communication in the network is mainly the operation of this card. 4 Conclusion This paper analyzes and studies the hardware and software system of CAN bus network, adopts a CAN bus-based networking protocol and data transmission method, and applies it to the electrical engineering experiment guidance system to realize network communication in the "master-slave" communication mode, achieving the expected goal. The equipment can meet the needs of the experimental environment.