Better AC sensing circuit for ADC conversion

Jerry-Hat-Trick

Joined Aug 31, 2022
828
The TS is designing a "voltage stabilizer". The AC line input might vary above or below the target output Line voltage.
It is supposed to monitor AC line voltage and adjust the line output (thru a selection of taps on an auto-transformer) to keep the output at a stable level. The TS has discussed this project in other forums. Its also supposed to detect over/under voltages
Thanks for explaining, I must have missed this. Presumably the resolution of measuring would be related to the number of possible taps? and these would probably be switched with relays which would suggest to me that a resistive divider directly into the processor pin just measuring half the wave and relays via opto isolators would be the simplest solution and peak to peak measurements should suffice? Knowing the spacing of taps would help. Most mains driven devices are reasonably tolerant of minor voltage changes. Without wishing to be unreasonable, but it seems to me to be another example of trying to solve a problem without saying what the problem is. On the plus side, it’s interesting to see the various approaches!
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
But without rectification, the ADC will be reading the full cycle, not half cycle.
There might be a language issue here, but nothing you have shown measures RMS power (requiring current (IRMS) measurement). Your voltage stabilizer requires an AC line voltage level reading.
If it's true then I won't avoid diode bridge, then the easy circuits are also useless!
 

eetech00

Joined Jun 8, 2013
4,707
Thanks for explaining, I must have missed this. Presumably the resolution of measuring would be related to the number of possible taps? and these would probably be switched with relays which would suggest to me that a resistive divider directly into the processor pin just measuring half the wave and relays via opto isolators would be the simplest solution and peak to peak measurements should suffice? Knowing the spacing of taps would help. Most mains driven devices are reasonably tolerant of minor voltage changes. Without wishing to be unreasonable, but it seems to me to be another example of trying to solve a problem without saying what the problem is. On the plus side, it’s interesting to see the various approaches!
This might help understand what the TS is trying to design:

https://forum.allaboutcircuits.com/...voltage-stabilizer-circuit-evaluation.207710/

Another consideration is overall system response time. How fast does an input change need to cause an output change.
 

drjohsmith

Joined Dec 13, 2021
1,613
I am working in a TOP global company, my clients are Meta, Google, AMD. but this is my personal project. Home made. Its a voltage stabilizer project.
So accuracy is not relevant , just change detection.
I.e you dont care if the nominal reads say 200 or 205 , you just want circuit to keep it the same . Be aware this is a feedback loop
... Input changes , you measure , you change something to keep input same , but this takes time, during which input could have changed !
Great possibility to be unstable .
Maths to check is complex , more than I can remember ..
. Practical solution , try a simple external circuit and fast simple code
The TS is designing a "voltage stabilizer". The AC line input might vary above or below the target output Line voltage.
It is supposed to monitor AC line voltage and adjust the line output (thru a selection of taps on an auto-transformer) to keep the output at a stable level. The TS has discussed this project in other forums. Its also supposed to detect over/under voltages
You have better memory than me on the other posts ! Thanks for heads up .
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
Thanks for explaining, I must have missed this. Presumably the resolution of measuring would be related to the number of possible taps? and these would probably be switched with relays which would suggest to me that a resistive divider directly into the processor pin just measuring half the wave and relays via opto isolators would be the simplest solution and peak to peak measurements should suffice? Knowing the spacing of taps would help. Most mains driven devices are reasonably tolerant of minor voltage changes. Without wishing to be unreasonable, but it seems to me to be another example of trying to solve a problem without saying what the problem is. On the plus side, it’s interesting to see the various approaches!
@Jerry-Hat-Trick, yes to have better peak to peak voltage, I also referenced 2 optocoupler circuits if you scroll up in this thread. Someone said, this won't help to get * True Vrms*. After A/D conversation, I have implemented ADC flash consisting 8 to 3 and 3 to 8 decoder and encoder. Then I use UNL2003, that helps to finalize which relay among 16 relays will turned ON according to truth table. My Arduino code works but may be something is wrong to identify specific active relay during load switching. Many people made this projects with PIC or even ST32 type MCU. It's a common project which any school boy can make. But using auto-transformer / tab changer is a big hassle.
 

drjohsmith

Joined Dec 13, 2021
1,613
@Jerry-Hat-Trick, yes to have better peak to peak voltage, I also referenced 2 optocoupler circuits if you scroll up in this thread. Someone said, this won't help to get * True Vrms*. After A/D conversation, I have implemented ADC flash consisting 8 to 3 and 3 to 8 decoder and encoder. Then I use UNL2003, that helps to finalize which relay among 16 relays will turned ON according to truth table. My Arduino code works but may be something is wrong to identify specific active relay during load switching. Many people made this projects with PIC or even ST32 type MCU. It's a common project which any school boy can make. But using auto-transformer / tab changer is a big hassle.
Sounds like your doing a lot in hardware that I'd do in the Arduino.
Arduino have plenty of outputs to control the relays directly via opto , or use opto relays .

Take step back on the input
If you had drawn a sine wave with distortion on graph paper , then you could calculate the voltages you want .
As to if it's true rms or approximation is up to your requirements .
How fast do you want to respond to a change.
As for processing, look at things like the teensy Arduino boards , 100 plus MHz clock speed , lots of lovely fast maths .
Re timing
If your using real relays , that take 10s of ms to switch , what's the minimum number of cycles between switching you looking at ? On every mains cycle or every 10 , ,100 or what ?
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
Sounds like your doing a lot in hardware that I'd do in the Arduino.
Arduino have plenty of outputs to control the relays directly via opto , or use opto relays .

Take step back on the input
If you had drawn a sine wave with distortion on graph paper , then you could calculate the voltages you want .
As to if it's true rms or approximation is up to your requirements .
How fast do you want to respond to a change.
As for processing, look at things like the teensy Arduino boards , 100 plus MHz clock speed , lots of lovely fast maths .
Re timing
If your using real relays , that take 10s of ms to switch , what's the minimum number of cycles between switching you looking at ? On every mains cycle or every 10 , ,100 or what ?
Well said. I am not exactly aware of how fast the relays should respond and how many cycles it should be. AC mains frequency is 50Hz, then after Bridge diode/RC filter/ Voltage divider, it's better to sample at 100Hz( general theory), over sampling is natural, shifting ADC bits also. The code I posted has different numbers. If we collect more data within short period, it's more better. I did see the teensy in Proteus part library. Do you think my attempt for reducing number of relays 16 to 8 is meaningful?
 

drjohsmith

Joined Dec 13, 2021
1,613
Well said. I am not exactly aware of how fast the relays should respond and how many cycles it should be. AC mains frequency is 50Hz, then after Bridge diode/RC filter/ Voltage divider, it's better to sample at 100Hz( general theory), over sampling is natural, shifting ADC bits also. The code I posted has different numbers. If we collect more data within short period, it's more better. I did see the teensy in Proteus part library. Do you think my attempt for reducing number of relays 16 to 8 is meaningful?
I'm not up to speed on the relay , the flash adc or the 16:8 you mention..
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
writing double Vrms = sqrt(sum_sq / (double)N_SAMPLES); in c is trivially easy, but it masks just how difficult and time consuming it is to calculate it on an 8-bit processor without a floating point arithmetic unit.
You won't get an answer until a week next tuesday.
As I said in post #45, there is actually no need to calculate the square root if all you are doing is a comparison,
and
implementing it as an IIR can be trivial if you want it to be, by choosing a time constant that makes it easy for the processor, and it has and advantage of needing only 3 bytes of storage, and producing an updated answer at every sample.
I will wait for you then. I will keep testing that code.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
I'm not up to speed on the relay , the flash adc or the 16:8 you mention..
Before implementing Arduino Uno , I use 16 parallel LM 741 opamp comparator ( many people don't like it ) and set them with reference voltages. Comparator outputs then fed to 2 pcs 74HC148, depending upon Low-High or High-Low level I have use NOT gates.Then this system was added to 2 pcs of 74HC154 and finlally ULN2003 and relays. I am thinking to divide all the system to half, the easy Arduino Uno code loop can be modify for 8 relays.
 

drjohsmith

Joined Dec 13, 2021
1,613
Before implementing Arduino Uno , I use 16 parallel LM 741 opamp comparator ( many people don't like it ) and set them with reference voltages. Comparator outputs then fed to 2 pcs 74HC148, depending upon Low-High or High-Low level I have use NOT gates.Then this system was added to 2 pcs of 74HC154 and finlally ULN2003 and relays. I am thinking to divide all the system to half, the easy Arduino Uno code loop can be modify for 8 relays.
sorry , not in place to do much, sorry not terribly well at moment.
looked at your orriginal posts , using an auto transformer , and a comparitor .

seems what the circuit is doing, is applyihg the incoming ac to a tap, dependunt on the input voltage, to change the output voltage.
looks like that has three taps, Im guessing step down an amount, pass through or step up an ammount .

do you know what the steps of the output are ? what voltage , im guessing around 20v up or down.

we talked about the adc resolution required a while back,
as you only have to decide up, nothing or down, then a few bits is all you need.

switching time, your driving relays , thesecare going to take a few ms to switch, during the switch , tne output voltage is going to dip. also relays have a limited life time, number of times they can switch.
yes you could use solid state relays , but the system you are replacing , and you say is common, uses relays, so my bet is they can only change every second at most.

so your adc only needs to detect is input voltage in a range of say 10 volts.

so what i woukd be looking at doing.

arduino reads the ac voltage via a simple transformer, droping 240v ac to say 3v ac, which is then conected into the arduino adc, using one of the circuits you have seen, with one side of the secondary at the arduino ground voltage .

the relays are directly driven by the arduino.

code :
first bit , constant read of the adc, input will be a sine wave , bit of maths, to find a running dc equivilent voltage .
you have loads of data per cycle , and no hurry to get a value

main loop, state machine .

for three relays, three states.,
step_dwn, in_eq _out, step_up

start in state in_eq_out, if voltage calculated is more than x volts above expected, go to step_dwn state
if voltage is less than x volts below expected, go to state step_up
else stay in the current state.


similar for other two states,

when in each state , the correct relays are set up.

you can do things like time delays to ensure relays dont "chater"


I hope this helps ,

i wish you the best , try not to kill yourself pleaae !
 

Reloadron

Joined Jan 15, 2015
7,891
True RMS implies measure complex waveform, like distorted sine, or other, the energy in each cycle.
Yes and actually reading true rather than average RMS for distorted waveforms requires some doing and doing it right comes with a cost. If you want to read true RMS I suggest using a good transducer. You want something like this. No they are not cheap or inexpensive but true RMS transducers don't come cheap. You can Google true RMS voltage transducer to shop around. Average responding transducers come in cheaper but true RMS which you call out don't come cheap. I like these transducers because as you see in the link they offer a variety of outputs like 0 to 5 VDC, 0 to 10 VDC and 4 to 20 mA.

The rest is easily done in your code.

Ron
 

Jerry-Hat-Trick

Joined Aug 31, 2022
828
Do we know the winding ratio of the taps and whether there is a relay (switch) between each tap or are they cascaded to short a number of taps such that only one relay needs to be switched at a time? And what is the load likely to be? These are basic requirements that I think should be stated, giving significant evidence of whether RMS measurement is necessary.

If peak to peak is all that’s required I’d use the mains supply to power an ATtiny85 via a resistor and full wave rectifier into an LM7805 for 5V dc, measure half the wave peak through another resistive divider and use two opto isolators to trigger up and down inputs to another processor, maybe a Seeeduino XIAO (or an Arduino UNO) on the low voltage side which should have enough I/O pins to drive transistors to switch the relays.
 

drjohsmith

Joined Dec 13, 2021
1,613
Do we know the winding ratio of the taps and whether there is a relay (switch) between each tap or are they cascaded to short a number of taps such that only one relay needs to be switched at a time? And what is the load likely to be? These are basic requirements that I think should be stated, giving significant evidence of whether RMS measurement is necessary.

If peak to peak is all that’s required I’d use the mains supply to power an ATtiny85 via a resistor and full wave rectifier into an LM7805 for 5V dc, measure half the wave peak through another resistive divider and use two opto isolators to trigger up and down inputs to another processor, maybe a Seeeduino XIAO (or an Arduino UNO) on the low voltage side which should have enough I/O pins to drive transistors to switch the relays.
I think you have to look at the previous posts the op has made over the last few years on this project .
Generally is it a good idea to short turns on the auto transformer as your suggestions . I know auto transformers are different to classic transformers.
 

Ian0

Joined Aug 7, 2020
13,145
I think you have to look at the previous posts the op has made over the last few years on this project .
Generally is it a good idea to short turns on the auto transformer as your suggestions . I know auto transformers are different to classic transformers.
Generally it's a very bad idea to short out windings on a transformer. It will usually destroy it. And autotransformers are really not much different from isolation transformers.
[Edit] The buck-boost connection would be the best way to go as it involves switching much less current with the relays, and there is no point when the load is completely disconnected from the supply.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
sorry , not in place to do much, sorry not terribly well at moment.
looked at your orriginal posts , using an auto transformer , and a comparitor .

seems what the circuit is doing, is applyihg the incoming ac to a tap, dependunt on the input voltage, to change the output voltage.
looks like that has three taps, Im guessing step down an amount, pass through or step up an ammount .

do you know what the steps of the output are ? what voltage , im guessing around 20v up or down.

we talked about the adc resolution required a while back,
as you only have to decide up, nothing or down, then a few bits is all you need.

switching time, your driving relays , thesecare going to take a few ms to switch, during the switch , tne output voltage is going to dip. also relays have a limited life time, number of times they can switch.
yes you could use solid state relays , but the system you are replacing , and you say is common, uses relays, so my bet is they can only change every second at most.

so your adc only needs to detect is input voltage in a range of say 10 volts.

so what i woukd be looking at doing.

arduino reads the ac voltage via a simple transformer, droping 240v ac to say 3v ac, which is then conected into the arduino adc, using one of the circuits you have seen, with one side of the secondary at the arduino ground voltage .

the relays are directly driven by the arduino.

code :
first bit , constant read of the adc, input will be a sine wave , bit of maths, to find a running dc equivilent voltage .
you have loads of data per cycle , and no hurry to get a value

main loop, state machine .

for three relays, three states.,
step_dwn, in_eq _out, step_up

start in state in_eq_out, if voltage calculated is more than x volts above expected, go to step_dwn state
if voltage is less than x volts below expected, go to state step_up
else stay in the current state.


similar for other two states,

when in each state , the correct relays are set up.

you can do things like time delays to ensure relays dont "chater"


I hope this helps ,

i wish you the best , try not to kill yourself pleaae !
Well explained. Thank you.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
Yes and actually reading true rather than average RMS for distorted waveforms requires some doing and doing it right comes with a cost. If you want to read true RMS I suggest using a good transducer. You want something like this. No they are not cheap or inexpensive but true RMS transducers don't come cheap. You can Google true RMS voltage transducer to shop around. Average responding transducers come in cheaper but true RMS which you call out don't come cheap. I like these transducers because as you see in the link they offer a variety of outputs like 0 to 5 VDC, 0 to 10 VDC and 4 to 20 mA.

The rest is easily done in your code.

Ron
@Reloadron, see on post 16, can they perform well besides RMS transducers ? Or they are somewhat same ?
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
Do we know the winding ratio of the taps and whether there is a relay (switch) between each tap or are they cascaded to short a number of taps such that only one relay needs to be switched at a time? And what is the load likely to be? These are basic requirements that I think should be stated, giving significant evidence of whether RMS measurement is necessary.
@Jerry-Hat-Trick

Can you check this image, let me know my autotransformer connection is wrong or not,

autotransformer.PNG




If peak to peak is all that’s required I’d use the mains supply to power an ATtiny85 via a resistor and full wave rectifier into an LM7805 for 5V dc, measure half the wave peak through another resistive divider and use two opto isolators to trigger up and down inputs to another processor, maybe a Seeeduino XIAO (or an Arduino UNO) on the low voltage side which should have enough I/O pins to drive transistors to switch the relays.
Post #25 circuit is not better ?

This thread was created just for few simple questions.
1. Why we need rectifier here?
2. Why we need to avoid DC level or not.
3. How cheapest those components are?
4. Why optocoupler or why not?
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
Generally it's a very bad idea to short out windings on a transformer. It will usually destroy it. And autotransformers are really not much different from isolation transformers.
[Edit] The buck-boost connection would be the best way to go as it involves switching much less current with the relays, and there is no point when the load is completely disconnected from the supply.
One of friend said to go with this idea but not sure how I can aply,

*You can make it smaller and simpler, with a 30V change-transformer (2 x 15V), of much lower power, that then has one relay select Phase for ADD/SUBTRACT and another relay selects 15/30 via series or parallel. A bypass relay can remove the correction transformer entirely for correct mains.
That gives 5 steps with 3 relays and a smaller transformer and lower losses.
Most mains loads easily tolerate +/-5%, and it is rare to find an electronic load that is not able to manage 110-220
*
 
Top