Friday, 31 August 2007


While testing my extruder I found that the filament diameter seems to vary with temperature and pressure. I wanted to investigate this further so I decided to add a shaft encoder to the output of the small gear motor which drives the polymer pump. This would allow me to regulate the speed precisely because the micro would know the exact position of the shaft at any instant.

My first thought was to use a magnetic shaft encoder such as the AS5035 but then I remembered I had an evaluation kit for some HP reflective optical encoders which I had saved since 1995. HP are no longer in the semiconductor business, that part of the business became Agilent and these chips have been passed on to Avago. The kit had a linear encoder strip, a rotary encoder wheel and three sensor chips.

One of the advantages of magnetic encoders is that they don't need such precise alignment as the optical ones. However, in my case I would have needed to build a raised mounting to hold it over the end of the shaft, whereas the optical encoder can be mounted flush against the gearbox. Here is another bizarre mix of surface mount and through hole components. Can you spot the SMT decoupling cap?

I doubt that I have complied with the strict mounting tolerances but it seems to work well enough for this purpose. Here it is with the code wheel in place :-

Here is what the outputs look like when the shaft is turning :-

Two square waves are produced which are 90° out of phase with each other. This is known as quadrature encoding and it allows both the distance and direction of movement to be determined. I would have expected the mark space ratio to be more equal but it is probably out of spec due to me not meeting the alignment tolerances.

Notice also the nasty glitches on the bottom trace. These are commutation noise from the DC motor despite having a 100n capacitor close to it and using screened cables. Here is what the noise looks like close up without the capacitor :-

And this is the improvement with the capacitor fitted:-

I also tried adding a resistor to form an RC snubber and adding a ferrite ring around the motor cable, but both made it worse. The only way to effectively suppress DC motors is to mount suppression components directly across the armature windings, i.e. the other side of the brushes.

So stuck with that much noise, it was impossible to use an edge triggered interrupt approach, so I polled the inputs from a fast interrupt and debounced them in software. Here is the code :-
// Process the shaft encoder signals
#define DEBOUNCE 3
static void scan_optos(void)
static byte last_raw = 0;
static byte debounce_count = DEBOUNCE;
byte delta;

