This is only a preview of the July 2018 issue of Silicon Chip. You can view 40 of the 104 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Super Clock now shows your electricity tariff":
Items relevant to "Raspberry Pi Tide Chart":
Items relevant to "How’s your memory? Build the Event Reminder":
Items relevant to "800W (+) Uninterruptible Power Supply (UPS) Part III":
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
Finishing our all-new
800 W plus . . .
Part 3:
by Duraid Madina
and Tim Blythman
Uninterruptible
U
ninterruptible
Power
Supply
S
upply
In this third article, we describe how to finish
building the rechargeable lithium battery-based UPS.
We’ll also cover testing, set-up and calibration. Finally, we'll
discuss how to connect it to a PC so that you can monitor its status
and so that it will shut down automatically before the battery goes flat.
T
his UPS is cheaper, smaller and
lighter than pretty much any
equivalent commercial UPS – at
least, none that we could find.
But it has another big advantage over
commercial units: it can be tailored to
suit your particular needs.
That includes:
• the possibility of increasing the
runtime by using more or larger
batteries
• reducing the cost by using cheaper
batteries
• or increasing the output power
through higher battery current capacity and/or a more powerful inverter.
Also, since it is based on a pure sinewave inverter, its output waveform is
very clean (cleaner than mains when
running from the inverter!) while
many commercial UPSes produce an
ugly, “modified” sinewave (really just
72
Silicon Chip
a two-step square wave).
Since this unit is controlled by an
Arduino microcontroller, you can
tweak the code to suit your particular
needs or you can just use the software
as is, since the default settings will
suit most users.
Our first article in this series (May
2018 issue), described how the UPS
works and detailed the design process.
The second article (June) gave the
majority of the construction details,
including most of the wiring.
Now we need to program the Arduino board with the control software,
test all of its functions and calibrate it
for accurate operation.
Before that, however, we'll add a
surface-mount USB socket to the front
panel and later, we'll explain how to
connect it to a computer’s USB port
and establish communications using
freely available computer software.
This will allow the UPS to be moniAustralia’s electronics magazine
tored either locally or remotely via the
internet, and allows the computer to
be cleanly shut down in the event of
an extended power failure.
Finally, we'll go into more details
over the expansion possibilities mentioned above.
Finishing construction
If you followed the instructions last
month, you now have a UPS which is
mechanically and electrically complete but has no software to control
it. So now let’s get it up and running.
The front panel label
First things first: you will note in the
photo above that the UPS front panel
is labelled (we like to make our projects look professional!).
However, the UPS doesn't really
need a front panel, except perhaps to
show what the three LEDs indicate
and the purpose of the push button.
siliconchip.com.au
Some constructors may leave the
front panel blank and simply print a
reminder on the rear panel with a fine
marker pen, ie:
Green LED: Mains On
Yellow LED: Output On
Red LED:
Battery Low
Push Button: Manual Start.
But if you do want to make a front
panel label, you will need to download
the panel artwork from the SILICON
CHIP website and print it onto clear
adhesive film.
However, it is almost impossible to produce
a label to cover
the whole panel,
which is standard rack-mount
size (19 inches or
~485mm) wide.
Not even an
A3 label (420mm
wide) would cover this expanse . . .
if you could even get the
material to make one.
Therefore the front panel artwork
we have prepared is designed to cover only a 297 x 130mm area of the left
side of the panel – easily accommodated on an A4 sheet.
You can get clear, self-adhesive A4
sheets from a variety of sources (including ebay) suitable for use with
inkjet printers.
You would print the artwork onto
these labels and then attach them to
the front panel.
If you can’t easily get adhesive clear
D
Fig.6: installing the TimerOne library can be done via the Library Manager.
Click on the option highlighted above (ignore the greyed section) and click
"install" when it appears.
labels, you could mirror the images
and print them onto clear film, then
stick the printed side of that film to
the front panel of the unit using a
thin smear of clear neutral-cure silicone sealant.
Incidentally, if you do use the SILICON CHIP panel artwork, the positioning of the LEDs and switch is much
more crucial, simply to get the labelling to line up.
Use the front panel artwork below
as a template (remember the panel below is printed at 50% – if you're photocopying to use as a template, you
need to enlarge it by 200%.)
This artwork can also be downloaded from siliconchip.com.au
Loading the software
You will need the Arduino UPS
firmware package, which can be downloaded from the SILICON CHIP website
(free for subscribers).
To compile and upload the test and
control software, you need to have the
Arduino IDE (Integrated Development
Environment) installed. This can be
downloaded from www.arduino.cc/
en/main/software, with versions available for Windows, macOS and Linux.
Download and install a version to
suit your operating system and start
it up. If you already have the IDE installed, the minimum version required
for the following steps is v1.6.4 so
upgrade it first if you have an earlier
version.
The software needs one library installed, to allow it to perform regular sampling of the mains waveform.
Open the Library Manager by going to
130mm
297mm
Fig.7: front panel artwork, reproduced 50% (ie, needs to be enlarged 200% if you wish to use this to make
a front panel and/or to use as a template for the LEDs and Manual Start switch). This is designed to fit on
a standard A4 sheet of clear, self-adhesive film. It covers less than half the width of the rack-mount panel.
siliconchip.com.au
Australia’s electronics magazine
July 2018 73
The three relay sockets are oriented so
the vertical pins (the coil connections)
are towards the rear panel and the
horizontal pins (the relay contacts)
towards the front.
the Sketch → Include Library → Manage Libraries... menu, type "timerone"
in the search box and click on the "install" button that appears.
Alternatively, we supply the library
in a ZIP package when you download
the sketch.
You can install this using the Sketch
→ Include Library → Add .ZIP Library
menu option.
Because this project involves high
voltages and you will want to make
sure that everything is working properly before “letting it loose”, we have
created a separate test program that can
be uploaded to the Arduino.
There’s also another separate
“sketch” which is used for calibration
and setup.
The download package includes
three separate sketches, called “Silicon_Chip_UPS_Control_V3” (the control software), “Silicon_Chip_UPS_
Testing” (for testing only) and “Silicon_Chip_UPS_Calibration” (for setup and calibration). The differences
are explained below.
Initial checks
Plug relays RLY1-RLY3 into the bases now. It’s very important that the relays are the right way around since if
you manage to accidentally install the
bases backwards, all the wiring will
be wrong.
So make sure that the pins for the relay coils go towards the rear of the case.
Note that the connection pins for the
coil are orientated differently to the
other six contacts – they're 90° rotated
compared to the switching contacts.
74
Silicon Chip
Compare your bases to the photo at left.
Once the relays are plugged in, you
should be able to see the armature and
contacts inside the relay and these
should be on the side towards the front
of the unit.
Now we check that there are no short
circuits between the mains and low
voltage wiring or between the mains
conductors.
Set your DMM to its highest ohms
range (usually megohms) and connect
the probes between the earthed chassis and the 0V terminal on the control shield.
The reading should be well over
1MΩ. If it's below 1MΩ then you will
need to check your wiring carefully
for mistakes.
Next, check the resistance between
the Active pin of the incoming mains
plug and chassis earth, and repeat the
test for the Neutral pin. Both readings
should also be above 1M. Perform the
same test with one of the GPOs, making sure that its associated switch is on.
Similarly, measure the resistance
between the earthed chassis and the
positive battery terminal. This should
also be high.
Finally, the resistance between any
of the earthed chassis pieces and the
mains plug earth pin should be low –
1 or less.
Shield testing
The testing sketch displays information on the voltages being monitored
and the operation of the inverter.
Remove RLY1-RLY3 from their sockets; they are not needed at this stage.
Make sure that the mains input cable is unplugged and ensure that the
inverter control cable is connected.
For the initial setup, leave the RST
DIS. jumper (JP1) off the control shield.
Plug the Arduino into your computer's USB socket and make sure the
correct COM port is selected under the
Tools → Port menu.
Then open the Silicon_Chip_UPS_
Testing sketch, upload it to the Arduino (Sketch → Upload) and check the
messages at the bottom of the window
to ensure it was successful. Then open
the serial monitor (Tools → Serial Monitor) and set the baud rate to 115,200.
Every five seconds, the test sketch
reads the analog inputs and displays
their raw values, as well as toggling
the inverter on and off.
You should see something similar
to the following on the serial monitor:
Australia’s electronics magazine
Inverter turn off:OK
Battery Sense:484
Mains Sense:479
VIN Sense:79
Mains RMS: 3
Mains P-P: 7
Inverter turn on:OK
Battery Sense:484
Mains Sense:479
VIN Sense:79
Mains RMS: 2
Mains P-P: 6
...
If the inverter is connected, it will
produce a brief chirp every five seconds as the Arduino turns it on and
off, with corresponding feedback on
the serial monitor showing that it is
reading the inverter state successfully.
The "sense" values are in ADC units,
so will be in the range of 0-1023. The
battery and mains values should be
close to 500 and VIN around 80. The
battery value will reflect the state of
battery charge, with a full battery being around 540 (29V) and a flat battery
being about 409 (22V).
Now measure the actual battery
voltage and write down this voltage
reading along with the current Battery
Sense value. These numbers will be required later, for calibration.
The Mains Sense value is around 500
because, in the absence of mains, the
biasing resistors bring the AC waveform near the centre of the Arduino's
ADC range.
Plugging in the mains should cause
this reading to vary between about 300
and 700 and the RMS and P-P should
increase to around 85 and 240 respectively.
The VIN Sense reading should also
rise to around 200 as the Arduino
is now being powered by the mains
transformer.
Measure the voltage between VIN
and GND on the Arduino shield and
note this down, along with the VIN
Sense reading displayed, again for use
later during calibration.
Now (carefully!) measure the mains
RMS voltage using a DMM set on a
high AC volts range and write this
value down, along with the RMS and
P-P values displayed simultaneously
in the serial console.
Unplug the unit from the mains
now. If your unit is not behaving as described above, go back and check the
wiring and shield construction.
In particular, high or low values for
siliconchip.com.au
any of the analog voltages are signs
that the wrong resistors were used in
the voltage dividers. Values close to
zero or 1023 might indicate an open
or short circuit on the shield.
Calibrating the unit
The control program relies on a
number of EEPROM calibration values
for correct operation. The calibration
sketch allows you to set these via the
USB/serial port, using a menu system.
If you don't set these, the first time
you run the control program, it will
load a default set of values (as determined using our prototype).
But component variation means that
these are unlikely to be exactly right
for your UPS, so it's better to use the
calibration sketch first. These are separate sketches because the USB/serial
interface is used to feed status information to the computer when running
the control program.
So open and upload the "Silicon_
Chip_UPS_Calibration" sketch to the
Arduino, using the same procedure
as described above and again, open
the Serial Monitor and check that the
baud rate is 115,200.
Press "d" and Enter, followed by "p"
and Enter. This will load the defaults
and then display them. You can also
press "?" and then enter to get the following help text:
UPS SETUP
? This Help
~ Toggle voltage status output on/off
A-O Enter parameter, followed by number and enter
s Save current to EEPROM
l Load from EEPROM
d Load from defaults
p Print current parameters
The default values should be shown
as follows after pressing "P":
Current Values:
A:VIN_SCALE :0.0538560
B:BATTERY_SCALE :0.0538560
C:MAINS_SCALE :2.7090001
D:BATTERY_CRITICAL
:23.0000000
E:BATTERY_MIN :25.0000000
F:BATTERY_OK :27.0000000
G:VIN_MIN :11.0000000
H:VIN_OK :11.5000000
I:MAINS_MIN :200.0000000
J:MAINS_DB :20.0000000
K:MAINS_MAX :260.0000000
L:MAINS_DELAY :10000.0000000
M:VIN_DELAY :5000.0000000
N:BATTERY_CRITICAL_DELAY:
5000.0000000
O:VIN_CRITICAL :10.5000000
Now calculate the correct VIN_
SCALE value for your unit by dividing the VIN that you noted earlier by
the VIN Sense reading.
You should get a value similar to that
shown above. Type "A" into the serial
console (it must be a capital), followed
by Enter, then type in the new VIN_
SCALE value and press enter.
Different batteries and other options . . .
While the UPS is very capable as presented, some readers might
want to change the design to reduce the cost, provide a higher
battery capacity, a higher maximum output power or faster battery recharging.
The IFM12-230E2 LiFePO4 batteries used in this project are rated
at 23Ah each. You could use IFR12-400-Y batteries instead, which
have a rating of 40Ah. These are larger and heavier and would not
fit in the specified case but they would almost double the runtime.
Note that you would need to ensure that the cable between the
batteries and those from the batteries to inverter are sufficiently
thick. Also, recharging would take twice as long unless you also
upgraded to a charger with a higher current rating.
Depending on your planned use of the UPS, a longer charge time
might be acceptable, if you just want to cover occasional outages.
On the other hand, if you plan to use the unit mainly for off-line
power or are in a location with frequent and long outages, a more
powerful charger would be a preferable. Keep in mind that you may
also need heavier cables between the charger and the batteries.
If you end up with a battery bank powerful enough to deliver
more than 50A, you could then consider using an inverter with a
higher power output than 1200W (up to a maximum of around
2400W/10A).
The good news is that if you decide to make these changes, the
relays, Arduino, control shield and other interface modules do not
need to be changed. If you use a different battery chemistry, you
will need to adjust the Arduino configuration to suit the different
voltage thresholds but that’s it.
Reducing cost or increasing run time
As we said right at the start of the first article, this UPS is not
cheap to build and that’s mainly due to the lithium-based rechargeable batteries.
As explained in that article, LiFePO4 batteries have significant
advantages over lead-acid batteries but they are still considerably
siliconchip.com.au
more expensive.
If you’re willing to accept the disadvantages of lead-acid chemistry, such as larger size, greater and weight and reduced lifespan
with multiple deep discharges, you can certainly save some money.
For example, you could substitute two Jaycar Cat SB1699 38Ah
deep cycle SLA batteries, which would give you a slightly higher
capacity (albeit more sensitive to discharge rate) and would make
the total cost for the UPS project to around $800-900. That’s a
lot cheaper than a commercial UPS with equivalent performance
would cost. The weight penalty would be around 10kg and you
would need a larger case.
Or you could go all out and use two 150Ah Deep Cycle AGM batteries (Jaycar Cat SB1684). This would give you a massive 3600Wh
total capacity, allowing you to draw 1200W for three hours or around
720W for about five hours.
The total cost would be similar to our original design, although
it would weigh nearly 100kg and would be about the size of a
small fridge!
Such a system would make a great power plant for a caravan,
mobile home or even a shed where you don’t have access to mains
power. In this case, you would probably want to use a 24V MPPT
solar charger or even a generator to keep the batteries topped up.
Mind you, its weight of 100kg must be considered if you have a
mobile home or need to tow a caravan.
Many solar regulators can simply be connected directly to the
batteries and they will quite happily work with other charging sources connected at the same time but you should check the specifications of the charger before hooking it up. And if you’re using lithium-based batteries, you absolutely must ensure that the charger
is designed to handle that particular chemistry.
The Arduino control board in our project doesn't care how the
battery is charged, as long as it occurs somehow. Charging the
batteries by wind power is possible too but again this will depend
on the capabilities of the wind turbine regulator.
Australia’s electronics magazine
July 2018 75
Repeat the procedure for the battery
voltage divided by the Battery Sense
reading (option "B").
This should also be around 0.05-0.06,
and the mains voltage divided by the
Mains RMS reading (option "C"), which
is normally around 2.7 but may vary
depending on the exact turns ratio of
your transformer.
The other values should not need to
be changed but you may wish to alter
them later to tweak the unit's behaviour, once it's up and running.
Press "s" and Enter to save the new
settings to EEPROM.
You can check that the values were
properly saved to EEPROM by resetting the Arduino and then using the "p"
command to display the stored values.
Loading the control software
Do a final check over the unit's wiring to make sure that everything is as
it should be, then open and upload
the sketch named "Silicon_Chip_UPS_
Control_V3" (if there's a newer version,
it may be V4, V5 etc).
As soon as it's loaded, the piezo
should sound for two seconds as the
UPS attempts to start up but it cannot
because the relays are not yet in place.
You can now access the APC-compatible status interface by opening the
Serial Monitor and setting the baud
rate to 2400.
Press "a" and you should get the "capability string", which looks like:
3.!$%+*.#BGKLMNQSUVYZaf
You might also get an asterisk ("*")
on a line by itself. This means that the
Arduino has detected a loss of power
and is shutting down. This indicates
that the software is working as designed, given that the hardware is not
yet complete. Disconnect the USB cable for the next few tests.
up for some time to charge the batteries.
If the incoming mains is switched off,
the yellow inverter light should come
on briefly before it all shuts down (as
the inverter relay is still missing). You
may also see the UPS spontaneously shut down if it detects any mains
glitches.
Testing the software
Testing the inverter
Ensuring that the mains lead is disconnected, plug RLY1 and RLY2 into
their sockets (the two left-most relays,
looking from the front). Set S1 to the
off position, plug in mains and switch
it on. The Arduino should power up,
detect there is no 12V supply from the
PSU and then shut down.
If the yellow light comes on at all
(except very briefly before the green
light), the UPS is probably not sensing
mains voltage correctly, as it is trying to
switch over to the inverter. You should
be able to measure 12.6VAC across the
mains transformer input to the shield
(CON1). If the UPS appears to be doing
something unexpected, turn everything
off and check the wiring thoroughly.
If all these tests went well, switch
off the mains, switch S1 on and then
turn mains back on. The UPS should
perform a normal startup, with a single
beep from the inverter and the green
light on the front panel will turn on.
You should have mains power available at the four-way GPO. The red light
on the front may be flashing if the battery is not fully charged.
If all is well, you can leave it powered
Unplug the mains and remove RLY1
(at left), then plug RLY3 (right-most)
into its socket. Check that the internal
mains plug is in one of the inverter’s
output sockets and then switch S1 back
off. The following procedure tests the
inverter so you do not need to connect
the unit to mains.
Now press and hold down the button
on the front of the UPS (S2). After about
a second, the yellow light will come
on and the green light should be flashing, indicating mains is not present.
The red light will probably be flashing too unless the batteries are fully
charged. When the button is released,
the inverter should beep (indicating a
successful shut-down), and all lights
should go out.
Now switch S1 back on and hold in
pushbutton S2 for about five seconds
before releasing it. The UPS should
now stay on, running in inverter mode
as above, until S1 is switched off, which
should cause a total shut-down
If all these tests were successful,
RLY1 can be plugged back into its socket. Plug the mains plug into a socket
and switch S1 back on.
Calculating the voltage scaling factors
In this article, we describe how to calculate the required scaling factors by measuring the voltages that are being sensed by
the Arduino and then dividing them by the integral number being
simultaneously produced by its analog-to-digital converter (ADC).
But you could calculate these values from the component values used in the circuit.
For the battery sense voltage applied to analog input A2 and the
VIN sense applied to analog input A3, this is quite easy. In both
cases, the divider resistor values are 100kΩ and 10kΩ and we can
compute the division ratio as 11 (100kΩ ÷ 10kΩ + 1).
Since the ADC has a 10-bit resolution, the values will range from
zero to 1023 (210 - 1) for signals from 0V to 5V.
Therefore, each ADC step represents 4.888mV (5V ÷ 1023) and
by multiplying this by our ratio of 11, to compensate for the voltage reduction due to the resistors, we get a figure of 0.05376V per
ADC step, very close to the default scaling factor used.
The calculations for the mains sense voltage are more difficult
because this involves three resistors – a 75kΩ resistor between the
transformer and analog input A1, plus two 10kΩ resistors which
go from A1 to ground and the +5V rail.
The easiest way to understand the effect of this configuration is
76
Silicon Chip
to analyse its DC and AC conditions separately.
The transformer has a low DC resistance to ground, so the 75kΩ
resistor is effectively connected to ground at one end and therefore
is in parallel with one of the 10kΩ resistors, giving an equivalent
resistance of 8.8kΩ.
In combination with the 10kΩ resistor to +5V, this gives a DC
level of 2.35V.
For the AC analysis, since both 10kΩ resistors connect to DC
rails, we can treat them as if they are in parallel, ie, equivalent to
a single 5kΩ resistor. In combination with the 75kΩ resistor, this
gives us a division ratio of 16 (75kΩ ÷ 5kΩ + 1).
Thus, we expect a quiescent ADC reading at A1 close to 480
(1023 x 2.35V ÷ 5V).
Assuming there is 6.3VAC across the transformer winding for
a 230VAC input, that gives a step-down ratio of 36.5 times (230 ÷
6.3). Multiplying this by the resistor divider ratio of 16 gives a total reduction of 584 times. So we can calculate the scaling factor
as 2.85 (584 x 5V / 1023).
In practice, the output voltage of a lightly loaded transformer
is higher than nominal, hence the step-down ratio is lower and so
our real scaling factor is 2.7.
Australia’s electronics magazine
siliconchip.com.au
The UPS should now be operating
normally, so once you switch the mains
supply on, it should start up. A glitch in
the mains can be simulated by turning
the incoming mains off and on quickly. You should see the UPS transition
to the inverter, wait for about ten seconds, then switch back over to mains
power after detecting that it has been
stable for a while.
At any time, you can use S1 to turn
off the UPS. The Arduino should recognise that it is not getting any 12V supply, and will shut itself and the inverter
down. To switch it back on, toggle S1
again and switch the incoming power
off and on (or press the reset button on
the Arduino).
S1 will also work to shut down the
UPS if it is running from its battery. In
this case, it can be restarted by toggling
S1 back on and holding pushbutton S2
in for about five seconds. This takes a
while as the inverter takes several seconds to reach a normal output voltage
and then the 12V DC switchmode supply output will come up.
Load testing
Once the batteries have been fully
charged, you may wish to do a load
and runtime test, to ensure the battery
capacity is as expected and that you get
enough warning before it shuts down
entirely.
A simple plug-in type power meter like Jaycar’s MS6115 or Altronics
P8137 should be used to confirm and
monitor the power usage of your test
load. We used an incandescent lamp
and a heat gun to provide a constant
load totalling close to 800W. It’s also
a good idea to connect a DMM across
the battery terminals with clip leads
so you can monitor their voltage during the load test.
Note that you can’t easily clip onto
the battery 0V terminal since it is insulated. The tab of REG1 on the control shield is a convenient 0V reference point.
Switch on your load(s), check that
the power consumption is about what
you expected, then switch off the mains
input to the UPS and note the time.
If the power meter has a cumulative
power option, now is a good time to
reset it to zero.
You might notice that the load indicated on the power meter changes
slightly when mains is switched off,
since the specified inverter produces
240VAC, while mains can vary from
siliconchip.com.au
below 230VAC to above 250VAC.
The red LED should start flashing after a few minutes as the battery starts
to discharge. The flashing frequency
will increase over time and eventually,
the red LED will be on continuously.
This means that shut-down is imminent. Once the unit switches off, you
will probably notice the battery voltage rebounds since the load has been
removed.
When the shut-down occurs, check
that the inverter shuts down as expected and note the time elapsed and
cumulative energy consumed. If you
have used the specified parts, the time
elapsed should be close to that specified in the first article in this series,
taking into account any differences between your load power and the nearest
specification.
Having completed the load test, plug
the UPS back in to allow the batteries
to fully recharge. This will take a few
hours. Ideally, you should leave it to
charge overnight.
If you notice any problems with the
final battery voltage or inverter shutdown, it may help to adjust the calibration values, as described later in this
article. If you run into any problems,
you may also find it helps to enable debug mode in the control sketch. Note
that this disables the PC interface (APC
protocol) but you can re-enable it later.
To do this, change line 20 of the
sketch from:
//#define DEBUG
to read:
#define DEBUG
and upload the modified
sketch.
After uploading this, you
will probably also want to
put a jumper shunt on JP1
on the control shield (“RST DIS.”) so
that plugging the Arduino into your
PC will not reboot it and reset the UPS.
You'll need to have either mains or
inverter power available so that the
Arduino doesn't try to shut down immediately. Type “?” and press Enter
in the serial monitor to see the list of
available debugging commands. Type
“~” and press Enter to toggle voltage information display on and off. Note that
this mode uses a baud rate of 115,200.
The UPS is now complete and working as designed. You can put the lid on
and use it as-is, or you can follow the
instructions below to add a USB port
so that its status can be monitored from
your computer.
Adding a USB interface
Computer software can be set up to
communicate with the UPS and this
can run “scripts” on certain events so
you can, for example, shut the computer down gracefully before the UPS
shuts down due to a low battery voltage
(during an extended blackout).
The software has other options like
email notifications but we won’t cover the steps required to set that up in
this article.
For these features to work, you need
a Type B USB socket on the outside
of the UPS case to connect it to your
computer. Unfortunately, most chassis-mount USB sockets are Type A, or
they require an accurate rectangular
cut-out. So we came up with
the idea of mounting a Type
A to Type B chassis adaptor
backwards so that the Type
B socket is on the outside.
Then you just need two
standard Type A to Type B
cables; one goes on the inside of the case and connects
The USB socket, mounted on the right side of the front panel. Precise position is
not important. Inset above is the same socket seen from inside the UPS.
Australia’s electronics magazine
July 2018 77
from the socket to the Arduino board,
while the other plugs into the Type B
socket on the outside of the case and
goes into the Type A socket on your
computer.
The part we decided to use is Altronics Cat P0835. The drilling template
is shown in Fig.8. Drill a pilot hole in
all three locations, then use larger or
stepped drill bits, or in the case of the
largest hole a tapered reamer, to expand them to the required sizes.
The Altronics part is reversible, so
if it looks like it would be facing the
wrong way around when installed,
undo the small screws and reverse
the insert in the housing, then reattach the screws.
Mount it in place from the outside
using M3 x 10mm machine screws, M3
nuts and M3 shakeproof washers, then
run a USB A-B cable from the socket
inside the case to the Arduino. We
chose to mount it at the front to keep
the cable run short, although a longer
cable will be fine as long as the total
run does not exceed the USB standard
of three metres.
Secure the cable with cable ties, and
bundle up any excess to keep everything tidy, adding extra cable clamps
if necessary.
If you enabled the debugging feature of the Arduino control sketch, you
will need to disable it and re-upload
the sketch before proceeding. Regardless, insert a jumper shunt on JP1 on
the control board (“RST DIS.”).
Installing the software
The open-source “apcupsd” software is available for Windows (XP onwards), macOS, Linux and more. We
tested it on Windows 10 but setting it
up and running it on the other operating systems should be similar.
The APC UPS protocol operates over
a serial port at 2400 baud with 8 bits
and no parity.
In our case, the serial port is emulated by the USB device using the CDC
protocol. Generally, the UPS host software issues single byte commands,
to which the UPS replies with a brief
multi-byte response.
The UPS may also spontaneously
generate a status signal (such as "power fail" or "battery low") for conditions
that the host computer should know
about immediately.
The APC protocol has been chosen
because it is the most widely supported and is straightforward to emulate.
78
Silicon Chip
Fig.8: the
front panel
cutout for
the USB
socket is a
standard
"D" series
pattern.
This
diagram
is at 1:1
scale.
We recommend running the computer from a separate power source
(ie, not through the UPS) during the
initial testing stages.
The software can be downloaded
from www.apcupsd.org Download
and install a version to suit your operating system. We tested using version 3.14.14.
Select all the possible options during installation and select the option to
edit the configuration file as suggested.
If you need to find the file manually,
it was installed on our system at C:\
apcupsd\etc\apcupsd\apcupsd.conf
It can be opened with a text editor
such as notepad. You will need to set
the following parameters:
UPSCABLE smart
UPSTYPE apcsmart
DEVICE COM5
Note that the DEVICE parameter
needs to match the COM port which is
assigned to the UPS on your computer and it will be in a different format
on other operating systems. This port
number will be the same as the one
you selected for uploading the sketch
in the Arduino IDE.
Save those changes to the configuration file. If you want more details on
the contents of this file, the software
manual is very detailed and can be
downloaded from www.apcupsd.org/
manual/manual.pdf
By default, if the apcupsd service is
running, the software will shut down
the computer if there is a fault detected, such as a critically low battery.
Instructions for disabling this can be
found in the manual.
The manual also explains how to
use the apctest utility, which tests both
the connectivity and settings.
The installer will automatically set
up the service to run at boot time and
it puts an icon in the notification area
of the Windows taskbar.
You can start it manually via the
Start menu. You may also need to run
the Apctray program to get the icon to
appear in the taskbar.
Right-click on the icon on the taskbar to view the UPS status. You can
also use this menu to set the icon to
start automatically with Windows,
view the event log and change other
settings.
If you have no connection indicated
from this icon, check that its configuration settings are correct, especially
the port value. The port should be set
to 3551, to match the port setting in
the apcupsd.conf file. The IP address
should be 127.0.0.1 (which refers to
the local computer).
You can also use this settings window to disable status pop-ups from
the icon.
If you need to change the apcupsd
configuration, first stop the apcupsd
service by selecting “Stop Apcupsd”
from the start menu.
The icon will stay in your taskbar but
it will complain about a network error.
After making changes to the apcupsd.
conf file, start the service as before.
Fig.9: the services window allows you to start and
stop the Apcupsd service. The red arrows highlight
the selections required.
Australia’s electronics magazine
siliconchip.com.au
Fig.10: part of the
status window showing
the vital UPS operating
parameters.
Here you can see line
voltage and battery
voltage as reported
by the Arduino, along
with other statistics
derived by the software
such as time since last
power failure, battery
staus, etc.
during normal operation. The software currently does not rely on this
value but it may be used in a future
version.
• VIN_OK (option “H”). Defaults to
11.5V. If VIN is above this voltage,
the unit is assumed to be running
off the 12V DC switchmode power
supply. Below this threshold (but
above VIN_MIN), it is assumed that
the mains sense relay is powering
the unit via RLY4.
• MAINS_MIN (option “I”). Defaults
to 200V. When the mains RMS voltage drops below this level, the output will switch over to the inverter.
Depending on your version of Windows, you may find that you can only
start and stop apcupsd from the Services dialog.
This can be accessed through the
Windows Run utility (accessible
through the Start menu or by holding
down the Windows key and pressing
R), typing “services.msc” and pressing Enter.
Here, the service can be started,
stopped and restarted, and more options can be found by right-clicking
and opening the properties window,
including whether the service starts
automatically (see Fig.9).
At this stage, the UPS should be up
and running and interacting with the
computer. If you want to test the automatic computer shut-down feature
without draining the battery, shut
down the apcupsd service, edit the
configuration file and find the BATTERYLEVEL parameter and change
it to 95.
The value is a percentage and is
calculated by the UPS based on the
battery voltage level, with the “battery_ok” EEPROM setting representing 100% and the “battery_critical”
parameter being 0%. Save the file and
restart the service.
The UPS can then be tested by unplugging its mains lead and waiting
a few minutes for the battery level to
drop to 95%. Your computer should
then shut down.
Remember to set the BATTERYLEVEL parameter back to 5% when you are
finished testing to avoid premature
siliconchip.com.au
shut-downs.
Once you are satisfied with the operation, check that the service is set to
start automatically and remember to
plug the computer’s power cord into
the UPS outlet.
Advanced calibration
and tweaking
We showed the fifteen different
EEPROM calibration values earlier
but only explained the purpose of the
first three. The remaining settings are:
• BATTERY_CRITICAL (option “D”).
Defaults to 23V. This is the battery
voltage at which the UPS will report
0% remaining capacity and initiate
its own shut-down
This is a fairly conservative value. We don’t recommend setting it
any lower than 21V. This should
not damage the specified batteries.
• BATTERY_MIN (option “E”). Defaults to 25V. This was intended to
be the threshold below which the
unit will start warning the user,
however, the current version of the
software does not use it. It may be
used in a future revision.
• BATTERY_OK (option “F”). Defaults to 27V. When the battery
voltage is this value or higher, the
remaining capacity is reported as
100% and the red LED remains off
even if the inverter is running.
• VIN_MIN (option “G”). Defaults
to 11V. This indicates the voltage
above which the VIN rail will sit
Australia’s electronics magazine
• MAINS_DB (option “J”). Defaults
to 20V. This is the hysteresis value
for MAINS_MIN (“DB” stands for
dead band). The mains RMS voltage must rise at least this high above
MAINS_MIN before the unit will
switch back on.
• MAINS_MAX (option “K”). Defaults to 260V. If the mains RMS
voltage rises above this threshold,
the output will switch over to the
inverter. It must fall below this by
the hysteresis amount (by default,
below 240VAC) before the output
will switch back to mains.
• MAINS_DELAY (option “L”). Defaults to 10 seconds (10000ms).
This is how long the mains RMS
voltage must be within the normal
range when the output is running
off the inverter before it will switch
back to mains.
• VIN_DELAY (option “M”). Defaults
to 5 seconds (5000ms). Not used
by the current version of the software as the unit shuts down immediately if VIN is below the critical
threshold.
• BATTERY_CRITICAL_DELAY (option “N”). Defaults to five seconds.
If the battery voltage remains below
BATTERY_CRITICAL for this long,
the piezo will sound continuously
for one minute, after which the unit
will shut down entirely.
• VIN_CRITICAL (option “O”). Defaults to 10.5V. If the VIN rail falls
below this value, the unit will automatically de-energise RLY1-3 and
then shut the Arduino control circuitry down. This normally will
only happen when power switch
S1 is turned off.
July 2018 79
Some early UPS feedback from our readers . . .
Why 24V and not 12V?
I must ask the obvious question
–why did you choose a 24V solution, rather than 12V, with the 2 x
12V batteries in parallel?
The 1200W inverters are virtually the same price, 12V or 24V. The
current draw on each individual
battery is the same, 2 x 12V parallel, or 2 x 12V serial.
Using 12V would delete the cost
of a battery balancer, and I would
think the cost of the small 12.6V
transformer (a simple mains-sense
relay could isolate the small Arduino from the now pair of batteries
– imbalanced load not a problem).
The cost of 10A 12V, and 5A 24V
LiFePO4 chargers appears about the
same? Just wondering…?
Ian Thompson
Perth, WA
That seems like a perfectly logical
alternative approach, Ian. But . . .
In fact, as part of our initial deliberations, we briefly considered it
but quickly rejected it. We cannot
recommend it.
The problem is that no two batteries are identical, with the same
internal impedance and open circuit voltage.
That means that they can never
share the load current equally and
ultimately one battery takes more
of the load.
Ultimately, it will lead to a reduction in life, compared to using
the same two batteries in a series
arrangement.
If you want another opinion, see
www.enerdrive.com.au/connecting-epower-b-tec-lithium-batteryseries-parallel
To quote from that site:
"When lithium ion battery packs
are connected in parallel and cycled, matching of internal resistance is important in ensuring long
cycle life of the battery pack.
Specifically, a 20% difference in
cell internal resistance between two
battery packs cycled in parallel can
lead to approximately 40% reduction in cycle life when compared
to two batteries parallel-connected
with the same internal resistance.
Series-connected lithium batteries would have the same reduction
80
Silicon Chip
life if a battery balancer was not used."
Off-peak hot water tones
I have some interest in your latest
UPS design.
My concern is our off-peak hot water signals sent down the mains interferes with lots of devices we have
around the house.
For those not aware of these signals,
it's a higher frequency (500Hz - 1kHz)
signal superimposed over the regular
230VAC, that is used to switch off peak
hot water systems on and off.
Switchmode power supplies mostly deal with it nicely, but not all. One
brand of LED lamps we have pulsate
while the signals are sent, the only
way around it is to experiment with
alternate brands, and replace all those
with more "tolerant" lamps.
My current Eaton UPS isn't immune
either, it commonly false triggers during the signals too.
I have an amplifier that buzzes, and
I used to have a pre-amplifier that had
an over-sensitive mute that conveniently muted audio at the least convenient time twice a day.
My point is, this is a big deal for
us, as much of the side-effects of these
signals are completely unacceptable.
The Arduino mains sense runs at
1000Hz, so it may "see" over voltage
and under voltage conditions hundreds of times a second.
While a passive band-pass filter at
the transformer output might work,
it may interfere with the bad-mains
sense, and this is probably fixable via
firmware anyway.
I'm not being paranoid, I just don't
want to commit to a significant cost
outlay to find out it won't work, and
can't be made to work after all.
John Tserkezis
via email
You raise an interesting point, John.
It is possible that the lightly loaded
transformer we are using to sense the
mains voltage may have an enhanced
response to mains tones signals. However, while the Arduino senses the
mains voltage at 1000Hz, the signal
from the transformer is filtered by the
attenuation network consisting of the
75kΩ and two 50kΩ resistors, shunted
by a 100nF capacitor.
This will have a -3dB point of about
Australia’s electronics magazine
50Hz and the AC signal will be attenuated by 6dB/octave above that. Hence,
a 1050Hz tone signal could be attenuated by about 50dB before sensing by
the Arduino control shield.
If that proves to be insufficient attenuation, it could be increased by using a larger filter capacitor, eg, 220nF
or 330nF.
UPS Inverters are SOLD OUT!
I have been a subscriber to your
excellent magazine for many years,
and have built many projects from
its pages.
When I saw the UPS project in the
May issue, I just had to build it, and
now have all the required components
except for the inverter, which I ordered
from Giandel on 6th March.
On 8th March, I received confirmation from them that my order had been
filled and despatched together with a
tracking number. About a week later,
I received a further email explaining
that unfortunately, this inverter was
out of stock, would not become available for several months, and that my
payment had been refunded.
Since then, I have been searching
for an equivalent inverter, but have
only found one on eBay with an asking price of AUD800+.
My question is: Can you suggest
where I may find a suitable alternative inverter?
Ian Hawke
via email
It appears that the UPS Project has
either been very popular or someone is
looking to make a killing in the hope
that it will be!
A number of readers have pointed
out that the Giandel online store has
sold out of the specific model of inverter that we have used in the UPS Project. The Giandel online store provides
a link to eBay, where the same inverter
can be purchased for $899 (about six
times the price we paid).
Curiously, an otherwise comparable 2200W 24V pure sinewave inverter (almost double the power of the inverter we used) can be purchased for
around $270.
The question we are being asked is
where can these (or an alternative) inverter be purchased.
We have done some research and we
siliconchip.com.au
would look at the following if we were
building a UPS from scratch now:
www.ebay.com.au/itm/332254283761
This is the 2200W inverter we noted
above. It will be substantially larger
than the original inverter, but being Giandel branded and sporting a
wired remote control, would probably
be the most electrically compatible.
There are MANY other cheaper
24V 1200/1500W pure sinewave inverters on ebay – however most do
not have remote control (see below)
and you will have to wait for many
of them to come from China!
www.elinz.com.au/Pure-Sine-Wave-Inverters
One of our staff members has suggested this online supplier, who appear to be based in Melbourne.
They have a 24V, 1500W inverter
(SKU: INTPW24V1500) which is rated slightly higher but not dissimilar
in size – so it should fit. It does not
have a remote control function. At
press time it was on sale at $209.99
www.jaycar.com.au/p/MI5712
The best match from Jaycar appears to be the MI5712, which is currently listed online at near half its
2017 catalog price.
It has a remote controlbut with a
different socket so some changes to
the control wiring and/or circuitry
will be required/
www.altronics.com.au/p/m8018a/
The Altronics M8018A does not
have a remote control facility, but otherwise appears to be suitable.
It's important to note that we have
not tested any of these alternative
inverters, and readers should check
the dimensions, power rating, input
voltage and the presence of a wired
remote control (which may or may not
have the same wiring as our prototype) before buying such an inverter.
Cheaper inverter lacks remote control
I am looking to build the SILICON
CHIP UPS, and online I have found an
inverter that looks suitable, (ie, 24V <at>
1200W) but it does not have a wired
remote control like the one used in
your design. Could I still use it?
Bill Blenkinsole
via email
Yes, but . . . the UPS itself will work
siliconchip.com.au
fine, however the Arduino will not be
able to shut down the inverter in the
event the batteries run down.
If the inverter has an internal lowvoltage cutout, this case may provide
some protection for your batteries. If
there is no low-voltage cutout, then
you run the risk of over-discharging
the batteries.
The inverter will continue to run
even when the UPS is shut down,
meaning the batteries may be slowly discharged if you wish to store or
transport the UPS.
The simplest solution may be a
(large!) relay or switch on the 24VDC
supply brought out onto one of the
panels to allow the inverter to be manually shut down. A relay fed from the
Arduino’s VIN and GND connections
would control the relay in an appropriate manner, but we suspect a relay
large enough to switch 24V (into a
large capacitor on the inverter) at up
to 40A might place an excessive load
on the 12V supply circuits.
LiFePO4 batteries are expensive
I saw your article in the May 2018
issue about building your own UPS
and I thought it was a great idea. So I
started ringing suppliers to put together the items I would need to build it.
I was shocked when I found out that
the batteries alone would cost over
$1000! How can it be competitive with
commercial devices when they're so
expensive? I can buy an Eaton UPS
with a high power output for well under $1000.
DT
via email
Well, we did say up-front (in the
very first sentence!) that it would not
be cheap to build. However, if you hunt
around you should be able to get the
specified LiFePO4 batteries in Australia
for well under $500 each (hint: phone
Master Instruments!).
The fact remains, though, that lithium-based rechargeable batteries are still
considerably more expensive than leadacid types. But they do have considerable performance advantages; primarily, a much longer lifespan if regularly
deeply discharged.
We asked Duraid about how the cost
of building our design compared to similar commercial units and he found the
following:
Australia’s electronics magazine
• The closest commercial equivalent
to our design that Eaton has is the
5P1550GR-L which is a rackmount
UPS with 1100W output and it uses
lithium-ion rechargeable batteries.
Its list price is US$2590 ($AU3450)
– you could definitely build ours for
significantly less.
• They offer no information on its battery capacity or runtime, however,
given that the volume of its case is
around one-quarter of ours, and indeed not much larger overall than
the total volume of the batteries we
used, we don't think it would operate for as long as our unit.
• The Eaton 5P3000RT is a larger unit
(similar in size to our design) that
uses lead-acid batteries. It has a very
high power output (up to 2700W) but
considerably lower battery capacity.
It appears to have around 270Wh of
batteries, ie, just a little over half that
of our design and so its runtime is
substantially lower by comparison,
for a given load power. The cost is
US$2106 ($AU2800); more than
ours would cost to build.
• The Eaton 5P1500R is a one-rack
unit lead-acid based UPS. It costs
US$1308 ($AU1750); similar to
what it would cost to build our design (perhaps slightly less). It also
has a similar power rating at 1100W.
But its runtime is very poor, as it only
has around 160Wh of batteries. At
788W, it would last only eight minutes; our UPS will last around four
times as long!
• The story is similar if you look at
products from other manufacturers. So while our UPS design may
be somewhat expensive to build,
it's still cheaper than its direct commercial equivalents, at least at list
prices and uses better battery technology than about 99% of commercial UPS designs.
• If the cost of the batteries we specified still puts you off, there is nothing stopping you from building it
with cheaper lead-acid batteries.
The total cost would almost certainly be under $1000 then, for a
unit which would still outperform
all the above (more expensive) commercial devices.
You would need to use a different battery charger and it would be
heavier but it would still be a worthwhile exercise.
SC
July 2018 81
|