Tuesday 9 October 2007

Measuring temperature the easy way

I have been asked for more details on my temperature measurement scheme so I have consolidated some of my previous articles :-

The objective is to measure temperature from room temperature to about 250°C using a thermistor. The thermistor resistance is a extremely non linear. It is approximated by a negative exponential of the reciprocal of absolute temperature.

Ro is resistance at known temperature To, in this case 25°C, expressed in Kelvin. Beta is a second parameter of the thermistor which can be calculated if you know the resistance at two different temperatures or can be found on the data sheet.

The RepRap thermistor is an Epcos B57540G0103+, data sheet here. R25 is 10KΩ and beta is around 3500. Several values are given on the datasheet for different temperature ranges illustrating that the above equation is only an approximation. Here is a graph of its resistance against temperature :-


This can be made more linear by putting a fixed resistors in parallel. The magic value to use appears to be the value of the thermistor at the middle of the temperature range. In this case it is about 470Ω. Here is the resulting combined resistance, the formula for two resistors in parallel is :-

1/R = 1/R1 + 1/R2

I.e. the total conductance is the sum of the two conductances.


The resulting resistance is a lot more linear, however to measure temperature with an ADC we need a voltage rather than a resistance. This is easy, instead of wiring the resistor in parallel connect it in series to a voltage source equal to the full scale voltage of the ADC.



The voltage across the thermistor is then :-

V = Vref . Rth / (R + Rth)

Here is a graph of the the output voltage when Vref is 5V.



Note that the voltage decreases as the temperature rises. This could be inverted by swapping the resistor and thermistor but I prefer to keep one end of the thermistor at 0V so I can use single screened cable. It is also a good idea to put a capacitor across the ADC input to filter out any noise when using long leads like RepRap does. I used a 10uF tantalum bead.

Another consideration is how much power is dissipated in the thermistor as it will cause heating and alter the reading. The maximum dissipation will occur when its value equals the value of the resistor. At this point half the voltage is across the thermistor so the power dissipated in it is :-

P = (Vref / 2)2 / R

In the example above this works out at 13.3mW. The thermistor datasheet specifies a maximum of 18mW and a dissipation factor (in air) of 0.4 mW /K. I think this means that the temperature will rise by 33°C by self heating. The error would be less when not in air, but it is still perhaps a bit high. My system uses a Vref of 1.5 volts which, because it is a square law, only dissipates 1.2mW giving a 3°C rise at the mid range temperature in air.

For a 5V system is is probably worth sacrificing some of the ADC resolution to reduce the self heating error. This can be done by using two resistors :-



The full scale voltage is now :-

Vfsd = Vref * R1 / (R1 + R2)

We also want the source impedance of this voltage, which is R1 in parallel with R2, to be 470Ω.

1/R = 1/R1 + 1/R2

Solving these simultaneous equations gives :-

R1 = R / (1 - Vfsd / Vref)

R2 = R . R1 / (R1 - R)

So for Vfsd = 1.5V, Vref = 5V and R = 470:

R1 = 671Ω and R2 = 1569Ω, preferred values are 680 and 1K6.

And finally here is the Python code to work out the temperature :-
from math import *

class Thermistor:
"Class to do the thermistor maths"
def __init__(self, r0, t0, beta, r1, r2):
self.r0 = r0 # stated resistance, e.g. 10K
self.t0 = t0 + 273.15 # temperature at stated resistance, e.g. 25C
self.beta = beta # stated beta, e.g. 3500
self.vadc = 5.0 # ADC reference
self.vcc = 5.0 # supply voltage to potential divider
self.vs = r1 * self.vcc / (r1 + r2) # effective bias voltage
self.rs = r1 * r2 / (r1 + r2) # effective bias impedance
self.k = r0 * exp(-beta / self.t0) # constant part of calculation

def temp(self,adc):
"Convert ADC reading into a temperature in Celcius"
v = adc * self.vadc / 1024 # convert the 10 bit ADC value to a voltage
r = self.rs * v / (self.vs - v) # resistance of thermistor
return (self.beta / log(r / self.k)) - 273.15 # temperature

def setting(self, t):
"Convert a temperature into a ADC value"
r = self.r0 * exp(self.beta * (1 / (t + 273.15) - 1 / self.t0)) # resistance of the thermistor
v = self.vs * r / (self.rs + r) # the voltage at the potential divider
return round(v / self.vadc * 1024) # the ADC reading

Monday 8 October 2007

Laying it on the line

I decided to investigate the conditions necessary for multiple layers of HDPE filament to stick together so I wrote a little Python test script to extrude 20mm squares stacked on top of each other. From my graphs in equations-of-extrusion I chose an output rate of 3mm/s which gives a filament diameter of about 1.2mm. That only requires about 60% PWM which I thought was not too stressful for a 5V motor running from 12V. I set the heater temperature to 200°C. Here is the first run :-



The first two layers look reasonable and then we are into basket work! The z-axis was raising 1.2mm between each layer but, although the nominal filament diameter should be about 1.2mm, the sides were not growing at the same rate. That meant the filament was dangling allowing it to wiggle around. Next I reduced the z-increment to 1.1mm :-



Better, the first four layers are OK this time, so obviously I tried z-increment 1.0mm next :-



Much better! What is happening is that the filament is no longer cylindrical. Each layer is about 1.0mm high and 1.4mm wide. It could be due to gravity but I think it is more to do with being bent through 90° as it comes out the end of the nozzle.

The fact that the filament weaved about when the nozzle was too high made me think that the feed rate might be too fast so I did a taller test with the XY travel 20% faster :-



Another basket case! What is happening here is that there is not enough material so the filament slumps down and holes start appearing.

I went back to the original feed rate and did a couple of 20mm high tests to check consistency :-



These are actually incredibly strong in the vertical direction. I can stand on one and it takes my full weight. Here is a video of the one on the right being made, the middle section is sped up 8 times :-




I also ran a test at 160°C to see if the filament would still weld to the layer below. It did but it did not stick to the foam board.

As you can see the main defect is that the bottom corners curl up. This was completely expected from the work Forrest published here: Ten-layers-with-no-curling, so next I will try his solution of laying down a raft first.

Another defect is that the filament width varies in waves. These seem to be related to the rotation of the extruder drive screw. You can hear the motor labouring more on part of the revolution. I think it is because something in the drive is a bit eccentric but more investigation is required.

Sunday 7 October 2007

Brush off

HydraRaptor was using a knife to remove excess filament from the extruder :-



It always cut the filament OK, but it was random whether the loose bit fell off or stuck to the far side of the nozzle. The soundtrack of a video I saw of a commercial FDM machine said that they use a brush. I thought I would need a wire brush for 200°C but then I reasoned that, if the nozzle passed through fast enough, the high specific heat capacity of plastic might mean that it would not have time to melt. I decide to give it a try with an old electric toothbrush head :-



It does seem to work quite well. Here is a video of it in action :-



The scrap of filament sometimes stays stuck to the brush but subsequent passes eventually knock it off.

When I was using HydraRaptor for milling I had a tray around the table and a plastic skirt to protect the mechanism of the precious XY table from loose plastic chips. When I moved on to FDM I thought these would not be needed because it is a lot less messy. Actually I was wrong as HDPE chips are appearing, presumable from inside the extruder, and the filament offcuts sometimes ping off from the brush. I have therefore refitted the tray and skirt.