Skip to content

Commit 1ff4d46

Browse files
committed
replace delay with timer
1 parent 323d52e commit 1ff4d46

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

examples/AutoTune_Filter_DIRECT/AutoTune_Filter_DIRECT.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void loop() {
7474
_myPID.Compute();
7575
analogWrite(outputPin, Output);
7676
}
77-
//delay(1); // adjust loop speed
77+
delay(1); // adjust loop speed
7878
}
7979

8080
float avg(int inputVal) {

examples/AutoTune_Filter_REVERSE/AutoTune_Filter_REVERSE.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void loop() {
7575
_myPID.Compute();
7676
analogWrite(outputPin, Output);
7777
}
78-
//delay(1); // adjust loop speed
78+
delay(1); // adjust loop speed
7979
}
8080

8181
float avg(int inputVal) {

src/QuickPID.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,18 @@ byte AutoTunePID::autoTuneLoop()
248248
break;
249249
case STABILIZING:
250250
if (_printOrPlotter == 1) Serial.print(F("Stabilizing →"));
251+
_t0 = millis();
251252
_peakHigh = _atSetpoint;
252253
_peakLow = _atSetpoint;
253254
(!_direction) ? *_output = 0 : *_output = _atOutput + _outputStep + 5;
254255
_autoTuneStage = COARSE;
255256
return AUTOTUNE;
256257
break;
257258
case COARSE: // coarse adjust
258-
delay(2000);
259+
if (millis() - _t0 < 2000) {
260+
return AUTOTUNE;
261+
break;
262+
}
259263
if (*_input < (_atSetpoint - _hysteresis)) {
260264
(!_direction) ? *_output = _atOutput + _outputStep + 5 : *_output = _atOutput - _outputStep - 5;
261265
_autoTuneStage = FINE;

0 commit comments

Comments
 (0)