220VAC Detecting by PIC18FXX

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
I dunno if this should go in uC forum. But here goes...:oops:
See the attached pdf for reference.
My aim is to detect the AC mains by the PIC. ( not PIC specific ).
I am not concerned about the diagram. I can make amends while building.
My problem is the PIC software confusion. Mind you this is not a zero crossing detection nor ADC. Just a digital input. I am going to run a PIC routine like "while (AC_OK) { blah blah blah }" :D

As you can see from the diagram the opto will output 100Hz square wave. That is why I am using C18, trying to filter it out to some extent. Still,
will the PIC pin (AC_OK) see 100Hz ?
And what will happen to the "while (AC_OK){ blaaaaah}" routine during a low level ?
I am thinking if the PIC pin goes low it will exit the routine even AC is there.
Will placing a cap at the PIC pin rectify my issue.

What is the best possible solution ?

{edit}
Sorry guys. I deleted the pdf. I do not want a n00b trying to attempt to build the circuit and get deep fried.
I got the answer so I think it is best not to talk about this. Those who posted images please check if they could be hazardous to n00bs and remove them if you do not mind.
 
Last edited:

#12

Joined Nov 30, 2010
18,224
This looks like it's going to violate TOS so I suggest the pros continue the conversation via PM.
 

MaxHeadRoom

Joined Jul 18, 2013
28,619
Yes the filtering turns it in to DC so no ripple, you should not need that much in the way of Capacity.
You could also use a 5v Wall Wart for the DC or use a Very small 240v to a low voltage transformer and rectify and smooth that.
Max.
 
Last edited:

cmartinez

Joined Jan 17, 2007
8,220
I dunno if this should go in uC forum. But here goes...:oops:
See the attached pdf for reference.
My aim is to detect the AC mains by the PIC. ( not PIC specific ).
I am not concerned about the diagram. I can make amends while building.
My problem is the PIC software confusion. Mind you this is not a zero crossing detection nor ADC. Just a digital input. I am going to run a PIC routine like "while (AC_OK) { blah blah blah }" :D

As you can see from the diagram the opto will output 100Hz square wave. That is why I am using C18, trying to filter it out to some extent. Still,
will the PIC pin (AC_OK) see 100Hz ?
And what will happen to the "while (AC_OK){ blaaaaah}" routine during a low level ?
I am thinking if the PIC pin goes low it will exit the routine even AC is there.
Will placing a cap at the PIC pin rectify my issue.

What is the best possible solution ?
I'm not sure I understand your intention. Do you just want to know if a 220VAC source is present? And if so, within what VAC tolerance? Or do you want to make a zero-crossing detector?

EDIT: I get it now... you did mention it's not a zero-crossing detector. So now my question would be, within what range of 220VAC do you want your detector to work?
 

Dodgydave

Joined Jun 22, 2012
11,285
Do you want to just detect if the mains is present or measure its value?

If you just want to detect it, i would just use a small 5V mains transformer and half wave diode, to detect a 50/60Hz clock pulse, or opto coupler.
 

cmartinez

Joined Jan 17, 2007
8,220
Do you want to just detect if the mains is present or measure its value?

If you just want to detect it, i would just use a small 5V mains transformer and half wave diode, to detect a 50/60Hz clock pulse, or opto coupler.
And you could add an RC filter at its output to make it a non-pulsing signal that would allow you to detect mains presence without needing to sync sampling.
 

#12

Joined Nov 30, 2010
18,224
One could also use an NE-2 neon bulb and a light dependent resistor to make a high voltage opto-coupler, but it would be awfully slow.
 

AnalogKid

Joined Aug 1, 2013
10,987
There will be ripple because the two LEDs in series will clip the peak C18 voltage at their combined Vf's at the sinewave peaks, and the LEDs will discharge the cap. However, the R18-C18 time constant is almost 5 seconds, so I think the LEDs will stay on while the input is at the lower parts of the AC cycle. To improve this and guarantee that the LEDs do not turn off, split C18 into two resistors with C18 in the middle. Good offline design practice requires that series current limiting resistors be split so there is not a single point of failure that can put full powerline on the LEDs.

ak
 
I think you have a couple of solutions, BUT you have to be somewhat careful as what "AC_OK" really means.

The standard way is the use of an I/O module.

Another way is to roll your own with possibly this http://www.avagotech.com/products/o...current-detector/acpl-k370-000e#documentation device. Look particularly at the application note #1004.

Difficulties are transients and response time, both on and off.

These http://www.grayhill.com/assets/1/7/IO_Mod_AC_Input.pdf are mad by many vendors.

I have some interest in what you come up with and I'd like to play with some sort of "universal" 120/240 50/60 Hz detection scheme where there is a constant source of AC power and a switched source of AC power.
I'd like to quickly detect off and on.
 

Thread Starter

R!f@@

Joined Apr 2, 2009
9,918
Thanks for all the answers guys.
First of all I posted the circuit to show what I will build. It might be a Tos violation, and that is why I did not ask about the circuit.
I asked about the PIC detecting the 100Hz and how to avoid that.

@#12
I have the X2 caps and I will try that method too but still I might end up with 100Hz.

I gtg now but I will go thru all the posts and get back to my PM's later.

PS... @JohnInTX
Interesting circuit..I will try that for a change. Will it avoid the ripple ?

ak gave some interesting thoughts and what I thought too. An RC filter approach... I will look into it.
 

cmartinez

Joined Jan 17, 2007
8,220
Alright, here's what I think could be best for your application.

This zero-crossing detector stays on logic high until zero volts are crossed by a 110VAC or 220VAC signal. Since the low pulse only lasts about 1 ms, it should be fairly easy to place an RC filter at its output that would allow you to very quickly detect (in less than half a sinewave, I think) if power has been lost or not.
@MikeML, I tried to sim the circuit in LTspice but kept on getting an error message, perhaps you could tell me what I've been doing wrong?

EDIT: for clarification purposes, this circuit must be used at the output of an isolation transformer, so as to comply with the TOS of this site.
 

Attachments

Top