Research on Multi-sensor Measurement and Control System Based on μc/OS-II

Publisher:数字奇迹Latest update time:2012-04-14 Source: eefocusKeywords:μcOS-II Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction

With the widespread application of embedded systems, the original single-sensor embedded systems have gradually developed into embedded multi-sensor systems. Therefore, the problem of multi-sensor task scheduling and allocation is raised. In this paper, combined with the temperature, humidity, oxygen concentration and other parameter requirements involved in the sweet potato preservation and storage project, the high-performance 16-bit single-chip microcomputer SPCE061A is used as the control chip, and the tailorable multi-task real-time operating system μc/OS-II is transplanted to manage the processing of multi-tasks. The high-precision temperature sensor DS18B20, humidity sensor HIH3605, and oxygen concentration sensor DW-02 are selected to build a high-precision, high-performance, and high-reliability multi-sensor embedded measurement and control system. The adjustable range of each controlled parameter is wide, which better meets the engineering requirements. The main parameters of the system are: working temperature: 10~14℃±0.5℃; working humidity: 80~95%RH±5%; oxygen concentration: ≮4.5%. At the same time, the display and storage of temperature and humidity data are realized; the control signals for temperature, humidity, oxygen concentration and other adjustments can be output, and it has the functions of fault and alarm status prompts.

2 System Hardware Design

2.1 MCU system design

The block diagram of the system hardware circuit is shown in Figure 1, which is mainly composed of SPCE061A microcontroller, temperature and humidity sensor, oxygen concentration sensor, LCD display circuit, keyboard circuit, RS232 communication circuit, clock circuit, etc. SPCE061A is a 16-bit microcontroller based on μ\'nSP core.

Figure 1 System hardware circuit block diagram

2.2 Sensor circuit design

The temperature detection circuit uses the three-wire digital temperature sensor DS18B20 produced by Dalls. The device has only 3 pins, does not require external components, and communicates on a data line. The detection temperature range of the circuit is designed to be 0~+50℃; the accuracy is 0.5℃; the temperature is represented by a 9-bit digital quantity; and it takes 200ms to convert the temperature into a digital quantity each time. In the single-bus working mode, multiple DS18B20s are allowed to be connected to one signal line, and DS18B20 has a unique ROM code. In the multi-point temperature measurement and control system, the ROM code is the basis for identifying and operating the DS18B20; whether reading or selecting to operate a certain sensor, SPCE061A must send a 64-bit ROM code.

This system uses three DS18B20s to detect the ambient temperature, ensuring that the temperature distribution is uniform within the measured environment and the measurement is more accurate. When using, place the DS18B20 at different locations in the measured environment. When obtaining temperature information, the IOB15 pin of SPCE061A first sends a 1ms reset pulse so that the DS18B20 will send a response pulse to SPCE061A after it is reset. After receiving the response pulse, SPCE061A will send a read ROM command to read the serial number of the DS18B20 to read the serial numbers of the three DS18B20s respectively; then, SPCE061A will issue a positioning command to select the online DS1820 and perform temperature conversion. When the temperature conversion is completed, the IOB15 pin of SPCE061A will send a storage command to the DS1820 to complete the conversion and reading of the temperature information data.

The 2-way humidity sensor uses the HIH3605 produced by Honeywell. It is a thermosetting polymer capacitive sensor with an integrated signal processing circuit, a 5 V constant voltage power supply, and an amplified linear voltage output of 0~5VDC corresponding to 0~100%RH (relative humidity), with an accuracy of ±3%RH. Low power consumption design 200μA drive current, wide operating temperature range -40℃~+85℃, good stability, low temperature drift, and excellent chemical corrosion resistance. Since the HIH3605 has a large signal output and good linearity, it can save complex signal amplification and shaping circuits. It only needs to convert the voltage value proportional to the humidity value into a 16-bit digital value through the A/D converter inside the CPU, compare it with the standard, and then decide whether to humidify or ventilate (wind with suitable temperature). [page]

The 2-way oxygen concentration detection uses the DW-02 oxygen concentration sensor, which is a chemical gas diffusion fuel cell, widely used in environmental protection, energy saving, aerospace and other fields, for monitoring the oxygen concentration in small environments. The main features are small size, fast response, good linearity, small temperature drift, and stability. Main technical indicators: response time ≤ 30 seconds (90% of full scale); measurement range 0-50% O2; temperature coefficient > 0.003% O2/℃; linear error +0.2%~-0.1% O2; operating temperature range -20℃~+50℃; output current 1.1mA+15%. The oxygen content measured by this system shall not be less than 4.5%.

Because it is winter, when the ambient temperature of the storage room is higher than 14℃ or the humidity is greater than 95%RH, or the oxygen concentration is lower than the set value of 4.5%, cold air cannot be directly sent into the storage room. The outdoor air must be heated to 12℃ before being sent in. Otherwise, the sweet potatoes will be cold and deteriorate. Among the three parameters, the most important one is the temperature value, followed by the humidity. The working conditions of the relay circuit are shown in Table 1.

Table 1 Relay control circuit working conditions


2.3 Keyboard, display circuit and communication interface design

The system keyboard circuit consists of three wires connected to IOA0~IOA2 of SPCE061A, which are function keys, increase keys, and decrease keys, which are used to realize the setting functions of upper and lower limits of temperature, humidity, oxygen concentration, and control time. The measurement and control instrument uses HT1621 to drive a 128-segment LCD display to display the temperature, humidity values, O2 concentration, and fault and alarm status on site. HT1621 is a 128 (32×4) segment, memory-mapped, multi-function, I2C interface LCD driver. Here, its two-wire serial mode is used to interface with the microcontroller, which simplifies the interface circuit design with the microcontroller and reduces the occupation of hardware resources.

In order to save the real-time collected oxygen concentration, temperature and humidity values, SPCE061A transmits the oxygen concentration, temperature and humidity values ​​to the host PC through the IOB7/10 RS232 bus so that the host computer can complete data storage.

3 Software Design

3.1 System Task Allocation

In order to give full play to the advantages of the operating system in task scheduling, task management, task communication, time management and memory management, it is necessary to first divide the tasks and assign the priorities of the tasks according to the functions to be realized. According to the functions required by the temperature and humidity measurement and control system, the entire system is divided into parallel task layers and interrupt programs. The task state transition in the μC/OS-II embedded real-time operating system is shown in Figure 2.

Figure 2 Schematic diagram of μC/OS-II task state transition

When a multi-task system is running, each task seems to occupy the CPU independently, so the system must allocate a piece of memory space for each task as the task stack of the task. The function of this stack is to save the values ​​of each CPU register and the data of the system stack before the task is switched. The main steps to be completed when switching tasks are as follows: ① Push all the registers of the current task CPU to the stack; ② Copy all the data of the CPU system stack to the task stack of the current task; ③ Get the pointer of the task stack of the next task with the highest priority in the running state; ④ Restore the value of the CPU register of the next task; ⑤ Restore the data in the system stack of the next task; ⑥ Through the interrupt return instruction or function return instruction, indirectly modify the value of the PC register to switch tasks. When writing task switching code for μC/OS-II, it should be noted that: μC/OS-II will generate task scheduling after each interrupt, but the task switching after the interrupt ends cannot call the ordinary task switching function, because the interrupt process is often accompanied by the operation of pushing the CPU status register to the stack.

Task switching method: Lingyang SPACE061A microcontroller has five general registers R1-R5, and one SR (CPU status register), plus PC, a total of 7 CPU internal registers need to be saved when switching tasks. The μC/OS-II system calls OSCtxSw() to implement task switching. The several tasks that exist in parallel in the system are ranked from high to low in priority: system monitoring task, data acquisition task, data processing task, data output task, and display task. In the actual system, each task is infinitely looped, each realizing a specific function, and is scheduled by the μC/OS-II kernel. The system monitoring task mainly completes the supervision of system reliability; the data acquisition task mainly completes the detection and A/D conversion of temperature, humidity and oxygen concentration; the data processing task mainly completes the comparison and judgment of the collected data and the set data; the data output task mainly completes the data output to the LCD, transmits it to the host through RS232, and outputs the control signal to the relay circuit to complete the functions of ventilation, heating, humidification, etc.; the display task mainly completes the display of temperature, humidity and oxygen concentration parameters. The task flow chart of the system main program is shown in Figure 3.
[page]

Figure 3 System main program task flow chart

3.2 Porting of μc/OS-II

μC/OS-II is a preemptive real-time multitasking operating system designed specifically for microcontrollers. It is provided in the form of source code. Its kernel mainly provides services such as process management, time management, and memory management. The system supports up to 56 tasks, each of which has a unique priority. Since its kernel is preemptive, the task with the highest priority in the running state always occupies the CPU. The system provides a wealth of API functions to achieve communication between processes and transformation of process states.

The software architecture of μC/OS-II is shown in Figure 4. As can be seen from Figure 4, if you want to use μC/OS-II, you must write three files for it: OS_CPU.H, OS_CPU_C.C, and OS_CPU_A.ASM. These three files are related to the hardware characteristics of the chip, and they mainly provide the functions of task switching and system clock. Other files are written in C, and they provide the system with functions such as task management, communication between tasks, time management, and memory management.

Figure 4 Schematic diagram of μC/OS-II software architecture

μC/OS-II system clock: The TMB2 time base signal of the Lingyang SPCE061A microcontroller is used as the system clock. An interrupt will be generated every clock beat, and the OSTickISR() function will be called in the interrupt service subroutine.

