Design and implementation of home controller based on CAN bus

Publisher:RadiantGazeLatest update time:2009-12-04 Source: 解放军信息工程大学 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

CAN (Controller Area Network) bus is a serial data communication protocol developed by Bosch of Germany to solve the data exchange between numerous control and test instruments in modern automobiles. It is a multi-master bus. The communication medium can be twisted pair, coaxial cable or optical fiber. The communication rate can reach 1Mbps and the communication distance can reach 10km. One of the biggest features of the CAN protocol is that it abolishes the traditional station address coding and replaces it with encoding the communication data block, so that the number of nodes in the network is theoretically unlimited. Because the CAN bus has strong error correction capabilities and supports differential transmission and reception, it is suitable for high interference environments and has a long transmission distance. Therefore, the CAN protocol is very attractive for distributed measurement and control in many fields. At present, CAN has become the ISO11898 standard, and its characteristics are as follows:

(1) CAN is a serial communication network that effectively supports distributed control and real-time control.

(2) The CAN protocol follows the ISO/OSI model and uses the physical layer, data link layer and application layer.

(3) CAN can work in multi-master mode, which is essentially a CSMA/CD mode. Any node on the network can actively send information to other nodes on the network at any time, regardless of master or slave. There are priorities between nodes, so the communication method is flexible. CAN uses non-destructive bit arbitration technology and priority transmission, which can greatly save bus conflict arbitration time and show good performance under heavy load. CAN can transmit and receive data in several ways, such as point-to-point, point-to-multipoint (grouping) and global broadcast.

(4) The maximum direct communication distance of CAN can reach 10km (transmission speed is 5 Kbps); the maximum communication rate can reach 1Mbps (transmission distance is 40m).

(5) The actual number of node data on CAN can reach 110.

(6) The CAN data link layer uses a short frame structure, with each frame consisting of 8 bytes, which is easy to correct errors. Each CAN frame has CRC check and other error detection measures, which effectively reduce the error rate of the data. In the event of serious errors, the CAN node has the function of automatically shutting down so that other nodes on the bus are not affected.

(7) The signal modulation and demodulation method adopts the NRZ encoding/decoding method, and the insertion of fill bits (bit filling) technology is adopted.

(8) The data bit has two logical values: dominant bit (0) and recessive bit (1). It uses clock synchronization technology and has the functions of hardware self-synchronization and automatic tracking of timing time.

Design of home controller bus based on CAN bus

In today's information age, people have higher and higher requirements for safety and comfort in their living environment. It is imperative to establish a computer management local area network for residential areas and realize the networking of comprehensive management of residential areas. Through home controllers and central computer systems throughout the residential area, intelligent management of residential buildings can be achieved.

Figure 1 is a schematic diagram of the overall structure based on the CAN bus. The system adopts a bus network that supports the CAN standard. The central computer system (host PC) is connected to the CAN bus through a CAN interface adapter card for data exchange. The central computer system and the home controller (lower intelligent node) are connected to a bus through twisted pair cables to form a low-level communication network. Due to the use of CSMA/CD information transmission control technology, each node on the bus is allowed to compete for the bus equally, thereby forming a redundant network structure with multiple master nodes.

In the low-level communication network, the central computer system and the home controller each have their own ID mark. Since the CAN standard is used as the network communication protocol, each node has the same status in the network, so we can virtualize the central computer system as the host, and the home controller as the slave to respond to the host's requirements. The central computer system is responsible for monitoring and managing the entire CAN bus system, and has functions such as system parameter (such as transmission rate, node address, etc.) setting, data transmission, data request, local status query, node status query, interrupt status query, etc. The system working process is that the upper computer sends commands to the lower node (home controller), and the lower node recognizes and executes the corresponding command. At the same time, each lower node can also exchange information as required.

[page]

In the data link layer, two frame types supporting the CAN protocol are specified: data frame and remote frame. Data frame is used to send data, and is used by a node to transmit information to any or all other nodes; remote frame is used for "remote transmission request", and is used by a node to actively request other nodes to send information. The specific formats of the two frames are shown in Figure 2.

Hardware circuit design

Home Controller Hardware Design

This system is a controller local network composed of many smart home controllers connected through CAN bus, so the design of CAN bus is extremely important. Among them, the selection of CAN controller, CAN transceiver and anti-interference measures will become the key to the design.

①Selection of CAN controller

