Fitting a DC Uninterruptible Power Supply (UPS) and separate 5V supply.

(and yet another wiring upgrade).

Although power cuts are quite rare occurrences where I live, they do completely wreck any print that may have been in progress when a loss of power takes place. As my printer is quite large, I often print large items which can take many hours or even days to complete. So power cuts or outages can at times be more than a little inconvenient. It is possible to use the Duet facility to auto save some parameters and resume a print on power loss but that is not without it’s drawbacks. Ideally one should re-home the printer when power is restored, but homing Z isn’t possible on my machine when a print is on the bed. Homing to Z max isn’t really a viable option either because that would mean having to wait while the bed travelled 760mm down and then up again every time I wanted to home Z. It wouldn’t work in any case with the way that I use the nozzle as a Z probe. So I wanted another way of dealing with power outages.

Another thing I wanted to address is the way that power is supplied to the Raspberry Pi (RPi) on generation 3 Duet electronics. The default way of doing this is to power the RPi from the Duet main board. But that doesn’t provide an easy way to turn it off other than turning off the power, and people who know more about SBCs than I do, tell me that this is not best practice and can result in a corrupted SD card. So I wanted to provide a separate 5V power supply to the RPi.

To get around the power outages, I have in the past toyed with the idea of fitting the type of UPS that I use on my PCs and NAS. I should point out that my bed heater is mains powered and 800 Watts so I wouldn’t want to try and run that from a UPS. I would need some way of turning off the bed heater when the UPS cut in. Also, non-essential things like lights could also be turned off to prolong the run time on batteries.

One thing struck me as being a bit daft with that type of UPS for this application is this. The printer runs off 24V DC. A conventional UPS takes battery power and uses an inverter to step that up the mains AC voltage at an efficiency of say 85%. The printer’s PSU then converts that AC voltage back the DC at a similar level of efficiency. So one could lose 30% of the potential run time simply through that double conversion process.

I posted that observation on the Duet user forums to see if anyone had any better ideas and I am very grateful to user @samlogan for his suggestion, which was to use a DC UPS (something that I had not heard of before). The DC UPS that Sam suggested is made by Phoenix Contact and they tend to be a bit expensive here in the UK. But I found one that seems to do the same job, made by MeanWell. This one https://www.meanwell.com/Upload/PDF/DR-UPS40/DR-UPS40-SPEC.PDF

It’s a 24V DC to DC UPS. What that means is that both a 24V PSU and 24V batteries are connected to separate input terminals. In normal use the PSU supplies power to the output, but when the battery voltage is higher than the PSU input voltage (as would be the case when mains power fails) then the UPS switches over and supplies power from the batteries. The PSU voltage needs to be set to 27.6 volts and this used to charge the batteries via a separate charging circuit. I use the plural term of “batteries” because 12V batteries are more common than 24V ones, so two 12V batteries would be used and connected in series.

I managed to pick one up via Ebay for £47.80 which is cheap for a UPS (but of course, I needed batteries too).

To my mind, this is an elegant solution because there are no losses in efficiency in converting from battery DC to AC then back to DC. Also, the mains powered bed heater will automatically turn off in the event of a power failure without having to do anything about it. Furthermore, I use a separate mains powered 12V supply for the lights, so in the event of a mains power failure, the lights too will automatically turn off. Essentially, only the stepper motors, fans and hot end heater will continue to consume power so with the right batteries, I thought I should be able to get quite a long run time.

That still left the RPi. I haven’t as yet found any compelling reason to use the RPi but I have no doubt that will change in the near future. As I mentioned before, I wanted to power this from a separate 5V supply so that it could be shut down in a controlled manner. Clearly a mains powered 5V supply would turn off in the event of a power failure which would cause a print to stop if I was using the RPi, and possibly lead to a corrupted SD card. So I elected to use a 24DC to 5VDC converter which would be powered from the UPS in the event of a power failure.

Thinking ahead, I decided to add a relay board that is powered by 5V and which could be used by either the RPi or the Duet board to switch other peripherals that I might want to add at some time in the future. I bought a very cheap relay board from Ebay so if I end up not using it, it won’t matter too much.

Finally, I realised that I would need some way to turn off the power to the boards for when I wanted to work on the printer or in an emergency situation. Clearly, turning off the mains switch as I had always done wasn’t going to work because the UPS would just switch over to battery power. So I decided to re-wire my emergency stop switch such that it will interrupt the 24V supply, rather than the mains supply. But this needed to only interrupt the 24V to the boards as I still needed to keep the 24V to the 5V supply, otherwise it would be like simply pulling the plug on the RPi.

