Research on the application of CAN bus in home intelligent control system

Publisher:数字梦想Latest update time:2011-04-19 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

O Introduction
The main functions of home intelligent control systems are concentrated in home security alarm, telephone or computer remote control, infrared remote control, automatic meter reading control, lighting and humidity control, etc. According to the different data and functions transmitted by intelligent terminal devices, it can be divided into two types of subnets. One type is home automation control equipment with small data volume and low rate; the other type is multimedia information (video, audio signals), with large signal volume and fast rate, such as video conferencing, audio on demand, etc. Home intelligent terminal devices can be formed into wired subnets and wireless subnets using bus structures. Because each device is distributed in different places in the home, the wiring for forming a wired subnet is relatively complicated, but if PLC and CAN bus are used to build a network, the cost will be reduced.
CAN (Controller Area Network) is a serial data communication protocol developed by Bosch in Germany for automobile detection and control in the early 1980s. It is a multi-host bus. The communication medium can be twisted pair, coaxial cable or optical fiber, and the communication rate is 1Mb/s. CAN bus has excellent performance, high reliability and unique design, and is widely used in many departments such as industrial automation, transportation, medical equipment, construction, and environmental control.

1 Composition of home intelligent control system
The home intelligent control system is the core of command communication and information management of equipment such as televisions, washing machines, air conditioners, water meters, electricity meters, and gas meters. Its main function is to communicate with the remote control system through digital transmission, receive various control commands, and complete real-time control of the corresponding equipment.
All monomers with embedded microprocessors or microcomputers in the control system are interconnected through the CAN bus. A distributed local network is formed to realize data exchange and information resource sharing. This design has the following advantages: reduced communication ports and connecting cables; strong anti-interference ability; flexible configuration, convenient system expansion and upgrade; simple debugging and convenient maintenance.
The principle of the home intelligent control system composed of CAN bus is shown in Figure 1.



2 Connection between PLC and CAN bus
Taking GE FANUC series 90 PLC as an example, a connection scheme between PLC and CAN bus is given.
GE series 90 PLCs are all equipped with converted RS 232 serial communication ports, through which the programming computer communicates and programs with the PLC. The RS 232 standard level adopts negative logic, stipulating that any level between +3 and +15V is a logic "0" level, and any level between -3 and -15V is a logic "1" level. The CAN signal is transmitted using differential voltage. The two signal lines are called "CAN_H" and "CAM_L". They are both about 2.5 V in static state. The state at this time is represented by logic "1", which can also be called "recessive"; CAN_H is higher than CAN_L to represent logic "0", which is called "dominant". When dominant, the voltage value is usually: CAN_H=3.5V, CAN_L=1.5V.
The frame format of RS 232 serial port is: 1 start bit, 8 data bits, 1 programmable 9th bit (this bit is the address/data bit for sending and receiving), and 1 stop bit. The data frame format of CAN is: frame information + ID + data (can be divided into two formats: standard frame and extended frame). Therefore, a microcontroller is needed to realize the conversion of level and frame format, etc. during design. The conversion method is shown in Figure 2.


The AT89C52 single-chip microcomputer is used as the microprocessor; SJAl000 is used as the CAN microcontroller. The physical layer and data link layer functions of the CAN protocol are integrated in SJAl000, which can passively handle the frame processing of communication data; high-speed photoelectric isolation is implemented by 6N137, which is used to prevent interference from serial signals; MAX232 is used to complete the conversion from RS 232 level to TTL level of the microcontroller interface chip. For the specific hardware interface circuit, please refer to the information of SJAl000, but there are several points to note:
(1) There is a 120 Ω resistor at both ends of the CAN bus, which is used to match the bus impedance and improve the anti-interference and reliability of data communication. But in fact, it is only necessary to ensure that the jumper resistor between "CAN_H" and "CAN_L" in the CAN network is 60 Ω.
(2) The RX1 pin 20 of SJAl000 can be grounded when not in use, and the bus length can be greatly increased with the setting of CDR.6.
(3) The connection method of pins TX0 and TX1 determines the level of serial output. For the specific relationship, please refer to the setting of the output control register OCR.
(4) There is a slope resistor between the RS pin of AT82C250 and the ground. The size of the resistor can be adjusted appropriately according to the bus communication speed, generally between 16 and 140 kΩ.
(5) MAX232 requires four electrolytic capacitors C1, C2, C3, and C4 on the periphery. These capacitors are also required for internal power conversion. Their values ​​are all 1μF/25 V. Tantalum capacitors should be selected and the position should be close to the chip. A 0.1μF decoupling capacitor should be connected between the power supply Vcc and the ground.
Under the control of the microprocessor, when RS 232 and CAN exchange data, the use of serial port reception and CAN interrupt mode can improve work efficiency. The initialization of SJAl000 can only be performed in reset mode, which mainly includes the setting of working mode, clock frequency division and acceptance filter register, baud rate parameter and interrupt enable register. The main program flow chart is shown in Figure 3.


Whether data can be accurately transmitted also depends on the baud rate and flow control, which is also a point that cannot be ignored during software design. Therefore, the following mainly introduces the setting of CAN baud rate, automatic detection of serial port baud rate, and serial port data flow control.
One of the elements in the CAN protocol is the baud rate. The bit sampling point position and sampling times in the bit period can be set so that the application network performance can be freely optimized, but in the optimization process, attention should be paid to the relationship between the tolerance of the bit timing parameter reference reference oscillator and the propagation delay of different signals in the system.
The system's bit rate fbit represents the amount of data bits transmitted per unit time, that is, the baud rate fbit=1/tbit. The rated bit timing consists of three non-overlapping segments SYNC_SEG, TSEG1 and TSEG2, and these three time periods are tSYNC_SEG, tTSEG1 and tTSEG2 respectively. Therefore, the rated bit period tbit is the sum of the three time periods: tbit=tSYNC_SEG+tTSEG1+tTSEG2. These segments in the bit period are represented by integer basic time units. This time unit is called time share TQ. The duration of the time share is one period tSCL of the CAN system clock, which can be obtained from the oscillator clock period tCLK. The CAN system clock can be adjusted by programming the pre-division factor (baud rate preset value BRP), that is, tSCL=BRP×2tCLK=2BPR/CLK.
Another very important time period for CAN bit timing calculation is the synchronization jump width (SJW), which lasts for tSJW. The SJW segment is not a segment of the bit period, but only defines the maximum TQ number of bit periods that are increased or shortened in a resynchronization event. In addition, the CAN protocol also allows users to specify the bit sampling mode (SAM), which is single sampling and triple sampling mode (selecting 1 out of 3 sampling results). In the single sampling mode, the sampling point is at the end of the TESG1 segment. The triple sampling mode takes two more sampling points than the single sampling, which are in front of the end of the TSEGl segment, with a difference of one TQ between them. The BPR, SJW, SAM, TESG1, and TESG2 mentioned above can all be defined by the user through the built-in registers BTR0 and BTR1 of the CAN controller. After setting BTR0 and BTR1, the actual transmission baud rate range is: maximum = 1/(tbit-tSJW), minimum = 1/(tbit+tSJW).
To detect the serial port baud rate of the converter, first set the host's receiving baud rate (taking 9600 b/s as an example) and send a specific character (taking a carriage return as an example) at the terminal. In this way, the host can determine the communication baud rate of the converter based on the received character information. The ASCII value of the carriage return is 0DH, and the values ​​received at different baud rates are listed in Table 1.


When data is transmitted between two serial ports, data loss often occurs. Since the microcontroller buffer is limited, if the buffer is full when receiving data, the data that continues to be sent will be lost. Flow control can effectively solve this problem. When the receiving end cannot process the data, the flow control system will send a "no longer receive" signal, and the sending end will stop sending until it receives a "can continue to send" signal. Therefore, flow control can control the process of data transmission and prevent data loss. The two commonly used flow controls are hardware flow control (including RTS/CTS, DTR/CTS, etc.) and software flow control XON/XOFF (continue/stop). The following only explains the hardware flow control RTS/CTS.

When using hardware for flow control, the serial terminal RTS and CTS are connected to the I/O port of the microcontroller, and the start and stop signals are received and sent by setting the I/O port to 1 or 0. The data terminal equipment (such as a computer) uses RTS to start the data stream sent by the microcontroller, while the microcontroller uses CTS to start and pause the data stream from the computer. When implementing this hardware handshake method, a high flag and a low flag are set according to the size of the receiving end buffer during programming. When the amount of data in the buffer reaches the high level, the CTS line is set low (send logic 0) at the receiving end, and when the program at the sending end detects that CTS is low, it stops sending data until the amount of data in the receiving end buffer is lower than the low level and CTS is set high. RTS is used to indicate whether the receiving device is ready to receive data.
The following is the CAN receiving subroutine:



3 Conclusion
Through the analysis of the home intelligent control system, PLC and CAN bus are used to build a control local area network. Through the test of the simulation system, the bus can fully complete the control of home intelligent terminal devices, but in order to further improve its control stability and real-time performance, more in-depth research is needed on this basis.

Reference address:Research on the application of CAN bus in home intelligent control system

Previous article:Control system based on PCS7 and Profibus-DP fieldbus technology
Next article:Embedded Control of Reconfigurable Optical Add-Drop Multiplexers (ROADM)

Latest Industrial Control Articles
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号