Welcome! Log In Create A New Profile


Experimental PID Temperature Controller

Posted by bothacker 
Experimental PID Temperature Controller
September 30, 2009 03:38PM
I've been experimenting with PID control of the heater element, with some success.

Details can be found here: [bothacker.com]

Would love to get some feedback...

Re: Experimental PID Temperature Controller
September 30, 2009 04:20PM
Hi Tim,

good idea smileys with beer .. i downloaded your code for testing with some other heaters, but this will last a while eye rolling smiley

Re: Experimental PID Temperature Controller
September 30, 2009 04:22PM
Hi Tim,

Very funny coincidence! I've been doing exactly the same thing last night with my CupCake (#180). I came to the same conclusion wrt. lack of resolution in heater resolution for the D part of PID control.

I changed the firmware to not return the average of a number of samplings, but rather the sum. However, it turns out that the analog input signal from the thermistor does not have enough noise to produce variable readings.

Essentially, the interval of interest (raw ADC values between 54 and 107) correspond almost linearly with temperatures. The resolution really is just 1 degree celsius. I've used a sample frequency of 1 Hz to 8 Hz, and there really isn't a continuous derivative that can be used.

So, I've essentially used a PI controller the P set to 5 times the error in degrees celsius and I to the cumulative error divided by 128 (at 8 Hz). This seems to work reasonably well: it does indeed take a little longer to heat, but then is very stable.

I have read a post by nophead a while back where he uses simple on/off control, but for me there seems to be too much delay between the heater turning on/off and the sensor reacting for that to work. With the existing simple on/low/off code I get temperature swings of 10-20 degrees celsius: way too much for my liking.

Maybe part of the problem is that I have a relatively low resistance heater (5.5 Ohms) that produces about 23 watts of heat. Also, my heater is not insulated.
I'm planning an experiment to use the 1.1v internal voltage reference when readings are below 180 or so. This should give 0.2 C resolution and printing temperatures.

I have to run now, but I'll follow up later.

Re: Experimental PID Temperature Controller
September 30, 2009 04:50PM
Nice work Tim, I will make reference to your code when I make an SMT oven controller in the near future.

What I am confused about is why you and others are seeing such a slow response from the thermistor / heater combination. I have made several extruders with different heater arrangements. I have never had more than ~ 3C swing about the set point.

I use bang-bang control in a fast interrupt routine. It cycles about every two seconds so I get the fastest warm up at 100% power and then never more than a degree or two away from the set point.

I do have the thermistor closely coupled with the heater. I have had it nearer to the nozzle and did get more overshoot, but never in the same order of magnitude that you are seeing. I wonder if yours is due to the insulating effect of the Kapton tape? I have always glued the thermistor with either JB-Weld or Cerastil. (Note that JB-Weld does not last, so I would not recommend it.) I also bury it into the heater rather than simply gluing it to the surface.

Re: Experimental PID Temperature Controller
September 30, 2009 06:34PM
Hi Nophead,

I hoped you'd chime in. I previously noted you're using simple use on/off control, but the crucial difference is that you're heater was switching with a period of about 2 seconds, while mine has a period of about 45 seconds, and Tim's is on the same order.

Both my nichrome and thermistor directly touch the brass barrel, so the Kapton tape should not be a factor. The nichrome is wound in the grooves while the thermistor is taped to the nozzle. I may try to relocate my thermistor to very close to the nichrome and using some heat sink compound for better contact.

The other thing is that my temperature readings have pretty much no noise. At times I get one or two alternating readings when switching from one read to the next, but at higher temperatures this essentially never happens. I'll see if using the 1.1V reference helps. Adding noise should help with resolution when averaged, and direct proportional control when used at a moderately high frequency.

Re: Experimental PID Temperature Controller
September 30, 2009 07:42PM
I have 10 bit resolution with full scale being only a little more than the room temperature voltage. By the time I get to 240C the voltage is quite small and has a few bits of noise, but that is still less than 1C. I round the values to 1C when displaying them and they just ramp up and down, i.e. no jitter in the displayed values.

