Very Simple PID script? PWM output w/ AD595 input

Hello my fellow tech heads...

I have a Seeeduino (Arduino Diecimila clone) and all I am trying to do is get it to read the 10mV/C output of my AD595-AQ Thermocouple Amp compare that to a desired temperature that I have SET and provide a single PWM output to the heater driver. Ideally I would like to be able to read the temp VIA computer or simply by reading the AD595's output (would that affect the seeeduino's reading?)

Now the good thing is that this isn't going to need lots of tuning and tweaking.

I am dealing with a very small heating element and the TC is in fairly close proximity....

Now I have messed around with the heater via a manual PWM controller and the element reaches its target temp in less and 3 seconds and does not overshoot that bad... so that makes things even better.... I hope..

Does anyone have any info or tip on a good way to proceed?

I've looked at the 3 examples in the arduino PID library and those seem just way too complicated for what I need...

Or would it be possible to omit some stuff from those and load it to my board and get what I need?

Thanks in advance!

-skeet

I am dealing with a very small heating element and the TC is in fairly close proximity

Having the control point too close to the sensor can cause problems.

Does anyone have any info or tip on a good way to proceed?

From what you've written, everything is working the way you want. For me that means "finished". ;)

What are you trying to heat?

  • Brian

I have taken the interference factor into account and have tested it with a stand alone PID controller and I can get clean temp readings.

Finished?

The seeediuno isn’t doing what I need it to.

I’d like for it to just act as a simple PID controller with a PWM output that I can wire to the MOSFET.

Is there a simple PID script around that I can customize to my liking?

Thats where I am stuck… finding the right script. :-/

Im heating just a small piece of heater wire.

Why do you think the PID library examples too complicated ?

http://www.arduino.cc/playground/Code/PIDLibrary

This first one is very simple;

/********************************************************
 * PID Simple Example
 * Reading analog input 0 to control analog PWM output 3
 ********************************************************/

#include <PID_Beta6.h>

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1);

void setup()
{
  //initialize the variables we're linked to
  Input = analogRead(0);
  Setpoint = 100;

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

void loop()
{
  Input = analogRead(0);
  myPID.Compute();
  analogWrite(3,Output);
}

Thanks for posting the link. This looks pretty easy to set up. The page has PID tuning advice. When I last looked, the only code available was the Espresso controller and I was thinking about excising the actual PID code for use. Viola! It’s been done!

Cool...

See I 've been playing with that and trying to upload it to my board and I can't seem to crack my problem.

I've been able to load other samples like the "Blinking LED" and such , but when I try and even simply compile the PID_Beta6 I get the following :

"23: error: PID_Beta6.h: No such file or directory In function 'void setup()': In function 'void loop()': "

I am pretty much a rookie when it comes to coding and stuff and I am guessing I am missing something thats obvious.

Anyone know where I'm screwing up?

Also, in regards to Setpoint = 100, what is thie referring to? Degrees or mV?

One last quick question.. where in the code could I put a limiter( or cap) on the PWM output. For example, so the duty cycle never goes above 70% or something.

Thanks again for all the help!

Anyone know where I'm screwing up?

You've probably not put the PID library in the right place. When you downloaded it, did you put it in the libraries foldeer?

Uhh.. no.

Well.. it works now. Thanks AWOL.

void SetOutputLimits(double, double); //Tells the PID what 0-100% are for the Output

So how exactly do I tell it that I want to cap it at 70% for example?

and could the sample time be changed to a faster rate like this:

void SetSampleTime(250); // * sets the frequency, in Milliseconds, with which // the PID calculation is performed. default is 1000

I put in 250 where there used to be "int"

Okay... So i've got the basic PID script loaded and working on the board.

Now.. I just need to hook up the output to the mosfet and give it a try.

I've already tried monitoring the PWM output (#3) and I can see the power increase and decrease as I mess with the temp of my thermocouple.

Now one problem I am foresee already is the sample rate for the PID script. Currently its set to 1 second sample rate like so:

void SetSampleTime(int); // * sets the frequency, in Milliseconds, with which // the PID calculation is performed. default is 1000

What I really need it to be able to change it to sample like at least 5 times a second. Almost like real time.... know what I mean?

Like how the airflow meter on a car is constantly effecting the mixture.

Where can I modify the script to change that?

Some success!

Its been many years since I’ve played with the C language but I think I might have got it going and at least sort of in the direction I want to go.

Here’s what i’ve got so far… I’ve added in:
myPID.SetSampleTime(250);
:

Now, while running the script on the board, I can see that the intensity of the PWM output changes much faster now instead of just one second increments.

Sweeeeet!


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

  • PID Simple Example
  • Reading analog input 0 to control analog PWM output 3
    ************************************************** ******/

#include <PID_Beta6.h>

//Define Variables we’ll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint, 2,5,1);

void setup()
{
//initialize the variables we’re linked to
Input = analogRead(0);
Setpoint = 100;

//turn the PID on
myPID.SetMode(AUTO);
myPID.SetSampleTime(250);
}

void loop()
{
Input = analogRead(0);
myPID.Compute();
analogWrite(3,Output);
}


So another thing I would like to toy with is the output limit.

I notice in PID_Beta6.h:

void SetOutputLimits(double, double); //Tells the PID what 0-100% are for the Output

So to set a limit I simply write in the same place I added in the “SetSampleRate”,

myPID.SetOutputLimits(0,70);

? or something like that… if I want to max it out at 70% output?

Thanks again!

So to set a limit I simply write in the same place I added in the "SetSampleRate",

myPID.SetOutputLimits(0,70);

? or something like that... if I want to max it out at 70% output?

Jetski,

The pid output will always range from 0% to 100%. What SetOutputLimits does is specify what those values ARE. By default, 0% = 0, and 100% = 255.

I chose those values as the default since those are the limits on a pwm output. I figured that's where most people would be sending the pid output. The default works great until you want to send the output to something else. or, as in your case, you don't want to use the full pwm range.

If you want to limit the pid output to 70% of pwm range, you first need to figure out what that value is. use that value as the pid output max, and you're done.

so: 255*0.7 = 178.5 myPID.SetOutputLimits(0, 178.5);

hope this clears things up!

Brett

(also, as a side note: you can call this function in the setup area, but you can also call it on the fly. if, in the middle of your program, you want to set new output limits, this function will work)