8000 Update RelayOutput for minimum relay on time and consistent window be… · jamesprior/Arduino-PID-Library@0aa6c0a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0aa6c0a

Browse files
committed
Update RelayOutput for minimum relay on time and consistent window behavior
1 parent d21d7e3 commit 0aa6c0a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

PID_v1/Examples/PID_RelayOutput/PID_RelayOutput.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ double Setpoint, Input, Output;
2424
PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT);
2525

2626
int WindowSize 8000 = 5000;
27+
int minWindow = 500;
2728
unsigned long windowStartTime;
2829
void setup()
2930
{
@@ -42,16 +43,16 @@ void setup()
4243
void loop()
4344
{
4445
Input = analogRead(0);
45-
myPID.Compute();
4646

4747
/************************************************
4848
* turn the output pin on/off based on pid output
4949
************************************************/
5050
if(millis() - windowStartTime>WindowSize)
51-
{ //time to shift the Relay Window
51+
{ //time to shift the Relay Window and recalculate
5252
windowStartTime += WindowSize;
53+
myPID.Compute();
5354
}
54-
if(Output < millis() - windowStartTime) digitalWrite(RelayPin,HIGH);
55+
if(Output > minWindow && Output < millis() - windowStartTime) digitalWrite(RelayPin,HIGH);
5556
else digitalWrite(RelayPin,LOW);
5657

5758
}

0 commit comments

Comments
 (0)
0