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.
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
- Popular Resources
- Popular amplifiers
- Analysis and Implementation of MAC Protocol for Wireless Sensor Networks (by Yang Zhijun, Xie Xianjie, and Ding Hongwei)
- Introduction to Internet of Things Engineering 2nd Edition (Gongyi Wu)
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Modern Motor Control Technology (Wang Chengyuan, Xia Jiakuan, Sun Yibiao)
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Seizing the Opportunities in the Chinese Application Market: NI's Challenges and Answers
- Tektronix Launches Breakthrough Power Measurement Tools to Accelerate Innovation as Global Electrification Accelerates
- Not all oscilloscopes are created equal: Why ADCs and low noise floor matter
- Enable TekHSI high-speed interface function to accelerate the remote transmission of waveform data
- How to measure the quality of soft start thyristor
- How to use a multimeter to judge whether a soft starter is good or bad
- What are the advantages and disadvantages of non-contact temperature sensors?
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Problems encountered when burning Flash to DSP28335
- Use CCS to install C2000ware and create a sample project
- HuaDa MCU Design Considerations Flash and Serial Programming Application Notes
- Playing with Zynq Serial 35——Online board debugging based on Vivado Virtual IO
- Facing the "Smith Chart" calmly, no longer confused
- Tell a joke every day to have fun in the busy life
- Does anyone have a simulation circuit diagram of the LMD18200 chip in proteus?
- Does turning on Bluetooth and NFC for 24 hours consume power?
- 【FAQ】Implementing MultiZone Security in RISC-V Applications | Microchip Security Solutions Seminar Series
- Overview of IoT Gateway and Its Role