// Debounce the inputs
byte bits = P1IN & (SHAFT_A | SHAFT_B);
if(bits != last_raw) {
last_raw = bits;
debounce_count = DEBOUNCE;
return; // Still changing
if(debounce_count) // Still debouncing
if(--debounce_count != 0)
return; // Not stable long enough
delta = bits ^ optos; // Which bits changed
if(delta) {
int dir = 1;
optos = bits; // New state
if(delta & SHAFT_A) { // Was it A or B that changed
while(delta & SHAFT_B) // If both not scanning fast enough
dir = -dir;
if(bits & SHAFT_A) // Work out the direction
dir = -dir;
if(bits & SHAFT_B)
dir = -dir;
motor_pos += dir; // update position
This keeps track of the shaft position: motor_pos increases as the filament advances. I then use a timer interrupt to decrement motor_pos at the rate I want the shaft to move at. motor_pos then becomes the error signal for my feed back loop. If it is positive the shaft is ahead of where it should be, if it is negative it is lagging. On-off control was too aggressive so I used PWM to give proportional control. Here is the code, called from the same fast interrupt :-
// Control the motor
#define MCYCLE 16
static void do_motor(void)
static int mcount = 0;
static int on_time = 0;

if(mcount >= MCYCLE) { // At end of cycle?
if(motor_pos <= 0) { // If lagging
on_time = -motor_pos >> 3; // Set PWM for next cycle proportional to the lag
mcount = 0;
if(motor_pos > 0 || mcount >= on_time)
P2OUT &= ~MOTOR; // Motor off
P2OUT |= MOTOR; // Motor on
This is the resulting PWM waveform and one shaft encoder signal, my scope only has two channels! :-

The speed control works well, no loss of torque as the speed is reduced. It has a bit of a damped oscillation with no load due to the slop in the gearbox but it is fine in the extruder where it has a constant load to hide the backlash.

Monday, 20 August 2007

Bang bang

I implemented the simplest form of temperature control, known as bang bang control, which is just turn the heater on if it is too cold and turn it off when it is too hot. This seems to work well, here is graph to compare with the last post. The time divisions are 4 minutes.

The warm up time has reduced from about 10 minutes to just over 1.5 minutes and you can't really notice any change in temperature while it was extruding.

Here is a graph on a faster time base of 1 minute per division showing the heater control signal. This one has not been inverted so temperature is upside down.

As you can see there is some ripple on the temperature of the order of about 10°C. I could probably improve that with PID control but I don't know if it will make much difference to the build quality. I might do it as an exercise out of interest as I have not implemented PID before.

There is a lot of noise in the system, which is not surprising with wires all over the place. It should get better when I make a PCB or veroboard version and mount it near the extruder. Fortunately glitches don't really matter because the thermal time constant smooths it all out.

The next task is to link it to the main controller and see if I can get accurate temperature readings back from it.

Sunday, 19 August 2007


I made a start on my extruder controller, on breadboard, as it is a bit experimental. As you can see it's is a strange mixture of surface mount and though hole technologies!

The little PCB on the far right is a 3.3V regulator which I hacked out of a scrap PCB complete with all its decoupling caps. It had three handy vias for the three connections I had to make. The rest of the parts are the heater controller. The circuit could not be simpler. The heater is switched with a BTS134 protected MOSFET. Even with only a 3.3V gate drive its on resistance is so low it does not even get warm when switching about 1.5A.

The thermistor is just wired to a potential divider which gives 0.6V with an impedance of 100Ω. That makes a voltage that varies almost linearly with temperatures between 20°C and 200°C that can go straight into an analogue channel on the MSP430F2013. The micro can also measure its own supply voltage so that can be used to null out the supply tolerance.

Here is a graph of voltage on the input, inverted as it is an NTC thermistor, so it is roughly a graph of temperature :-

The heater was driven with a fixed 50% PWM drive. The temperature rises exponentially until it reaches equilibrium after about 12 minutes. I then turned on the motor and let it extrude some plastic. You can see the temperature drops significantly and rises again when I stopped the motor. This is because the hot plastic leaving the extruder carries heat away with it. Because plastic has a very high specific heat capacity this effect is significant. Finally the temperature falls exponentially when the heater is switched off.

The graph shows why closed loop control is necessary. The rise will be much faster because full power will be applied until the target temperature is met. That will reduce the warm up time considerably. I also hope to reduce the sag that happens when extruding which will make the extruded filament more consistent.

So a little bit of software now to close the loop.

Friday, 17 August 2007

All wound up

My years of hoarding junk is finally starting to pay dividends. I decided to address how I was going to feed the filament to my extruder. It only uses it slowly but when it runs out you have to strip down the extruder to start off a new piece. HDPE comes on a big 5 Kg reel like this :-

I thought it was asking a bit much for the extruder to rotate something that big and heavy so I started to look round for a smaller reel. I came up with this :-

It is a reel of 10000 4.7V zener diodes which I rescued from a skip. I removed the diodes, if anybody wants an envelope full just ask. It is about 270mm diameter, 70mm wide with an internal diameter of 70mm and a 30mm hole for a spindle. I wound some HDPE on to it and found that despite it being a lot smaller and lighter than the original reel it holds almost exactly half the plastic, i.e. 2.5Kg. The only problem I might have is that the plastic is quite tightly curled on the inside. Hopefully the extruder will have enough pull to straighten it.

So a plan was forming, I just needed an axle with descent bearings. Another piece of junk I had rescued from a skip was this aluminium roller:-

It was exactly the right diameter and was mounted inside a metal housing with ball bearings. I chopped up the housing to make two mounting brackets and moved the bearings around.

All that was left to do was screw it to the top of my machine. The roller is a bit long for an axle but it was easier to leave it full length than cut it and turn the end back down to fit the bearing. My lathe is nowhere near big enough for that. Here it is mounted up :-

I even managed to re-use the rubber 'O' rings on the roller to hold the reel in place. The bearings are so good that a quick twist will leave it spinning for more than 30 seconds so the extruder has no problem dragging the filament off.

Finally I replaced the knobs that I made with proper wing nuts as they are easier on the fingers.

The next task is to design the electronics to drive the extruder.

Sunday, 12 August 2007

Sore thumbs

Well thumbs and fingers actually through stripping down and rebuilding my extruder a few times to solve teething problems. It has actually taken me a couple of days to get it working reliably. There were only two problems really :-

The first was that I was not tightening the springs enough. My springs are bigger diameter than the recommended ones and are too stiff to compress with ones fingers but even so I need to have them fully compressed for the extruder not to jam. What happens when they are not tight enough is that the screw thread slips against the filament and starts grinding it away instead of moving it.

The biggest problem was that my soldered joint between the steel cable and the drive screw kept breaking. The reason being that the drive screw is stainless steel which can not be soldered with normal flux. I tried cutting a cross in the end of the screw to give the solder something to hold onto. That did not work because the solder just forms a bead that does not penetrate the slots.

In the end I stuck it with JB Weld. For some reason it does not cure properly in the recommended 15 hours so I transfered it to the oven and baked it for 2 hours at gas mark 6. That seems to have done the trick.

I have found that running the extruder at different speeds gives different sized filaments.

The one on the left was extruded with the motor running from 4V and is about 0.8mm and the one on the right was extruded with the motor running from 10V and is 1.2mm. They are both extruded from a 0.5mm hole. I think what happens is that the plastic is compressed as it enters the hole and expands as it leaves it. The faster the motor runs the higher the pressure so the more it contracts and expands. The strange thing is that other people have not seen this effect. Possibly the hole in my nozzle is too deep or too shallow, I am not sure which.

I was surprised when I saw this piece emerge :-

But not when I examined the thermocouple I had used to measure the temperature of the molten plastic :-

It is supposed to work up to 250°C but it looks like the heatshrink sleeving they used is not up to the job.

My extruder occasionally produces swarf from the gap between the pump and the clamp. I am not sure of the exact mechanism for this is but it does not seem to affect its operation.

Here is a video of the extruder in operation and the filament produced showing self organising behaviour.

Saturday, 11 August 2007


I need to knock up a controller for the extruder. This will take commands from the main controller via an I²C bus and control the motor speed and heater temperature. It may also need to control a fan to cool the workpiece and monitor a filament out detector.

I decided to drive the extruder with bench power supplies to see if it works first and get an idea of its parameters and hence the requirements for the controller. Here is my test setup :-

As you can see I have plenty of meters. I have been hoarding them for years but it is not often I get to use more than two at a time. Here I am measuring extruder voltage and current, temperature and thermistor resistance. I have another three or four about somewhere but I doubt I will ever need to measure 8 parameters!

The bench power supplies are ancient, I think the big one has valves in it and I built the small one when I was a child. I had a near perfect memory then so I never saw a need to label anything. I have several other items of equipment from that era, including an oscilloscope, with no labels on anything.

Here is the raw data I measured :-

0 W23 C2108 R
0.77 W48 C897 R
1.36 W64 C533 R
2.13 W87 C280 R
3.06 W114 C145 R
4.17 W145 C73 R
5.44 W173 C42 R
6.89 W207 C21.9 R
8.5 W243 C12.2 R

I plotted a graph of temperature against power. I expected it to be a straight line because the rate of heat loss is proportional to the temperature difference between the nozzle and its surroundings and at equilibrium that must equal the input power.

As you can see it is a bent line with a change of gradient at 150°C which I can't explain. I measured the temperature with a thermocouple inside the barrel. It is rated for use up to 250°C but the strange thing is that if I plot a graph of the temperature indicated by the thermistor then the graph is much straighter. I calculated the thermistor parameters from the thermocouple data ignoring the last three points.

So I am not sure what to make of it. I may have to repeat the experiment with my IR thermometer. As long as the thermistor measurements are repeatable I don't suppose absolute accuracy is necessary, other than to swap setting with other RepRappers.

The thermistor resistance is a extremely non linear. Its is approximated by a negative exponential of the reciprocal of absolute temperature.

Ro is resistance at known temperature To, in my case room temperature, expressed in Kelvin. Beta is a second parameter of the thermistor which can be calculated if you know the resistance at two different temperatures. I calculated it for each of the first six power levels and then took an average. It's probably not a very accurate value because the thermistor, being on the outside of the barrel, was probably at a significantly lower temperature than the thermocouple on the inside. However, it is the inside temperature I am interested in so I probably get a value of beta that sort of compensates for that.

Here is the graph of resistance against temperature :-

I plan to measure this with the analogue to digital converter in the MSP430 micros I am using. The problem is to cover such a large resistance range would end up with very little accuracy at the high temperature end where the machine will operate.

I had an idea that putting a fixed resistor in parallel would close up the bottom end without affecting the top much. Indeed it does, here is a graph of the combined resistance against temperature with a 100 Ohm resistor in parallel. You can see it is not far off being a straight line, much easier to digitise accurately.

Thursday, 9 August 2007

Knobby nuts

Having assembled and dismantled my extruder a few times I found it quite fiddly and time consuming. The reason being is that all the fasteners need either an Allen key and a spanner or two spanners. I solved this by placing shake proof washers between the screw heads and the plain washers that are there for load spreading. Only problem was I had to buy them in packs of 250 so I have enough to last the rest of my life!

The result is that once the bolts are finger tight the washers bite and hold the head so only one spanner is required to tighten the nuts.

The nuts that tighten the springs were still a bit tedious. This is because they need tightening a long way down the thread to tension the spring and you need a spanner all the way because the springs are stiff. Wing nuts are the obvious answer but I didn't have any and I am not sure whether there is room to spin them. Instead, I milled some knobs out of Perspex and tapped them to act as nuts. I have christened them knobby nuts but that probably only strikes a chord with people in the UK.

Tuesday, 7 August 2007

Roll out the barrel

I don't seem to have achieved much in the last week as I have been waiting for a few things to arrive. I have managed to mount the extruder on the bottom bracket that previously held the milling drill. I had planned to do that to make it easy to swap between the two, so I used a smaller diameter PTFE rod for the thermal barrier to allow it to fit through the same hole as the drill. What I forgot was that the wires would also have to pass through the same hole! It is a tight squeeze as you can see. The heater wires actually have some plastic insulation where they pass through the aluminium, I hope it doesn't melt!

Another thing I forgot to allow for is that I had to mount the extruder clamp on standoffs to clear the bolt heads and leave space for the wires to exit. Unfortunately that means the nozzle doesn't quite reach the XY table so whatever base material I decide to extrude onto will have to be at least 5mm thick.

On the left of the nozzle you can just see a small thermistor to measure its temperature. The recommended part from RS is on back order but one of my fellow reprappers called englewood was kind enough to send me the alternative one you can see. I hope to repay him with some HDPE extruder parts if my machine is successful at making them.

I attached it by filing a flat on the barrel and clipping it with a couple of coils cut from a small spring. I used a little thermal grease between the two.

The next step is to calibrate the thermistor and see if it will extrude.