- This project makes use of a custom-designed PCB; please refer to Custom PCB Design with an EFM8 Microcontroller for guidance on incorporating EFM8 devices into your custom hardware.
- You can find a brief overview of thermocouples along with some general information about the MAX31855 in Make an EFM8-Based System for Monitoring and Analyzing Thermocouple Measurements.
- An Introduction to Control Systems: Designing a PID Controller Using MATLAB’s SISO Tool
- Negative Feedback, Part 1: General Structure and Essential Concepts
- Introduction to Bipolar Junction Transistors
The Legendary P-I-D
PID controllers have perhaps attained a somewhat mythical status. When a physical variable needs to be controlled—temperature, angular velocity, position, flow rate, etc.—the power of PID is invoked, and with PID comes the confident hope of speedy success. PID’s popularity and renown are not necessarily undeserved; PID control is elegant, flexible, and robust, and it has proved its efficacy in countless practical applications. However, it is possible that our knowledge of PID far exceeds our experience with PID, especially considering that PID implementations are often hidden inside so-called programmable logic controllers (PLCs), with various low-level details abstracted away from the user. PLC manufacturers make really good PID controllers that far surpass anything I could design; of this I have no doubt. But I like designing things myself, from the ground up—it’s more fun and it helps me to actually understand important concepts and techniques.
Hence, this series of articles will explore practical, low-level PID control by means of a simple circuit that can measure the temperature of a resistive heating element. We will not go into the details of PID theory, which are aptly covered in An Introduction to Control Systems, and we will not incorporate every possible feature and refinement into our algorithm. Instead, we will try to illuminate the foundational principles of PID control by applying them to a straightforward temperature-control circuit.
A PID controller is a particular implementation of negative feedback:
To understand the enduring success of PID control, you first need to understand negative feedback’s venerable ability to easily accomplish complicated control tasks. Here I will quote from Negative Feedback, Part 1: General Structure and Essential Concepts: often in life,
The solution: negative feedback.
In the case of a PID (proportional-integral-derivative) system, the “open-loop amplifier” is actually an algorithm that operates on the most recent error as well as previous errors and anticipated errors. Herein lies the elegance of PID control: the proportional term adjusts the output in response to the current state of the system, the integral term fine-tunes the output by accumulating past errors, and the derivative term makes the output more responsive by predicting future errors based on how the output is changing.
The functionality of this project is essentially that of a thermostat: the “heater” is simply a 2.4 Ω, 5 W resistor. The feedback signal is provided by a K-type thermocouple in conjunction with the MAX31855 thermocouple-to-digital converter. However, our thermostat is more interesting than the typical household variety because it’s not limited to “on” and “off”; rather, we can choose from 256 different levels of heater power. This is accomplished with the following circuit:
The leads of the heating-element resistor are screwed into the two terminals of terminal block J7, so when you look at J7, imagine a resistor in its place:
The DAC is an 8-bit voltage-output device controlled by the EFM8 microcontroller via SPI. The reference voltage (provided by the EFM8) is 2.4 V, so the DAC’s output range is 0 V to 2.4 V in steps of (2.4 V)/(28) = 9.4 mV. The puny DAC output driver can continuously source only about 10 mA, and we’re not going to get much heat out of our resistor with only 10 mA. This is where the op-amp and BJT (p/n DSS20201L from Diodes Inc.) come into play.
We could simply use the op-amp to buffer the DAC output, but the op-amp’s output-current capacity is also insufficient. So what you see here is the standard circuit for increasing an op-amp’s drive capability. The BJT can sustain continuous collector current of 2 A, which is more than enough for our purposes. The control voltage (i.e., the DAC output voltage) is applied to the op-amp’s positive input. The general circuit configuration is that of a unity-gain voltage follower, but notice how the feedback signal (connected to the op-amp’s negative input) comes from the voltage applied to the heating element, not from the op-amp’s output terminal. This arrangement tells the op-amp to adjust its output voltage in whatever way is necessary to ensure that the voltage applied to the heating element is the same as the control voltage.
Another important detail is the following: Although the op-amp does not directly drive the heating element, its output-current capacity is not irrelevant. The current flowing into the base of Q1 will be approximately equal to the heater current divided by the BJT’s active-region DC current gain, otherwise known as beta or hFE. (Note that Q1 will always be in cutoff or active mode, because the base voltage will not exceed 2.4 V + ~0.7 V = 3.1 V, whereas the collector is always at 5 V. An npn transistor will not enter saturation as long as the base voltage does not exceed the collector voltage by more than ~0.4 V.) The minimum beta for our transistor is 200, so if we are driving 1 A into the heating element, the op-amp must be able to supply 5 mA to the base. I think that just about any op-amp can handle 5 mA, but if you modify this circuit for significantly higher heater current, remember to confirm that your op-amp can safely provide the necessary base current.
There are basically two requirements for the heating-element resistor: its resistance must be very low so that our low drive voltages will produce high current, and its power rating must be sufficiently high (much higher than what we are used to with typical through-hole or surface-mount resistors). I can’t draw much more than 1 A from the USB charger I am using as a power supply, so I chose a resistance of 2.4 Ω: the maximum drive voltage is 2.4 V, and thus when the drive voltage is at max, the current will also be at max. The power dissipation at max current is simply 2.4 V × 1 A = 2.4 W. I like to maintain about 2x safety margin, so a 5 W resistor will do the trick. Here is a photo of the hardware setup:
Even at 1 A this system does not generate huge amounts of heat, so during operation I extend the usable temperature range by wrapping the resistor in fluffy insulating fabric:
We introduced the general concept and benefits of PID control, and we discussed in detail the “thermostat” circuit that we will use to explore PID functionality. In the next article we will focus on the firmware needed to gather temperature data from the MAX31855 and to adjust the heater drive current via the DAC.
Next Article in Series: Embedded PID Temperature Control, Part 2: Board-Level Integration
Give this project a try for yourself! Get the BOM.