Better AC sensing circuit for ADC conversion

MrAl

Joined Jun 17, 2014
13,717
Hi

Only thing I can think of is to synchronize AC load switching with zero crossing. But that's more applicable to solid state load switches (TRIACs, etc.). Relays are too slow.
But do you need such a complicated circuit to do that? That's all I was wondering. Since I don't know exactly what you want or need from this, I can only suggest a rough circuit you can use. It's always your choice of course.

To start, you have an optocoupler. It has an LED internally that when you drive it with maybe 5ma it turns 'on'. Depending on load though, you may get away with even less current.
Now with a full wave rectified sine input, you drive the LED though maybe a 50k resistor. Now the voltage threshold is dependent on the drop of two diodes and one LED. That total drop might be about, let's say, 3 volts. Now 3 out of 325 is less than 1 percent, so the conduction angle will be low. That means you'll get an output signal that goes higher around the zero crossing and stays low above that 3 volts. That's your zero crossing signal.
You can even set the pulse width to be wider by adding an extra diode drop. That ensures a wider pulse to work with.
The error in say calculating the RMS voltage using that signal as a start and end time would be minimal. It could be very low less than 0.1 percent. We can go over that calculation though if you like.
So this circuit requires a full wave rectifier, a resistor on the output that feeds the optocoupler input, and a pullup resistor on the output of the optocoupler. That's pretty simple, but of course you have to figure out if that is good enough for what you are doing.
 

MrAl

Joined Jun 17, 2014
13,717
at least MrAI , hes decided on a circuit and is moving forward.
Hi,

I was just looking at simpler methods.
Back in the day we created one that just used one resistor and two diodes, and since we were already using comparators we used a comparator.
The resistor connects between the line and the two diodes. The two diodes are connected antiparallel so they clamp the voltage across them to plus and minus around 0.7 volts. That signal is then picked up by a comparator and the comparator output is used as the zero crossing reference.
This was used on a very high power (100 amps, 240vac) static switch for commercial/industrial/military clients.
 

eetech00

Joined Jun 8, 2013
4,709
But do you need such a complicated circuit to do that? That's all I was wondering. Since I don't know exactly what you want or need from this, I can only suggest a rough circuit you can use. It's always your choice of course.

To start, you have an optocoupler. It has an LED internally that when you drive it with maybe 5ma it turns 'on'. Depending on load though, you may get away with even less current.
Now with a full wave rectified sine input, you drive the LED though maybe a 50k resistor. Now the voltage threshold is dependent on the drop of two diodes and one LED. That total drop might be about, let's say, 3 volts. Now 3 out of 325 is less than 1 percent, so the conduction angle will be low. That means you'll get an output signal that goes higher around the zero crossing and stays low above that 3 volts. That's your zero crossing signal.
You can even set the pulse width to be wider by adding an extra diode drop. That ensures a wider pulse to work with.
The error in say calculating the RMS voltage using that signal as a start and end time would be minimal. It could be very low less than 0.1 percent. We can go over that calculation though if you like.
So this circuit requires a full wave rectifier, a resistor on the output that feeds the optocoupler input, and a pullup resistor on the output of the optocoupler. That's pretty simple, but of course you have to figure out if that is good enough for what you are doing.
I don't disagree Mr Al, it was a rhetorical statement.:)
The signal conditioning would need to be different. There's no point in ZCD if using relays to switch the load.
 

MrAl

Joined Jun 17, 2014
13,717
Hi

Only thing I can think of is to synchronize AC load switching with zero crossing. But that's more applicable to solid state load switches (TRIACs, etc.). Relays are too slow.
Hi,

I am not sure what you mean. You mean he is using relays?
 

MrAl

Joined Jun 17, 2014
13,717
Yes. His circuit shows relays to switch the taps on the (Load) auto-transformer.
Hi,

Oh ok, then I would think he would want to try to time it somehow, if that is possible.
Another possibility is to sense the current in the coil of the relay and use that as feedback in order to adjust future activations. Maybe that would help anyway.
 

eetech00

Joined Jun 8, 2013
4,709
Hi,

Oh ok, then I would think he would want to try to time it somehow, if that is possible.
Another possibility is to sense the current in the coil of the relay and use that as feedback in order to adjust future activations. Maybe that would help anyway.
I don't think ZCD is useable with relays cause they're too slow. The purpose ZCD is to synchronize the tap switching devices so switching occurs exactly at zero cross every time, to reduce transients. Most fast electro-mechanical relays take about 10-20ms to begin moving the armature and another 5-10ms to transfer the contacts, so at worst 30ms to complete the switching operation once commanded. The designer would also be up against device manufacturing tolerances.

Just my humble opinion...
 

MrAl

Joined Jun 17, 2014
13,717
I don't think ZCD is useable with relays cause they're too slow. The purpose ZCD is to synchronize the tap switching devices so switching occurs exactly at zero cross every time, to reduce transients. Most fast electro-mechanical relays take about 10-20ms to begin moving the armature and another 5-10ms to transfer the contacts, so at worst 30ms to complete the switching operation once commanded. The designer would also be up against device manufacturing tolerances.

Just my humble opinion...
Hi,

Oh no you do have valid points there no doubt.
The thing is though that when we go about to engineer something, we look for ways to improve things usually through some sort of optimization. That's why I mentioned sensing the current as a rough idea what might work because the magnetic activity would be directly related to the current, but it may even work to use a second set of contacts to sense when the relay actually closes (or opens) and use that as a guide for next time. Something like this would help to mitigate individual component tolerances.
For example, start with a measurement like 30ms and use that as a starting point, then adjust after each closure.
Of course this brings up the question about why use relays in the first place :)
 

drjohsmith

Joined Dec 13, 2021
1,614
But do you need such a complicated circuit to do that? That's all I was wondering. Since I don't know exactly what you want or need from this, I can only suggest a rough circuit you can use. It's always your choice of course.

To start, you have an optocoupler. It has an LED internally that when you drive it with maybe 5ma it turns 'on'. Depending on load though, you may get away with even less current.
Now with a full wave rectified sine input, you drive the LED though maybe a 50k resistor. Now the voltage threshold is dependent on the drop of two diodes and one LED. That total drop might be about, let's say, 3 volts. Now 3 out of 325 is less than 1 percent, so the conduction angle will be low. That means you'll get an output signal that goes higher around the zero crossing and stays low above that 3 volts. That's your zero crossing signal.
You can even set the pulse width to be wider by adding an extra diode drop. That ensures a wider pulse to work with.
The error in say calculating the RMS voltage using that signal as a start and end time would be minimal. It could be very low less than 0.1 percent. We can go over that calculation though if you like.
So this circuit requires a full wave rectifier, a resistor on the output that feeds the optocoupler input, and a pullup resistor on the output of the optocoupler. That's pretty simple, but of course you have to figure out if that is good enough for what you are doing.
yep.
The OP has been around a few ideas,
Im certainly not clear as to what they have decided, and every new idea seems to change the direction of travel,

At least they are now saying they have a reliable way of reading the input voltage.

Im thinking , as they are simulating only , its easy for them to change direction.

the OP has not been around the forums for a while ,
Im looking forward to seeing the code and circuit they propose to use on the relay control
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
Thank you
Sorry with so.many hundreds of posts , it's easy to get lost.

So your happy with your AC reading circuit and code.
That's great .
Have you tried it with the range of AC values in your expecting to work over ?
Is the voltage value you decode updated in your code on a fixed period , or randomly as the main loop runs ? I.e. if you add to the main loop , the period between readings would get longer

What is the plan for the output code ?
This I think has to take as input the voltage value , and output control lines to select which relays to activate or not.
Sounds to me like a state machine ?
All questions you asked here is solved at least.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
"panic mode, post: 2021705, member: 141873"]
no kidding... 300+ posts.
What I will do if story is going on ? People loves to share knowledge, loves to add more any more no matter its not specific or not. By the way you are not busy now days ?


the first circuit shown in post #16 is a naive attempt to measure and sync to mains. chosen part is an AC optocoupler with low CTR. that is the reason for lower series resistor and output that resembles rectified AC sine. this optocoupler is meant for only checking AC presence, not measuring amplitude. the good news is that one can sample this signal by ADC and determine voltage as well as zero crossing points. there are also bunch of useless parts (C1,C2,R2)
.

Good point of view, yes some other wanted to avoid this circuit but it has benefit. I dont think here is any useless parts not contributing well. But I can tell its input AC is more protected to use now. I am trying to work with it.



the bad news is that already bad CTR is only going to get worse and this means need for repeating calibration over time. the same happens if it ever need to be replaced. also since signal is rectified sine wave, there are no steep edges to sync onto. and syncing on peaks is not reliable doe omnipresent noise. so not something i would consider a first choice.
My code has calibration formula, you can not avoid it because you are handling AC sampling.

the second circuit has more parts but... it is a better, more mature design. it also contains useless parts (R4,D3,D5) thate are only making clutter. one of the advantages of this circuit is that current draw is small due to much larger value of resistor. this optocoupler is DC type but with much higher CTR, so with moderately high value of R3 transistor easily saturates. this means output is digital signal and the shape will be true even with aging. and current limiter sets the current to some 0.4mA so average current is the same but no high peaks. capacitor is charged and discharged slowly which translates to pulse width. falling edge is nice and rather sharp - great for syncing. it is drifting slightly depending on mains voltage but this is negligible (15-20uS over 20ms is under 0.1%) and if needed can be compensated by measured voltage. rising edge is not as steep but measurement will be consistent since sampled by same GPIO. and - no ADC is needed. post #314 talks about synchronisation to every half-cycle which is not true. this circuit only synchronizes to positive half-periods. which is once per period, not half-period.
This circuit has ability to attenuated the signal, but other circuit also have larger R values. Good point is we can syncronized sensing A0 and ZCD at pin 2. Better measurement capabilities for sure.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
But do you need such a complicated circuit to do that? That's all I was wondering. Since I don't know exactly what you want or need from this, I can only suggest a rough circuit you can use. It's always your choice of course.

To start, you have an optocoupler. It has an LED internally that when you drive it with maybe 5ma it turns 'on'. Depending on load though, you may get away with even less current.
Now with a full wave rectified sine input, you drive the LED though maybe a 50k resistor. Now the voltage threshold is dependent on the drop of two diodes and one LED. That total drop might be about, let's say, 3 volts. Now 3 out of 325 is less than 1 percent, so the conduction angle will be low. That means you'll get an output signal that goes higher around the zero crossing and stays low above that 3 volts. That's your zero crossing signal.
You can even set the pulse width to be wider by adding an extra diode drop. That ensures a wider pulse to work with.
The error in say calculating the RMS voltage using that signal as a start and end time would be minimal. It could be very low less than 0.1 percent. We can go over that calculation though if you like.
So this circuit requires a full wave rectifier, a resistor on the output that feeds the optocoupler input, and a pullup resistor on the output of the optocoupler. That's pretty simple, but of course you have to figure out if that is good enough for what you are doing.

Which of the circuit parts is complicated to you? Post #16 or #293? You want me to use full wave rectifier in which configuration ?
 

MrAl

Joined Jun 17, 2014
13,717
Which of the circuit parts is complicated to you? Post #16 or #293? You want me to use full wave rectifier in which configuration ?
#314

I am not saying to definitely use the alternate idea, just to consider a simpler solution.

This one is very easy:
Use a full wave rectifier to rectify the input sine.
Connect a resistor from the positive output and to the optocoupler input (LED).
The output of the opto still needs a pullup, as large as you can get away with so you can make the input resistor as high as possible.

I was asking if that would work for your application also.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
#314

I am not saying to definitely use the alternate idea, just to consider a simpler solution.

This one is very easy:
Use a full wave rectifier to rectify the input sine.
Connect a resistor from the positive output and to the optocoupler input (LED).
The output of the opto still needs a pullup, as large as you can get away with so you can make the input resistor as high as possible.

I was asking if that would work for your application also.
Simple is always a beauty! But very simple fails in market, for that reason people use post #16
 

drjohsmith

Joined Dec 13, 2021
1,614
Simple is always a beauty! But very simple fails in market, for that reason people use post #16
It's great you have decided on a final input circuit. It's not my favourite as others have explained, but it will probably do for your application , esspecialy in simulation .
Great news

I see from #16 , you are going for the option without the zero crossing circuit then. Much easier circuit.

How you getting on with the code for the Arduino ?
 
Last edited:

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
so what is the plan for the code / hardware to take your voltage reading to control your relays ?
Professor @drjohsmith It has been said several time to see my code in the post, but may be you are tired on watching same thing.
There is one formula to adjust the AC value, my 8 relay system ( not ZCD included) working fine now.

I have defined my relays like,
C:
// Relay pins (adjust as needed)
int relayPins[8] = {2, 3, 4, 5, 6, 7, 8, 9};
The calibration factor should be like here,

C:
// Calibration factor
float calibration = 0.52;   // Adjust after testing
NB: I hope you understand here,

I made a delay,

C:
// Delay between switching (ms)
unsigned long switchDelay = 1500;

// Track last switching time
unsigned long lastSwitch = 0;

Then I run a loop for relays and at the same time read AC voltage that it Vrms.
That's it.
 

Reloadron

Joined Jan 15, 2015
7,892
Based on some 300 post ago my understanding was that you wanted to sense True RMS AC?
Average-responding meters (or averaging RMS) are digital multimeters that measure the average value of an AC signal and multiply it by a scaling factor (

) to estimate the Root Mean Square (RMS) value, assuming a pure sine wave. They are accurate only for pure sine waves and often inaccurate for distorted waveforms.
Using a full wave bridge will give you average and not true RMS, so what did you want?

Ron
 
Top