Standalone project. True/Rms

Hi everyone and thanks for helping.

I'm developing a standalone project with an ATMEGA328p.

it consists of measuring different variables like temperature, humidity, and others.
These days I've been struggling with an apparently simple part of the project and is the calculation of True-RMS current signal.

To introduce what I'm doing ill show pictures and give a brief description.
I'm obtaining the AC signal (current), form a TC 100/0.05 current output, then, I add it a variable Offset [0.7-1.8]V this offset is controlled by a trimmer and wired to the input of a follower(also called buffer, amp. G=1).

It'd be something like this (see signal.JPG as an example of the AC signal + offset).

Then I implement an active antialiasing filter (2nd) order (see Filter.JPG) the AC signal is @60Hz in ideal conditions and when the load is a fan or heating devices(resistive), not the same with electronic loads as computers, TV, screens is still 60 Hz but the signal is not a Sin(x) anymore (distortion) ...

![](http://C:\Users\Joshua Blanco\Desktop\signal.JPG)

In parallel, I'm using a Schmitt trigger zero-cross detection, this takes the offset that was added to the AC signal (- input) and the AC signal (+ input) of the comparator, the inputs of the comparator are wired from the output of the amplifier (antialiasing). The output comparator is wired to a digital input in the ATMEGA it works fine.

I'm using 2 ADCs, the ATMEGA's and the MCP3202(it works with SPI protocol and 12bit) so the ATMEGa analog port and the MCP3202 receive the filter output, and they do its conversion, the MCP obviously is wired to the ATMEGA by SPI ports.

the ATMEGA receives this signals SPI, AC+Offset, Offset, and the comparator output.

MY CODE (one part, the relevant):

Edge_Counter_L: Number of cycles that I want to sample, related to the comparator input
Num_Samples: number of samples taken for calculating RMS.

while(Edge_Counter_L < 6 && Num_Samples < 500){

Comp_State = digitalRead(Comp_Pin);

if (Comp_State != last_Comp_State) { //edge verification cycles
Edge_Counter_L++;
}

last_Comp_State = Comp_State;

/** analog read the used a lib for the MCP next take readings from the MCP and the ATMEGA's
ADC**/

/** V_mean_INA is the VDD or voltage supply of the ADCs and y_3_Mean is the Offset added***/
/** Offset_Opam is the offset due to the opamp, not the offset added in the beginning **/

channel0_MCP = adc.readChannel(0);
channel2_0_MCP = channel0_MCP * (V_mean_INA / 4095) - y_3_Mean - Offet_Opam; //MCP

channel1_2 = analogRead(SensorPin2);//A2 ATMEGA signal
channel2_2 = channel1_2 * (V_mean_INA / 1023) - y_3_Mean -Offset_Opam;

/* ATMEGA's ADC and the MCP3202 was callibrated for DC signal and resulting in these formulas*/
/y_0_MCP y_3 V_acc are double /
y_0_MCP = (0.9846821
channel2_0_MCP + 0.00002821247);/// MCP error less than 1%
y_3 = 0.9942
channel2_2 + 0.0205; //

V_acc = V_acc + (sq(y_0_MCP ));
V_acc2 = V_acc2 + (sq(y_3));

Num_Samples = Num_Samples +1;

delay(50);
}

VTC = (sqrt(V_acc/ Num_Samples));//rms from the MCP
VTC2 = (sqrt(V_acc2/ Num_Samples));//rms from the ATMEGA

  • I'm powering all my circuits with 3[V]
    So I'm posting this because when I start to run all of this, the measures that I'm taking has a relative error of 5%, this change when I change the load and rip off or add distortion, I'm comparing my measurements with the METERK MK06 multimeter, this has an absolute error of (1,2%+- 10 digits) i the range that I'm working, so, my questions are.
    How could I know that my measures are correct?
    How can I identify the SPI sample rate of the MCP3202?, I read in the Datasheet that at 2,7 V operates with 50kSps, for a 60Hz that in my calculations is 833 Samples per cycle, which I consider is enough for an accurate RMS, but I would like another opinion about this, so in my code I put a delay of 50 ms, but honestly I'm kind of confuse with this value, the signal for example with delay(25) doesn't show up properly in the serial plotter, why?, instead at (50 ms and 100 ms) it show up nice, so I would like a recommendation or advice in order to accurate measurings knowing that I'm reading distortion signals, I know that harmonics could be at 27f or even 41f, but would be nice an advice in order to fit a filter and delay timing for this design with the electronics available for this project.
    How could I know the sample rate of the ATMEGA ADC at 3[V]?, (I tryed the Nick gammon's tutorial for the standalone project but at 8Mhz the signal didn't show up nice in the serial plotter)

Thanks for helping

signal.JPG

Hello JoshBlanco,

Welcome to the forum.

In your enthusiasm to ask your question you skipped by 'how to use this forum - please read'. Please do that and come back and try asking again, this time following the help given in that post, it makes it easier for people to help you.

I'm sorry and Thanks for answering.
I'll do it again