Pages: [1]   Go Down
Author Topic: PID controlling solid state relay question  (Read 1149 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
#include <PID_Beta6.h>

 unsigned long windowStartTime;
 unsigned long RampStartTime;
 double Input, Output, Setpoint;
 PID pid(&Input, &Output, &Setpoint, 3,4,1);

unsigned long printTime= millis();

 void setup()
 {

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


 void loop()
 {

  //Set Point Ramp
   if(millis()-RampStartTime<300000)
   {
     Setpoint = ((double)(millis()-RampStartTime))/(300000.0)*500.0;
   }
   else Setpoint = 500;

   //Set Tuning Parameters based on how close we are to setpoint
   if(abs(Setpoint-Input)>100)pid.SetTunings(6,4,1);  //aggressive
   else pid.SetTunings(3,4,1); //comparatively moderate

   //give the PID the opportunity to compute if needed
   Input = analogRead(0);
   pid.Compute();

   //turn the output pin on/off based on pid output
   if(millis()-windowStartTime>4000) windowStartTime+=4000;
   if(Output > millis()-windowStartTime) digitalWrite(0,HIGH);
   else digitalWrite(0,LOW);

 }

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?

Thanks.
Logged

0
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12745
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: