Searching \ for '[PIC:] AC zero-crossing circuit idea (LM339 hints?' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/power.htm?key=ac
Search entire site for: 'AC zero-crossing circuit idea (LM339 hints?'.

Exact match. Not showing close matches.
PICList Thread
'[PIC:] AC zero-crossing circuit idea (LM339 hints?'
2004\10\21@161535 by Chris Loiacono

flavicon
face
Forget the comparator idea, it's fraught with problems. Where'd that come
from anyway, someone on the Basic Stamp list?

An opto is the way to go. You may also think about using more than one opto
in series to increase the life of the PIC.

CL

Subject: [EE:] [PIC:] AC zero-crossing circuit idea (LM339 hints?)


I am designing a PIC circuit which needs to stay synchronized
with the AC line's zero-crossing point.  I want to arrange things
so that the PIC gets an interrupt every time the AC voltage
crosses 0V.

My original idea used an H11AA1 optoisolator as shown in this
schematic:  http://home.quixnet.net/xyzzy/ee/zcopto.gif

The optoisolator connects the INT line on the PIC to ground when
there's an AC voltage, but when it goes to near 0V, it turns off
and lets the INT line pull up to +5V, interrupting the PIC.

Someone on another list suggested I use an LM339 comparaotr
instead of the optoisolator, but I'm not that savvy about this
component.  His suggestion was like this:
http://home.quixnet.net/xyzzy/ee/zccomp.gif

Does this look right?  Does it look like a better design than the
optoisolator?

____________________________________________

2004\10\21@173610 by David Minkler

flavicon
face
As Desi would have said, "Ohhh Luuucy, you got some 'splainin to do".

Dave

Chris Loiacono wrote:

>You may also think about using more than one opto
>in series to increase the life of the PIC.
>


____________________________________________

2004\10\21@175846 by Jinx

face picon face
> >You may also think about using more than one opto

http://home.clear.net.nz/pages/joecolquitt/txless.html

A transformer isn't always available

____________________________________________

2004\10\21@214400 by Mike Reid

picon face
In our lighting control system, we use an opto isolator that is a
schmitt triggered gate. I forget the part number as I'm out of the
office now. Our circuit is just a voltage divider off the mains feed. I
think it's a couple of 15k resistors for the 120 VAC model and 30k for
the 240 VAC version. The schmitt trigger gives a very clean trigger for
the zero cross detect.


{Original Message removed}

2004\10\22@084301 by Eisermann, Phil [Ridg/CO]
flavicon
face
piclist-bounces@mit.edu wrote:
> An opto is the way to go. You may also think about using more than
> one opto in series to increase the life of the PIC.
>

why is that? I have used optos on 230V with no problems. Two
current-limiting resistors, one on each side of the opto.

If there is a reason to use more than one opto in series, I'd
love to hear it, please.
____________________________________________

2004\10\22@092113 by Bill & Pookie

picon face
Think it takes 0.6 volts to get a diode to conduct.  Therefore two
diodes/rectifiers in series will drop 1.2 volts.  By putting the two
diodes/rectifiers , biased the same as the opte's diode, in parallel with
the opto, you limit the forward voltage to the opto to 1.2 volts.  And you
may not need a current limiting resistor.

Then a single diode/rectifier biases in the opposite direction across the
circuit will limit the reverse voltage across the opto's diode to 0.6 volts.

Or....  you can replace the single diode/rectifier (to limit reverse
voltage) by putting a second opto/(diode/rectifier pair) across the first
but bias in reverse direction.  This will protect both opto diodes from
excessive forward and reverse voltage.  And give you another pulse.

Bill

{Original Message removed}

2004\10\22@122244 by David Minkler

flavicon
face


Bill & Pookie wrote:

>Think it takes 0.6 volts to get a diode to conduct.  Therefore two
>diodes/rectifiers in series will drop 1.2 volts.  By putting the two
>diodes/rectifiers , biased the same as the opte's diode, in parallel with
>the opto, you limit the forward voltage to the opto to 1.2 volts.  And you
>may not need a current limiting resistor.
>  
>
What limits the current through the series pair?  How do I get control
over the current through the opto diode?  What if the opto's diode needs
more (or less) than two diode drops to respond correctly?  What about
temperature effects?  Current through the opto's LED is what you are
really trying to limit.  If you limit current through it, the opto's
diode will manage its own Vf.  A properly sized resistor is a cheap
reliable solution.

>Then a single diode/rectifier biases in the opposite direction across the
>circuit will limit the reverse voltage across the opto's diode to 0.6 volts.
>  
>
Certainly a good idea if significant reverse potential is possible.  You
still need to limit current through that diode.

>Or....  you can replace the single diode/rectifier (to limit reverse
>voltage) by putting a second opto/(diode/rectifier pair) across the first
>but bias in reverse direction.  This will protect both opto diodes from
>excessive forward and reverse voltage.  And give you another pulse.
>
If you need it.

Dave


____________________________________________

2004\10\22@131640 by Eisermann, Phil [Ridg/CO]

flavicon
face
piclist-bounces@MIT.EDU wrote:
> Think it takes 0.6 volts to get a diode to conduct.  Therefore two
> diodes/rectifiers in series will drop 1.2 volts.  By putting the two
> diodes/rectifiers , biased the same as the opte's diode, in parallel
> with the opto, you limit the forward voltage to the opto to 1.2
> volts.  And you may not need a current limiting resistor.

you mean like this (crude ascii)?

-+->|-->|--+-
|         |
+--->|----+

unless I misunderstood your description, I'm not sure how you intend
this to work, especially without a resistor.

you'll still need a current limiting resistor, and preferably two to
reduce the voltage stress on the resistors. e.g. calculate the resistor
value, then use 1/2 that value on either side. For ac-line sensing,
consider getting an opto designed for this, such as H11AA series or LTV-814
They have two back-to-back diodes instead of just one.
____________________________________________

2004\10\22@143526 by Jan-Erik Soderholm

face picon face
Bill & Pookie

> Then a single diode/rectifier biases in the opposite
> direction across the
> circuit will limit the reverse voltage across the opto's
> diode to 0.6 volts.
>
> Or....  you can replace the single diode/rectifier (to limit reverse
> voltage) by putting a second opto/(diode/rectifier pair)
> across the first
> but bias in reverse direction.  This will protect both opto
> diodes from
> excessive forward and reverse voltage.  And give you another pulse.

All this seems highly over complicated.

Why not just use a single "AC-opto" with a single
current limiting resistor ???

Jan-Erik.
____________________________________________

2004\10\22@152456 by Byron A Jeff

face picon face
On Fri, Oct 22, 2004 at 08:35:25PM +0200, Jan-Erik Soderholm wrote:
> Bill & Pookie
>
> > Then a single diode/rectifier biases in the opposite
> > direction across the
> > circuit will limit the reverse voltage across the opto's
> > diode to 0.6 volts.
> >
> > Or....  you can replace the single diode/rectifier (to limit reverse
> > voltage) by putting a second opto/(diode/rectifier pair)
> > across the first
> > but bias in reverse direction.  This will protect both opto
> > diodes from
> > excessive forward and reverse voltage.  And give you another pulse.
>
> All this seems highly over complicated.
>
> Why not just use a single "AC-opto" with a single
> current limiting resistor ???

The other two soltions are acceptable also and only raises the component
count by one part. The key thing is that you need two anti-parallel diodes
and a current limiting resistor.

The last time I did such a circuit was for the trigger detect for a motion
detector. I used an opto, an antiparallel LED that lit locally when the
detector was activated and a 10K 2W resistor. I didn't care about the phase
of the pulses, just that they were generated.

BAJ
____________________________________________

2004\10\22@213015 by Bill & Pookie

picon face
The  circuit was intended to sense current to a model train.  I liked it for
that purpose.  But it may not suite your needs.  What it does do is since AC
or DC current, can withstand any current or voltage, and only affects the
circuit with a 1.2 V drop.  Witch is nothing at all condersiddering today's
inflation.

The two diode/rectifier pairs can be as delicate or as robust as needed.
They are acting as a rectifier and small ones can handle a amp.  It is a
case of  "I don't gota show you no stinking badges!"  But you do need a load
in the circuit to protect the power supply, else it would be basically a
short circuit.

The diodes in the opto's are basically led's and if you insure that the
voltage across a led will never exceed 1.2 V,  do you still need a limiting
resister?  Does a limiting resistor limit the current or does it use the
current to limit the voltage?

If there is not a load on the circuit, then the simplest implementation
would be to parallel a small diode (or a led if you want a indicator)
(reversed bias) across the opto's diode and put a limiting resistor in
series with that parallel circuit.

Bill

{Original Message removed}

2004\10\23@091247 by Jan-Erik Soderholm

face picon face
Bill & Pookie wrote :

> The diodes in the opto's are basically led's and if you
> insure that the voltage across a led will never exceed 1.2 V,

What "1.2 V" ?
Are you talking about the "forward volatge drop" ?
That varies from one LED to another, I'd guess. The data
sheet will give the correct value. But, it's not *that*
interesting, since you don't want to drive a LED
from a constant *voltage* source anyway.

You do not limit the *voltage across* the LED, you limit
the *current through* the LED !!

This is no different then any diod actualy. If you connect
a standard diod to a constant *voltage* source
a little above the "forward voltage drop", you will blow it.

> do you still need a limiting resister?

Yes.

> Does a limiting resistor limit the current

Yes. It *is* a "current limiting resistor".

> or does it use the current to limit the voltage?

No.

Jan-Erik.

____________________________________________

2004\10\23@093221 by Martin McCormick

flavicon
face
"Mike Reid" writes:
>In our lighting control system, we use an opto isolater that is a
>schmitt triggered gate. I forget the part number as I'm out of the
>office now.

       That right there is the trick.  The part isn't detecting a
zero-crossing but is providing a stable reference point in the cycle.
That Schmitt Trigger is going to change state at precisely the same
points in the cycle every time.  Actually, it's the same points in the
half-cycle.  If you want each half-cycle to trigger which you most
likely would in a lighting controller, then put a full-wave bridge
ahead of the LED in the opto.  Your 15 or 30-K resistors would most
likely go between the two AC inputs to the bridge and the mains.

       There is nothing sacred about a circuit like this detecting
the exact point in which there are 0 volts on the line.  That's not
practical.  What is sacred is that the timing doesn't advance or
retard from cycle to cycle.

       The temperature of the circuit will change the trigger point
slightly, but precious little.  We are talking about a sinusoidal
signal that goes from 0 to 170 volts for 120-volt mains or up to 325
volts for 230-volt service.  This signal is being clipped down to
something like 1.5 volts by the LED as soon as that much voltage is
across it.  I haven't done the trigonometry, but that's pretty close
to 0 anyway you look at it.

       One thing that has crossed my mind is the fact that spikes can
appear on a power line from inductive loads.  This would certainly be
picked up by the opto circuit and could confuse the timing of the next
firing of the triac in the lighting controller or whatever is being
regulated.  I would think that one would need a snubbing circuit on
the opto isolater to keep only the slow sine wave signal and not pass
any spikes.

Martin McCormick WB5AGZ  Stillwater, OK
OSU Information Technology Division Network Operations Group
____________________________________________

2004\10\23@093805 by Dave VanHorn

flavicon
face

>
>         One thing that has crossed my mind is the fact that spikes can
>appear on a power line from inductive loads.  This would certainly be
>picked up by the opto circuit and could confuse the timing of the next
>firing of the triac in the lighting controller or whatever is being
>regulated.  I would think that one would need a snubbing circuit on
>the opto isolater to keep only the slow sine wave signal and not pass
>any spikes.

Depending on how much horsepower you have available, you can disable the
int until a little bit before it should occur, and/or average the time
between crossings and throw away anything that varies more than say 1-5%.

Beware! Power utilities DO vary the grid frequency by small amounts.  Your
AC powered clock is a good example of how the grid is stable long term,
because the utilities actually hand-tweak it, but also unstable in the
short term.  I used to watch the school clocks slow down when the local
steel mill arced it's furnace. (hawaii, not on the national grid)

____________________________________________

2004\10\23@100854 by Martin McCormick

flavicon
face
Dave VanHorn writes:
>Depending on how much horsepower you have available, you can disable the
>int until a little bit before it should occur, and/or average the time
>between crossings and throw away anything that varies more than say 1-5%.

       That would certainly work.

>Beware! Power utilities DO vary the grid frequency by small amounts.  Your
>AC powered clock is a good example of how the grid is stable long term,
>because the utilities actually hand-tweak it, but also unstable in the
>short term.  I used to watch the school clocks slow down when the local
>steel mill arced it's furnace. (hawaii, not on the national grid)

       One would only have to worry about the time between each half-cycle.
The stopwatch, as it were, would start new upon receipt of each new
half-cycle signal.  With the exception of catastrophic failure, the
cycle to cycle variation is almost nill.
____________________________________________

2004\10\23@131125 by Dave VanHorn

flavicon
face

>
>         One would only have to worry about the time between each half-cycle.
>The stopwatch, as it were, would start new upon receipt of each new
>half-cycle signal.  With the exception of catastrophic failure, the
>cycle to cycle variation is almost nill.

I only mentioned it because it's important to understand the difference
between long term accuracy and short term stability.

____________________________________________

2004\10\23@170630 by Jinx

face picon face
> short term.  I used to watch the school clocks slow down when the
> local steel mill arced its furnace. (hawaii, not on the national grid)

Many lessons have the same effect .......

(My CLOQ logo has a dial frozen at 2:55 in honour of 7th period
Geography on Friday afternoon. Took forever to reach 3:00pm)

> > I would think that one would need a snubbing circuit on the opto
> > isolater to keep only the slow sine wave signal and not pass any
> > spikes

If you're expecting or don't want to be caught out by spikes then the
circuit should be physically protected from them anyway

> average the time between crossings and throw away anything that
> varies more than say 1-5%.

That works. Also you can synch an internal timer so that any mains
drop-out or anomaly doesn't upset timing functions or h/w output

____________________________________________

2004\10\24@103647 by Bill & Pookie

picon face
Thanks, I now see the light.

The 1.2 V is the voltage drop across two other diodes in my circuit that are
in parallel with the opto.

See now that if the diode had some sort of internal current limiting device,
the voltage drop across it would change, and it doesn't.    It would need an
internal variable resistor.But in meantime must remember to always put in
limiting resisters.

Thanks for help.

Bill

{Original Message removed}

2004\10\24@163301 by Steve Willoughby

flavicon
face
Thanks to all who offered suggestions for the AC zero-crossing
detector.  I will experiment some with a couple of the ideas presented
here and see how it all goes.  I'm intrigued by one idea someone
pointed me to, which is just to connect the PIC's interrupt pin
directly to the 120V AC line without transformer, isolator, or
anything:
                                _______
       NEU <--------3 || E-----|Rect.  |----> +
120V AC              3 || E     |Bridge |
       HOT <----*---3 || E-----|_______|----> GND
                |
                |                     ______________
                +-------/\/\/\/------| RB0/INT      |
                          5M         |              |
                                     | PIC16F777    |
                                     |______________|

Now, color me paranoid, but this makes me a little nervous :)
The basic idea is that the 5M resistor drops the current to
about 36uA (at 120V), which is safe for the PIC, but it's still
at 120V (or, if I get my RMS calculation right, 169.7V peak)
on a pin that shouldn't see more than 5V.  Or am I forgetting
a voltage drop in there somewhere?  (Also, I don't see that
the resistor needs to be any significant size, 1/4W or so,
if I take 36uA at 170V, that's like 6mW... does that sound
right?)  Sorry if that's such a basic question, but I want
to be sure I'm right when doing anything with mains voltage :)

This idea comes from Microchip's own appnotes, though, and they
(Microchip) claim that this is all okay, and the internal static
protection diodes in the PIC will clamp the overvoltage just fine.

Has anyone else done this?  Is there perhaps a more refined version of
this circuit which would be better, or ought this to be adequate as
drawn above?

--
Steve Willoughby     | "It is our choices... that show what we truly
<spam_OUTsteveTakeThisOuTspamalchemy.com>  | are, far more than our abilities."
                    |     --Albus Dumbledore, in Harry Potter and the
                    |            Chamber of Secrets, by J. K. Rowling

____________________________________________

2004\10\24@175731 by Jose Da Silva

flavicon
face
On Sunday 24 October 2004 01:29 pm, Steve Willoughby wrote:
> Thanks to all who offered suggestions for the AC zero-crossing
> detector.  I will experiment some with a couple of the ideas presented
> here and see how it all goes.  I'm intrigued by one idea someone
> pointed me to, which is just to connect the PIC's interrupt pin
> directly to the 120V AC line without transformer, isolator, or
> anything:
>                                  _______
>         NEU <--------3 || E-----|Rect.  |----> +
> 120V AC              3 || E     |Bridge |
>         HOT <----*---3 || E-----|_______|----> GND
>
>                  |                     ______________
>
>                  +-------/\/\/\/------| RB0/INT      |
>                            5M         |              |
>
>                                       | PIC16F777    |
>                                       |______________|

I missed reading some of the other postings, but That isn't going to work.

According to the diagram above, you have your circuitry isolated behind a
transformer. The PIC pin has to be in "reference" to something, and
according to that diagram, you only have one pin going out to the main
120vac side. If the GND on your circuit doesn't connect to the NEU on the
120v side, you don't have a reference, if it does, then you have a
reference, but you also have the potential to electrocute someone if someone
plugs the circuit in backwards to the 120v side (exposing your GND to HOT!).

> Now, color me paranoid, but this makes me a little nervous :)

For safety's sake, put all your circuitry behind the safety of the
transformer unless you really know what you are doing!!!
Use an opto-isolator to get your zero crossing signal and put your opto-input
on the 120vac side if you want to get your crossing directly from the AC.

{Quote hidden}

Yes it will, but it won't take care of a lightning spike.
The other thing is that the PIC is running on HOT lines, so the entire
circuit must be isolated from any external GND, CHASSIS, etc or you must be
200% sure that your circuit is never plugged in where the HOT is plugged
into the NEU and the NEU into the HOT.
If you connect to an external GND of any sort, you have a problem, including
something as simple as a metal chassis and you standing in a puddle of water
to complete the circuit.

> Has anyone else done this?  Is there perhaps a more refined version of
> this circuit which would be better, or ought this to be adequate as
> drawn above?

If you want to be on the safe side by keeping everything behind the
transformer.  Monitor the 5v to 0v transistion, when that happens, add a
delay XuSec for your zero crossing because with an 8v transformer, the 5v to
zero volt transistion happens significantly early. Since you are dealing
with a full-wave bridge, you could probably try something like this:

        NEU <-3 || E--|Rect.  |--+--|>|--> +
120V AC       3 || E  |Bridge |  |
        HOT <-3 || E--|_______|----------> GND
                                 |
                                 Z 10k
                                 |     ______________
                                 +----| RB0/INT      |
                                 |    |              |
                            100k Z    | PIC16F777    |
                                 |    |______________|
                                GND

You can do the math to figure out what the delay XuSec is needed, or if you
are not willing to do the math, then you can experiment to find the zero
crossing.

Hopefully that helps you keep it safe ;-)
____________________________________________

2004\10\24@180139 by Gerhard Fiedler

picon face
>                                  _______
>         NEU <--------3 || E-----|Rect.  |----> +
> 120V AC              3 || E     |Bridge |
>         HOT <----*---3 || E-----|_______|----> GND
>                  |
>                  |                     ______________
>                  +-------/\/\/\/------| RB0/INT      |
>                            5M         |              |
>                                       | PIC16F777    |
>                                       |______________|
>
> (Also, I don't see that
> the resistor needs to be any significant size, 1/4W or so,
> if I take 36uA at 170V, that's like 6mW... does that sound
> right?)  

> Has anyone else done this?  Is there perhaps a more refined version of
> this circuit which would be better, or ought this to be adequate as
> drawn above?

This can work. But you only get an interrupt every other zero transition. I
probably would put two protective diodes in, just to be sure :)

The question is why not take the signal from the secondary coil of the
transformer. Seems safer... but the zero detection won't be as "sharp".

The resistor power rating is not that critical, but its voltage rating is.

As with all the circuits, you need to take into account that you don't
really get the zero transition, but are a bit off. Which may or may not be
significant, depending on the "bit" you're off and the requirements. With a
comparator on the secondary coil, you can get very close to the actual zero
crossing (if that's needed).

Gerhard
____________________________________________

2004\10\24@182322 by Steve Willoughby

flavicon
face
On Sun, 24 Oct 2004, Gerhard Fiedler wrote:
> This can work. But you only get an interrupt every other zero transition. I
> probably would put two protective diodes in, just to be sure :)

The appnote which suggests this also says to have your interrupt handler
swap the interrupt control bit every time, so it's rising-edge triggered,
then falling-edge, and so forth, so you will get an interrupt every crossing.

> The question is why not take the signal from the secondary coil of the
> transformer. Seems safer... but the zero detection won't be as "sharp".

The only reason is for the phase offset you'll get from the tansformer.
Personally, I'd like to still have an isloator on it, though, it just
seems way safer.

--
Steve Willoughby     | "It is our choices... that show what we truly
<.....steveKILLspamspam@spam@alchemy.com>  | are, far more than our abilities."
                    |     --Albus Dumbledore, in Harry Potter and the
                    |            Chamber of Secrets, by J. K. Rowling

____________________________________________

2004\10\24@190807 by Bob Axtell

face picon face
Actually, I'm surprised that Microchip recommended this circuit. It is
poor engineering practice in several ways.

The MAIN problem with it is that the 5M resistor has to holdoff a LOT
of voltage (P-P 180V), and many small resistors are not designed to do it
very well. In essence, its possible that a "flashover" could occur in
the resistor
itself and damage the device. What about a high-humidity day? Also, the raw
120V might take lightning spikes, etc. If you insist on using it, break
the 5M
into several  1M - 2M resistors in series to reduce the preassaure on
any one.

But the safer method is to drive it from the secondary side of the
transformer,
with the R being MUCH lower in value. The transformer will still pass
lightning
spikes, but they will be greatly attenuated. I'd place a Zener diode
(rated VCC+0.6V)
from the PIC pin to GND.

--Bob


Steve Willoughby wrote:

{Quote hidden}

--
Note: Attachments must be sent to
attachspamKILLspamengineer.cotse.net, and
MAY delay replies to this message.
       520-219-2363

____________________________________________

2004\10\24@191001 by Steve Willoughby

flavicon
face
On Sun, 24 Oct 2004, Jose Da Silva wrote:
> Use an opto-isolator to get your zero crossing signal and put your opto-input
> on the 120vac side if you want to get your crossing directly from the AC.

I think that makes a great deal more sense than taking the appnote so
literally (yes, I know they're supposed to be more concepts to get you
started than actual finished designs).  There's just too much to deal with
in avoiding getting mains voltage where you don't want it.

I still like the idea I was originally going with, of just using an opto
to generate a positive-going pulse every crossing:
                         ______
      <---3 || E-----*--|Rect. |---->+5V
120V AC    3 || E     |  |Bridge|
      <---3 || E---*----|______|---->GND
                   | |
                   | Z
                   | Z                +--\/\/\-->+5V
                 __|_|_______         |           _____________
                | H11AA1     |--------*----------| RB0/INT     |
                |  Opto      |                   |             |
                |____________|-->GND             |_____________|

The H11AA1 has AC input (2 LEDs back-to-back) and NPN bipolar output
so it connects INT to GND all the time except when the AC current is
too low to light the LEDs, so pretty close to the zero crossing point.

The problem with this is the transformer output being out of phase
with the 120V input, but since this is trying to dim 120V lights it's
got to be synced with that side.

So I can either try putting the optoisolator input on the 120V side
of the transformer or else leave it on the low-voltage side and
use software in the PIC to compensate for the phase delay.

--
Steve Willoughby     | "It is our choices... that show what we truly
<.....steveKILLspamspam.....alchemy.com>  | are, far more than our abilities."
                    |     --Albus Dumbledore, in Harry Potter and the
                    |            Chamber of Secrets, by J. K. Rowling

____________________________________________

2004\10\24@191727 by Steve Willoughby

flavicon
face
On Sun, 24 Oct 2004, Bob Axtell wrote:
> Actually, I'm surprised that Microchip recommended this circuit. It is
> poor engineering practice in several ways.

Yeah, me too... I looked at it and said, "okay... well, they must know
what they're doing, but... but..."

--
Steve Willoughby     | "It is our choices... that show what we truly
<EraseMEstevespam_OUTspamTakeThisOuTalchemy.com>  | are, far more than our abilities."
                    |     --Albus Dumbledore, in Harry Potter and the
                    |            Chamber of Secrets, by J. K. Rowling

____________________________________________

2004\10\24@193713 by olin_piclist

face picon face
Steve Willoughby wrote:
> I'm intrigued by one idea someone
> pointed me to, which is just to connect the PIC's interrupt pin
> directly to the 120V AC line without transformer, isolator, or
> anything:

Not without anything.  The 5Mohm is a lot of something.

{Quote hidden}

OK, you're paranoid.

> but this makes me a little nervous :)

You should be nervous with this setup, but something like it can be
appropriate in the right circumstances.  The biggest drawback is that the
PIC is not isolated from the AC line.  That's OK in some self contained
units, but not if the PIC connects to jacks or other things the user can
connect to or touch.  If isolation is not an issue, then there is nothing
wrong with a few 10s of uA thru the protection diodes.

The part I don't like is the full 170V plus spikes accross a single
resistor.  I'd prefer at least two resistors with maybe a capacitor to
ground in the middle, or three resistors.  Two form a voltage divider and
the third goes from the divider to the PIC pin.

Still if this is a high volume design for a low cost product where the cost
of failure is just "buy another one", the single resistor could be
appropriate.  Of course in that case you'd very unlikely have a transformer
in there.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com
____________________________________________

2004\10\24@193918 by p.cousens

flavicon
   

     <---- LAMPS ------AC      + ------+------------- D

120V AC                   bridge        = .1uf/100R    G  FET
     <-----------------AC      - ------+------------- S

PWM the fet via an opto, zero crossing not required

{Original Message removed}

2004\10\24@194158 by olin_piclist

face picon face
Gerhard Fiedler wrote:
> This can work. But you only get an interrupt every other zero
> transition.

There are some easy ways to deal with this.  First, the power line frequency
is quite accurate, so a timer will tell you very well where the second zero
crossing is if you know the first.  Second, it's only a few instructions to
change the edge polarity of the interrupt every interrupt.  You only have to
do this ever 8.3mS.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com
____________________________________________

2004\10\25@032310 by Ake Hedman

flavicon
face
Just a follow up questin on this.

If you let the complete circuit be on the "live" side  by skipping the transformer etc and using  opto couplers to interface the real world with some serial interface.Is there still some problems to look out for  (taking the resistor suggestions into account)? Any reasons not to?

/Ake

Steve Willoughby wrote:

{Quote hidden}

--  ---
Ake Hedman (YAP - Yet Another Programmer)
eurosource, Brattbergavägen 17, 820 50 LOS, Sweden
Phone: (46) 657 413430 Cellular: (46) 73 84 84 102
Company home: http://www.eurosource.se      Kryddor/Te/Kaffe: http://www.brattberg.com
Personal homepage: http://www.eurosource.se/akhe
Automated home: http://www.vscp.org


___________________________________________

2004\10\25@045955 by Russell McMahon

face
flavicon
face
FWIW:
Allowing current to flow in the protection diodes while the PIC is being
used violates the data sheet specs. The 40uA odd in the protection diodes is
entirely capable of making an on chip A2D converter misbehave. And it MAY
make the IC as a whole misbehave depending on what version of dead fish was
waved while preparing the mask version of the processor you are using, what
pin you use and what other currents are flowing in other parts of the
circuit at any moment.

While you *MAY* get away with this very successfully, you also *MAY* not. If
you want a circuit that *MAY* give you an interesting time in a  random and
intermittent manner then by all means violate the manufacturer's
specifications and let current flow in the protection diodes while the
processor is operating. If you prefer peace and predictability (so boring)
then not doing this is one step in that direction.

The manufacturer DOES allow you to have current flowing in the protection
diodes when the processor is NOT doing useful work, but this is a survival
and not an operational specification. The processor may malfunction after
this until it has been powered down completely and left turned off for an
(unspecified) period. My own experience with some ICs shows that this period
may be from 10's of seconds to 10's of minutes !!!! (Charge is trapped
capacitively in a normally non conducting node and affects operation of one
or more internal transistors. Until the charge leaks away the affect can
remain)


{Quote hidden}

       RM

____________________________________________

2004\10\25@075433 by Bill & Pookie

picon face
And putting a visible led reversed bias in parallel with the opto will
protect opto against reverse voltage and be a AC ON indicator.  The led will
share the limiting resistor with the opto, for as 'we all know'. you must
have a limiting resistor.

Bill

{Original Message removed}

2004\10\25@081721 by olin_piclist

face picon face
Russell McMahon wrote:
> Allowing current to flow in the protection diodes while the PIC is being
> used violates the data sheet specs.

Oh?  Can you provide a reference.  I just flipped thru the PIC18Fxx2 data
sheet and couldn't find any support for your assertion.  I did find an
absolute maximum rating of 20mA, but saw nothing one way or the other about
protection diode current during normal operation.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com
____________________________________________

2004\10\25@083643 by Jan-Erik Soderholm

face picon face
Bill & Pookie wrote :

> And putting a visible led reversed bias in parallel with the opto will
> protect opto against reverse voltage and be a AC ON
> indicator.

Note that the actual opto used in the schematics below (to
which you replied) is an "AC-opto" with two reversed LEDs.
So an additional external LED isn't of much use...
/Jan-Erik.


{Quote hidden}

____________________________________________

2004\10\25@095501 by Wouter van Ooijen

face picon face
> > Allowing current to flow in the protection diodes while the
> PIC is being
> > used violates the data sheet specs.
>
> Oh?  Can you provide a reference.  I just flipped thru the
> PIC18Fxx2 data
> sheet and couldn't find any support for your assertion.  I did find an
> absolute maximum rating of 20mA, but saw nothing one way or
> the other about
> protection diode current during normal operation.

Not directly. The allowed voltage on the I/O pins is specified as Vss ..
Vdd. If you stay within this range, these diodes will be in reverse, so
the only current will be leakage.

Wouter van Ooijen

-- -------------------------------------------
Van Ooijen Technische Informatica: http://www.voti.nl
consultancy, development, PICmicro products
docent Hogeschool van Utrecht: http://www.voti.nl/hvu


____________________________________________

2004\10\25@101243 by Russell McMahon

face
flavicon
face
>> Allowing current to flow in the protection diodes while the PIC is being
>> used violates the data sheet specs.

> Oh?  Can you provide a reference.  I just flipped thru the PIC18Fxx2 data
> sheet and couldn't find any support for your assertion.  I did find an
> absolute maximum rating of 20mA, but saw nothing one way or the other
> about
> protection diode current during normal operation.

There was an 16F777 in the ASCII art diagram, but my comment was meant to be
generic to PICs in general and indeed to most microprocessors.

Using 18FXX2 datasheet at
http://ww1.microchip.com/downloads/en/DeviceDoc/39564b.pdf

They don't of course spell out WHY a spec exists so you have to read between
the lines. but the relevant electrical requirement is given in section 22 of
the above document in two locations.

Interestingly, they have tightened up the non-operating specification so as
to make it meaningless. This appears to be an error - they have taken a
limit out of older data sheets for maximum and minimum voltages WHILE
OPERATING and applied it to ABSOLUTE MAXIMUM.

ie

   22.0 ELECTRICAL CHARACTERISTICS

       Voltage on any pin with respect to Vss (except VDD, /MCLR and
     -0.3V to (VDD + 0.3V)

This says that pins may never be taken more than 0.3V outside either rail.
This means the protection diodes must never be allowed to conduct!!!.
Obviously that is not what the designers intend, That spec is what you
usually find in a PIC spec sheet for OPERATING conditions.
As you say, they do indeed specify an input clamp currently for when pin
voltage is outside the supplies of 20 mA in or out. This makes nonsense of
the above voltage spec.
Not a good start.
Note that these clamping currents are specified in the Absolute Maximum
ratings section (22.0) and they specifically footnote that functional
operation is not implied at these values.

For operating values we have to look further down.
The operating conditions spec is even tighter.
Page 265. Section 22.2
DC characteristics
   Input low voltage
       Min = Vss
   Output high voltage
       Max = Vdd

They have either got lazy or ultra-safe here and say that no I/O pin may
ever be taken outside supply voltage range while operating if operation is
to be guaranteed. This is the explicit interpretation of these figures plus
the footnote at the bottom of page 259.
In practice, I would personally be happy with an excursion that didn't allow
body diodes to conduct :-) - but if that caused problems I couldn't blame
Microchip.

Digital and A2D operation (usually seem to) have different degrees of
sensitivity to body diode current. I would be reasonably happy that 40 UA
body diode current wouldn't affect processor digital operation - but not
absolutely certain. I would avoid such an arrangement in any equipment that
I wished to work reliably. People have reported onlist that very low level
body diode currents have badly impacted A2D operation.



       Russell McMahon



____________________________________________

2004\10\26@065947 by Peter L. Peres

picon face

On Mon, 25 Oct 2004, Olin Lathrop wrote:

> Russell McMahon wrote:
>> Allowing current to flow in the protection diodes while the PIC is being
>> used violates the data sheet specs.
>
> Oh?  Can you provide a reference.  I just flipped thru the PIC18Fxx2 data
> sheet and couldn't find any support for your assertion.  I did find an
> absolute maximum rating of 20mA, but saw nothing one way or the other about
> protection diode current during normal operation.

The maximum voltage on any pin is Vdd-0.3V to Vcc+0.3 afair. If you run
20mA through ay of those diodes the voltage will likely exceed the limit
above.

Peter
____________________________________________

2004\10\26@081628 by Russell McMahon

face
flavicon
face
Hypnosis and the art of PIC sanity maintenance.

>>> Allowing current to flow in the protection diodes while the PIC is being
>>> used violates the data sheet specs.

>> Oh?  Can you provide a reference.  I just flipped thru the PIC18Fxx2 data
>> sheet and couldn't find any support for your assertion.  I did find an
>> absolute maximum rating of 20mA, but saw nothing one way or the other
>> about
>> protection diode current during normal operation.

> The maximum voltage on any pin is Vdd-0.3V to Vcc+0.3 afair. If you run
> 20mA through ay of those diodes the voltage will likely exceed the limit
> above.

I assume you meant to say Vss-0.3V

This is a much travelled and shell-holed battleground.

I will now tell you only the truth.
You are falling under my spell.
Your eyelids are growing heavy.
These are not the ones you want. Move along ...

See my prior post on this to see what the 18Fxx2 data sheet says.
The person who wrote it had brain fade.
They say *absolute max* Vin range is Vss-0.3v to Vdd+0.3v.
They also say that max protection diode current per pin is +/- 20 mA.
Those two specs can never be satisfied at the one time.
It is vital to note that these are ABSOLUTE MAXIMUM specifications. They
explicitly say that the PIC may walk funny and not talk proper if run like
this.

They also give an OPERATING Vin range of vss to Vdd.

OLDER PIC data sheets made more sense.
They gave an ABSOLUTE MAXIMUM protection diode current.
This was the non-operating spec.

They also gave an operating Vin range of typically Vss-0.3v to Vdd+0.3v.
This range ensured that the protection diodes did not conduct more than a
few nanoamps of current.
ie essentially nothing at all in the protection diodes.

NEVER confuse "absolute maximum" and 'operating" sections of the datasheet,
lest thy product curl up and die.

WARNING:
Do not be fooled into the heretical thinking that there is only the one true
church of the Microchip.
There are at least two schisms.
First there is the true church of the IC designer. He knows what it does (he
hopes) and he tells his acolyte the spec sheet writer to write the truth.
The spec sheet writer may sometimes err, as for the 18FXX2 datasheet,
although his heart is in the right place and you can usually deduce the
truth that he is trying to convey.

Then there are the heretical sects of the applications note writer, the
sales-person and their ilk. They will provide application circuits which
violate the dogma of the IC designer and the spec sheet writer with
impunity. Do not run after them by citing examples of what they say is OK,
to prove that the evil that you wish to commit is indeed holy writ, for in
the day that thou doest it, or perhaps in some days latterly, and sometimes
not at all, and sometimes often, thy A2D shall produce results worthy of the
journal of irreproducible results, and thy floating point calculations may
become fixed, and thy fixed point calculations may never return from the
calls whither though hast called dispatched them unto and thy countenance
may be dismayed all the days of they life, which may be shorter than thou
hadst expected if this was a mission critical system.

DON'TLETPROTECTIONDIODESCONDUCTWHILEORBEFORETHEPROCESSORISMEANTTOOPERATENORMALLY.

I will now slowly count from 5 to 1.
When I say "1" you will open your eyes.
You will remember everything I told you.



       RM


.



____________________________________________

2004\10\26@092826 by olin_piclist

face picon face
Russell McMahon wrote:
> I will now slowly count from 5 to 1.

Shouldn't that be "From 5 to 1 I shall count, and the numbers of the
counting shall be from 5 to 1.  I shalt not count to 3 except when
proceeding to 2.  Zero is right out..."


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com
____________________________________________

2004\10\26@094113 by Dave VanHorn

flavicon
face
At 09:28 AM 10/26/2004 -0400, Olin Lathrop wrote:
>Russell McMahon wrote:
> > I will now slowly count from 5 to 1.
>
>Shouldn't that be "From 5 to 1 I shall count, and the numbers of the
>counting shall be from 5 to 1.  I shalt not count to 3 except when
>proceeding to 2.  Zero is right out..."

Come to think of it, this does sound like a rather "embedded systems"
approach to counting.. :)


____________________________________________

2004\10\26@094113 by Dave VanHorn

flavicon
face
At 09:28 AM 10/26/2004 -0400, Olin Lathrop wrote:
>Russell McMahon wrote:
> > I will now slowly count from 5 to 1.
>
>Shouldn't that be "From 5 to 1 I shall count, and the numbers of the
>counting shall be from 5 to 1.  I shalt not count to 3 except when
>proceeding to 2.  Zero is right out..."

Come to think of it, this does sound like a rather "embedded systems"
approach to counting.. :)


____________________________________________

More... (looser matching)
- Last day of these posts
- In 2004 , 2005 only
- Today
- New search...