Here is the wiring diagram that I came up with.

Wiring diagram

The mains inlet comes in via an IEC socket, and then a double pole switch with integrated neon indicator mounted at the back of the printer, and then to DIN rail terminal blocks. There is second neon indicator at the front of the printer. The mains supplies for the two PSUs are taken from those terminal blocks as is the live to the SSR which controls the bed heater. The neutral and earth to the bed heater are taken from the switched side of the incoming mains supply. One feed from the 24V PSU is taken via the emergency stop / board power switch to another set of DIN rail terminals. The VIN supplies to the 4 Duet boards are taken from these terminals. The second 24V feed goes directly to the 24V to 5V converter. The 5V DC output feeds both the relay board (for future use) and the RPi. The 12V output goes to the LED lights via separate switches (not shown). The negative side of all the DC supplies are connected together, along with the mains and chassis earths.

When it comes to the practicalities of installing everything, things are never quite as straight forward as they seem. The UPS is DIN rail mount. The 24V power supply that I was using is non-adjustable and although I do have a PSU that could be set to the required 27.6V, it is physically too large to fit in the space available on my printer. So I bought yet another 24V PSU, that is also DIN rail mount. This one in fact https://www.meanwell-web.com/content/files/pdfs/productPdfs/MW/NDR-240/NDR-240-spec.pdf

But it was still difficult to package the existing 12V PSU that I use for lights. So in the end I decided to change that to DIN rail too. I didn’t have a 24V to 5 converter so I had to buy one and decided that I might as well get a DIN rail version of that as well. At which point, I decided that I might as well use DIN rail terminal blocks and mount everything on a DIN rail. Which of course meant changing all the mains wiring. Then I realised that the DIN rail terminals blocks were taller than the ones I used before so I had to redesign and print another mains inlet box.

I finally got it done and this is how it looks now.

This is the mains wiring inside the box.

One final thing, is that the SSR has an LED that glows when it switches on. With my previous wiring, the low voltage side of the SSR was outside of that box so that I could see this LED. But I didn’t have room to do it like that, so I had to mount it fully inside. I made the box lid with a hole in it so that the LED could be viewed but it is a long way below the lid of the box. So I bought a piece of 8mm acrylic rod which, I cut down and polished the ends using very fine wet and dry abrasive. This fits in the hole in the lid and just touches the LED on the SSR so acts as a “light pipe”. Here is a close up picture so you can see that it works very well indeed.

One last thing I thought about was that when power fails and the bed heater stops, after a period of time the Duet board will flag up a heater fault. I’m not sure if a bed heater fault would lead to the print being paused but in any case, it isn’t desirable. The UPS does have a number of sets of contacts which close on various events, one of which is when it switches to battery power. So I connected these contacts to a spare io port on the Duet main board and used M581 to set external triggers when those contacts change state. So when the contacts “make” it runs a trigger macro which simply sets the bed heater fault parameters to a silly value of 60 deg C. This effectively disables heater fault detection when the heater is not powered. When mains power is restored, the contacts open which triggers another macro which in turn restores the heater fault detection values back to sensible numbers.

The next thing I needed to do was choose batteries. Here the Mean Well data sheet is a little sketchy. It simply states batteries of “4, 7, 12 AH (typical)” and a charge current of “2A (typical)”. Again, Sam came to my rescue and asked his local Mean Well rep who said that larger batteries can be used – they will just take longer to recharge.

In order to calculate the battery size, the first thing I needed to decide was what run time I needed. For this I used bed temperature as the criteria because I print on heated glass (with 3D Lac). My reasoning being that when the temperature drops sufficiently, the part that is being printed will simply fall off. So there would be no point in having a battery run time longer than the time it takes for the bed to cool. This isn’t quite true because it depends on the area that is in contact with the glass. Indeed, large parts often require a slight tap even when the glass has fully cooled. But smaller parts tend to be easy to remove when the temperature drops to around 40 deg C. So although that is a somewhat arbitrary value, it seemed a reasonable value to use.

