I am trying to create a front end for a sous vide / smoker setup, and am at the last stage - implementing the PID controller.
This is example 2 from the PIDLibraryhttp://www.arduino.cc/playground/Code/PIDLibrary (http://www.arduino.cc/playground/Code/PIDLibrary).
unsigned long windowStartTime;
unsigned long RampStartTime;
double Input, Output, Setpoint;
PID pid(&Input, &Output, &Setpoint, 3,4,1);
unsigned long printTime= millis();
pid.SetOutputLimits(0,4000); //tell the PID to range the output from 0 to 4000
Output = 4000; //start the output at its max and let the PID adjust it from there
pid.SetMode(AUTO); //turn on the PID
windowStartTime = millis();
RampStartTime = millis();
//Set Point Ramp
Setpoint = ((double)(millis()-RampStartTime))/(300000.0)*500.0;
else Setpoint = 500;
//Set Tuning Parameters based on how close we are to setpoint
else pid.SetTunings(3,4,1); //comparatively moderate
//give the PID the opportunity to compute if needed
Input = analogRead(0);
//turn the output pin on/off based on pid output
if(Output > millis()-windowStartTime) digitalWrite(0,HIGH);
What does the 4000 stand for in "pid.SetOutputLimits(0,4000);"? Is it 4 seconds? Does that mean the PID will cycle the heating element on for a max of 4 seconds and min of 0?
What do the last 4 lines of code mean (excluding the bracket), where it says "turn the output pin on/off based on pid output"? Can someone walk me through the calculations?
Its in arbitrary units - here 4000 is chosen because the saw-tooth-wave used to run the heater (or whatever the load is) has a period of 4000ms. Well, I think that's the reason.