anj
Member level 3
- Joined
- Aug 16, 2012
- Messages
- 66
- Helped
- 7
- Reputation
- 14
- Reaction score
- 7
- Trophy points
- 1,288
- Location
- Rajkot, Gujarat, India
- Activity points
- 1,679
Hi... all..
i am working on my college project and currently i am trying to sample the AC signal(0-12V) 50Hz and then from sampled values i want to calculate RMS value of signal.
my
now after sampling what to do for getting rms value. vref+=12V, vref-=gnd and 10 bit conversion is going on. please help. Regards.
i am working on my college project and currently i am trying to sample the AC signal(0-12V) 50Hz and then from sampled values i want to calculate RMS value of signal.
my
Code:
#include<htc.h>
#include<pic.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
#include "func.h"
void main()
{
int i;
long s1[20];
i=0;
TRISB = 0; //Set PORTB to inputs
TRISC = 0;
ADCON0= 0b10000001;
ADCON1=0b10001000;
init_rs232();
delay_ms(20);
for(i=0;i<20;i=i+2)
{
GO=1;
while(GO==1);
s1[i]=ADRESL;
s1[i+1]=ADRESH;
delay_ms(2); // 10 samples at 2ms delay so 10*2=20ms i.e. 1 cycle. of 50 hz
}
txdat("adc value: "); // serial tx of string
for(i=0;i<20;i=i+2)
{
Serial_Hexbyte(s1[i+1]); // hex conversion of samples and display on virtual terminal in proteus to see the samples.
Serial_Hexbyte(s1[i]);
delay_ms(2);
txdat(" ");
}
Last edited: