AC mains Power supply status

Discussion in 'General Electronics Chat' started by sujith.g, Aug 17, 2015.

  1. sujith.g

    Thread Starter Member

    Jul 7, 2015
    48
    0
    HI,

    I am currently designing a circuit in which I need my microcontroller to detect if the AC mains power supply is ON or OFF. Initially I thought I could use a zero-crossing opto-coupler. But I will be using its interupt for dimming application of a lamp. So do I need to use another dedicated opto-coupler for detecting power supply ON-OFF status or can you please suggest an alternative solution. Please help.

    Thanks in advance!!!
     
  2. pwdixon

    Member

    Oct 11, 2012
    488
    56
    Can you post your current schematic?
     
  3. Externet

    AAC Fanatic!

    Nov 29, 2005
    763
    57
    Superglue a neon bulb to a photodiode or a sectioned optointerrupter and fit all in black shrink tubing.
     
  4. sujith.g

    Thread Starter Member

    Jul 7, 2015
    48
    0
    Hi,
    Please find the schematics.
     
    • s1.png
      s1.png
      File size:
      26.3 KB
      Views:
      19
  5. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    Why does the controller need to know that the AC is off?

    Anyway, cant it be done with some code using the existing zero crossing detector, which generates two interrupts per cycle of the AC? Set up a timer that decrements at several tens to several hundred counts per 5ms (50Hz line) or 8.333ms (60Hz line). Reload the counter in the ISR. If the counter ever decrements to zero, then no zero crossing happened, ergo the line is off.
     
    Last edited: Aug 17, 2015
    sujith.g likes this.
  6. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,546
    1,252
    The output that drives the interrupt pin can drive multiple pins in parallel, so you can monitor another pin with a missing-pulse rouine, like setting an internal counter to twenty, restart it on each zero crossing, and have it generate a software interrupt when it downcounts to zero. Twenty zero crossings is 10 cycles of AC, so you don't get a false trip on a brownout. Or build it into the ISR as above.

    ak
     
    sujith.g likes this.
  7. RichardO

    Well-Known Member

    May 4, 2013
    1,238
    385
    Be warned that the opto-isolator in your circuit will turn on and off very slowly by computer standards. The result is that the input circuit of the I/O pin may oscillate causing many, many interrupts for each zero crossing.
     
    sujith.g likes this.
  8. sujith.g

    Thread Starter Member

    Jul 7, 2015
    48
    0
    Hi Mike,

    Thanks for your reply. Actually I need my MCU to keep track of Power cuts as part of the end application. If I add more tasks in interupt handler, it affects the dimming leading to flickering. So I need to keep the cpu usage low so that we sync at the right time with the interupt. Do I need to add external hardware?
     
  9. sujith.g

    Thread Starter Member

    Jul 7, 2015
    48
    0
    Hi AK,
    Thanks for your suggestion. I'll try it out.
     
  10. AnalogKid

    Distinguished Member

    Aug 1, 2013
    4,546
    1,252
    The hardware effort / software latency tradeoff is up to you. If you want to go with a hardware missing-pulse detector, you already have part of it. You can connect a circuit to the output of the optocoupler in parallel with the interrupt pin, or add a 2nd optp by putting its input diode in series with the first. The circuit is an R-C timer that is continuously reset by the input AC, and times out when the AC is absent for a period of time set by you. If you don't need a fast edge to mark the transition from present to absent, the circuit is an opto coupler and pullup resistor (lime U3-R9) with a capacitor to ground. If you want a faster output edge, a dual comparator like an LM393 is very common.

    ak
     
    Last edited: Aug 24, 2015
    sujith.g likes this.
Loading...