Design and implementation of temperature control system based on MSP430
[Copy link]
Temperature control devices such as refrigerators, freezers, and air conditioners have been widely used in the general public. These devices have brought more comfort to people, and people are becoming more and more dependent on them. To this end, our team built an automatic temperature control system to simulate the operation of temperature control devices in daily life and deeply explore its working principle and optimization potential.
1 System composition
This system uses the MSP430 system board as the control core, including modules such as temperature acquisition, PID algorithm power control, temperature adjustment, and human-computer interaction. It uses the digital temperature sensor DS18B20 as the temperature sampling element. Under the control of the general timer B periodic interrupt, the low-power microcontroller MSP430F449 reads the sampling value from the DS18B20 through its general I/O port, and then calculates the control quantity through the PID control algorithm to control the current direction of the main circuit and the output of the PWM wave. The current direction determines whether the temperature control object is heated or cooled, and the output PWM wave drives the power MOSFET IRF540, thereby achieving the purpose of controlling the heating or cooling power of the thermoelectric module. The system composition block diagram is shown in Figure 1.
2 Introduction to MSP430F449
MSP430F449 is a 16-bit ultra-low power mixed signal processor launched by TI, integrating digital and analog circuits. It has the following features: 16-bit CPU connected to memory and peripheral modules through bus; directly embedded simulation processing, with JTAG interface; multiple clocks can reduce power consumption, multiple buses can reduce noise; 16-bit data width, data processing is more efficient. Its integrated debugging environment Embedded Workbench provides a good C language development platform.
Both timer A and timer B of MSP430F449 can realize PWM: when the timer works in PWM wave generation mode, register CCR0 can be used to control the period of PWM waveform, and another register can be used to control the duty cycle, which is convenient for generating PWM wave. And the segment LCD driver module is integrated in the chip, which is convenient for displaying temperature value.
3 PID control algorithm principle
3.1 PID control system introduction
PID control system is shown in Figure 2, D(s) completes the PID control law, called PID controller. PID controller is a linear controller. It uses the linear combination of the proportion, integration and differentiation of the time function e(t)=r(t)-y(t) of the error between the output quantity y(t) and the given quantity r(t) to form the control quantity u(t). It is called proportional, integral and differential control, or PID control for short.
PID control combines the three basic control laws of proportional control, integral control and differential control. It realizes control by changing the parameters of the regulator. Its basic input-output relationship is:
In practical applications, three different control combinations of proportional (P) controller, proportional + integral (PI) controller and proportional + integral + differential (PID) controller can be flexibly adopted according to the characteristics of the controlled object and the performance requirements of the control.
3.2 Analysis of PID parameter control effect
The three basic parameters of PID control are KP, KI and KD. The actual control effects of these three parameters are:
Proportional control parameter (KP) reflects the deviation of the system in proportion. Increasing KP makes the system more sensitive, faster and reduces the steady-state error, but the number of oscillations will also increase and the adjustment time will be longer. In this feedback loop, this value mainly affects the speed.
Integral adjustment parameter (KI) Eliminates the static (steady-state) error of the system and improves the control accuracy of the system. Integral adjustment will reduce the stability of the system, slow down the dynamic response, and increase the overshoot. Integral control generally does not act alone, but acts in combination with P or PD.
Differential adjustment parameter (KD) Reflects the rate of change of the system deviation signal, which can foresee the trend of the deviation change and produce a leading control effect. Therefore, differential control can improve the dynamic tracking performance of the system and reduce the overshoot, but it has an amplifying effect on noise interference. Excessive differential adjustment will cause the system to oscillate violently, which is not conducive to resisting interference.
In conventional PID control systems, it is difficult to achieve both reducing overshoot and improving control accuracy. This is mainly caused by the defects of the integral action. If the integral action is reduced, the static error is not easy to eliminate, and the error elimination speed slows down when there is disturbance; and when the integral action is strengthened, it is difficult to avoid overshoot, which is also a common problem in conventional PID control. Therefore, in this system, the integral parameter is processed in sections, and the ideal effect has been achieved.
4 Temperature control device and principle
DS18B20 supports "one-wire bus" interface, and the measurement temperature range is -55~+125℃, with a wide measurement range. DS18B20 can be programmed to set 9~12-bit resolution, with an accuracy of 0.0625℃ and high resolution. It supports a voltage range of 3~5.5V. The field temperature is directly transmitted in a digital way of "one-wire bus", which greatly improves the anti-interference ability of the system. And it only takes up one I/O port of the microcontroller, saving I/O ports. This system uses PR-35 package. The
control circuit selects VDD power supply mode, that is, VDD is connected to +5V, GND is grounded, and I/O is connected to the microcontroller I/O.
The main components of DS18B20: 64-bit laser ROM, temperature sensor, non-volatile temperature alarm trigger TH and TL, and height register.
4.1 Protocol for single-wire bus access to DS18B20
DS18B20 requires strict protocol to ensure data integrity. The protocol includes several types of single-wire signals: reset pulse, presence pulse, write 0, write 1, read 0, and read 1. All of these signals, except the presence pulse, are issued by the bus controller.
4.1.1 Initialization
All execution over the single-wire bus begins with an initialization sequence (a reset pulse issued by the bus controller followed by a presence pulse issued by the slave). The presence pulse then lets the bus controller know that the DS18B20 is on the bus and is ready for operation.
4.1.2 ROM Operation Commands
Once the bus controller detects a presence pulse, it can issue any of the five ROM commands: Read ROM, Match ROM, Skip ROM, Search ROM, and Alarm Search.
Since only one DS18B20 is used, the Skip ROM instruction is selected, and the address sequence number check is not required, which can increase the software operation speed.
4.1.3 Memory Operation Commands
4.1. 4 RAM Operation Instructions are shown in Table 1
Generally, the temperature conversion instruction is executed first, and then the 16-bit temperature value is read into the master controller using the read register instruction.
4. 1.5 Execution/Data
Before executing data, make sure that the instructions have been entered first and strictly follow the time sequence. When executing and data, please note that only when the data time slot is accurately grasped can the data be read and written correctly.
4.2 Read and write time slots
The data reading and writing of DS18B20 is confirmed by the time slot processing bit and command word to exchange information. The required data must be read or written at the exact time when the time slot starts. Therefore, the timing control of DS 18B20 must strictly grasp the time segmentation. When the host pulls the data line from the logic high level to the logic low level, the write time slot begins; when reading data from DS18B20, the host generates a read time slot.
5 TEC1-12708 drive circuit
Refrigeration chip TEC1-12708: The thermoelectric refrigeration component made according to the Peltier effect is light in weight, small in size and has a relatively high cooling capacity. It is particularly suitable for cooling in limited spaces. Since the refrigeration component is a solid-state heat pump, it does not require maintenance, has no noise, can work in any position, and has strong shock and vibration resistance. In addition, when the working current model of the component is changed, heating can be achieved, and the cooling power can be adjusted by changing the current intensity.
Since the driving current required by TEC is bidirectional, the power tube MOSFET is selected, and the H-bridge circuit is formed by combining the bidirectional thyristor photocoupler to control the direction of TEC. The on-resistance of the power MOSFET tube IRF 540 is very small, which can effectively increase the maximum power supplied to the load. The photocoupler is an electric-optical-electric conversion device that isolates the light source and the light receiver with a transparent insulator, which will not cause any damage to the circuit and has better performance than the relay.
Figure 3 shows that the bidirectional thyristor photocoupler constitutes 4 switch circuits controlled by a high level. The 4 switch circuits are connected into an H-bridge circuit to achieve heating and cooling of the cooling plate. When switches 1.3 are closed, the current flows through the cooling device in the forward direction, and the refrigerator starts to heat; when switches 2 and 4 are closed, the current flows through the cooling device in the reverse direction, and the cooling device cools down.
After analyzing the control principle, the overall control principle diagram of the cooling plate is shown in Figure 4. By controlling the duty cycle of the PWM wave to control the conduction time of the power tube IRF540, the effective current and direction provided to the cooling plate by the circuit are controlled. The control effect is good.
6 System software design
The system software completes functions such as cooling and heating, setting temperature values, and automatic temperature adjustment. Important algorithm implementations include PID algorithm and control of digital temperature sensor DS18B20. The overall process is: system initialization, waiting for key interruption. After selecting cooling or heating, set the specified temperature value; receive the temperature data collected, compare it with the set temperature value, and calculate the duty cycle for power control after the difference is passed through the PID algorithm to adjust the temperature. Among them, the PWM wave is generated by the timer B of the MSP430F449. In this mode, register CCR0 is used to control the PWM wave frequency, and any other register controls the duty cycle. The control is flexible and quite convenient. Control the integral adjustment parameter pair, and adopt the segmented integral PID algorithm to control the system overshoot. The software flow is shown in Figure 5.
The system software completes functions such as cooling and heating, setting temperature values, and automatic temperature adjustment. Important algorithm implementations include PID algorithm and control of digital temperature sensor DS18B20. The overall process is: system initialization, waiting for key interruption. After selecting cooling or heating, set the specified temperature value; receive the temperature acquisition data, compare it with the set temperature value, and calculate the duty cycle for power control after the difference is passed through the PID algorithm, thereby adjusting the temperature. Among them, the PWM wave is generated by timer B of MSP430F449. In this mode, register CCR0 is used to control the PWM wave frequency, and any other register controls the duty cycle, which is flexible to control.
7 Test Results
7. 1 Test process
In order to prevent the room temperature change from affecting the test, a place with air conditioning and constant room temperature was selected for testing. At room temperature of 16°C, the test data is shown in Table 2.
7.2 Analysis of test results
From the above experimental data, it can be seen that the temperature reading can reach 0.1°C, and the maximum difference between the set temperature value and the final temperature value reading is 0.8°C, which fully meets the experimental requirements of ±2°C. From the second group of experimental data, it can be seen that when the temperature difference is greater than 15°C, the time required to reach the specified temperature is 2 minutes and 43 seconds.
|