Prince Vegeta
Member level 5
Hi there, I found this code in an old post... It's about calculating RMS value of a sine wave:
Now, there are stuff I don't really understand... if I reduced the signal to 5v peak:
1- What about Negative Cycle?
2- Should I start sampling from the 0 point?
3- I made a circuit that makes -Vp=ov and 0v=2.5v and +Vp=5v... will the previous code work here??? here there's no Negative cycle but it's presented by low ADC values... will this work with previous code?
4- about sampling, how can I pick sampling frequency and use it properly in mikroC?
Finally, is there a better way of measuring RMS value? I posted several threads about it but I didn't get any answer so I though about posting this code.
thank you.
Code:
Consider your line frequency = 50.00 Hz
50.00 Hz = 20ms = 20000 us
for example if you grab sinewave sample @ 100us interval time you get 200 samples .
store in some buffer, your ADC is 8 bit so you need buffer of size
signed char adcbuf[200]
ok...
now do following
signed int rawrms ;
int rms ;
for( count = 0 ; count < 200 ; count++ )
{
rawrms += adcbuf[count] * adcbuf[count] ;
}
rms = rawrms / 200 ;
rms = sqrt(rms) ;
Now, there are stuff I don't really understand... if I reduced the signal to 5v peak:
1- What about Negative Cycle?
2- Should I start sampling from the 0 point?
3- I made a circuit that makes -Vp=ov and 0v=2.5v and +Vp=5v... will the previous code work here??? here there's no Negative cycle but it's presented by low ADC values... will this work with previous code?
4- about sampling, how can I pick sampling frequency and use it properly in mikroC?
Finally, is there a better way of measuring RMS value? I posted several threads about it but I didn't get any answer so I though about posting this code.
thank you.