-
Notifications
You must be signed in to change notification settings - Fork 16
Examples_MAX6675_PTC_SSR
- Arduino Uno
- PTC Heating Plate (110VAC, 140W, 220℃)
- CPC40055ST AC Power Switch
- MAX6675 Type Thermocouple Temperature Sensor Module
- Thermocouple Type-K 0-600°C
- A series 330Ω resistor was connected from UNO pin 3 to pin 3 of the SSR (LED+)
- SSR Pin 4 (LED-) was connected to GND
- The PTC black wire was connected to AC Neutral
- SSR load pin 2 connected to the PTC red wire
- SSR load pin 1 connected to 120VAC power
- To connect the MAX6675 board, follow instructions here
This setup uses a stainless steel type-K thermocouple and the older MAX6675 sensor module. The thermocouple was attached to the aluminum PTC heater with a clip. The surface area in contact with the aluminum wasn't ideal, as the threaded sleeve and threaded mounting hole wasn't used. Also, this thermocouple has much greater mass than the glass bead type thermocouple, so this added to the delay for thermal transfer. The MAX6675 sensor module has greatly reduced resolution and increased noise compared to the MAX31856 module.
Overall, this setup was good for testing the capability of sTune. It was found that myPID.SetSampleTimeUs(outputSpan * 1000 * 0.2);
worked best for ideal response, wheras the multiplier used for the MAX31856 / glass bead type-K setup was 0.4
. The lower 0.2
value was most likely required due to the increased thermal inertia.
Note that the ZN_PID
tuning method was used. Other tuning methods are available if different response characteristics are required.
sTune tuner = sTune(&Input, &Output, tuner.ZN_PID, tuner.directIP, tuner.printOFF);
In this example, sTune is initialized usin the ZN_PID
tuning method. The inflection point directIP
test is run and the serial print results is turned off to allow the plotter function to plot the complete sTune test and PID run.
// user settings
uint32_t settleTimeSec = 10;
uint32_t testTimeSec = 500; // runPid interval = testTimeSec / samples
const uint16_t samples = 500;
const float inputSpan = 200;
const float outputSpan = 1000;
float outputStart = 0;
float outputStep = 50;
float tempLimit = 150;
uint8_t debounce = 1;
-
settleTimeSec
is used to provide additional settling time prior to starting the test. -
testTimeSec
at minimum, should be set to one time constant (the time it takes for the input to reach 63% of the max value after a step change of the controller output. -
samples
is the number of samples used to perform the test. To get an accurate representation of the reaction curve, the suggested range is 200-500. -
testTimeSec / samples
determines the sample period -
inputSpan
represents the maximum operating range of input -
outputSpan
represents the maximum operating range of output. This also specifies thesoftPWM
windowSize, the PID output max limit, the PID sample time and is also used in gain calculations in various tuning methods. -
outputStart
is the initial control output value which is used for thesettleTimeSec
duration and sample 0 -
outputStep
is the stepped output value used for sample 1 to test completion -
tempLimit
is used to specify the emergency stop value at which the test aborts (reset) and the output is set to zero -
debounce
controls several features in thesoftPWM()
function.
// variables
float Input, Output, Setpoint = 80, Kp, Ki, Kd;
- These variables are linked to sTune and QuickPID
void loop() {
float optimumOutput = tuner.softPwm(relayPin, Input, Output, Setpoint, outputSpan, debounce);
switch (tuner.Run()) {
case tuner.sample: // active once per sample during test
Input = module.readCelsius();
tuner.plotter(Input, Output, Setpoint, 0.5f, 3); // output scale 0.5, plot every 3rd sample
break;
case tuner.tunings: // active just once when sTune is done
tuner.GetAutoTunings(&Kp, &Ki, &Kd); // sketch variables updated by sTune
myPID.SetOutputLimits(0, outputSpan * 0.1);
myPID.SetSampleTimeUs((outputSpan - 1) * 1000);
debounce = 0; // ssr mode
Output = outputStep;
myPID.SetMode(myPID.Control::automatic); // the PID is turned on
myPID.SetProportionalMode(myPID.pMode::pOnMeas);
myPID.SetAntiWindupMode(myPID.iAwMode::iAwClamp);
myPID.SetTunings(Kp, Ki, Kd); // update PID with the new tunings
break;
case tuner.runPid: // active once per sample after tunings
Input = module.readCelsius();
myPID.Compute();
tuner.plotter(Input, optimumOutput, Setpoint, 0.5f, 3);
break;
}
}
In the loop(), the softPWM
function runs continuously and drives a time proportioned output on relayPin 3. The function returns the internaloptimumOutput
signal used for SSRs. This allows plotting and diagnostic use.
The switch case controlled by sTune has 3 main states - sample
, tunings
and runPid
.
- Active once per sample during sTune inflection or full test. Here, the Input reading is updated and the plotter function is run
-
active just once when sTune is done
-
tuner.GetAutoTunings
updates the Kp, Ki and Kd sketch variables with the new gains -
myPID.SetOutputLimits(0, outputSpan * 0.1);
Here, the max limit is set to 10% of theoutputSpan
because this is the minimum output value needed to drive the temperature of the PTC heater to maximum. -
myPID.SetSampleTimeUs((outputSpan - 1) * 1000);
The PID sample time is regulated at 1 second in the
runPid
case. -
debounce = 0;
When debounce is set to 0, software PWM uses SSR optimum cycle mode -
The PID is set to
automatic
,pOnMeas
andiAwClamp
. Note thatpOnError
mode isn't used because the output won't react in advance as the input approaches setpoint. Also,iAwCondition
mode isn't used as it counteracts the beneficial effect of theoptimumOutput
software PWM mode.
This case is active once per sample period (1-sec intervals) after tunings. Here, the temperature is read, PID compute is run and the plotter function is run.