Maker Pro
Maker Pro

How to detect power cutout for PC?

F

Fred Bloggs

I need a circuit that can detect when electricity goes out
and sends a signal to the serial port of my PC, so that a
program that continously listens to the serial port can
understand the situation and send a poweoff command to the
operating system. I already have a simple UPS but I need
such an extra circuit because UPS doesn't last for long.

I have two purposes:

1- Learn how to build such a circuit.

2- Save my PC from unhealthy shutdowns.

I have only beginner's knowledge of electronics
so any resource, URL, etc. that provides
clear instructions will be very useful.

You don't want a line monitoring circuit- you want to break into the UPS
and signal the PC when the battery hits 1.8V/cell or sometime before its
internal cutout threshold if it exists. This would make much more sense,
you will be working with low voltage grounded DC, and no separate
circuit housing or power supply is required.
 
J

Jasen Betts

["Followup-To:" header set to sci.electronics.basics.]
Once I have it working correctly on the hardware level,
it is going to be a "simple matter of programming" for
my Debian GNU/Linux running PC.

you'll be wanting to open /dev/ttyS0 (or ttyS1 etc) and use ioctl() calls
to get the status bits, or I think you can get the OS to send a SIGHUP
signnal when the carrier detect line goes off if you first ctty() to the
serial port.

Bye.
Jasen
 
K

Ken Smith

Mark Zenier said:
Then you run two very simple daemon processes. One reads the serial port
(recommend in raw mode) and reads the current time and writes this to a
shared memory (or a file on ram disk) for each (or every n) character(s).

The characters will be happening about 60 times per second. (600 Baud/10)
The code could prescale the rate down so that the shared memory only gets
updated about twice per second. This would save some CPU time.

Also, I'd put some resistance between the transformer and the serial port
and perhaps a MOV across it. If you unplug the transformer, the inductive
kick could cause trouble.
 
E

ehsjr

John said:
I read in sci.electronics.design that ehsjr <[email protected]>



Will it?

Of course. John, you've got to read the thread. The cap
discussed is a large electrolytic and the example given
was 4,700 uf. The power supply specified was a 12 volt DC
regulated wall wart.

Ed
 
J

John Woodgate

I read in sci.electronics.design that ehsjr <[email protected]>
wrote (in said:
Of course. John, you've got to read the thread. The cap
discussed is a large electrolytic and the example given
was 4,700 uf. The power supply specified was a 12 volt DC
regulated wall wart.
And the current is?

Suppose it's 60 mA. That means the load resistance is 200 ohms. The
time-constant with 4700 uF is 940 ms. After less than a second, the
voltage is down to 0.37 x 12 = 4.4 V. After less than 3 s, it's 0.6 V.
 
R

Rich Grise

And the current is?

Suppose it's 60 mA. That means the load resistance is 200 ohms. The
time-constant with 4700 uF is 940 ms. After less than a second, the
voltage is down to 0.37 x 12 = 4.4 V. After less than 3 s, it's 0.6 V.

Well, DigiKey has a relay (several, actually) with a 12V, 960 ohm coil,
that'd be a time constant of 4.512 S, which would hold up for a glitch,
but that's about it.

Now, if you really insist on letting a cap discharge, just amplify
it. :) Use a MOSFET, although you'd probably want to use another
transistor for a little positive feedback so you'd get a snap
action - I don't know if you'd want your MOSFET to be in the linear
region for 2-3 minutes. :)

Cheers!
Rich
 
R

Rich Grise

The characters will be happening about 60 times per second. (600 Baud/10)
The code could prescale the rate down so that the shared memory only gets
updated about twice per second. This would save some CPU time.

Also, I'd put some resistance between the transformer and the serial port
and perhaps a MOV across it. If you unplug the transformer, the inductive
kick could cause trouble.
Oh, MOVs are _so_ retro! (And they wear out.) Use a TransZorb. :)

Cheers!
Rich
 
M

Mark Zenier

The characters will be happening about 60 times per second. (600 Baud/10)
The code could prescale the rate down so that the shared memory only gets
updated about twice per second. This would save some CPU time.

The OP is in Turkey, so that would be 50 char/sec out of a possible 60
char/sec. On an American power circuit, you'd probably want to configure
the the serial port to "7 bits no parity" so the UART has time to get
reset after the stop bit, to avoid an occasional overrun error.
Also, I'd put some resistance between the transformer and the serial port
and perhaps a MOV across it. If you unplug the transformer, the inductive
kick could cause trouble.

Oops, yea. Or maybe just put an incandescent lamp across the low voltage
AC.

Mark Zenier [email protected]
Googleproofaddress(account:mzenier provider:eskimo domain:com)
 
B

Bob Monsen

Now, if you really insist on letting a cap discharge, just amplify
it. :) Use a MOSFET, although you'd probably want to use another
transistor for a little positive feedback so you'd get a snap
action - I don't know if you'd want your MOSFET to be in the linear
region for 2-3 minutes. :)

No, fred bloggs is on to the answer. Open it, measure the voltage across
it's internal battery, use that as a trigger. Compare it with a reference
built out of a TL431 or something, use that to turn on an optoisolator,
used to drive the input signal, perhaps a parallel port pin. This gives
him a signal only when it is required.
 
E

ehsjr

John said:
I read in sci.electronics.design that ehsjr <[email protected]>

And the current is?

Suppose it's 60 mA. That means the load resistance is 200 ohms. The
time-constant with 4700 uF is 940 ms. After less than a second, the
voltage is down to 0.37 x 12 = 4.4 V. After less than 3 s, it's 0.6 V.

John, *READ* the thread!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
"If you use a relay with a high coil resistance, such as
Radio Shack #275-248 and a 4,700 uF 16 volt (or higher)
capacitor, you will get a few seconds delay. The higher
the coil resistance and/or the higher the capacitance,
the longer the delay. For example, and Omron G5V-1-2-DC12
relay has more than twice the coil resistance as the
Radio Shack relay. If you used that relay, you would
get a delay approaching 10 seconds."
 
E

ehsjr

Rich said:
Well, DigiKey has a relay (several, actually) with a 12V, 960 ohm coil,
that'd be a time constant of 4.512 S, which would hold up for a glitch,
but that's about it.

Now, if you really insist on letting a cap discharge, just amplify
it. :) Use a MOSFET, although you'd probably want to use another
transistor for a little positive feedback so you'd get a snap
action - I don't know if you'd want your MOSFET to be in the linear
region for 2-3 minutes. :)

Cheers!
Rich

The brief delay is all he needs. He can sense the relay with
software once every desired_delay_time and won't need a routine
that says if power bad, sense again in 4 seconds, if power
still bad, signal.

However, since people seem to think the full delay needs to
be in hardware, the cap amplifier is a good idea. I did that a
long time ago, with bjt. Here are two circuits, aimed at the OP's
self-described level of familiarity (and perhaps a bit beyond it).
I think the first is the simplest of the two for the OP to get
longer hardware delay - it yields about 1 1/2 minutes delay as
drawn.


1N400x
+----|<-----+
| |
| 5V | 166 ohm relay
+12 VDC---7805 ---[10R]---+---Relay---+
| | |
| === 1F 5.5v |
| | |
Gnd --------+-------------+-----------+


For more delay, he can parallel another supercap or super caps.

======================================================

It gets a bit more complex below, for some newbies.

Converting the relay circuit to transistor driven, he needs 2
power supplies - one to sense the line drop, the other to power
the circuit.

Here's an actual circuit (slightly modified) that is in use with a
30 amp Bosch (88 ohm AIRC) automotive relay, using a power darlington:

D1
+------------>|----------+
| D2 |
| +----->|----+
| | | D3
Power | +---[Ry1]---+---|<--- +12 from UPS
Sensing | | powered
Wall Wart | / wall wart
+12 ---+----+---[R1]---| Q1
| | e\ +-------- Gnd
[C1] [POT]* | |
| | | |
Gnd ---+----+------------+-----------+


C1 - 4,700 uF 16v (470 used in original for ~ 40 S delay)
D1-3 - 1N400x
Q1 - TIP 120
POT - 100K (* = if desired for delay adjustability)
R1 - 4.7 K
Ry1 - Any 12 volt relay.

The use of wall warts is specifically intended to avoid using
any circuitry inside UPS. From his post, it is highly doubtful
that the OP would have the confidence or capability to tap into
the existing circuits.

Ed
 
P

Pooh Bear

ehsjr said:
The addition of the cap adds a delay

No it doesn't.
that is useful to
ignore power "blips", and the circuit is within the
restriction of "newbie trying to find my way". So saying
"it won't do any good anyway" makes one wonder what
that other poster had in mind. As it turns out, that poster
seems not to understand what adding the cap does.

Funny that !

I've designed more power supplies than you could shake a stick at.
He said:
"Shoving a cap across even a DC output won't result in a
noticeable time delay!"

Indeed it won't.

It simply makes the reservoir cap bigger and reduces ripple.

To make a delay you need an *RC* network !

You don't seem equipped even to understand the very basics of electricity.

Graham
 
P

Pooh Bear

ehsjr said:
Of course. John, you've got to read the thread. The cap
discussed is a large electrolytic and the example given
was 4,700 uf. The power supply specified was a 12 volt DC
regulated wall wart.

So ?

I can't find a note of the power rating but lets say it's 6W - so can
supply 500mA.

dV/dt = I /C
delta t = C * delta V / I = 4700*10^-6 * 12 / 0.5 = 113ms

113 milliseconds isn't much of a delay.

And actually the current available to charge the C will be > the steady
state figure making delta t shorter than above anyway.

Graham
 
P

Pooh Bear

ehsjr said:
John, *READ* the thread!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
"If you use a relay with a high coil resistance, such as
Radio Shack #275-248 and a 4,700 uF 16 volt (or higher)
capacitor, you will get a few seconds delay. The higher
the coil resistance and/or the higher the capacitance,
the longer the delay. For example, and Omron G5V-1-2-DC12
relay has more than twice the coil resistance as the
Radio Shack relay. If you used that relay, you would
get a delay approaching 10 seconds."

You're not very good at this electricity stuff are you ?

Why not learn some basic science ?

Graham
 
P

Pooh Bear

Rich said:
Well, DigiKey has a relay (several, actually) with a 12V, 960 ohm coil,
that'd be a time constant of 4.512 S, which would hold up for a glitch,
but that's about it.

Please *please* explain how the resistance of a relay coil across a 12V
supply affects the charge time for a parallel cap !

Graham
 
P

Pooh Bear

Bob said:
No, fred bloggs is on to the answer. Open it, measure the voltage across
it's internal battery, use that as a trigger. Compare it with a reference
built out of a TL431 or something, use that to turn on an optoisolator,
used to drive the input signal, perhaps a parallel port pin. This gives
him a signal only when it is required.

Or use a PIC ! ;-)

Graham
 
F

Fred Bloggs

Pooh said:
Bob Monsen wrote:




Or use a PIC ! ;-)

Graham

Quite the bad mood ehh? A simple Radio Shack project would be like so-
you don't like the direct coupling?- then use an optocoupler:
View in a fixed-width font such as Courier.

..
.. 7805/TO-220
.. ------- 1K
.. +----|IN OUT|---+----+--------+-----+ +-/\/\--<RTS
.. | | | | | | | |
.. | | GND | +|1u | | | |
.. | ------ === | | | +------->CTS
.. | | |10V | | | |
.. | 0.1u | | | | | | 1N914
.. +--||----+-------+ / | / +-|<|--+-COM
.. | 50V | \ | \ | |
.. | GND 47K / | 4.7K/ | |
.. | \ | \ | |
.. | | | | | |
.. | +--/\/\--|-----+ | |
.. | | 1M | | | |
.. | | | | | |
.. | 110K | | \ | c |
.. Vbatt>-+--/\/\--+---+---------------|- \ | 10K |/ |
.. | | | | >---+-/\/\-|2N4401 |
.. Vbatt | | | +--|+ / |\ |
.. ----- -> | | | | | / e |
.. 12 / +|2.2u / | | LM339 | |
.. 10K \ === \<--+ | | |
.. / |10V 50K / | | |
.. \ | \ | | |
.. | | 15T | | | |
.. | | | | | |
.. +------------+---+--------+--------+--------------+------+
.. |
.. - -
.. GND
..
 
F

Fred Bloggs

Might as well help out that 7805 with input ripple rejection- this works
for 12V or 24V:
View in a fixed-width font such as Courier.

..
.. 7805/TO-220
.. ------- 1K
.. +----|IN OUT|-+------+--------+-----+ +-/\/\--<RTS
.. | | | | | | | |
.. | | GND |+|1u | | | |
.. | ------ === | | | +------->CTS
.. | 50V | |10V | | | |
.. | 0.1u | | | | | | 1N914
.. +--||----+-----+ / | / +-|<|--+-COM
.. | + | \ | \ | |
.. +-----||-------+ 47K / | 4.7K/ | |
.. | 22u/35V | \ | \ | |
.. / GND | | | | |
.. 100 \ +--/\/\--|-----+ | |
.. / | 1M | | | |
.. \ | | | | |
.. | 110K | | \ | c |
.. Vbatt>-+--/\/\--+---+---------------|- \ | 10K |/ |
.. | | | | >---+-/\/\-|2N4401 |
.. Vbatt | | | +--|+ / |\ |
.. ----- -> | | | | | / e |
.. 12 / +|2.2u / | | LM339 | |
.. 10K \ === \<--+ | | |
.. / |10V 50K / | | |
.. \ | \ | | |
.. | | 15T | | | |
.. | | | | | |
.. +------------+---+--------+--------+--------------+------+
.. |
.. - -
.. GND
..
 
R

Rich Grise

Please *please* explain how the resistance of a relay coil across a 12V
supply affects the charge time for a parallel cap !

It doesn't. It affects the _discharge_ time. :)

Cheers!
Rich
 
E

ehsjr

Pooh said:
ehsjr wrote:




No it doesn't.




Funny that !

I've designed more power supplies than you could shake a stick at.




Indeed it won't.

It simply makes the reservoir cap bigger and reduces ripple.

To make a delay you need an *RC* network !

You don't seem equipped even to understand the very basics of electricity.

Graham

Graham,

I don't know why you are missing this, but what you present as
fact is blatantly and repeatedly wrong. You seem so intent on
making belittling comments - maybe that's why you are missing
it. If you breadboard the circuit you'll be able to see the
delayed relay dropout with the cap. Or if you rely on your opinion
of the poster instead of math or breadboarding, then think about
what John Woodgate or Rich Grise said concerning the delay. I
assume you have a high opinion of them?

Ed
 
Top