Hello guys, i've questions about pid.
Im making a project which uses compressor to cool some kinda laser diode.Compressor has a special driver which has a input 5V analog input. Im driving compressor with arduino and made a spimple dac to convert digital signal to analog signal(via port manuplation).My cause to use pid is the compressor will be used different ambient temperatures so it should adjusts its speed by temperature changes.Now im working at home so i don't have a system here but i've ds18b20 temperature sensor and my dac circuit that all i need.I wrote the pid code with dac and ds18b20 codes.So my input is temperature and my output is voltage(0-~5V).I set the Setpoint 23 degree celsius.
My understanding of pid is the input value reaches the setpoint it oscillates a little but doesn't change more.
In my code input(temperature sensor value) reaches the Setpoint but my Output(voltage) increases continuosly until maximum.
Ofcourse the cause should be from my pid tuning parameters i set my parameters with this method;
-Set all gains to zero.
-Increase the P gain until the response to a disturbance is steady oscillation.
-Increase the D gain until the the oscillations go away (i.e. it's critically damped).
-Repeat steps 2 and 3 until increasing the D gain does not stop the oscillations.
-Set P and D to the last stable values.
-Increase the I gain until it brings you to the setpoint with the number of oscillations desired (normally zero but a quicker response can be had if you don't mind a couple oscillations of overshoot)
I also suspicious about map command which mapped my sensor value but i don't know a newbie drowning pid sh*t........
here is my code
#include <OneWire.h>
#include <DallasTemperature.h>
#include <PID_v1.h>
double Setpoint, Input, Output;
//double aggKp = 4, aggKi = 0.2, aggKd = 1;
double consKp = 0.5, consKi = 0.05, consKd = 0.25;
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
PID myPID(&Input, &Output, &Setpoint, consKp, consKi, consKd, DIRECT);
void setup()
{
sensors.begin(); // Start up the library
Serial.begin(9600);
for (int i=42;i<50;i++)// PORT manuplation it implies "PORTL"
pinMode(i,OUTPUT);
//Input = sensors.getTempCByIndex(0);
Setpoint = 23.3;
myPID.SetOutputLimits(50, 236); //MIN,MAX value the compressor working between these values
//(0.8V-4.5V)
//turn the PID on
myPID.SetMode(AUTOMATIC); // MANUAL
}
void loop(void)
{
sensors.requestTemperatures();
Serial.print("Temperature: ");
Serial.print(sensors.getTempCByIndex(0));
Serial.print((char)176);//shows degrees character
Serial.print("C | ");
//print the temperature in Fahrenheit
Serial.print((sensors.getTempCByIndex(0) * 9.0) / 5.0 + 32.0);
Serial.print((char)176);//shows degrees character
Serial.println("F");
delay(500);
Setpoint = 23.3;
Input = map(sensors.getTempCByIndex(0), 0, 1023, 0, 255);
//double difference = abs (Setpoint-Input);
//if(difference<1){
myPID.SetTunings (consKp, consKi, consKd);//}
//else{
//myPID.SetTunings (aggKp, aggKi, aggKd);}
myPID.Compute();
PORTL = Output;//(VOLTAGE OUTPUT)
}
the attached image is my dac circuit btw.