Distributed workshop temperature and humidity detection system based on CAN bus

Publisher:tetsikaLatest update time:2013-05-15 Source: 电子设计工程 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
    Many industries such as textiles, cigarettes, chemicals, and food processing have certain requirements for the temperature and humidity of production workshops. Some of these companies often need a workshop temperature and humidity detection system that can be independent of the air conditioning control system. This workshop temperature and humidity detection system is a redundant design or auxiliary means of air conditioning control, and the cost is often relatively low.
    As a widely used non-standard detection system, the temperature and humidity detection system has different designers and different application requirements, which makes the design schemes of such detection systems present a variety of types. The document introduces a design of a temperature and humidity measurement and control system for vegetable greenhouses. With the P87LPC76x microcontroller as the main controller, it can use the PID algorithm to control the heating and humidification of the actuator to adjust the temperature and humidity of the vegetable greenhouse. The system has been widely used in rural vegetable greenhouses in Songyuan, Jilin, and it runs well. The document introduces a design of a temperature and humidity detection system that can be used in a variety of industrial occasions. The system is developed based on the AT89C52 microcontroller and can transmit the temperature and humidity signals collected by the sensor to the host computer through the RS485 network. The system is simple and practical with good cost performance. The literature introduces the design of a data collector for detecting the internal temperature and humidity of a building equipped with central air conditioning. The detection device works independently of the central air conditioning and provides basic data for evaluating the operating quality of the central air conditioning and debugging the air conditioning system. The system is developed based on the 16-bit single-chip microcomputer MSP430F and communicates with the PC in real time. The data collector parameters can be set and the data collector operation can be controlled through the PC.

1 System Design
   
The system independently designed two module circuits: (1) Detection module. Each detection module will be installed in different locations in the workshop to detect the temperature and humidity at different locations in the workshop. The system supports up to 64 detection modules working simultaneously. (2) Communication module. The communication "bridge" between the monitoring computer and each detection module. A communication module contains 4 communication channels. Each communication channel can be connected to a computer COM port to realize the monitoring computer's group polling of the detection module.
    The detection module and the communication module communicate through the CAN bus. The CAN (Controller Area Network) bus was proposed by the German company BOSCH in 1986. It is a multi-master serial communication bus. It was first used in automotive circuits. After decades of development, it has become increasingly perfect and is now widely used in many fields such as automobiles, petroleum, chemical industry, and manufacturing. It is known as "one of the most promising bus technologies." The CAN bus was chosen because it has obvious advantages over the traditional RS485 bus, which are mainly reflected in the following three points: (1) The traditional RS485 bus only has an electrical protocol, while the CAN bus has a complete communication protocol and is easy to develop. (2) The communication distance of the traditional RS485 bus does not exceed 1.5 km, while the communication distance of the CAN bus can reach up to 10 km at a rate of 5 kbit·s-1. (3) When there is an error in the system of the traditional RS485 bus and multiple nodes send data to the bus at the same time, the bus will be short-circuited and some nodes will be damaged. However, in the case of serious errors, the CAN node has the function of automatically shutting down the output, which will not affect the entire CAN bus.
    In this system, the serial communication rate between the communication module and the COM port becomes the communication bottleneck of the entire system, but the computer COM port is still considered to collect data instead of a professional interface card, mainly due to cost considerations. In order to alleviate the system bottleneck, the computer is installed with a PCI to RS-232 serial port expansion card (SYBA 9865-4S) to expand the computer serial port to 4. At the same time, the communication module is designed with 4 communication channels. On average, each communication channel can communicate with up to 16 detection modules in groups to speed up the data update rate.

a.JPG


    Since the communication module and the computer COM port use RS232 communication mode, the theoretical RS232 communication distance is 15 m, so the distance between the communication module and the computer must be kept below 15 m, and the actual installation is within 1.5 m. The communication rate can ensure stable communication at 38.4 kbit·s-1.

2 Design of the host computer monitoring program
   
The computer monitoring program uses C#2010 to develop the console program and Access2010 to develop the backend database. The program mainly has the following functions: (1) Administrator and technician secondary user permissions. (2) Setting the upper and lower limits of temperature and humidity alarms. (3) Recording temperature and humidity historical data. (4) Printing temperature and humidity reports.
    Here we mainly introduce the programming ideas of the communication part of the monitoring program:
    (1) The monitoring program can open four computer COM ports, send data strings to the connected COM ports according to the detection module number range set for each COM port to be polled, and activate the communication module to poll each detection module. The length of the data string sent is 5 bytes, as shown in Figure 2. The format is: the first byte is the "read data" command field, the second byte is the station number of the first detection module connected to the communication channel connected to the COM port, the third byte is the station number of the last detection module connected to the channel, and the fourth and fifth bytes are CRC checksums.

