Temperature PID controller using thermocouple and MAX31855

Hi,
I’m working on a project where I want to control the temperature of a thermocouple to around 200C. I’m using an arduino nano and the PID library together with a thermocouple type k and a MAX31855 breakout board. For heating Im using a piece of kanthal wire that I have rolled into a coil.
It should be quite straight forward but I’m having some difficulties with the heater. For powering the heater I have connected the coil to a computer power supply and a n-channel mosfet. The mosfet is IRFZ44N (not logic level) so Im trying to control it using a standard bipolar transistor (2n4401) driven by a pwm signal from the arduino. To avoid inverting the output from the arduino I connected an additional transistor to its base (I know, really unnessecary since it can easily be modified in the code). See schematic attached.

However, one problem is that when the output from the arduino is anything else then 0 or 255, the temperature reading from the max31855 is 0.0 degree C which screws up everything. If I heat or cool the TC maually with a lighter or by blowing on it, the temperature readings and PID control seems to work fine and the temperature readings also work when the mosfet is fully on or off but not when pwm. I can really not figure out why this is happening but I temporary solved it a crude way by instead of using pwm just set the output HIGH and delayed it the number of millisec given by the PID output before setting it low again. Its not a nice solution but it seems to kind of work… The setpoint temperature is in the attached plot orange (50C in this test, should be higher later on), the measured temperature blue and the PID output is red (output devided by 10 to plot in the same range). I know I have to tune the parameters and its a really bad controller now but its just a test so far. If someone have any idea of what can be wrong, I would really appreciate it! :slight_smile:

The next problem is that the mosfet is getting really really hot, even when using a heatsink. After a few minutes it broke and there was some magic smoke… Im not very experienced with electronics and I guess Im doing something very wrong here… :stuck_out_tongue:

Below follows my simple calculations, please let me know where its going wrong.

The heating coil is made of ~34 cm wire with an resistance of 3.55 ohm per meter, ie. 1.2 ohm.
With the 12V from the power supply I assume the current should be 10A (I=U/R). This mean my heater is 120W (P=UI) if its fully on.

With 10A through the mosfet and according to the datasheet the on resistance should be around 17.5mohm and the heat dissipation should then be 1.75W (P=I2R) which should be no problem with a heat sink…?

If you have any idea, please, let me know what I’m doing wrong!

Thanks in advance!
Best regards
Olle

The code:

#include <SPI.h>
#include <PID_v1.h>
#include "Adafruit_MAX31855.h"

#define MAXDO   3
#define MAXCS   4
#define MAXCLK  5

#define PIN_OUTPUT 10

double Setpoint, Input, Output;

double Kp = 15, Ki = 1, Kd = 2;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
Adafruit_MAX31855 thermocouple(MAXCLK, MAXCS, MAXDO);

void setup() {
  Setpoint = 50;  // just for testing, should be 200C
  Input = Setpoint;
  Serial.begin(9600);
  delay(500);
  myPID.SetMode(AUTOMATIC);
}

void loop() {
  double c = thermocouple.readCelsius();
  Input = c;
  if (isnan(c)) {
    Serial.println("Something wrong with thermocouple!");
  } else {
    Serial.print(c);
    Serial.print(" ");
    Serial.print(Setpoint);
    Serial.print(" ");
    myPID.Compute();
    digitalWrite(PIN_OUTPUT, HIGH); // temporary solution
    delay(Output);                  // since temperature 
    digitalWrite(PIN_OUTPUT, LOW);  // measurements does not
    delay(255 - Output);            // work with PWM
    Serial.print(" ");              
    Serial.println(Output / 10); // divided by 10 to show in the same range as temperatures when used with serial plotter
  }

}

plotter.png

What PWM pin were you trying? There may be a conflict of resources (timer, etc.).

From your observations I guess that something is wrong with the switched load. Perhaps the ATX power supply doesn't like fast switching load? Do you power the Arduino from the same supply? What if you take a lower (dummy) load, for program logic testing?

Cannot say anything about the FET, except that there is something wrong if it gets hot ;-)

The 10k gate resistor slows switching. Switching losses could heat up the mosfet.
Try <= 470ohm.

The diagram does not show how you power the Nano.

Did you measure the 3.3volt supply for the MAX.
Nanos have a very weak 3.3volt pin, especially clones.
Leo…

Thanks for all replies! 2 of 2 problems solved! :slight_smile:

jremington:
What PWM pin were you trying? There may be a conflict of resources (timer, etc.).

I was using pin 10 as the pwm pin. I first tried to lower the pwm frequency from 490.2Hz (default) to 30.64 but the result was similar. When I changed to pin 13 as output pin the first problem was solved!

DrDiettrich:
From your observations I guess that something is wrong with the switched load. Perhaps the ATX power supply doesn’t like fast switching load? Do you power the Arduino from the same supply?

I thought a computer is a fast switching load as well and the supplies are designed for that? I might be wrong though.
The arduino is powered by the usb from the computer and not connected to the power supply (except for ground).

Wawa:
The 10k gate resistor slows switching. Switching losses could heat up the mosfet.
Try <= 470ohm.

The diagram does not show how you power the Nano.

Did you measure the 3.3volt supply for the MAX.
Nanos have a very weak 3.3volt pin, especially clones.
Leo…

I now changed the gate resistor to 470 ohm and it’s still getting quite hot but not enough to fry the mosfet this time…

Thanks again for useful input!
Best regards
Olle

PS. I also tried to monitor the 3.3V pin on the nano and there was ripples on maximum ±0.2V when the oscillations started (measured with an old oscilloscope). In the datasheet for max31855 the power supply voltage should be between 3.0 and 3.6 so I guess it should be fine…

Highflower:
With 10A through the mosfet and according to the datasheet the on resistance should be around 17.5mohm and the heat dissipation should then be 1.75W (P=I2R) which should be no problem with a heat sink…?

That’s assuming the chip inside the mosfet is 25 degrees C.
Leo…

The thermocouple only provides 40uV/C, which is a very tiny signal, and could easily be overriden in a noisy environment..... and your 10A/12V is a big signal...

so

1/ put a capacitor across the thermocouple - perhaps 100nF

2/ be very careful that your heavy current wiring is seperate from the low level stuff - in particular wire earths directly back to a common reference - eg the big psu. Don't 'daisy chain' them

regards

Allan.