Pages: [1] 2 3   Go Down
Author Topic: Peltier current control  (Read 5050 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Apologies. Moved from Sensor section. Topic removed.

The camera CMOS cooling project is nearing completion. Recapping, a Peltier cools a copper finger attached to the back of the CMOS. Max deltaT is 34C from ambient with no temp control. A TMP36 is located near the CMOS on the cold finger.

I want to control the temperature of the cold finger using the readings from the TMP36 using (as previously suggested) a Logic Level N-Channel MOSFET low rds(on) controlling current to the TEC  (-ve to Drain).

This is working at the moment by setting a digital pin HIGH and LOW. Effectively hard banging. There is a lag in response to the TMP analog input and switching the digital pin equal to the frequency of polling the temperature. This doesn't seem ideal and using PWM is making more sense for smoother results.

As I understand PWM pulse width is related to current flow and therefore a fixed temperature for a given system. The cold finger is very sensitive to temperature deviation at minus temperatures, and a different temperature may be required for each imaging session (dew point).

I am not clear on the best approach or how to write a PWM sketch. In-fact understanding how to implement PWM is not clear to me at all. Missing something here?

Many thanks.

Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31548
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
In-fact understanding how to implement PWM is not clear to me at all.
You just use analogWrite(pin, value);
Where pin is one of the PWM capable pins, and value is between 0 (off) and 255 (fully on).
For further discussion see:-
http://www.thebox.myzen.co.uk/Tutorial/PWM.html
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks GM. Clear as day. Great instructional.

Now working. Temperature becomes readout only in the simplest form, setting a value for a given temp. There must be a way of setting PWM in response to temperature to achieve a set point. Manually a pot might do it crudely, but in a filter that would mean varying the value of the capacitor. Alternatively, I could set up some tables temp/PWM value.
Logged

Montreal
Offline Offline
Edison Member
*
Karma: 23
Posts: 2487
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to implement PID regulator control loop. There is a library:
http://www.arduino.cc/playground/Code/PIDLibrary
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not completely sure that PID will do what I plan with a better understanding of PWM.

If I use two temp sensors I can read ambient temp and monitor cold finger temp and set PWM as a variable of;

ambient temp - deviation from zero * (256 / max system delta.

e.g. 20 - -5 * (256 / 35) = 182 - where 35 is the maximum demonstrated temp differential. PWM will change to keep cold finger temp constant with changes in ambient temp. Assuming that PWM is linear.

That's the concept I have in mind...? As night time temps cool power requirements reduce, while all images have the ~same EXIF temp.

During winter lower temps can be achieved by declaring new values - say -10 or 15.
« Last Edit: December 19, 2011, 10:14:19 pm by geoland » Logged

Montreal
Offline Offline
Edison Member
*
Karma: 23
Posts: 2487
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't understand what you are trying to control by PWM:
1. Keep difference between two (ambient and finger's) temperatures constant;
2. Keep absolute finger's temperature constant.
PWM is just a means to adjust power of heat pump, necessary to achieve ether task.
PID is a way, to get to set-point fast, and after that keep it stable, it also works for 1 or 2.

BTW, why you are colling CMOS, decreasing a noise floor?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31548
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'm not completely sure that PID will do what I plan with a better understanding of PWM.
Yes it is.
The net effect is that when the temperature is a long way off what you want then the PWM will be on at full belt. When you get closer the PWM backs off the power. Then at the requited temperature it turns the power off. As it drifts back up it will give it a short blast of low power to gently push it down again.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks GM and Magician.

I want to read ambient air temp which varies while maintaining a constant and much lower temp at the cold finger.

It occurred to me after my previous post that the temp needs to be driven down to set point quickly. What I proposed wouldn't do that.

Apologies Magician PID is necessary. Important is a stable temp at the cold finger irrespective of ambient temp.

I have read the PID documentation beginning to end an will search around for some examples. Doesn't look straight forward, but is more appropriate than PWM from what I can see now.

Problem is, that regardless of the ambient temperature, the system is only capable of a max differential of 35C. So at 30 C ambient the lowest possible temp is -5. At 15 degrees -20. The power requirements are very similar. Using PWM ambient temperature will be 0, and at the lowest possible temperature 255, irrespective of the ambient or set point temp. The only constants using a TMP36 are voltage and temperature reading 0-1023. So drive down temperature at full power using PID to a set point voltage and then maintain that PWM style.
« Last Edit: December 20, 2011, 02:58:09 am by geoland » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31548
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For an example look at the Teapot software for 3D printers, the file that is called heater.c has what you are looking for, only it is going up and you are going down.
You need to monitor the external temperature and subtract 30 from it and put that as a target for your PID.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks GM. That is Apple software I think. The only other reference that approximates what I'm doing is the coffee machine in Playground.

Methinks another learning curve coming up. I did try a basic PID script but it froze the board an older Diecimila.

Back to PWM. In the short term I will drive the temp down to within 1/2 a degree of set point and set a PWM value to maintain at or near the setpoint. Main thing is stability rather than accuracy. Not so concerned whether stable at -5, 5.5 or -6.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

While still working on a PID solution, below is a PWM sketch, which is a bit noisy because of the ~0.32 error in temp reading of both sensors. At least, that's what I think is happening. Otherwise, setting a fixed PWM value performs well with acceptable accuracy. But doesn't account for changing ambient air temp. Consequently, the actual temp of the cold finger changes too.

EDIT: In practice the temperature is fairly stable with transient readings of +/- 0.33. Accuracy is within 0.3 of the set point temperature and in one trial 0.05.

Following this approach should I use a resistor capacitor filter to smooth the pwm out. Or is there way to smooth things with code?

Code:
//Adapted from http://www.ladyada.net/make/logshield/lighttemp.html

/* Utilizing two TMP36 temperature sensors to read ambient air temperature and cold finger temperature, a PWM value is calculated to maintain constant cold finger temp i
 with changing ambient air temp. Includes allowance for sensor ambient readouts. Typically the cold finger sensor is lower than the ambient air sensor. */

#define setPointT 2 // target cold finger temp

#define deltaS 0.33 // sensor delta ambient air - ambient finger

#define aref_voltage 3.3

int fingerT;
int ambientT;

int tempPin = 1;
int tempPin1 = 2;

int tempReading;
int tempReading1;

void setup(void) {

  pinMode(10, OUTPUT);

  Serial.begin(19200);

  analogReference(EXTERNAL);

}

void loop(void) {

  tempReading = analogRead(tempPin);
  tempReading1 = analogRead(tempPin1);

  float voltage = tempReading * aref_voltage;
  voltage /= 1024.0;

  float voltage1 = tempReading1 * aref_voltage;
  voltage1 /= 1024.0;

  float fingerT = (voltage - 0.5) * 100;

  float ambientT = (voltage1 - 0.5) * 100;

  Serial.println(fingerT);
  //Serial.println(ambientT);

  /* PWM control - read ambient air temperature and apply PWM calibration (5.45) and sensor ambient delta to ambient temperature - setPoint temperature delta.
  
   Read cold finger temp and PWM max power to setPoint temp. Then within standard read error of the sensor apply variable PWM for set point. Note: cold finger response is slow decreasing temp and rapid when power is removed
   */

  int pwmV = (ambientT - deltaS - setPointT) * 5.45;

  //Serial.println(pwmV);

  if (fingerT > setPointT) {

    analogWrite(10, 255);

  }
  else
  {

    if (fingerT  > (setPointT + 0.1)) {

      analogWrite(10, pwmV);
    }
    else
    {
      if (fingerT < setPointT) {

        analogWrite(10, pwmV);
      }
    }
  }
}

« Last Edit: December 22, 2011, 03:54:08 am by geoland » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31548
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
That is Apple software I think.
No it is for the arduino:-
http://reprap.org/wiki/Teacup_Firmware

Quote
should I use a resistor capacitor filter to smooth the pwm out.
If you do it on the gate side of the FET then you send it into linear mode and it will get very hot. If you do it on the load side of the FET then you will need an absolutely huge capacitor with a ginormous current ripple rating.

Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks GM. I might leave out a filter for now. On that score the FET is getting hot without a sink, but I think this may be related to the value of the resistor, 220ohms - too much current. I'm guessing 1meg would be better.

I'm reviewing the teacup heater files as we speak. The penny will eventually drop re PID.
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31548
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but I think this may be related to the value of the resistor, 220ohms - too much current.
If that is the resistor between the FET's gate and the arduino then:-
No the gate FET takes hardly any current at all, you up that resistor and you will make it turn on slower and that will cause over heating. If anything drop it to 100R.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK. I will replace the resistor.

The results of the posted code seem to be within the standard read error of the TMP36, +/-0.32C, with occasional spikes of 1 or 1.5C. I notice when removing power from the TEC that thermal inertia is about 2 or 3 seconds, so averaging the readings ignoring the outliers should be representative of actual temperature.
Logged

Pages: [1] 2 3   Go Up
Jump to: