reading values when no analog input

Discussion in 'Embedded Systems and Microcontrollers' started by Anjanav, Apr 22, 2010.

  1. Anjanav

    Thread Starter New Member

    Mar 2, 2010
    16
    0
    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
     
  2. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    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.
     
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  4. Anjanav

    Thread Starter New Member

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

    am already connected 100ohm resistor to each pins of analog channel(0-7)...
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  6. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    What do you have them connected to?
     
  7. Anjanav

    Thread Starter New Member

    Mar 2, 2010
    16
    0
    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
     
  8. Anjanav

    Thread Starter New Member

    Mar 2, 2010
    16
    0
    to reduce the noise....
     
  9. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  10. Anjanav

    Thread Starter New Member

    Mar 2, 2010
    16
    0
    ok t06afre....

    I will check the adc setup and code and say....
    can u say me y 0x07 constant is used in programs...
     
  11. rjenkins

    AAC Fanatic!

    Nov 6, 2005
    1,015
    69
    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.
     
  12. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,913
    2,187
    A little signal processing of the ADC result for slowly changing measurements helps.

    C18 fragment

    Code ( (Unknown Language)):
    1. float lp_filter(float new, int bn,int slow)                             // low pass filter, slow rate of change for new, 8 channels, slow/fast select
    2. {
    3. static  float   smooth[LPCHAN]={0},x;
    4. float                   speed;
    5.         if (bn>LPCHAN) return new;
    6.         if (slow) {
    7.                 speed=63.0/64.0;
    8.         } else {
    9.                 speed=3.0/4.0;
    10.         }
    11.         x=new+(speed*(smooth[bn]-new));
    12.         smooth[bn]=x;
    13.         return x;
    14. }
    15.  
    16.         OpenADC( ADC_FOSC_RC      &
    17.          ADC_RIGHT_JUST   &
    18.          ADC_4_TAD,
    19.          ADC_CH2          &
    20.          ADC_REF_VDD_VSS  &
    21.          ADC_INT_OFF , ADC_9ANA);
    22.  
    23.         SetChanADC(ADC_CH5);                    // RF0  for input current AMP300
    24.         Delay10TCYx(250);
    25.  
    26.         Vin=0;
    27.     for(i=0;i<64;i++)
    28.     {
    29.         ConvertADC();
    30.         while(BusyADC());
    31.         Vin += (unsigned int) ReadADC();
    32.     }
    33.     Vin /= 64;
    34.         CloseADC();
    35.  
    36.         a300=Vin;                                                               // raw ADC value
    37.         Vin=Vin-AMP300_OF;                                              // set zero null point
    38.         current=Vin*(ADC5_OFF-127+adc_cal[5]);
    39.         current=current/10;
    40.         current=current/AMP300_SEN;
    41.         current=(long)lp_filter((float)current,3,TRUE); //      use digital filter on noisy sensor
    42.  
    43.  
    44.  
     
Loading...