raman00084
Full Member level 6
Im having the problem in reading the adc for the ac signal
it is working for the 800mv above the 800mv
im reading only 800mv.
i think the problem in int32 overflow due to the squaring the int16 adc value.
im using ccs c complier for the pic18f
is there any option to use 64bit multiplication in ccs for 8 bit microcontroller
following is the code.
it is working for the 800mv above the 800mv
im reading only 800mv.
i think the problem in int32 overflow due to the squaring the int16 adc value.
im using ccs c complier for the pic18f
is there any option to use 64bit multiplication in ccs for 8 bit microcontroller
following is the code.
Code:
float read_adc_AC(unsigned char adc_inChannel,int16 samples,unsigned int16 in_usADCzero)
{
unsigned int16 usADCValue = 0 ;// usAccADC = 0;
unsigned int16 usLoop = 0 ;
int32 ulAccuADCvalue = 0;
int32 tmpadc = 0;
float ulTemp = 0;
float ftemp = 0;
set_adc_channel( adc_inChannel);
for(usLoop = 0 ; usLoop <samples; usLoop ++)
{
usADCValue = read_adc() - in_usADCzero ;
ulAccuADCvalue += (int32)(usADCValue*usADCValue);
delay_us(155);
}
ulTemp = sqrt(ulAccuADCvalue /samples);
//! return (ulTemp*(4.880)) ;
return (ulTemp) ;
}