-
Notifications
You must be signed in to change notification settings - Fork 16
/
Get_All_Tunings.ino
72 lines (64 loc) · 2.35 KB
/
Get_All_Tunings.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/***************************************************************************
sTune Get All Tunings Example (MAX6675, PTC Heater / SSR / Software PWM)
This runs a fast inflection point test to determine tuning parameters.
Open serial printer to view test progress and results.
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 SO = 12;
const uint8_t CS = 10;
const uint8_t sck = 13;
// user settings
uint32_t settleTimeSec = 10;
uint32_t testTimeSec = 500; // sample 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;
// 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(relayPin, OUTPUT);
Serial.begin(115200);
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;
}
}