I am trying out the PID library by Brett Beauregard. Have also read the excellent tutorial by him on same.
I have a doubt on the Manual mode. I understand the point about bump less transfer between Auto / Manual on the fly.
To study the effect, I modified the example to run alternately in AUTO and MAN modes for 10 sec each. My expectation was that when in Manual mode, the input is directly passed to output …
But it does not seem to be case. When in Manual, it just holds the OUTPUT as it was in AUTO mode. So now if I want to control the output with my Setpoint directly do I have to make a parallel path between SP and OUTPUT and close it when MAN is selected ?
Maybe I am missing something…
The code i used is given below :
#include <PID_v1.h>
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1,P_ON_M, DIRECT); //P_ON_M specifies that Proportional on Measurement be used
//P_ON_E (Proportional on Error) is the default behavior
bool modeFlag ;
unsigned long modeSwitchMs = millis();
unsigned long modeSwitchIntvl = 10000;
void setup()
{
Serial.begin(115200);
//initialize the variables we're linked to
Input = analogRead(0);
Setpoint = 100;
//turn the PID on
myPID.SetMode(MANUAL);
myPID.SetSampleTime(1000);
}
void loop()
{
Input = analogRead(0);
Serial.print(Input);
myPID.Compute();
analogWrite(3,Output);
Serial.print(" : ");
Serial.println(Output);
if ( millis() - modeSwitchMs > modeSwitchIntvl ) {
modeSwitchMs = millis();
modeFlag = !modeFlag;
}
if (modeFlag) {
myPID.SetMode(AUTOMATIC);
Serial.print("AUTO" );
Serial.print(" : ");
}
else {
myPID.SetMode(MANUAL);
Serial.print("MAN" );
Serial.print(" : ");
}
}