The control is done at ADC resolution, not temperature, so it does see the noise, giving a very narrow band of proportionality. I.e. very large but finite P coefficient. The host calculates the ADC value for the set point and sends it to the controller.

Does the RepRap firmware convert the temperature to degrees and then compare with the set temperature? In which case it would have to change by a whole degree before turning off the heater. That may explain the large overshoot as mine will switch off as soon as it changes by one ADC unit, many times less.

Also the RepRap firmware uses a table for conversion, so may lose some accuracy at the important end of the scale as well.

If that is the case then simply converting the temperature to ADC value when the command is processed and controlling the heater with that value may fix the overshoot. It would also reduce the CPU overhead massively. My temperature control is just and ADC read and an if statement.

PID is the way to go when there is genuinely a big thermal time constant but it is good to avoid if possible because of the need to tune it for different extruder designs.

Re: Experimental PID Temperature Controller
September 30, 2009 07:58PM
I'm using the MakerBot "plastruder", and their 100KΩ thermistor. Here are the relevant lines of the conversion table:
// Thermistor lookup table for RepRap Temperature Sensor Boards (http://make.rrrf.org/ts)
// Made with createTemperatureLookup.py (http://svn.reprap.org/trunk/reprap/firmware/Arduino/utilities/createTemperatureLookup.py)
// ./createTemperatureLookup.py --r0=100000 --t0=25 --r1=0 --r2=4700 --beta=4066 --max-adc=1023
// r0: 100000
// t0: 25
// r1: 0
// r2: 4700
// beta: 4066
// max adc: 1023
#define NUMTEMPS 20
short temptable[NUMTEMPS][2] = {
    1, 841  }
    54, 255  }
    107, 209  }

See how the beginning the ADC resolution is approximately 1 value per degree Celsius? I changed the code to compute with raw ADC values instead of first converting to Celcius, but predictably this makes almost no difference. I added some debugging code that displays the raw ADC readings and there is too little noise. Only just when slowly cooling down it might switch back and forth between values once or twice. I really should introduce some decent noise in the thermistor signal smiling smiley

ADC without dithering noise results in distortion instead of noise, which is bad for almost any kind of signal processing.

Re: Experimental PID Temperature Controller
September 30, 2009 08:54PM
Looks like Geert and I are working with the same extruder design (mine a copy of the Makerbot plastruder).

The slow response time Geert and I are experiencing is definitely an impediment to improving the bang-bang controller. In the plots I showed, the temperature readings can continue to rise for more than 5 seconds after the heater has switched to low or zero power.

Nophead has got me wondering whether the thermistor is giving an accurate reading of the thermal dynamics.

Is the slow response due to slow heat transfer between the heated zone and the thermistor, or is the heat conduction at the thermistor so poor that what I'm mainly observing is the thermal inertia of the thermistor itself?

Nophead, can you point me to a picture showing the heater/thermistor arrangement on your extruder?

Re: Experimental PID Temperature Controller
October 01, 2009 04:36AM
This one has the best response: [hydraraptor.blogspot.com], about +-1C swings.

The one shown here works fine as well [hydraraptor.blogspot.com]. Bigger thermal mass, but still very tight thermal coupling.

Possibly the worse overshoot was when I had this arrangement [hydraraptor.blogspot.com], but still fine, no more than +-3C swings.

I am using an Epcos 10K termistor rather than 100K, but I wouldn't have thought that made any difference.

Re: Experimental PID Temperature Controller
October 01, 2009 05:07AM
... we're developing high precision gassensors (~10ppm accuracy and noise, 100ppm absolute repeatability) based on thermal conductivity of the specific gases.

For a better definition of the ambient temperature we heat the housing with two resistor-heaters up to 60 centigrades and the PID-controller measures with a PT1000 and regulates the 60 centigrades with an accuracy of 0.001 centigrades when in stable conditions!

If i change the gas-flow or put the sensors in an oven and change the ambient tempreature by 20 centigrades in short time, the response of big changes is 3 to 5 minutes, until the stable temp is restored again.

