This notebook demonstrates how to perform temperature control operations with Mathematica through the bTop-2. We begin with a naive temperature control scheme and then present a simple improvement which greatly decreases the temperature error.
Sample data for this demonstration was taken with a 2.6 W (0.5A) incandescent light bulb acting as the heater, and a National Semiconductor LM34 Precision Fahrenheit Temperature Sensor as the thermometer. A wiring diagram for this experiment is available from Perfectly Scientific, Inc.
Connect one bTop-2 board to your computer via an available USB port, and load the BTopTools package with the following command.
These commands define convenience functions to control the heater, and measure the temperature.
We begin by verifying that everything is connected and working properly. We measure the temperature at the thermometer for 20 seconds with the heat turned off, then 20 seconds with the heat turned on, then 20 seconds with the heat off again. If everything is working, we should see that the temperature remained relatively constant for the first 20 second interval, climbed during the next 20 second interval, then peak and begin to fall during the last 20 second interval.
Why does the temperature continue to rise after the 40 second mark? Because the heater remains warm even after it has been turned off, and continues to increase the temperature of the thermometer until the thermometer and the heater have nearly equal temperatures. The delay between the HeatOff command and the temperature peak will figure into our more advanced temperature control system.
Our first temperature control method will be very simple. We will set a predetermined target temperature, and divide a 10 minute interval into 60, 10 second intervals. Every ten second interval will begin with the heat on for zero or more seconds (M). When, after a ten second interval, the temperature is greater than the target, M will be decreased. When, after a ten second interval the temperature is less than the target, M will be increased. We take the sum of the absolute value of the error during the last 400 seconds in order to quantize the quality of the control system.
With this control scheme, the temperature is made to settle and oscillate around the target. There will always be some oscillation around the target, but in this case the amplitude of the oscillation is greater than it needs to be. We can improve our results by taking into consideration not only the current temperature, but also the derivative of the temperature. In this next system we take a weighted sum
, and decrement M when that sum is greater than zero, and increment M when that sum is less than zero.
and
are both non negative, so M is decreased whenever the temperature is too high and rising, and increased whenever the temperature is too low and falling. If the temperature is too high, but also falling, M may or may not be adjusted depending on the current error and the rate at which the temperature is dropping. If the temperature is too low but still rising, M may or may not be adjusted. The trick with this kind of control system is to get the constants
and
adjusted to obtain optimal results.
As you can see, the new method is a considerable improvement, with only an error of 0.095 over the last 400 seconds, instead of an error of 0.212.
Created by Mathematica (January 24, 2007)