Pi circuitry, its voltage also passes
through diode D2 which has a
forward voltage drop (Vf) of 0.55V at
1A. Therefore, in the worst-case
scenario (i.e., a dead battery pack),
V
( 6.30V – 0.55V) or less, so the circuit
should function correctly until the
battery pack is fully depleted at 6.3V.
Of course, we’re going to use a
PICAXE processor to monitor the
functioning of our UPS. We’ll display
the real time data for two variables:
the voltage of our main power
supply; and the voltage of our
backup battery pack. So, let’s again
turn our attention to the two voltage-
Figure 1.
Voltage-Sensing Circuit (R1 and R2)
for the Main Supply
We don’t need to know the
actual voltage of the main power
supply. We’re only interested in
whether it’s good or if it has failed.
Therefore, we don’t need an ADC
(analog-to-digital converter) input for
this purpose; we just need to choose
R1 and R2 to produce a digital high
or low voltage at an input pin on the
PICAXE. In order to do that, we need
to know the minimum voltage level
that results in a high input when
using a 3.3V supply.
There are some differences
between PICAXE processors, and
even between specific pins on any
given processor. The details are
presented in the documentation for
the inputtype command in Section 2
of the PICAXE manual. However,
rather than bore you with those
details, we’ll simply use a value of
2.7V which exceeds the minimum
voltage level necessary to produce a
high level on all input pins of all
current PICAXE processors.
With a 12V supply and a
0.55V voltage drop across the
1N5818 diode, if we choose a
68K resistor for R1 and a 22K
resistor for R2, the standard
voltage divider rule yields the
following result:
Therefore, if the line that’s
labeled “Power” in the schematic
is connected to a PICAXE input
pin and the 12V main power
supply is functioning correctly,
the input pin will be in a high
state. On the other hand, if the
main power supply goes down,
R2 will pull the Power input
down to ground, so the input pin
will be in a low state. This gives
us a simple way to know
whenever the main power goes
down. We could also set up a
PICAXE interrupt routine, so that
the program could immediately
respond to the main power
outage.
There is an important caution
about the main supply that I need to
mention. Typical wall wart power
supplies frequently output a voltage
that’s less than or greater than the
stated value. If the voltage is much
below 12V, the input pin may not be
in a high state. More importantly, if
the power supply’s actual voltage is
14V or higher, the input pin will be at
a level that’s higher than 3.3V which
could damage the pin. Therefore, it’s
important to test the specific 12V
supply you intend to use before
connecting the Power line to an input
pin on the PICAXE processor. This
needs to be done when the Pi is
being powered by the main supply
because the voltage level can change
significantly, depending on whether
or not it’s actually providing power.
To check the voltage of your
main supply, power the Pi from it and
measure the voltage at the power
connector on the UPS. The pin at the
back end of the connector is +V and
the shell of the USB connector is
grounded, so it’s easy to do with the
probes of a multimeter.
Voltage-Sensing Circuit (R3 and R4)
for the Battery Pack
For the backup battery supply,
we’re definitely interested in
monitoring the real time analog
voltage level, so we need to connect
the UPS “Batt” line to an ADC input
on the PICAXE processor. We also
need to choose appropriate values
for R3 and R4. When I first built my
UPS, I included all four resistors on
the stripboard circuit. However, as I
was testing the supply, I realized that
I needed to experiment further with
different values for R3 and R4.
To do so, I removed R3 and R4
from the UPS, and modified the
stripboard circuit so that the Batt line
was directly connected to the
positive terminal on the battery pack.
(After we’ve constructed the UPS,
we’ll discuss this issue further.)
Finally, in the schematic of Figure
1, the Power line, the Batt line, and
ground are attached to H1 (a 2x3
10 June 2014
Post comments on this article and find any associated files and/or downloads at
www.nutsvolts.com/index.php?/magazine/article/june2014_PICAXEPrimer.
■ FIGURE 3. Stripboard layout
(two resistors).
R2
Vout = R1 + R2 • 22k Vin = 68k + 22k •
22 (12V -0.55V) = 90 11.45V = 2.80V •