220VAC Detecting by PIC18FXX

Discussion in 'Embedded Systems and Microcontrollers' started by R!f@@, Dec 3, 2015.

  1. R!f@@

    Thread Starter AAC Fanatic!

    Apr 2, 2009
    8,750
    759
    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: Dec 4, 2015
  2. #12

    Expert

    Nov 30, 2010
    16,261
    6,770
    This looks like it's going to violate TOS so I suggest the pros continue the conversation via PM.
     
  3. bertus

    Administrator

    Apr 5, 2008
    15,647
    2,346
  4. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    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: Dec 3, 2015
  5. #12

    Expert

    Nov 30, 2010
    16,261
    6,770
  6. cmartinez

    AAC Fanatic!

    Jan 17, 2007
    3,560
    2,529
    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?
     
  7. Dodgydave

    Distinguished Member

    Jun 22, 2012
    4,977
    744
    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 likes this.
  8. cmartinez

    AAC Fanatic!

    Jan 17, 2007
    3,560
    2,529
    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.
     
  9. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    991
  10. #12

    Expert

    Nov 30, 2010
    16,261
    6,770
    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.
     
    cmartinez likes this.
  11. cmartinez

    AAC Fanatic!

    Jan 17, 2007
    3,560
    2,529
    It would also be awfully safe ;)
     
    ErnieM and #12 like this.
  12. #12

    Expert

    Nov 30, 2010
    16,261
    6,770
    Not safe enough for the Terms of Service at this site.:rolleyes:
    I think I will try to politely back out now because I feel uncomfortable from remembering Wendy rapping my knuckles with a ruler.:oops:
     
    R!f@@ likes this.
  13. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    I've asked the question about TOS with this kind of thing. It's a pretty common thing to need to do.
     
    R!f@@ likes this.
  14. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,523
    1,247
    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
     
    R!f@@ likes this.
  15. KeepItSimpleStupid

    Well-Known Member

    Mar 4, 2014
    1,143
    202
    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.
     
  16. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,523
    1,247
    Or, delete C18 and move C17 so it is in parallel with R19.

    ak
     
  17. R!f@@

    Thread Starter AAC Fanatic!

    Apr 2, 2009
    8,750
    759
    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.
     
  18. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,024
    Yup. Sample it as any DC input.
     
    R!f@@ likes this.
  19. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,515
    2,369
    What is wrong with low-tech?
    Miniature 240vac relay?
    Max.
     
    PeterCoxSmith likes this.
  20. cmartinez

    AAC Fanatic!

    Jan 17, 2007
    3,560
    2,529
    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.
     
Loading...