-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relay example seems backwards for digitalWrite(relayPin,HIGH) == On #136
Comments
Additionally, the RelayOutput.ino example needs to set:
The code currently does not set the pinMode: Arduino-PID-Library/examples/PID_RelayOutput/PID_RelayOutput.ino Lines 32 to 44 in 9b4ca0e
In https://wokwi.com/projects/410423413759806465 To make the Wokwi simulation seem natural, I swapped the sense of the relay setting conditional so large outputs energize the relay, set the pinMode, moved the setpoint to the middle of the Sensor/Pot, and set kP so you get a full-scale output at Input=0:
Thinking about the conditional more, if the Output is pegged at the upper 5000 limit, then when millis() - windowStartTime = 5000, it still takes the second branch of this conditional: Arduino-PID-Library/examples/PID_RelayOutput/PID_RelayOutput.ino Lines 58 to 59 in 9b4ca0e
|
Arduino-PID-Library/examples/PID_RelayOutput/PID_RelayOutput.ino
Lines 51 to 59 in 9b4ca0e
Is the relay example intended to turn the relay on during the first part of the window and off for the remainder?
With a windowSize of 5000, and an Output of 100, for the first 100ms of the window this conditional won't trigger:
so it's else clause will:
else digitalWrite(RELAY_PIN, LOW);
and for after 100ms this will trigger:
so this one won't:
else digitalWrite(RELAY_PIN, LOW);
So for a 5000 ms WindowSize and an Output of 100, RELAY_PIN will be LOW for 100ms followed by RELAY_PIN = HIGH for 4900ms. It would make sense with an active-low RELAY, and if you depend on using the else clause first in the window, but the double-negative logic seems awkward to explain.
If I were writing this up as an example intended for a beginner, I'd add a couple variables/consts to disambiguate HIGH vs OFF, add curly braces to the if/else and switch the logic of the if match the "turn the output pin on/off based on pid output" comment.
Switching the '
<
' for '>
' makes the if() conditional into positive logic rather than inverse, so the ON/OFF caluses match the on/off comment, and it is clear how to handle active LOW versus active HIGH relays, rather than assuming active LOW.Similar to #10, #30 and #61, but this issue proposes a different change to deal with both active-HIGH and active-LOW relays.
The text was updated successfully, but these errors were encountered: