Go Down

Topic: PID controlling solid state relay question (Read 1 time) previous topic - next topic


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: [Select]

#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
     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);

   //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?



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.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131