PID_v1.h - Query on Manual Mode

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(" : "); 
  }
}

In manual mode the PID does nothing at all - look at the tutorial. it's there so you can change the output yourself and the PID won't interfere. If you want it to change, you need to code it explicitly.

wildbill:
In manual mode the PID does nothing at all - look at the tutorial. it's there so you can change the output yourself and the PID won't interfere. If you want it to change, you need to code it explicitly.

Thanks ... so my understanding has been right about this. I will need to code separately so that if MAN mode is activated the output just tracks the SETPOINT after saving the OUTPUT at the instance of changeover.

And when switched back to AUTO ensure that the OUTPUT Is returned to the last saved OUTPUT . Or is it safer to simply make the OUTPUT zero and catch up based on the current SETPOINT ??

Not sure how this is normally done. Maybe I will go read the tutorial again.

Ok got what I was looking for HERE

I only have to make sure that I reset the OUTPUT when moving back to AUTO from MANUAL.