Somewhere here i've already posted some specs, but didn't find the post ... maybe i'll rebuild this for me and post then some more infos ...

Re: Experimental PID Temperature Controller
October 01, 2009 05:28AM
... here's a diagramme of the temperature-controlling where every 10 minutes i change the concentration of a binary gasmixture (here CO2 in Argon) by 25%.

After around 15 minutes i'll have a 'wave' of +/- 0.001 centigrades around 60 ...

open | download - Geh-Temp60.JPG (64.5 KB)
wow ok now back to ideas that people can actually use......

Ive tried various locations for my 100k thermistor (Makerbot #182) and i still get the 20-30 degree swings. Ive tried three prints and each time the nozzle and barrel have clogged up. I used acetone the first two times but was able to push the plastic out of the barrel while the heater was on the third time (i removed the nozzle with some pliers)

I think nophead has a good idea by increasing the thermal mass but I think there is a much easier way to do this. adding a couple nuts and some washers to the heater barrel could do the same thing but cost less than 50 cents and a 15 min trip to the hardware store

Ill try it over the weekend and report back
Re: Experimental PID Temperature Controller
October 02, 2009 04:15AM
Adding thermal mass will increase the lag around the feedback loop and increase the overshoot.

What I have got is good thermal coupling (i.e. conduction), so there can be very little temperature difference between the thermistor and the heater and any change is transfered to it quickly.

Aluminium is a significantly better conductor than brass. IIRC 400 : 250.

If you are fimiliar with electronics this is like a simple low pass RC filter where R is thermal resistance and C is thermal mass, i.e. mass times specific heat capacity.

The shorter the time constant the faster it will cycle and the less the overshoot will be.

Re: Experimental PID Temperature Controller
October 02, 2009 06:33PM
I'm working on modifying the firmware in a couple of ways to allow for better control:
    * Use internal 1.1V reference to measure low voltages
    * Use higher resolution for accumulating sensor readings
    * Directly control these high resolution readings rather than rounded degrees Celsius.
    * Use an automatic test in ReplicatorG to calibrate heater settings and store constants in EEPROM.
The nice thing is that extrusion temperatures over 170 C can be measured using the 1.1V reference, giving almost 5 times the resolution of the default 5V reference. So, we'll be able to measure temperature changes earlier.

In order to make control easier, I use a scale of 0 .. 1024*50 (=51200) to represent 0 to 5V for ADC readings, instead of 0 .. 1024. Now when using the 5V reference, I sum 10 readings and multiply the result by 5. When using the 1.1V reference, I just sum 11 readings. The reference to be used is determined by
the first sensor read if that is low enough (<200) I use the 1.1V reference.

While I had implemented PID control, I removed it for now in order to see how simple "bang-bang" temperature control will do with better temperature measurements.

I also wonder if the 10 µF capacitor used isn't a bit too large. When reading and summing a few thermistor samples a little randomness will effectively add resolution. With 10 readings and an ideal amount of noise, you'd gain about 3 bits. In effect, any value in the range 0..9999 and any multiple of 5 between 10000 and 51150 is a possible outcome of the sensor reading, a total of 18230 values.

More importantly, in the most important temperature range of 210 C to 230 C, I have 1389 distinct sensor values, while the current firmware using Celsius only has 21 distinct values. That's a factor 66 more sensor results. By completely avoiding divisions in the control circuitry, we avoid accidentally mapping distinct sensor readings to the same outcome as we now repeatedly do.

I haven't been able to test my new firmware in the actual extruder yet, but I have no doubt that I'll be able to achieve significantly better results using the simple on/off method. Possibly enough so, that it is simply not necessary to use PID control. If it's still desirable to have PID control, I definitely want a host software routine to fire up the heater at max, and measure the temperature profile during heating and cool down and then compute appropriate constants.

nophead, i understand what you are thinking but i dont agree. there are too many other variables to take into account. Heating a larger mass will be a slower process, so despite having a slow reaction time to taking the temp, the controller should still turn off the heater before the mass gets too far above the target temp. there would also be the increased convection due to the larger surface area, which may cause it to cool quicker but also help to keep overshoot.

I am willing to try anything at this point..... im getting really sick of cleaning out a clogged heater barrel

Geert, if you need a guinea pig to test im willing
Re: Experimental PID Temperature Controller
October 04, 2009 08:14AM
I use a combination of 2 5 Watt ceramic resistors and fire cement (all wrapped up in PTFE tape) for my rebuilt BfB extruder(it's hard to find insulated nichrome in Australian electronic stores). Normally if it was running at room temperature I would need about 10 seconds before it started to show any effect in repg and (ie the lag between the ceramic heaters and the thermistor is pretty big) so my range would be around 235-255(probably much higher) for a setting of 250.

Running the PID enabled makerbot firmware I've found that for something with such a large mass and time lag then I needed to adjust the PID settings. The effect was that it would tend to sit about 5-10 degree's below the set point because it would stop driving as hard a little too low. I adjusted the PID settings and now it runs pretty much perfectly, with it floating at 248-250.

My settings are:

#define TEMP_PID_PGAIN 8.5
#define TEMP_PID_IGAIN 0.13
#define TEMP_PID_DGAIN 30

Basically what I did was increase the max drive a little (more to make initial warmup a bit faster for me, i'm not running the motor at this point anyway so it won't really have that much of an effect). I then drove the PID more towards a PI controller than a PID. I've found that this controller works when the dominant effect is loss of heat. At low temperatures (I tried it at 150C) then the weakened derivative controller really has an effect and it see saws alot (it really moved around in a range of 135 to 165 and was all over the place). But I've found that at higher temperatures with a lot of heat loss then there is much less fluctuation and the stability is great.

BfB's wiki page on Gcodes already defines an M code which is made to change the PID controller variables. This would make tuning much easier so I'm having a go at simply making these an M code that the extruder can understand with a quick patch to the firmware.
Re: Experimental PID Temperature Controller
October 04, 2009 12:48PM
One thing I just noticed is that Tim's first graph shows the heater getting up to temperature in only 20s. The graph also looks very linear whereas it should tail off exponentially towards a maximum when the heater is in thermal equilibrium. That implies that on full power the heater would get to many times 240C.

On the other hand my extruders take about 90s to get to 240C, with a 6 ohm heater, and show some exponential tail off. I.e. the initial rise rate is probably 2 or three times faster. With no control they max out around 290C.

Either there is a vast discrepancy in thermal mass and heat loss, or what I suspect is that the thermistor is seeing the temperature of the nichrome rather than the true temperature of the barrel.

This theory is born out by looking at the subsequent switching cycles. The on times get successively less and further apart. To me that implies that there is some second order thermal effect. I.e. something else is heating up more slowly so is taking less heat away from the thermistor. It could be the effect of the plastic, as it does have a high specific heat capacity and low conduction, but it may be simply that the heating element can raise the temperature of the thermistor faster than the barrel heats.

Edited 1 time(s). Last edit at 10/04/2009 01:55PM by nophead.

Re: Experimental PID Temperature Controller
October 04, 2009 03:41PM
pattywac Wrote:
> wow ok now back to ideas that people can actually
> use......

... i mentioned our heater concept because this could be adopted easily for heating the extruder nozzle.

The housing of the sensor is a bulk block of nearly 40x25x25mm stainless steel with a central cavity for the sensor, two 10W-heaters in TO-housing connected to the sides and the temperature is measured with a PT1000 near the center.

The termal mass is gigantic compared to the extruder nozzle and i tested heating and sensing with PT1000-resisitors until 500 centigrades, so the interesting temp. span is in the sensing range too.

With resistor-heaters of 5 to 10 Watt and a PT1000 or PT100 sensor with a nearly linear characteristic it shouldn't be a problem building a heater with thermal accuracy below 1 centigrade.

I'll make this for my repstrap, but actually i'm more occupated with milling and lasercutting, then paste-dispensing at room-temp and only after this with heated extruding ...

Doing PID Temperature Controller. I need C code for the PID Algoritm
Sorry, only registered users may post in this forum.

Click here to login