The main contents of the porting work: use #define to set a constant value (OS_CPU.H); declare 10 data types (OS_CPU.H); use #define to declare 3 macros (OS_CPU.H); write 6 simple functions in C language (OS_CPU_C.C); write 4 assembly language functions (OS_CPU_A.ASM).

4 Conclusion

μC/OS-II RTOS is one of the hot spots of embedded applications today. The application of RTOS improves the reliability and real-time performance of the measurement and control system and reduces the R&D cycle. The measurement and control system built based on μC/OS-II in this paper is applied in the 20 million kg sweet potato storage and preservation project of Luohe Agricultural Bureau, and fully meets the designed control indicators: temperature 10-14℃±0.5℃, humidity 80-95%RH±2%, oxygen concentration ≮4.5%. It reduces the deterioration of sweet potatoes caused by abnormal temperature, humidity and oxygen concentration, and the intact rate is 100%. Compared with the storage without using this system, the loss is reduced by 25%, about 5 million kg, with direct economic benefits of more than 5 million yuan, and also achieves good social benefits. In addition, the system has good scalability and can be easily expanded to other fields with certain requirements for temperature, humidity or oxygen concentration. According to the test, the temperature measurement range can reach -20-85℃±0.5℃; humidity 20-98%RH±2%; oxygen concentration ≮1.5%. Therefore, this measurement and control system has broad application prospects.

The innovation of this paper is to use high-performance SPCE061A single-chip microcomputer and high-precision temperature sensor, humidity sensor and oxygen concentration sensor, and to build a high-precision and high-reliability multi-sensor embedded measurement and control system by transplanting μC/OS-II multi-task real-time operating system. The actual engineering application shows that the system has good scalability, high measurement and control accuracy and stable performance.

Keywords:μcOS-II Reference address:Research on Multi-sensor Measurement and Control System Based on μc/OS-II

Previous article:Application Program Design for Embedded Detection System
Next article:New embedded ultrasonic distance measurement system

Recommended ReadingLatest update time:2024-11-16 20:29

What are the measurement methods of sensors?
A sensor is a device or apparatus that can sense a specified measured object and convert it into a usable signal according to certain rules. It is usually composed of a sensitive element and a conversion element. There are three main forms of sensors in measurement. Different measurement methods are related to whether
[Test Measurement]
Digital waveform generator provides flexible frequency adjustment for sensor impedance measurement
introduction Many of today's industrial and instrumentation applications involve sensor measurement technology. The function of a sensor is to monitor changes in a system and then feed the data back to the main control unit. For simple voltage or current measurements, the sensor can be resistive. However, in some sens
[Test Measurement]
Digital waveform generator provides flexible frequency adjustment for sensor impedance measurement
Apple develops under-screen optical Touch ID sensor with angled light
      Apple is working on new fingerprint sensing technology that can work through the iPhone display using off-axis angle light. The company has been working on various types of display-embedded fingerprint technology, including capacitive systems and ultrasonic sensors. Current reports suggest that Apple is planning
[Mobile phone portable]
Heraeus' sensor business is booming, accelerating the development of automotive electronics
Heraeus is accelerating and expanding its sensor technology strategy by establishing the global business unit "Heraeus Nexensos". Heraeus' sensor business has been repositioned under the new name "Heraeus Advanced Sensor Technologies" and is continuing its success story with a focus on the key markets of the future -
[Automotive Electronics]
Heraeus' sensor business is booming, accelerating the development of automotive electronics
Zigbee sensor node hardware design based on single chip microcomputer
introduction ZigBee Alliance defines two types of physical devices: one is full function device FFD (full function device); the other is reduced function device RFD (reduced function device). The construction of the network requires the participation of the coordinator (FFD). The entire network formation proces
[Microcontroller]
Zigbee sensor node hardware design based on single chip microcomputer
Application of power amplifier in metal particle material recognition of inductive sensor
Experiment Name: Application of power amplifier in metal particle material recognition of inductive sensor Purpose: A dual phase-locked amplifier circuit is used to convert the complex domain signal generated by the particles into a pair of DC signals. A signal processing method based on fuzzy m
[Embedded]
Application of power amplifier in metal particle material recognition of inductive sensor
C language programming of 18B20 temperature sensor and LCD display based on AVR microcontroller
******************************************************/ #include #include #define uchar unsigned char #define uint unsigned int #include "1602LCD_drive.h" //Include LCD driver software package #include "DS18B20_drive.h" //DS18B20 driver software package #define beep_0 (PORTD=PORTD&0xbf) //The buzzer on PD6 sou
[Microcontroller]
Design and implementation of automatic sun tracking controller based on COMS image sensor
There are many methods for tracking the sun, which can be mainly divided into two methods, namely photoelectric tracking and tracking based on the apparent sun's motion trajectory. The advantages of photoelectric tracking devices are high sensitivity, simple structural design, and the ability to eliminate cumula
[Security Electronics]
Design and implementation of automatic sun tracking controller based on COMS image sensor
Latest Test Measurement 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号