The next thing I did was to heat the bed to 60 deg C which works well for most things that I print (I don’t print ABS) and then turn off the bed and see how long it takes to cool down to 40 deg C. My bed is 400 mm x 400mm and consists of a 10mm thick piece of aluminium tooling plate, topped with 6mm thick glass and with 12mm of semi rigid insulation underneath. The time to cool from 60deg C to 40deg C at an ambient of 21 deg C was around 40 minutes. So that was my target run time.

The next thing I needed to do was to calculate the AH rating of batteries which would attain that 40 minutes run time, and for that I needed to know the power consumption. I calculated this as being around 9 amps but that’s probably on the high side (it was – confirmed it later). I took the rated current of all the steppers at the rated voltage to calculate the power in watts and added 50%. Then added the wattage of the hot end heater and added a bit more for fans and the boards themselves plus a bit more for the RPi. In reality, I set the motor currents to about 85% of their rated values, only 2 or 3 of the 6 extruders would be used at any one time, and once up to temperature, the hot end heater would not be using 40 Watts. So 9 Amps is on the high side but given that batteries would deteriorate over time, it still seemed like a reasonable value to use for the purpose of determining battery capacity.

Plugging these numbers into an online calculator revealed that somewhere around 35 AH would give me the run time of around 40 minutes. After a lot of research, I came to the conclusion that AGM lead acid batteries would be suitable and I found a pair of Lucas 12V 20 AH batteries (so 40 AH in total) on Ebay for £69.90 including delivery. So for the UPS, the total spend was £117.70. That is considerably cheaper than a conventional mains powered UPS of similar capacity.

I also ordered suitable cable, an inline fuse holder, terminals and a battery isolator switch. The batteries arrived the next day but I had to wait a little longer for the other items. However, I was impatient to know if this would work so I temporarily connected everything up using some 1.5mm mains flex that I had lying around (I have some 6mm^2 on order which will be lower resistance).

Here is a picture of my temporary “lash up” (don’t try this at home folks)

Still being impatient, I then ran a test print without knowing what state of charge these new batteries were in. I took some video clips and I’ll make I’ve made a little video and upload uploaded it to my YouTube channel. I’ll put a link in here later today. Here is a link.

https://www.youtube.com/watch?v=JqEo_k1Ugig

One thing I forgot to do was set the bed temperature to 60 degrees C instead of 50 which is what I have been using for this test print. In the event, the part stayed attached to the bed for the duration, even though the bed temperature dropped to around 30 deg C, so it wasn’t a problem.

About 10 minutes, after the print started, I simply pulled out the mains plug. The 12V printer lights went off as expected and so did the mains powered bed heater. The contacts on the UPS closed when it switched to battery power and macro ran to set the bed heater fault detection parameters. The print continued as if nothing had happened apart from a slight change in the sound of the hot end cooling fan which had been running on 27.3V and was now on about 24.4V. It should be noted that Vin on the Duet is 0.3 degrees lower than the voltage as measured with my multimeter. So the true voltage is 0.3 degrees higher than stated.

5 minutes later, Vin was showing 23.7V and the print continued as normal. At 35 minutes, Vin was still showing 23.7. I reached my target of 40 minutes with Vin showing 23.6V (so a true 23.9V).

I let the print run for an hour, after which Vin was showing 23.4 (so a true 23.7 V). At that point, I plugged the mains lead back in and checked that the macro to reset the bed heater fault detection ran, which it did.

So it seems that my calculation of power consumption was indeed high and I could probably have use smaller batteries. Especially as for this test, I was only using 1.5mm cable so resistance may be on the high side, and have no idea what the state of charge of these new batteries was. I do not know how long the printer would run on fully charged batteries – probably several hours. However, I’m happy with the knowledge that these batteries will probably last for very many years.

For now I will disconnect the batteries. I’m not entirely comfortable about having them in what is in effect just a spare bedroom. I plan to move the printer to a more permanent home in my garage and I’ll reconnect them properly (with the correct cable, terminals, a fuse and an isolator switch) once the printer is moved.

I have one more thing to do and that is to make use of another set of contacts that the UPS has. These contacts close when the battery voltage drops to 21V. I plan to use these to initiate a macro which will do a controlled shutdown of the RPi, as well as park the print head and turn off all motors, heaters and (once the hot end temperature has dropped) the fans. Effectively turning everything off which will prevent the batteries from becoming completely exhausted.

As ever, I hope that there is something in the above that others might find useful. Feel free to leave any comments (very few people bother).

Ian

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s