From 0aa6c0a88f9ad7021c97ad5688df329d0b54df0d Mon Sep 17 00:00:00 2001 From: James Prior Date: Wed, 23 Jan 2013 19:38:45 -0600 Subject: [PATCH] Update RelayOutput for minimum relay on time and consistent window behavior --- PID_v1/Examples/PID_RelayOutput/PID_RelayOutput.ino | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/PID_v1/Examples/PID_RelayOutput/PID_RelayOutput.ino b/PID_v1/Examples/PID_RelayOutput/PID_RelayOutput.ino index ed67e03..22f1066 100644 --- a/PID_v1/Examples/PID_RelayOutput/PID_RelayOutput.ino +++ b/PID_v1/Examples/PID_RelayOutput/PID_RelayOutput.ino @@ -24,6 +24,7 @@ double Setpoint, Input, Output; PID myPID(&Input, &Output, &Setpoint,2,5,1, DIRECT); int WindowSize = 5000; +int minWindow = 500; unsigned long windowStartTime; void setup() { @@ -42,16 +43,16 @@ void setup() void loop() { Input = analogRead(0); - myPID.Compute(); /************************************************ * turn the output pin on/off based on pid output ************************************************/ if(millis() - windowStartTime>WindowSize) - { //time to shift the Relay Window + { //time to shift the Relay Window and recalculate windowStartTime += WindowSize; + myPID.Compute(); } - if(Output < millis() - windowStartTime) digitalWrite(RelayPin,HIGH); + if(Output > minWindow && Output < millis() - windowStartTime) digitalWrite(RelayPin,HIGH); else digitalWrite(RelayPin,LOW); }