DS18b20 temp sensor and its gain ?

I have a system using the relay PID code from this site using a DS18b20 temp. sensor, the P setting seems to reduce gain in the system only to a point , how do I understand the return from the sensor in terms of gain ?
I had to reduce power the heater by 50% and I am very close but if I reduce the P below 100,000 it gets unstable like the gain has been increased.

CODE

/********************************************************

********************************************************/

#include <PID_v1.h>
#include “OneWire.h”
#include “DallasTemperature.h”

//#define PIN_INPUT 0
#define RELAY_PIN 6
#define SSR 5 //SSR POWER pin

// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

//Define Variables we’ll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
double Kp=100000, Ki=350, Kd=60000; // 6x8" plates,p=5000 i=1000 d=10000 perform better
// 5x5" plates Kp=100000, Ki=500, Kd=60000
// have 2nd plate inline to reduce power 50% - MUCH better
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, REVERSE);

int WindowSize =5000; // was 5000
unsigned long windowStartTime;

void setup(void)
{ pinMode(SSR , OUTPUT);
// start serial port`
Serial.begin(9600);
Serial.println(“Dallas Temperature IC Control Library Demo”);
pinMode(RELAY_PIN, OUTPUT);
// Start up the library
sensors.begin();
windowStartTime = millis();

//initialize the variables we’re linked to
Setpoint =55;

//tell the PID to range between 0 and the full window size
myPID.SetOutputLimits(0, WindowSize);

//turn the PID on
myPID.SetMode(AUTOMATIC);
}

void loop()
{

// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
//Serial.print(" Requesting temperatures…");
sensors.requestTemperatures(); // Send the command to get temperatures
//Serial.println(“DONE”);
Input = (float)sensors.getTempCByIndex(0); // in Input variable you have to put temperature value
Serial.println(Input);
Serial.println(Setpoint);
myPID.Compute();

/************************************************

  • turn the output pin on/off based on pid output
    ************************************************/
    if (millis() - windowStartTime > WindowSize)
    { //time to shift the Relay Window
    windowStartTime += WindowSize;
    }
    if (Output < millis() - windowStartTime) digitalWrite(RELAY_PIN, LOW) ;else digitalWrite(RELAY_PIN, HIGH);
    // set ratio for power % low 100%=100% ON
    digitalWrite(SSR, LOW); // turn the LED on (HIGH is the voltage level)
    delay(400); // wait for a second
    digitalWrite(SSR, HIGH); // turn the LED off by making the voltage LOW
    delay(1500); // wait for a second
    }

buzzkill: I have a system using the relay PID code from this site using a DS18b20 temp. sensor, the P setting seems to reduce gain in the system only to a point , how do I understand the return from the sensor in terms of gain ? I had to reduce power the heater by 50% and I am very close but if I reduce the P below 100,000 it gets unstable like the gain has been increased.

P is a automatic control system parameter from a 'PID' control system. It is one of the multiplication factors. P is known as 'proportional gain'. It is a value that you set.

For "PID" control (which is actually "P plus I plus D" control), if you set P to 'zero', you would still have the "I plus D" in the system. So basically, if you want nothing to pass through your control system, setting P = 0 and I = 0 and D = 0 would stop everything.

When you mention the word 'gain', you might be referring to the gain of your PID negative feedback system, right? That 'gain' there is the absolute value of the ratio : |(system output/system input)|. Is that what you're referring to?

If you want low gain (or no gain), you'd have to make all the parameters relatively small .... or even zero. But, for a PID control system, you usually have finite values for the P and I and D values.

At the moment....... you probably need to clarify the meaning of 'gain' from your point of view.

With a system that uses and analog input I understand GAIN better , I understand PID and have tried setting I and D to zero and very low P values but it just runs away and will not settle , the P seems to be negative gain wise ? I may be using GAIN in the wrong terms ? If I am please provide a good explanation if possible.

My settings are p=100,000 , I = 3000 , D =60,000 these numbers seem VERY high to me ?

I had to actually chop the power using a relay and on/off to 50% or less, the Heater block I have I think is over powered thus having to reduce the power. see the code

" // set ratio for power % low 100%=100% ON digitalWrite(SSR, LOW); // turn the LED on (HIGH is the voltage level) delay(400); // wait for a second digitalWrite(SSR, HIGH); // turn the LED off by making the voltage LOW delay(1500); // wait for a second } "

Does anybody have any more in site to what types of PID values to be used ? examples of what you are doing ?

 if (Output < millis() - windowStartTime) 
    digitalWrite(RELAY_PIN, LOW) ;
  else 
    digitalWrite(RELAY_PIN, HIGH);
// set ratio for power % low 100%=100% ON
  digitalWrite(SSR, LOW);   // turn the LED on (HIGH is the voltage level)
  delay(400);                       // wait for a second
  digitalWrite(SSR, HIGH);    // turn the LED off by making the voltage LOW
  delay(1500);                       // wait for a second

This is a VERY bad mistake. You are trying to control the output pulse time to the nearest millisecond in a 5 seconds window BUT YOU SPEND 1.9 SECONDS IN DELAYS! Your ON times and OFF times can therefore never be less than 1.9 seconds out of the 5. TAKE OUT THOSE DELAYS.

If the heater is getting too hot because it shouldn’t be on more than half the time, set the Output upper limit to 2500 instead of 5000.

it just runs away and will not settle , the P seems to be negative gain wise ?

It is possible that a negative gain is required. It depends on how you calculate the error term (setpoint - actual) or (actual - setpoint). Either way is acceptable, although people usually choose the one that leads to positive Kp.

When initially selecting Kp values, make sure that they make sense! Do this by putting Serial.print statements at key places in the code, so you can see what is happening.

For example, check that if the temperature is too low, the heater is turned on, and not vice versa. If the heater has proportional control, check that if the temperature is way too low, the system turns on the heater even harder.

for such things, you could do a more simple control.

if the error is more than 5 degree from setpoint then PWM your relay at 70% if the error between 5 degrees and 2 degrees, PWM at 30% if the error is between 2 and 0,2 degrees PWM at 5%

you could do the output as : digiatalWrite(RELAY_PIN, HIGH) delayMicroseconds(10) digitalWrite(RELAY_PIN,LOW) delayMicroseconds(90)

or some such.

each scan through the program will be in 100 microseconds. but note that this would need to be for a dedicated temperature controller, and not a larger program that has to do ANYTHING else.

as was noted, using ANY sort of delay() even delayMicrosecons() can lead to dire consequences.

dave-in-nj: each scan through the program will be in 100 microseconds.

I don't think a relay will be accurate when cycled at 10 kHz. That is why the PID library examples uses a 5 second window.

Hi, Can you post a picture of your project please?

What are you heating?

What is the application?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :)