Part 2: PID Controller With SPICE-Modelled Thermistor Allows for Precise Temperature Profile Control
Nowadays it has become relatively simple to build temperature control systems with software like Simulink MATLAB. Depending on the complexity of these systems, the regulation can be performed with PI, PID, or fuzzy logic controllers. Simplicity of use, however, is not necessarily linked to low costs, as such programs can be very expensive. If you consider temperature control applications based on NTC thermistors, the level of precision that can be reached will depend strongly on the characterization method of the thermistor, including its tolerances. The focus of this article isn’t Simulink, but a zero-cost DIY method for achieving good temperature PID regulation in a simple system. This will be done with the help of a performant LTSpice electronic simulator and a precise thermistor model previously described.
In Old-School Analog Temperature Control Circuits Solved with Modern LTSpice Thermistor Dynamic Models, Part one1 , we saw that it is possible to provide a SPICE model representing the temperature of a simple system and to feed it back to a voltage-driven thermistor, which is used to control the temperature of the system. Now we go to a next level of regulation with a NTC thermistor-based (completely analog) PID controller and its LTSpice model. This PID controller is intended to control the temperature of a system such as a small oven with a defined profile. The goal of the simulation is to stick to the defined profile as much as possible, with minimal deviation of temperature. For this application, the oven temperature will need to change as follows over a period a bit longer than one hour:
This temperature profile is one of the principal reasons why we need a PID controller, which will be able to very accurately follow the required dwells and slopes, while also avoiding big oscillations as much as possible. The second mission of our PID controller is to enable the system to react to external heat / cold noise, for example a variation of the external temperature as the alternative profile in figure 1 (grey curve). We are thus going to elaborate on a circuit proposal, simulate it, optimize it, and give some hints on how to relate this theoretical work to practical measurements.
Presentation of the Simulation
The total circuit is represented in Figure 2, with the following notes:
- There are two NTCLE203E3103_B0 thermistors in the sensing bridge. One is the physical sensing thermistor: the temperature sensor that senses the system temperature, with a time delay equal to the RC constant of the network connected to the node Ti. The second thermistor is there only for simulation. A piecewise linear file voltage is connected at the Tset node. This file contains the temporal information about the temperature profile to be followed (as defined in Figure 1). This is an ideal way to program our reference profile
- The PID section is mainly a copy of a circuit found at the eCircuit Center: Op Amp PID Controller2
- The heater unit consists of two fixed resistors R8 and R9 and a Darlington mounting based on two model ZTXB49 NPN transistors
- On the right of the “system” is a rough schematic of the oven, with a thermal mass represented by the capacitor Csystem. The heat generated in the oven is modelled by the B4 ABM (analog behavior) voltage source, which includes the dissipation from the oven to the surrounding temperature Tamb
- A pulse source (heat noise, and in this case it will be a cold source) is added in series to adequately represent the variation of the external ambient temperature (pulse of amplitude dT in the parameters)
- The SPICE directives contain the PID parameters Kp, Kd, and Ki; parasitic ambient source dT; thermistor response time Tau; fixed resistor tolerance RTOL .; and the NTC thermistor tolerance Rntctol and BTOL . for the B25/85 coefficient. The analysis is also performed for a worst case analysis with two special functions: vb() and wc() 
- The err function is the LTSpice RMS function of the difference between the produced system temperature Tsystem and the set temperature Tset. This err function must be minimized globally over the simulation time and will provide the optimal values for all circuit parameters
With the help of this circuit, we have performed different simulations in order to proceed to the parameter optimization. What we need to find is the values of Kp, Kd, and Ki so that the err function will be minimal. LTSpice lets you sweep a maximum of three parameters per simulation, so you could even optimize Kp, Kd, and Ki in one run (albeit a very long run). Of course, we will only present one step of optimization here together with final results.
In Figure 3, the simulation presents the result of V(Tsystem) and the target V(Tset) in the lower pane, and the difference between voltages / temperatures in the upper pane. In the SPICE directives of Figure 2, we ask to measure the err function, which is the least square of the sum of the difference between the result and the target on the whole time span of the simulation. This err result is written in the “SPICE Error Log” file available from the “View “menu of LTSpice.
In Figure 3 you will find the optimization step of Ki, where Ki is swept from 1.6 m and 2.6 m.
The least square err function can be read in the function of the Ki value after the completion of the simulation in Figure 2. The graphical representation of the SPICE Error Log file data will show the optimal Ki value in Figure 4 (Kp = 2.1 m).
At the same time, we need to optimize the Rheat value for the two pre-selected NPN transistors, and make our regulation robust when ambient temperature changes. This is the simulation performed in Figure 5. In the lower pane, we see the two traces of the ambient temperature (one constant at 20o C and the other swinging from 20o C to -10o C (thus a dT of -30o C)). In the upper pane, we see that these ambient changes are nearly counteracted by the increasing of the heating current, in order to maintain the system temperature as close to the set temperature as possible.
Computing the err function again by looking in the SPICE Error Log (Figure 6), we arrive at the optimized values for Rheat: 1.5 Ω , whatever the transistor model.
When all parameters are optimized, we proceed again to the simulation and obtain the final result (Figure 7). Note that the optimization has been performed for V(Tsystem) vs V(Tset) (red curve). Over the time span from 0 Ks to 4 Ks, the offset is contained within +/- 0.5o . The deviation of the temperature seen by the NTC thermistor (blue curve) with respect to the set profile is also presented. We see that it’s slightly out of phase due to RC (Tau) delay during the temperature ramps.
Introducing the circuit tolerances
So what about the component tolerances? That’s what the LTSpice worst case analysis is for. Remember that all the components values of the simulation have been given a tolerance and that the simulation process of LT spice is designed to explore all the combinations (positive and negative) of the thermistor and the fixed resistors3
We have given tolerances to the thermistor (+/- 1 % for both R25 and B25/85 , thus on the slope), to the thermistor response time (20 %), and +/- 0.5 % to the fixed resistors R1 and R3. There are five tolerances in total for which we can thus perform 25 = 32 runs, which will explore the full combination of the minimums / maximums of each device. We performed these 32 simulations for the two Tamb profiles.
The result is in Figure 8, which presents the same results as Figure 7, but now includes the tolerances. Note the broadening of the tolerances as temperature increases due to the B value tolerance: at 85o C we maintain the temperature within +/- 1.8o C, whatever the ambient temperature variation.
Of course if this accuracy is not sufficient, the designer can choose different tolerances for the components and study then the influence on the result.
How to Relate the Simulation Results With a Real Application
It’s now the time to think about how the simulation can represent a real application.
In practice, the designer will have to identify the system parameters in order to perform a realistic simulation. But how do they measure the thermal mass Csystem and characterize the dissipation Dsystem?
Well even for that purpose, this simulation can help. Suppose that we heat the system in an open loop without temperature control (we can easily put the sensor in an open circuit) and make a modified simulation. The Tsystem profile will follow the pattern represented in Figure 9, going from ambient to the maximum power temperature. This result can be correlated to a practical measurement because it’s very easy for the designer to measure the rising temperature of their oven heated at full power.
In a second step, when the whole system has reached the maximum temperature, we can cut the power and let it cool down (for this, we can open the branch of the heating element and adopt for initial conditions a high value for Tsystem). We then get the pattern shown in Figure 10.
Correlation of real measurements in these two conditions with simulation results should bring realistic values for the system characteristics.
And this is made even easier as the practical measurement data can be imported into LT spice and compared with the simulation results.
In conclusion, we can state that the principles developed in this article (PID, LTSpice, and a thermistor driven by temperature) are likely to help a designer of thermal applications to theoretically define the base of their application. With the help of a few characterizations of his system (thermal mass and dissipation), it will be possible to theoretically define a complete application before implementation.
The diverse features of LT spice (measurement directives, worst case analysis, possibility to import real practical measurements into the software) together with the voltage driven NTC thermistor models are very useful tool to the temperature control designer.
Of course, other simulation programs such as Simulink MATLAB might provide more readily available solutions, but as we have already said, LTSpice and temperature- / voltage-driven models are both completely free of charge. The quality / price ratio of the DIY method presented in this article is unbeatable.
As usual, the simulation presented in this article is available on request at firstname.lastname@example.org
- Stas, A. “Old-School Analog Temperature Control Circuits Solved with Modern LTSpice Thermistor Dynamic Models, Part one.” Planet Analog. AspenCore, Feb. 21, 2017. Web. Feb. 2017.
- “Op Amp PID Controller.” eCircuit Center. Web. Feb. 2017.
- “LTSpice Nouvelles Commandes, Applications Inédites, Création et Importation de Modèles et de Sous-Circuits.” Chapter 15, Dunod, 2015.