reading values when no analog input

Thread Starter

Anjanav

Joined Mar 2, 2010
16
Hi....
Am using 8 (0-7) analog inputs in pic18f4550... am getting values when these pins are not connecting to any analog inputs... what will be the problem for this....


Thanks
 

retched

Joined Dec 5, 2009
5,207
Your inputs are floating. Im no sure if the 18f4550 has internal pull-up resistors or not. If not, you will want to set the pins you are NOT connecting anything to as OUTPUTS.
 

t06afre

Joined May 11, 2009
5,934
As long as your signal input is floating, the input must be regarded as undefined. This is not a problem. You can avoid this by connecting the input to ground with a 10Kohm resistor
 

t06afre

Joined May 11, 2009
5,934
By the way then say values what do you refer to. It is quite normal that you see the least significant bits fluctuate somewhat then working with ADCs even if the input is 100% stable
 

Thread Starter

Anjanav

Joined Mar 2, 2010
16
thanks for ur replies....

am getting like 229 313 429 323 227 429 129 250......
if am connecting a pot of 5v to pin0 means 500 225 313 339 429 129 250 371
when i did't connect anything to that pins means it should read zero only na....

thanks
 

t06afre

Joined May 11, 2009
5,934
I think you have done something wrong in the ADC setup. Like you do not check if the convert cycle is done before reading the result. This is a wild guess it could also be something else. I think code and schematic is needed to give more precise input
 

rjenkins

Joined Nov 6, 2005
1,013
As well as checking the conversion has completed, make sure you have enough settling time after changing the ADC input selection, before starting the conversion.

The input signal to the ADC should also be fairly low impedance, and/or you should fit a 0.1uF cap at the ADC input pin.

Make sure the main 5V supply to the PIC is well decoupled to ensure that is not fluctuating.
 

nsaspook

Joined Aug 27, 2009
16,471
A little signal processing of the ADC result for slowly changing measurements helps.

C18 fragment

Rich (BB code):
float lp_filter(float new, int bn,int slow)                             // low pass filter, slow rate of change for new, 8 channels, slow/fast select
{
static  float   smooth[LPCHAN]={0},x;
float                   speed;
        if (bn>LPCHAN) return new;
        if (slow) {
                speed=63.0/64.0;
        } else {
                speed=3.0/4.0;
        }
        x=new+(speed*(smooth[bn]-new));
        smooth[bn]=x;
        return x;
}

        OpenADC( ADC_FOSC_RC      &
         ADC_RIGHT_JUST   &
         ADC_4_TAD,
         ADC_CH2          &
         ADC_REF_VDD_VSS  &
         ADC_INT_OFF , ADC_9ANA);

        SetChanADC(ADC_CH5);                    // RF0  for input current AMP300
        Delay10TCYx(250);

        Vin=0;
    for(i=0;i<64;i++)
    {
        ConvertADC();
        while(BusyADC());
        Vin += (unsigned int) ReadADC();
    }
    Vin /= 64;
        CloseADC();

        a300=Vin;                                                               // raw ADC value
        Vin=Vin-AMP300_OF;                                              // set zero null point
        current=Vin*(ADC5_OFF-127+adc_cal[5]);
        current=current/10;
        current=current/AMP300_SEN;
        current=(long)lp_filter((float)current,3,TRUE); //      use digital filter on noisy sensor
 
Top