The design problem was defined in a previous post. Now, I want to sketch the solution as a proof-of-concept. In practice, that means presenting a simplified physical model of the incubator, a basic PID controller, and a quick implementation on the microcontroller. Also, I’ll set quality measures and a testbench.

Control loop

Figure 1. Control loop and signal definitions.

Simple plant’s model

At this point, I’ll model the plant (incubator) as a very basic physical process. The fundamental idea is that a resistor generates heat, which is transferred to an aluminum piece, increasing its temperature. The temperature is measured with a PTC thermistor. The controller reads the temperature and controls the voltage applied to the heating element.

Simplified plant's model

Figure 2. Simple plant model based on heat transfer.

The amount of energy Q necessary to change the temperature of an object with mass m by ΔT is given by the heat transfer equation. Where c is the specific heat of the object’s material.

\[\begin{aligned} Q &= m\cdot c\cdot \Delta T \\ \Delta T &= T_{2} - T_{1} \end{aligned}\]

With the same equation, we can calculate the final temperature of the object after applying Q [J].

\[T_{2} = \frac{m\cdot c \cdot T_1 + Q}{m\cdot c}\]

Now, we can consider the total heat transfer Q to have two components. One, Qi, adds heat to the system, while the other, Qo, represents heat leaving the system.

\[Q = Q_i + Q_o\]

We already defined that the heating element is a resistor. Let’s say the heating element has a resistance R and the control signal is the voltage u(t). Then, the power that the resistor adds to the system is:

\[P = \frac{u(t)^2}{R}\]

The heat transferred by the resistor in a period Δt is:

\[Q_i = \frac{u(t)^2}{R} \cdot \Delta t\]

On the other hand, the heat leaving the object, Qo, is zero when the object is at room temperature and negative when its temperature is above room temperature. So, the total heat transferred when the objects cool down from T1 to room temperature is.

\[Q_o = m \cdot c \cdot (T_{room} - T_1)\]

Now, the time it takes for the object to cool to room temperature depends on many factors, such as its geometry, the cooling method, and humidity. So, to keep things simple at this point, I will assume that the object loses a small fraction k of its heat over a period Δt.

Summarising the equation, we have:

\[\begin{align} T_{2} &= \frac{m\cdot c \cdot T_1 + (Q_i + Q_o)}{m\cdot c} \\ Q_i &= \frac{u(t)^2}{R} \cdot \Delta t \\ Q_o &= k \cdot m \cdot c \cdot (T_{room} - T_1) \end{align}\]

We are now in the position to test the model. We need to define the values. I will say that the object is a 1 kg aluminum block. At t = 0, the object is at room temperature, 21°C. The resistor is 20Ω, and the sampling time is 1s. In summary:

\[\begin{aligned} m &= 1 kg\\ c &= 0.91 \cdot 10^3 J/(kg°C)\\ R &= 20 \Omega\\ \Delta t &= 1 s\\ k &= 0.07\\ T_{room} &= 21°C \end{aligned}\]

The test simulates the plant’s pulse response. The input voltage is a 10V pulse with a width of 100 seconds. The pulse starts 10 seconds after starting the simulation. I programmed the simulation in Python. Here are the results:

Pulse response

Figure 3. Plant’s response to an input pulse.

The model simulates the basic dynamics of the plant. When a voltage is applied to the heating element, the temperature begins to increase. At the beginning, the heat loss is small because the difference in temperature from the room temperature is small, but it increases as this difference increases. In the steady state, the input and output heat balance, reaching a constant temperature (21.08°C). It takes about 65 seconds to reach steady state. After turning the input off, the object cools quickly at first, then slows as its temperature approaches room temperature. At the end, the object reaches room temperature.

Sensing

Looking at Figure 1, the plant output y(t) is the object temperature at time t, but what the controller sees is the measured signal ym(t), which includes the sensor characteristics. In this example, the sensor is a PT100, and ym(t) is proportional to the temperature-dependent resistance RT. The PT100 equation is a third-order polynomial, but higher-order terms are not relevant at low temperatures. Then, I approximate it to a line.

\[R_T(t) = A\cdot T_2(t) + R_0\]

Here R0 is 100 Ω, A is 0.391 Ω/°C1, and T(t) is the object’s temperature at time t.

There are many ways to connect an RTD. In this case, I will use a constant-current source to produce a voltage ym(t) that depends on RT.

\[y_m(t) = R_T \cdot I\]

Where I is a constant current running through the PT100. Then, the output is the analog voltage ym(t). That voltage can be read with an ADC in the microcontroller.

The controller

In time domain, a proportional–integral–derivative (PID) controller has the form:

\[u(t) = P\cdot e(t) + I\cdot \int_0^t e(\tau) d\tau + D\cdot \frac{d e(t)}{dt}\]

The problem now is to find the values of P, I, and D so that the closed loop follows the reference signal, is stable within the defined bandwidth, is robust, and reaches steady state within the time specified in the requirements. There are several techniques for tuning a PID. When necessary, I will use an empirical tuning, the Ziegler-Nichols oscillation method.

Testbench

I’d like to test the controller in a real incubator, but I don’t have one, so I’ll simulate it. To do so, I will program the model derived above in a microcontroller, the input is a voltage (u(t)) representing the action on the heating element, and the output is another analogue voltage (ym(t)) representing the voltage in RT.

I will implement the controller in another microcontroller and connect both through the control (u(t)) and measurement(ym(t)) signals. As a result of this implementation, I will need to scale the input and output voltages to match the microcontroller’s dynamic range.

Quality measurements

We will say that the design is accepted if it can satisfy the following requirements:

  1. The steady state temperature is reached in a period of less than 1 minute.
  2. The steady state temperature has a tolerance of ±0.5°C.
  3. Over- and undershoots are accepted in a range of 4 times the steady state tolerance (±2°C).
  4. The closed loop has to be stable.

Conclusion

This post turned out to be more of a control engineer exercise than an STM32 example. But that was necessary to define the problem and design a conceptual solution correctly. This exercise was still a simplified analysis, and many more details remain to be considered in the next phases of the design process. For now, the previous results are sufficient to proceed with the proof of concept.

In the following posts, I will cover the plant and controller implementations in an STM32 microcontroller.

  1. Values from the Fluke PT-385