In order to further expand the system, SJA1000 that supports CAN2.0B communication protocol can be selected. SJA1000 is the latest CAN controller produced by PHILIPS that supports both CAN2.0B and CAN2.0A. It is fully compatible with the CAN controller PCA82C200 that only supports CAN2.0A in hardware and software.

②CAN transceiver

PCA82C250 is the interface between PHILIPS's CAN controller and the physical bus, providing differential transmission and reception capabilities for the bus. It is fully compatible with the ISO11898 standard and has three different working modes: high speed, slope control and standby, which can be selected according to actual conditions.

③Photoelectric isolation

In order to further improve the anti-interference ability of the system, an isolation circuit consisting of a high-speed isolation device 6N137 is added between the controller SJA1000 and the transceiver PCA82C250, and the power supply uses a DC-DC converter.

The purpose of using PCA82C250 in the hardware circuit is to increase the communication distance, improve the system's instantaneous anti-interference ability, protect the bus, reduce radio frequency interference (RFI), and achieve thermal protection.

The hardware structure diagram of CAN device and microprocessor is shown in Figure 3.

CAN interface adapter card and CAN bus repeater

The CAN interface adapter card completes the communication of the CAN-PC bus. The adapter card consists of a single-chip microcomputer 89C51, a CAN controller SJA100, a CAN transceiver 89C250 and its control circuit.

Due to the limitation of CAN transceivers, there can be at most 110 CAN nodes in a CAN bus network. The CAN bus can be expanded by using a repeater, which can not only increase the total number of CAN nodes to 2032, but also double the CAN communication distance. At the same time, two CAN networks with different speeds can be connected together to form a more complex CAN network.

The repeater uses a specific control logic to control a pair of CAN transceivers 82C250. The CAN transceivers are connected back-to-back to connect two physically independent CAN networks and transmit data in both directions. From the physical layer point of view, the repeater realizes the transparent relay of CAN bus signals.

Software Design

Host computer software

[page]

The software is developed using Visual Basic 6.0. It is divided into two functional modules: high-level system management module and low-level communication module. The program flow chart is shown in Figure 4.


Home Controller (Node) Software

Realize information exchange with the host computer and other nodes.

In software design, we follow the modular design concept and adopt structured programming scheme to make it have good modularity, modifiability and portability.

The initialization design of the CAN bus system is the key to software design. If this part is not designed well, the system will not be able to work properly. Therefore, the initialization design is a difficult point and a key point.

Before initialization, the reset request bit of the output control register (OCR) should be set high, and then other registers should be set. The control register (CR) sets the interrupt; the command register (CMR) controls the receiving status of the buffer; the interrupt register (IR) and the status register (SR) query the working status of SJA1000; the receiving code register (ACR) sets the working address; the receiving mask register (AMR) sets the working mode, and the bus timing register (BTR0, BTR1) sets the working frequency and sampling frequency; the output control register (OCR) is generally a normal output mode. Finally, the reset request bit should be changed from high to low to make the CAN controller enter the normal working state. Therefore, initializing the CAN controller is actually accessing the registers ACR, AMR, BTR0, BTR1 and OCR.

After successfully initializing the SJA1000, the system can use it to transmit messages.

Conclusion

CAN bus is gaining more and more attention due to its high performance, high reliability and unique design, and is recognized as one of the most promising buses. We applied this bus technology in the home controller system, designed the hardware circuit and software, and put it into practical use.

Reference address:Design and implementation of home controller based on CAN bus

Previous article:Design and implementation of an instant messaging monitoring system
Next article:Design of three-level intelligent fire alarm system based on CAN bus

Recommended ReadingLatest update time:2024-11-17 05:27

CAN bus test program based on SJA1000
code show as below: /*************Define address pointer, pointing to base address***********/ unsigned char xdata *SJA_base_Adr = SJA_BaseAdr; /*************Define the data structure of SJA1000 read and write buffer***********/ struct BASICCAN_BUFStruct{                   unsigned char IDH8;                  
[Microcontroller]
Design and implementation of CAN bus control system based on SJA1000
0 Introduction CAN-bus (Controller Area Network) is one of the most widely used field buses in the world. CAN-bus was originally designed as a microcontroller communication tool in the automotive environment, used to exchange information between various electronic control units (ECUs) on board, thus forming an
[Industrial Control]
Design and implementation of CAN bus control system based on SJA1000
Latest Security Electronics 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号