Ok...smxx said:And for fully sine wave you can calculate this by two samples.
V1 : sample at t1 time
v2 :sampe at (t1+π/2)
V1=Vm sin(t1)
V2=Vm sin(t1+π/2)
Vm²=V1²+V2²
Vrms= Vm /√2
FvM said:n/2 must be equal to 1/4 period of the input frequency (90° phase shift), otherwise the nice algorithm doesn't work. Also V1, V2 must be DC-free.
uRMS = √(1/n*∑u² - (1/n*∑u)²)
shoaibali said:Use microcontrollers adc to take n(100 would be fine) samples of the input sginal for one cycle of the sine wave and do the rms calculations for that. You will need to bias the sinusoidal signal if the adc low reference voltage is 0 volts.
For example, for 50Hz sinusoidal signal,
take 100 samples each 20ms/100 = 200us apart
This can be done using a timer and adc in the microcontroller
Regards
gameelgamal said:shoaibali said:Use microcontrollers adc to take n(100 would be fine) samples of the input sginal for one cycle of the sine wave and do the rms calculations for that. You will need to bias the sinusoidal signal if the adc low reference voltage is 0 volts.
For example, for 50Hz sinusoidal signal,
take 100 samples each 20ms/100 = 200us apart
This can be done using a timer and adc in the microcontroller
Regards
Should the 100 samples be in the one cycle, or it can be tooken over more than one cycle
#include <16F877A.h>
#device ADC=10
#include <math.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
void main()
{
int16 value, samples[29]; //Value is a 10bit data sample
int i;
float volts;
setup_port_a(ALL_ANALOG); // All the 8 channels are analog
setup_adc(ADC_CLOCK_INTERNAL); // Internal ADC Clock
set_adc_channel(0); // RA0/AN0(Pin2) is analog input channel
while(1)
{
for(i=0;i<=29;i++)
{
samples[i]=read_adc();
delay_us(666);
}
for(i=0;i<=29;i++)
{
samples[i]=samples[i]*samples[i]; // Sqaure
value=samples[i]+value; // Sum total
}
value = value/30; // Mean of 30 samples
value = sqrt(value); // Square root
volts=(float)value*0.0048828125; // 1024 discrete levels, 5/1024 = 0.0048828125
printf("Voltage is : %3.3f\n",volts);// Print upto 3 decimal places
delay_ms(500);
}
}
Jack// ani said:Wrote a little code on CCS PIC, nothing fancy standard deviation with 30 samples at work as discussed by FvM.
Have run out of 16F877A, so couldn't burnt and tested it. Any comments, mistakes, improvements are always appreciated...
#include <16F877A.h>
#device ADC=10
#include <math.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
void main()
{
int16 value, samples[29]; //Value is a 10bit data sample
int i;
float volts;
setup_port_a(ALL_ANALOG); // All the 8 channels are analog
setup_adc(ADC_CLOCK_INTERNAL); // Internal ADC Clock
set_adc_channel(0); // RA0/AN0(Pin2) is analog input channel
while(1)
{
for(i=0;i<=29;i++)
{
samples=read_adc();
delay_us(666);
}
//SQUARE OF SAMPLES
for(i=0;i<=29;i++)
{
samples=samples*samples; // Sqaure
value=samples+value; // Sum total
}
value = value/30; // Mean of 30 samples
value = sqrt(value); // Square root
volts=(float)value*0.0048828125; // 1024 discrete levels, 5/1024 = 0.0048828125
printf("Voltage is : %3.3f\n",volts);// Print upto 3 decimal places
delay_ms(500);
}
}
Jack// ani said:Hi shoaibali, Yeah the value=0 should be initialized to avoid any previous junk value.
Regarding DC_Average, its not necessary as samples will be taken over a complete cycle, so DC Average will be zero.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?