b.JPG


    (2) After each channel master controller of the communication module polls all the detection modules connected to it, it actively returns data to the computer and refreshes the temperature and humidity data displayed by the monitoring program. The length of the data string returned by a communication channel is determined by the number of detection modules connected to the communication channel. When the number of detection modules is n, as shown in Figure 3, the format is: the first Byte is the "read data" command field. The monitoring computer can identify this data string as the data returned by the lower computer through the first Byte. The second to 3n+1 bytes are the temperature and humidity data returned by all the detection modules connected to the communication channel. 3 consecutive bytes form a group, which records the return data of a single detection module. The 3n+2 and 3n+3 bytes are CRC check codes.

c.JPG[page]

3 Design of communication module
3.1 Hardware design of communication module
   
The communication module has 4 communication channels, which can be connected to 4 computer COM ports respectively. Each communication channel is independent of each other and is generally divided into 3 parts: main controller (4), RS232/TTL level conversion circuit (2), and CAN driver (4). The +5 V voltage is unified:
    (1) The main controller is the PIC18F25K80 microcontroller produced by Microchip. The microcontroller is rich in resources, with 32 kB program memory, 3 648 Byte data memory, 1 024 Byte data EEPROM, and an integrated CAN controller. Connect the two-way DIP switch to the microcontroller I/O port to set the station number of the communication module on the CAN bus. The station number range is 00 to 11.
    (2) The communication module exchanges data with the computer COM port through the level conversion circuit AX232 chip. Since one MAX232 supports two sets of serial port data independent transmission and reception, it can be used for two communication channels at the same time.
    (3) The main controller PIC18F25K80 has an integrated CAN controller, so there is no need to add an additional CAN controller. You only need to connect a CAN driver PCA82C250 to communicate with the CAN bus.
    The CAN controller integrated in the PIC18F25K80 widely supports multiple versions of the CAN1.2, CAN 2.0A, CAN 2.0B Passive and CAN 2.0B Active protocols, supports DeviceNet data byte filtering, supports standard frame data and extended frame data, and the communication rate can reach up to 1 Mbit·s-1.

d.JPG


    PCA82C250 is the most widely used CAN driver at present. Its maximum communication rate can reach 1 Mbit·s-1, it can support up to 110 nodes, and it has multiple protection functions, which is safe and reliable. The CAN transceiver pins CANRX and CANTX of PIC18F25K80 are connected to PCA82C250 through two optocouplers 6N137, and PCA82C250 is directly connected to the CAN bus.
3.2 Software design of
   
communication module After receiving the command from the host computer, the communication module starts to poll the detection module connected to it. The communication module sends a read data command to the first detection module connected to it, and then sends a read data command to the next detection module after the queried detection module returns data, and so on. If the queried detection module does not return data within 1 000ms, the read data command is resent. After repeating 3 times, if the queried detection module still does not return data, the detection module will automatically set all the corresponding units in the read data buffer array to FF, and set the corresponding flag position to 1. In the next polling, this detection module will be automatically skipped. After the maintenance personnel eliminate the fault, they can manually send a clear flag command through the monitoring computer or power off and reset the communication module to restore the communication module and all detection modules. Finally, all detection modules are read, and the communication module automatically uploads the data to the upper monitoring computer. The program flow chart is shown in Figure 5.

e.JPG


    The read data command sent by the communication module to the detection module consists of 2 bytes: the first byte is the CAN station number of the module channel, and the second byte is the CAN station number of the queried detection module. Since the command sent by the detection module to the queried module is only a read data command, there is no need to add a command code byte.

f.JPG


    In the CAN 2.0B specification, there are two frame formats for data frames: standard frame data format and extended frame data format. The difference between the two is that the former has an 11-bit identifier and the latter has a 29-bit identifier. As shown in Figure 6, the arbitration segment identifier of the standard frame format is only 11 bits, while the arbitration segment identifier of the extended frame format has 18 more identifiers than the arbitration segment identifier of the standard frame format, that is, 29 identifiers. The CAN controller will automatically generate an output pulse sequence according to the frame format based on the user's setting value of the register. For developers, the former only needs to configure a 2-byte TX identification code, while the latter needs to configure a 4-byte TX identification code to describe the "data identity" of the frame data on the bus. In view of the relatively simple communication relationship between the communication and detection modules, the standard frame data format is selected here. The 2-byte TX identification code is the data source and the data target address, that is, for the communication module, the first Byte is defined as the station number of a channel of the communication module, and the second Byte is defined as the station number of the detection module accessed by the communication channel at a certain moment.

