1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Power detector using 8051 microcontroller

Discussion in '8051/8951' started by paridhi jain, Oct 3, 2015.

  1. jayanthd

    jayanthd New Member

    Dec 17, 2015
    Ok. You are using an optocoupler to detect the mains presence. Am I right ? If yes, then you interface 50 Hz to MCU using optocoupler. You use INTx pin (external interrupt) to detect the presence of 50Hz signal. You should also use a timer interrupt. When ever a pulse is detected that comes from optocoupler then reload the timer registers. Say you have a timer of 100 ms. Also use a counter in timer ISR code. make sure whenever there is external interrupt you also clear this counter. So timer is reloaded every 20 ms and counter is cleared every 20 ms.

    You should use something like this in Timer ISR

    Code (text):

    if(counter == x) {
       //mains not present
       counter = 0;
    where x represents the value needed to complete say 2 sec.

    100 ms timer interrupt. 20 * 100 ms = 2 sec So, x = 20.
  2. xainnasir

    xainnasir New Member

    Jan 7, 2012
    Lahore Pakistan
    Commercial link deleted - Moderator
    Last edited by a moderator: Feb 1, 2016

Share This Page