Discussion in 'Embedded Systems and Microcontrollers' started by mohamedadly71, Jul 1, 2011.

Nov 18, 2010
2
0
hello everybody
i am writing a code to read a sine wave of 50hz frequency
which is shifted by 2.5v and an amplitude 2.5v
i have to calculate the R.M.S of the wave using 4 sample method
which i should read a sample from sine wave every 5 milli second
and by using analoge to digital converter to convert it to digital.
i want to define the i/p as porta bit0
but when calculating the value of each sample i found that pic doesn't give the calculated sample on lcd
so please can anyone teel me if the ADC takes time to convert the sample or explain the ADC briefly
the code is:
float t,x5,x6;
char text2[13];
int i;
float y[4]={0,0,0,0};
void main()
{
trisa=1;
trisb=0;
lcd_config(&portb,0,2,1,7,6,5,4);
lcd_cmd(lcd_cursor_off);
lcd_cmd(lcd_clear);
for(i=0;i<4;i++)
{
x6=(x5*5)/1024;
y=x6;
t=y[2];
floattostr(t,text2);
lcd_out(1,1,text2);
delay_us(4900);
}
}

//so by changing the value of y i can read the sample on the screen
thanks for ur assist

Nov 18, 2010
2
0
i am using an external oscillator of 4 MHz

3. ### Markd77 Senior Member

Sep 7, 2009
2,803
596
What do you see on the LCD?
I would imagine with the short delay you would, at best, see 1 value.

4. ### nigelwright7557 AAC Fanatic!

May 10, 2008
527
74
x6=(x5*5)/1024;

Are you sure this is right ?
If you divide by 1024 then the first part needs to be greater than 1024 or you will get a zero result.