Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

220v AC detect problems

johnny78

Full Member level 5
Full Member level 5
Joined
Jun 28, 2017
Messages
270
Helped
1
Reputation
2
Reaction score
5
Trophy points
1,298
Activity points
3,462
hi Guys
im using this method to detect presence of mains supply (220v AC)
opto-coupler.jpg

on the MCU side i have set the internal pull ups & detect the presence by reading the status of the input pin
Code:
  if (digitalRead(MainsDetect) == LOW) { // && (TurnOnDelay2V) == 1) {
    MainsDetectV = 1;
  }
  if (digitalRead(MainsDetect) == HIGH) {
    MainsDetectV = 0;
  }
sometimes it fails to detect mains & the MainsDetectV going 0
the main problem is at my place it works fine since years without any problem but sometimes at other places it keep doing problems detecting mains
what may get different on other places i dont know
i've noticed 2 problems
1:when mains present sometimes the mainsDetect goes 0 & re goes 1 & i've tried to use 1uf cap instead of the 22u i use & i see my detection blinking between 0 & 1 so i think using bigger capacitor may solve this issue
2: when no mains present i saw once the detection reading 1 & this is impossible to happen because i use internal pull ups & no mains present to drive the optocoupler led(is it possible that the internal pull up resistors of the MCU are damaged? or the led of the pc817 is damaged ? or maybe i have low ac mains present which may appears like that mains is present)
is there any chip to do this detection for me?
of how to enhance my circuit

i think of alot of reasons may cause this problem but actually i cant see any of this problems happens here at my place it only happens when i install my device
at another place which i dont have tools to test or try
any ideas will be great
thanks in advance

Johnny
 
Last edited:
Hi,

there are free circuit simulation tools. Did you check your circuit with it?
This helps to understand the working principle of the ciruit.
It also helps to understand what output signal to expect .... especially at varying input voltage RMS.
It also helps to improve the circuit to work the way you (your application ) needs.

But when designing a new circuit ... I mean your ATMEGA application ... the first thing you should do is to decide the inputs you need.
Every designer needs to do this.

So if I had to do this, I´d maybe define MY requirements as:
* input is rather pure sinewave
* it should be continously ON when input RMS voltage is above 190V RMS
* it should be continously OFF when input signal is below 150V RMS
hi Klaus
i need your help to avoid detecting power when its below 150v
im using the simple circuit which was suggested by Brian
simply use 2x 100k ohms to power the bridge & it works but in some cases it detects power even when there is only 50v

any ideas

thanks
 
Hi,

I can help you .. but you have to do your job first.

I´m not the man for trial-and-error. (For this you don´t need professional assitance)
I will help you by using physics and math.

* Select a simulation tool of your choice first, then draw the schematics in the current version and start the simulation.
* Alternatively draw the schematics (even by hand is OK) and show us the math behind

No need to be complete, no need to be correct. Just a basis to start with.. to discuss about ... a circuit to improve.
So we can see your idea, your circuit, the parts you want to use.
(Also to avoid to scroll up an down through several posts / schematics ...)

Klaus
 
A first pass at problem.

1723117750560.png


Some notes :

1) Might be able to replace bridge with just 1/2 wave rectifier.
2) Zener sets drop trip voltage.
3) The 10 Meg is just to sim rough isolation when using optocoupler between
line neutral and OpTo output circuitry.
4) If isolation not an issue could replace opto with a comparator and Vref to manage trip.
You can get 1 chip Vref and Comparator.
5) Circuit has significant latency due to filtering RC time constants, you can experiment
with that if its a problem.
6) I used sim parametric model for PC817 as I could not find a workable spice model
to import into Simetrix.
7) I used 12V for output side coupler, 5V should work just fine.

You can sim this in pretty much any simulator to play with. I used Simetrix.


Regards, Dana.
 
Last edited:
Hi,

I can help you .. but you have to do your job first.

I´m not the man for trial-and-error. (For this you don´t need professional assitance)
I will help you by using physics and math.

* Select a simulation tool of your choice first, then draw the schematics in the current version and start the simulation.
* Alternatively draw the schematics (even by hand is OK) and show us the math behind

No need to be complete, no need to be correct. Just a basis to start with.. to discuss about ... a circuit to improve.
So we can see your idea, your circuit, the parts you want to use.
(Also to avoid to scroll up an down through several posts / schematics ...)

Klaus
PSU.jpg

here is the circuit i use
give me an idea on how to simulate this on proteus

thanks
 
I have never used Proteus. But first pass do a transient simulation, set
your input source as sine, output C initial condition as 0 V, time increment
in simulator as 1uSec.

Look at a Proteus video on YouTube on doing a basic transient sim.

1723120478701.png


Your circuit has several issues :

1) Add a series R to pin 1 of 817 to limit current. Start with 10K.
2) Pin 4 of 817 should have a pullup, either MCU input pullup
or external.



Regards, Dana.
 
thx Dana
im using the internal pullup of the input is it necessary to use external resistor instead of it ?
I have never used Proteus. But first pass do a transient simulation, set
your input source as sine, output C initial condition as 0 V, time increment
in simulator as 1uSec.

Look at a Proteus video on YouTube on doing a basic transient sim.

View attachment 192938

Your circuit has several issues :

1) Add a series R to pin 1 of 817 to limit current. Start with 10K.
2) Pin 4 of 817 should have a pullup, either MCU input pullup
or external.



Regards, Dana.
 
What is value internal pullup ? It matters because the opto current transfer
spec is one of the determinants of the output current/switch point. If its in the
area of 10K should be fine, otherwise you tune the input current and along
with worst case Current transfer ratio design for the input current needed.

Example, you have a 5K on output, you design for worst case input of 1 mA,
the worst case current transfer is 2, then Vout = (2 x 1 mA) x 5K = 10 V
swing on output, which should be more than enough for MCU. In fact its' too
high for MCU so either lower the Pullup V source its pulled to, or use a simple
series R from 817 output to MCU in, with a diode clamp to MCU VCC to keep
inoput to MCU from exceeding its spec. That R should be 4.7K or there abouts.


Regards, Dana.
 
I would NOT add a series resistor in pin 1, it already has 200K in series with it via the bridge rectifier.
You do need a pull-up at pin 4.
I would add a small resistor in series with pin 4. Ideally something much smaller than the pull-up, maybe 100 Ohms and a 5K pull up. The cap goes to their junction. The reason for the additional resistor is to limit the discharge current from the capacitor as the opto transistor conducts.
I'm not sure what symbols Proteus uses but the negative side of the capacitor goes to ground. The shaded side of the symbol is usually negative.

Brian.
 
My error which betwixt picked up, that no additional R needed into pin 1, totally agree.

Note the peak input current into opto is 311V (peak) / 200K =~ 1.5 mA. The 817 has a transfer
ratio nominal ~ 2 so thats 3 mA available into output, so use that to calc worst case pullup
needed to meet logic 1 into your MCU.


Regards, Dana.
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top