rms voltage measurement with 16F877

Status
Not open for further replies.

MARWEN007

Junior Member level 2
Joined
Apr 16, 2011
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,481
I want to measure RMS voltage between points a (0.5) V and I rewrite a program in C to achieve my purpose may i know it does not work with me each time I simulate, I vary the amplitude of input signal to the peak I receive on an LCD value false efficient value
isis on my diagram is more than just a pic 16F877 connected with an LCD and a sine signal related to port A pin A1
frequency signal is 50Hz
I have tried this formula for calculation of trapezium numerical integral, exactly calculated the rms and this is my code
I hope someone passes a Glance
Code:
#include <16F877.h>
#device adc=8

#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)


#include <math.h>


void main() {
   const long N =3000 ;
   long i;
   int value;
   float voltage;


   setup_port_a( ALL_ANALOG );
   setup_adc( ADC_CLOCK_INTERNAL );
   set_adc_channel( 1 );

   while(TRUE)
   {
      voltage = 0;
      for(i=0; i<N; ++i)
      {
         value = Read_ADC();
         voltage += (float)value*(float)value;
      }

      //voltage currently holds the sum of ADC values squared.
      //to convert an ADC count to voltage -> ADC VALUE * (5 Volts)/(0xFF)
      //0xFF is the resolution of the ADC.
      //since ADC values are squared, for this routine:
      //    Voltage=ADC VALUE * (5 Volts)/(0xFF) * (5 Volts)/(0xFF) = ADC VALUE/2601      voltage /=2601.0;
      voltage /=2601.0;
      
      voltage = sqrt(voltage/(N));
      printf("\r\nInput =  %f V     , voltage);
   }
}
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…