[page]

4 Design of temperature and humidity detection module
4.1 Hardware design of temperature and humidity detection module
   
The detection module can be roughly divided into four parts: main controller, temperature sensor, humidity sensor, and CAN driver:
    (1) The main controller also uses PIC18F25K80 microcontroller. The 6-way DIP switch is connected to the I/O port of the microcontroller to set the station number of the detection module on the CAN bus. The station number setting range is 1100 0000~1111 1111.
    (2) The temperature sensor uses the one-line digital temperature sensor DS18B20 produced by Dallas Company. This sensor has the advantages of miniaturization, low power consumption, high performance, and strong anti-interference ability. DS18B20 can directly convert temperature into serial digital signals for microcontroller processing. The temperature measurement range is -55~+125℃, and the temperature measurement resolution can reach 0.0625℃. The temperature measurement range and accuracy fully meet the project requirements.
    (3) The humidity sensor uses the HIB4000 relative humidity sensor produced by Honeywell. The sensor integrates a signal processing function circuit, which can convert the relative humidity value into a capacitance value, and then convert the capacitance value into a linear voltage output. The PIC18F25K80 microcontroller integrates an 8-input A/D module, which can directly convert the linear voltage analog output of the HIH4000 into a 12-bit digital quantity and store it in the PIC18F25K80 microcontroller.
    (4) Similar to the communication module, the CAN transceiver pins CANRX and CANTX of the PIC18F25K80 are connected to the CAN driver PCA82C250 through two optocouplers 6N137, and the PCA82C250 is directly connected to the CAN bus.

g.JPG


4.2 Software design of temperature and humidity detection module
   
The detection module continuously reads the data collected by the temperature sensor and humidity sensor. After collecting the temperature and humidity data each time, it detects whether there is a read data command from the communication module. If so, the collected temperature and humidity data are returned to the communication module. If not, it continues to read the data collected by the temperature sensor and humidity sensor. The program flow is shown in Figure 8.

h.JPG


    Consistent with the communication module, the CAN communication data frame format of the detection module also adopts the standard frame data format. Among them, the TX identification code of 2 is set as the data source address and the data target address respectively, that is, the first Byte is set as the detection module station number, and the second Byte is set as the station number of the communication channel connected to it; only 3 data bytes are used, the first Byte and the second Byte high 4 bits totaling 12 bits are used to store data from the temperature sensor, and the second Byte low 4 bits and the third Byte totaling 12 bits are used to store data from the humidity sensor. Compressing
the two into 3 bytes and writing them into the CAN driver send buffer can effectively improve the data update rate.

5 Conclusion
   
The development of fieldbus technology, the enhancement of single-chip microcomputer functions, the improvement of sensor linearization and integration, etc., have brought convenience to the design of the system and also provided a guarantee for the stability of the detection system; the development of Dot Net technology has provided conditions for the rapid development of stable and reliable computer applications. After development and design, the system is currently in the small-scale trial operation stage. After a period of trial operation, it has been proved that the system has many advantages such as stability and reliability, long communication distance, strong anti-interference ability, etc., and can meet the needs of enterprises.

Reference address:Distributed workshop temperature and humidity detection system based on CAN bus

Previous article:PIC microcontroller instruction cycle calculation
Next article:Design of kitchen controller based on PIC microcontroller

Recommended ReadingLatest update time:2024-11-15 07:42

How to automatically recover from bus-off in STM8CAN
Hardware requirements: STM8AF52A8, TJA1040T Software requirements: IAR This is just one case of bus-off: when CANH and CANL are short-circuited together, the STM8 CAN controller stops working. How to make CAN work again? Theoretically: Look at the reference manual of STM8, where the sixth bit ABOM of the CAN master
[Microcontroller]
How to automatically recover from bus-off in STM8CAN
CAN BUS architecture features, application advantages and case analysis
As the automotive industry continues to pursue goals such as safety and reliability, ultimate performance, comfort and convenience, and low cost, the highly complex system network within the car makes the wiring harness too large, resulting in increased costs and difficulty in continuously improving the network archit
[Automotive Electronics]
CAN BUS architecture features, application advantages and case analysis
Latest Microcontroller 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号