aswathymohan
Member level 4
- Joined
- Nov 11, 2012
- Messages
- 68
- Helped
- 5
- Reputation
- 10
- Reaction score
- 5
- Trophy points
- 1,288
- Activity points
- 1,727
Hi
I wish to calculate the rms voltage of a sine wave(230V 50hz) and displayed the same on the serial terminal.I am using pic16f877a.I wrote the code,but it is not working properly,can anyone advise me how to solve the issues
1.errors I am getting,not enough ram
2.rms voltage calculation
3.selection of no of samples for accurate measurement
I wish to calculate the rms voltage of a sine wave(230V 50hz) and displayed the same on the serial terminal.I am using pic16f877a.I wrote the code,but it is not working properly,can anyone advise me how to solve the issues
1.errors I am getting,not enough ram
2.rms voltage calculation
3.selection of no of samples for accurate measurement
Code:
char uart_rd[50],uart_rd1[50];
float val[100],val1[100],val2[100];
float a,rms;
float sum=0.0;
int i;
void main()
{
TRISA=0XFF;
UART1_Init(9600); // Initialize UART module at 9600 bps
while (1) { // Endless loop
for(i=0;i<100;i++)
{
val[i]= ADC_Read(1);
val1[i]=(val[i]*230.0)/1023.0;
val2[i]=val1[i]*val1[i];
sum=sum+val2[i];
}
a=(float)sum/i;
rms=sqrt(a);
FloatToStr(rms,uart_rd);
strncpy(uart_rd1,uart_rd,5);
UART1_Write_Text(uart_rd);
UART1_Write(10);
UART1_Write(13);
delay_ms(150);
}
}