-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New examples for MAX6675 and PTC heater
- Loading branch information
Showing
11 changed files
with
251 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
examples/MAX31856_PTC_SSR/Get_All_Tunings/Get_All_Tunings.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
examples/MAX6675_PTC_SSR/Get_All_Tunings/Get_All_Tunings.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/*************************************************************************** | ||
sTune Get All Tunings Example (MAX6675, PTC Heater and SSR) | ||
Reference: https://github.com/Dlloydev/sTune/wiki/Examples_MAX6675_PTC_SSR | ||
***************************************************************************/ | ||
|
||
#include <max6675.h> | ||
#include <sTune.h> | ||
|
||
// pins | ||
const uint8_t inputPin = 0; | ||
const uint8_t relayPin = 3; | ||
const uint8_t drdyPin = 5; | ||
const uint8_t SO = 12; | ||
const uint8_t CS = 10; | ||
const uint8_t sck = 13; | ||
|
||
// user settings | ||
uint32_t settleTimeSec = 10; | ||
uint32_t testTimeSec = 500; | ||
const uint16_t samples = 500; | ||
const float inputSpan = 220; | ||
const float outputSpan = 1000; | ||
float outputStart = 0; | ||
float outputStep = 50; | ||
float tempLimit = 100; | ||
|
||
// variables | ||
float Input, Output; | ||
|
||
MAX6675 module(sck, CS, SO); //SPI | ||
sTune tuner = sTune(&Input, &Output, tuner.ZN_PID, tuner.directIP, tuner.printALL); | ||
|
||
void setup() { | ||
pinMode(drdyPin, INPUT); | ||
pinMode(relayPin, OUTPUT); | ||
Serial.begin(115200); | ||
while (!Serial) delay(10); | ||
delay(3000); | ||
Output = 0; | ||
tuner.Configure(inputSpan, outputSpan, outputStart, outputStep, testTimeSec, settleTimeSec, samples); | ||
tuner.SetEmergencyStop(tempLimit); | ||
} | ||
|
||
void loop() { | ||
tuner.softPwm(relayPin, Input, Output, 0, outputSpan, 1); | ||
|
||
switch (tuner.Run()) { | ||
case tuner.sample: // active once per sample during test | ||
Input = module.readCelsius(); | ||
break; | ||
|
||
case tuner.tunings: // active just once when sTune is done | ||
Output = 0; | ||
tuner.SetTuningMethod(tuner.TuningMethod::DampedOsc_PID); | ||
tuner.printTunings(); | ||
tuner.SetTuningMethod(tuner.TuningMethod::NoOvershoot_PID); | ||
tuner.printTunings(); | ||
tuner.SetTuningMethod(tuner.TuningMethod::CohenCoon_PID); | ||
tuner.printTunings(); | ||
tuner.SetTuningMethod(tuner.TuningMethod::Mixed_PID); | ||
tuner.printTunings(); | ||
tuner.SetTuningMethod(tuner.TuningMethod::ZN_PI); | ||
tuner.printTunings(); | ||
tuner.SetTuningMethod(tuner.TuningMethod::DampedOsc_PI); | ||
tuner.printTunings(); | ||
tuner.SetTuningMethod(tuner.TuningMethod::NoOvershoot_PI); | ||
tuner.printTunings(); | ||
tuner.SetTuningMethod(tuner.TuningMethod::CohenCoon_PI); | ||
tuner.printTunings(); | ||
tuner.SetTuningMethod(tuner.TuningMethod::Mixed_PI); | ||
tuner.printTunings(); | ||
break; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/*************************************************************************** | ||
sTune PID_v1 Example | ||
This sketch does on-the-fly tunning and PID SSR control of a | ||
PTC heater. Tunning parameters are quickly determined and | ||
applied during the temperature ramp-up to setpoint. Open | ||
Reference: https://github.com/Dlloydev/sTune/wiki/Examples_MAX6675_PTC_SSR | ||
***************************************************************************/ | ||
|
||
#include <max6675.h> | ||
#include <sTune.h> | ||
#include <PID_v1.h> | ||
|
||
// pins | ||
const uint8_t inputPin = 0; | ||
const uint8_t relayPin = 3; | ||
const uint8_t drdyPin = 5; | ||
const uint8_t SO = 12; | ||
const uint8_t CS = 10; | ||
const uint8_t sck = 13; | ||
|
||
// user settings | ||
uint32_t settleTimeSec = 10; | ||
uint32_t testTimeSec = 500; | ||
const uint16_t samples = 500; | ||
const float inputSpan = 200; | ||
const float outputSpan = 1000; | ||
float outputStart = 0; | ||
float outputStep = 30; | ||
float tempLimit = 75; | ||
uint8_t debounce = 1; | ||
|
||
// variables | ||
double input, output, setpoint = 50, kp, ki, kd; // PID_v1 | ||
float Input, Output, Setpoint = 50, Kp, Ki, Kd; // sTune | ||
|
||
MAX6675 module(sck, CS, SO); //SPI | ||
sTune tuner = sTune(&Input, &Output, tuner.ZN_PID, tuner.directIP, tuner.printOFF); | ||
PID myPID(&input, &output, &setpoint, kp, ki, kd, P_ON_M, DIRECT); | ||
|
||
void setup() { | ||
pinMode(drdyPin, INPUT); | ||
pinMode(relayPin, OUTPUT); | ||
Serial.begin(115200); | ||
while (!Serial) delay(10); | ||
delay(3000); | ||
Output = 0; | ||
tuner.Configure(inputSpan, outputSpan, outputStart, outputStep, testTimeSec, settleTimeSec, samples); | ||
tuner.SetEmergencyStop(tempLimit); | ||
} | ||
|
||
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, 1, 3); | ||
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.SetSampleTime(outputSpan * 0.2); | ||
debounce = 0; // switch to SSR optimum cycle mode | ||
setpoint = Setpoint, output = outputStep, kp = Kp, ki = Ki, kd = Kd; | ||
myPID.SetMode(AUTOMATIC); // the PID is turned on | ||
output = outputStep; | ||
Output = output; | ||
myPID.SetTunings(kp, ki, kd); // update PID with the new tunings | ||
break; | ||
|
||
case tuner.runPid: // active once per sample after tunings | ||
Input = module.readCelsius(); | ||
input = Input; | ||
myPID.Compute(); | ||
Output = output; | ||
tuner.plotter(Input, optimumOutput, Setpoint, 1, 3); | ||
break; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
examples/MAX6675_PTC_SSR/sTune_QuickPID/sTune_QuickPID.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/*************************************************************************** | ||
sTune QuickPID Example | ||
This sketch does on-the-fly tunning and PID SSR control of a | ||
PTC heater. Tunning parameters are quickly determined and | ||
applied during the temperature ramp-up to setpoint. Open | ||
the serial plotter to view the graphical results. | ||
Reference: https://github.com/Dlloydev/sTune/wiki/Examples_MAX6675_PTC_SSR | ||
***************************************************************************/ | ||
|
||
#include <max6675.h> | ||
#include <sTune.h> | ||
#include <QuickPID.h> | ||
|
||
// pins | ||
const uint8_t inputPin = 0; | ||
const uint8_t relayPin = 3; | ||
const uint8_t drdyPin = 5; | ||
const uint8_t SO = 12; | ||
const uint8_t CS = 10; | ||
const uint8_t sck = 13; | ||
|
||
// user settings | ||
uint32_t settleTimeSec = 10; | ||
uint32_t testTimeSec = 500; | ||
const uint16_t samples = 500; | ||
const float inputSpan = 200; | ||
const float outputSpan = 1000; | ||
float outputStart = 0; | ||
float outputStep = 30; | ||
float tempLimit = 75; | ||
uint8_t debounce = 1; | ||
|
||
// variables | ||
float Input, Output, Setpoint = 50, Kp, Ki, Kd; | ||
|
||
MAX6675 module(sck, CS, SO); //SPI | ||
sTune tuner = sTune(&Input, &Output, tuner.ZN_PID, tuner.directIP, tuner.printOFF); | ||
QuickPID myPID(&Input, &Output, &Setpoint); | ||
|
||
void setup() { | ||
pinMode(drdyPin, INPUT); | ||
pinMode(relayPin, OUTPUT); | ||
Serial.begin(115200); | ||
while (!Serial) delay(10); | ||
delay(3000); | ||
Output = 0; | ||
tuner.Configure(inputSpan, outputSpan, outputStart, outputStep, testTimeSec, settleTimeSec, samples); | ||
tuner.SetEmergencyStop(tempLimit); | ||
} | ||
|
||
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, 1, 3); | ||
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 * 1000 * 0.2); | ||
debounce = 0; // switch to SSR optimum cycle mode | ||
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, 1, 3); | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=sTune | ||
version=2.3.0 | ||
version=2.3.1 | ||
author=David Lloyd | ||
maintainer=David Lloyd <[email protected]> | ||
sentence=Open loop PID autotuner using a novel s-curve inflection point test method. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters