Better AC sensing circuit for ADC conversion

Reloadron

Joined Jan 15, 2015
7,891
The circuits from post 16 are best for determining peak to peak AC, its not helping to calculate RMS ? I knew about this IC, https://www.ti.com/lit/an/snoa690/snoa690.pdf
National Semiconductor
LinearBrief
25 June1973

I read the link you provided. The link is dated June 1973. I don't see an IC but rather a circuit of discreet components so not sure about that? There are much better components today than for example the operational amplifiers used in the circuit. This is the circuit:

Precision OP Amp CKT.png

Now if you want to build that circuit have at it but keep in mind it's a circuit not an IC so you need to make a board. Personally I don't get how this circuit is True RMS as it's an average responding circuit. You also need a +/- 15 volt supply. My suggestion for True RMS remains what I suggested, however, your circuit and design.

Ron
 

Ian0

Joined Aug 7, 2020
13,158
It's a logarithmic/exponential amplifier. If you take the logarithm of the input signal, and multiply by two its the same as taking the logarithm of the square of the signal. It is then averaged, and squarerooted by taking the exponential of half the voltage.
As with all logarithmic amplifiers it requires well-matched transistors and will probably be a pain to calibrate.
 

drjohsmith

Joined Dec 13, 2021
1,613
A thought
rms : from wray castle .
RMS is calculated by taking the root mean square value or root of the arithmetic mean of the squares of a set of numbers. This involves squaring each value, finding the average of these squares, and then taking the square root of that average. The result is always a non-negative value that reflects the energy or intensity of the values in question

if your sampling a signal that goes from say 10 to 240, ( 8 bits )
all numbers are positive, so why square , just take the average over many cycles ,
 

Ian0

Joined Aug 7, 2020
13,158
so why square?
Because power = Voltage squared divided by resistance. To obtain a figure that represents the amount of voltage that would dissipate an equivalent power in a resistor to a DC voltage then one has to calculate the average power that it would dissipate. hence the average of the square. (And the average of the square is not equal to the square of the average)
Squaring is easy - most microcontrollers have a single cycle multiply these days. Square rooting is difficult, but unnecassary. Just compare the mean-square value you have calculated to the square of the target value.
 

drjohsmith

Joined Dec 13, 2021
1,613
Because power = Voltage squared divided by resistance. To obtain a figure that represents the amount of voltage that would dissipate an equivalent power in a resistor to a DC voltage then one has to calculate the average power that it would dissipate. hence the average of the square. (And the average of the square is not equal to the square of the average)
Squaring is easy - most microcontrollers have a single cycle multiply these days. Square rooting is difficult, but unnecassary. Just compare the mean-square value you have calculated to the square of the target value.
there was some discussion earlier about the maths, and complexity needed,
just done some quick thoughts on the need to square, which is to make all signals positive if all signals are positive.
as you say no need to take squareroot , hence it just becomes a running average ! seems strange , but thought id ask,
 

Ian0

Joined Aug 7, 2020
13,158
there was some discussion earlier about the maths, and complexity needed,
just done some quick thoughts on the need to square, which is to make all signals positive if all signals are positive.
as you say no need to take squareroot , hence it just becomes a running average ! seems strange , but thought id ask,
You also don't need to store all the samples, you can just run an IIR filter routine. If you choose a time constant for the filter of 256 samples, then the filter is trivial even on an 8-bit processors.
If you have a 24-bit accumulator (3 bytes), the the filter consists of subtracting (accumulator/256) which is trivial because it is just the top two bytes and adding the new sample. On a 32-bit processor it's a complete doddle.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
@Reloadron @lan0 @ drjohsmith @panic mode @Jerry-Hat-Trick
I do appreciate all of your suggestions and comments here. Looks like we are making complexity, thinking either way around and as a result the goal of this project is not going correctly.

As I posted #79 the circuit is silly, but kindly consider following facts,

1. We understand why the analog input at A0 Arduino uno pin is fluctuating too much. I have my Arduino code, and unfortunately, when I run the voltage comparison loop to activate relays, the relays get confused which load they should turn on, may be I have to draw a good tab changing transformer proteus Model.
2. Couple of circuit has presented for measuring perfect peak to peak AC and possibilities to get true RMS value.
3. We need a rectifier from the AC source, we need voltage divider. If we consider DC component and ripple may be we need low pass RC?
4. Start with a small (safely connected) mains transformer, 4 to 6 VAC would do, then you can work out the resistor values to give around the 4 to 4.5 volts at the ADC. Whether you have the ADC looking for the rectified peak values, or a slower smoothed DC voltage depends on how fast you need the voltage value updated. With such a very small current through the diodes (<1mA) they won't heat up, so the 0.6V across them won't change much. I like this simple way, kindly put your comments here,
diode_solution.png

5. I already posted a solution using opto-coupler, but here is a DIAC as a simple voltage to time generator. (DIAC model found on web)The better diacs have 28~34V specs and 15uA trigger, but they do not bother to spec temperature tolerances of the dV
ST do spec the break over voltage so you get some idea. You would need to measure some, and maybe do a 2 point calibrate, and table/equation but it is very simple in hardware. The code would capture dT and look for the shortest time per half cycle to extract the peak voltage. Its cheaper, It is much smaller and cheaper than a transformer There is a precision/cost trade off - 'jellybean' DIACs are under 1c at lcsc, tighter tolerance, lower trigger max parts from ST are ~ 5c .

DIAC_Mains_measure.png



Kindly discuss only this points and the code I posted.
 

drjohsmith

Joined Dec 13, 2021
1,613
@Reloadron @lan0 @ drjohsmith @panic mode @Jerry-Hat-Trick
I do appreciate all of your suggestions and comments here. Looks like we are making complexity, thinking either way around and as a result the goal of this project is not going correctly.

As I posted #79 the circuit is silly, but kindly consider following facts,

1. We understand why the analog input at A0 Arduino uno pin is fluctuating too much. I have my Arduino code, and unfortunately, when I run the voltage comparison loop to activate relays, the relays get confused which load they should turn on, may be I have to draw a good tab changing transformer proteus Model.
2. Couple of circuit has presented for measuring perfect peak to peak AC and possibilities to get true RMS value.
3. We need a rectifier from the AC source, we need voltage divider. If we consider DC component and ripple may be we need low pass RC?
4. Start with a small (safely connected) mains transformer, 4 to 6 VAC would do, then you can work out the resistor values to give around the 4 to 4.5 volts at the ADC. Whether you have the ADC looking for the rectified peak values, or a slower smoothed DC voltage depends on how fast you need the voltage value updated. With such a very small current through the diodes (<1mA) they won't heat up, so the 0.6V across them won't change much. I like this simple way, kindly put your comments here,
View attachment 362028

5. I already posted a solution using opto-coupler, but here is a DIAC as a simple voltage to time generator. (DIAC model found on web)The better diacs have 28~34V specs and 15uA trigger, but they do not bother to spec temperature tolerances of the dV
ST do spec the break over voltage so you get some idea. You would need to measure some, and maybe do a 2 point calibrate, and table/equation but it is very simple in hardware. The code would capture dT and look for the shortest time per half cycle to extract the peak voltage. Its cheaper, It is much smaller and cheaper than a transformer There is a precision/cost trade off - 'jellybean' DIACs are under 1c at lcsc, tighter tolerance, lower trigger max parts from ST are ~ 5c .

View attachment 362029



Kindly discuss only this points and the code I posted.
1. what do you mean by " the analog input at A0 Arduino uno pin is fluctuating too much"
relays confused, you shoukd be able to see which relay is on, and from the volts in, you know what relay that is. no need for transformer model as there is no feddback.

2. statment is true , external circuits and maths have been presented

3. wrong. you can chose to rectify the ac , or sample the ac , its up to you as to which route to use.
filtering can be done in components, or much better in software, its your choice .

4. why bother rectifying. when arduino can accept the sine wave directly , its up to you

5. opto coupler and diac input to arduino ! what forum is that circuit from ?

l agree with your comment about complexity
You seem to be posting on different forums , with different parts of the question,
it really is upto you to manage the project from these many un connectd posts.

to avoid complexity in hardward, the ac into arduino, driving relays direct is easiest. its all sw.
to avoid complexity in sw, you have the hw of the initial desihn.

the best solution tend to come where the requirments are specified and understood at the begining.
 
Last edited:

MrAl

Joined Jun 17, 2014
13,716
Dear All,

I am trying to design one of the AC sensing circuit as follows, my goal is to make 5V analog to ADC's by Arduino Uno which is taking the input at A0 analog pin.

View attachment 361525

C4 and C5 are used to smooth the pulsating DC com-ing from the rectifier. C4 performs the main bulk filter-ing by reducing low-frequency ripple, while C5 filters out high-frequency noise. The integrated digital voltmeter measures and shows the DC voltage after this filtering stage.R14 forms part of a feedback path or voltage divider used for voltage monitoring. The load resistors R12 and R13 are elements of an additional smoothing network. C6 further filters the output. D27 and D28 provide reverse-polarity protection and also function as part of a clamping/regulation circuit.

Kindly suggest me anything better.
Hi,

This thread grew too fast so there are a lot of pages that I can't read right now, but I thought I would throw in a little.

For something like this we have to know what the expectations are for the output. That is, how accurate does it have to be. That includes the number of bits the ADC will be using to sample the output.
Filtering is the easy part there are a lot of ways to filter, including in code.

We also have to know how FAST you have to sample the output. Is it once per millisecond, once per second, or once every 10 seconds for example. This makes a BIG difference in the way we would filter it.
In one application I did a while back I only had to sample once every 10 seconds so the filtering was really simple.

Another key point is how fast do you have to sample after the circuit is first turned on. That tells us how fast the circuit has to reach steady state. There are some tricks that can be used here too, but only if needed.
 

drjohsmith

Joined Dec 13, 2021
1,613
@MrAl
wel. said , if your catching up, be aware the op has multiple posts over multiple forums over multiple years on this project ,
Qdos to them for keeping at it , but its hard to understand
.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
@MrAl
wel. said , if your catching up, be aware the op has multiple posts over multiple forums over multiple years on this project ,
Qdos to them for keeping at it , but its hard to understand
.
@drjohsmith, kindly consider this post only. Don't mixed up things with other references/ forums. LM324 voltage stabilizer is different one. It's not hard to understand. Keep it as simple as it is. Post #111 should discuss here.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
Hi,

This thread grew too fast so there are a lot of pages that I can't read right now, but I thought I would throw in a little.

For something like this we have to know what the expectations are for the output. That is, how accurate does it have to be. That includes the number of bits the ADC will be using to sample the output.
Filtering is the easy part there are a lot of ways to filter, including in code.

We also have to know how FAST you have to sample the output. Is it once per millisecond, once per second, or once every 10 seconds for example. This makes a BIG difference in the way we would filter it.
In one application I did a while back I only had to sample once every 10 seconds so the filtering was really simple.

Another key point is how fast do you have to sample after the circuit is first turned on. That tells us how fast the circuit has to reach steady state. There are some tricks that can be used here too, but only if needed.
@MrAI, If you have time kindly read this full thread. See the reference code, sampling parameter is already defined.
 

drjohsmith

Joined Dec 13, 2021
1,613
@drjohsmith, kindly consider this post only. Don't mixed up things with other references/ forums. LM324 voltage stabilizer is different one. It's not hard to understand. Keep it as simple as it is. Post #111 should discuss here.
Uhm .
You say don't consider other forums , but your the one that references previous posts in other forums .. !
I assume it's with reference to yourself when you say it's not hard to understand..
That's great news ,
Lets hope we move to a clear set of definitions and not the apparent ever changing set of pictures / code / schematics from who knows where.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
Uhm .
You say don't consider other forums , but your the one that references previous posts in other forums .. !
I assume it's with reference to yourself when you say it's not hard to understand..
That's great news ,
Lets hope we move to a clear set of definitions and not the apparent ever changing set of pictures / code / schematics from who knows where.
Your response should be to the point.
If you don't want to respond its good sometime. If I were you, I will just avoid things that is Hard. Let's say you have 40+ years experience but it's should not be click always
 

panic mode

Joined Oct 10, 2011
5,013
@MrAI, If you have time kindly read this full thread.
for me threads with too many replies are a red flag. usually this means problem is not stated clearly and concisely. an XY problem...

and yes, this thread is precisely that... discussion is all over the place and goal posts are constantly shifting - from reading AC voltage to calculating RMS to controlling dozens of relays....

there is never mention of type of power transformer which is at the heart of the problem. there is never mention of desired output voltage tolerance etc.

btw. i may glance the thread but have no time to read everything. i need to manage my time and the same probably applies to other who volunteer their time here. hence i find suggestion to anyone, that they should read 100s of posts simply ridiculous.

one eventually finds out that entire concept is flawed. for example if any part of this system fails, entire system is useless since there is no manual override. a much simpler, cheaper and more flexible system would be self-regulating variac, possibly with a single relay to enable output when voltage is in range. if needed automatic correction can be turned off and in this case variac can be set manually.
 
Last edited:
Top