td micro
Member level 5
hi,
i m doing simle adc sample pgm.(using pic 18f, in c18 compiler). im my pgm,i m using potentiometr in portA1.and varying it.then i printed that integer, aftr adc conversion.since i m using 10 bit adc, i m getting values from 0 to 1023 while changing the potentiometer.ie, in below pgm, im getting xvalue as 0-1023.
but, aftr the calculation
i printed y on hyper.when the value of xvalue increases, y is also increasing w.r.t the formula,up to xvalue = 820.ie, at xvalue 820 , im getting 103. that is ok. but when i varied potentiometr, ie, when i made xvalue to 849, i m getting y as 4. actual value after calculation should be 108.but we are getting 4. and like that at xvalue 1023, in hyper its displaying 32.bt actually we are expecting 135. why the displayed value is changing from xvalue 830?upto that the calculated value is displayed exactly on hyper.but aftr 830, it is changing.
here is my code...
im getting in hyper
please give me one solution to solve this different out displayed in hyper..
i m doing simle adc sample pgm.(using pic 18f, in c18 compiler). im my pgm,i m using potentiometr in portA1.and varying it.then i printed that integer, aftr adc conversion.since i m using 10 bit adc, i m getting values from 0 to 1023 while changing the potentiometer.ie, in below pgm, im getting xvalue as 0-1023.
but, aftr the calculation
Code:
z = (100*(xvalue-164));
y = z/634;
here is my code...
Code:
unsigned int z = 0;
unsigned int y = 0;
char rstr[8];
unsigned char xvalueASCII[8];
while(1)
{
xvalue = ADC_Convert();
z = (100*(xvalue-164));
y = z/634;
putrsUSART( "\n\rread adc value is......");
itoa(xvalue, rstr);
putsUSART( rstr );
putrsUSART( "\n\rxvalueASCII is......");
itoa(y, xvalueASCII);
putsUSART( xvalueASCII );
im getting in hyper
Code:
read adc value is......619
xvalueASCII is......71
read adc value is......793
xvalueASCII is......99
read adc value is......802
xvalueASCII is......100
read adc value is......818
xvalueASCII is......103
////////// up to this, output is ok.....
read adc value is......849
xvalueASCII is......4 ///////////////actualll 108
read adc value is......872
xvalueASCII is......8 /////////////////// 111
read adc value is......896
xvalueASCII is......12 ///////////////// 115
read adc value is......921
xvalueASCII is......16
read adc value is......947
xvalueASCII is......20
read adc value is......965
xvalueASCII is......22
read adc value is......974
xvalueASCII is......24
read adc value is......1023
xvalueASCII is......32
please give me one solution to solve this different out displayed in hyper..