Problems with ADC


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2008
    Location
    Charlottesville, VA
    Posts
    31

    Post Problems with ADC

    Hell again all... seems like I get one thing fixed and something else goes wrong. I am having a problem with my ADC on the PIC16F877A. Here is the code that I am using:

    Code:
    DEFINE OSC 20
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 1
    PAUSE 1000
    
    LIGHT VAR WORD
    
    ADCON1=%10000010
    TRISA=%11111111
    TRISB=%00000000
    TRISD=%00000000
    
    MAIN:
         ADCIN 1, LIGHT
            LIGHT.0=PORTD.6
            LIGHT.1=PORTD.7
            LIGHT.2=PORTB.0
            LIGHT.3=PORTB.1
            LIGHT.4=PORTB.2
            LIGHT.5=PORTB.3
            LIGHT.6=PORTB.4
            LIGHT.7=PORTB.5
            LIGHT.8=PORTB.6
            LIGHT.9=PORTB.7
    GOTO MAIN
    END
    This measures the voltage coming from a CDS Photocell circuit. I have Vcc to photocell to 10k resistor to ground. ADC is connected between the photocell and 10k resistor, so as the resistance of the photocell changes, as does the voltage. I can measure this with a meter but when I try to output to light up the corresponding LEDs it doesn't work right. Any help with this will be greatly appreciated.

    Morris Beasley
    Manufacturing Test Technician
    B.S. Industrial Technology (2007)

    For more information on our robotics, please visit:
    http://www.ish-electronics.webs.com

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    2 things
    1. CDS usually have high impedance, but the PIC require a max of 10K. You'll need to use a buffer in between (op-amp, transistor, FET, ...)
    2. The way you have it now, you read PORTB and D and place it in your LIGHT variable

    try
    Code:
            PORTB = (LIGHT >>2)
            PORTD.6 = LIGHT.0
            PORTD.7 = LIGHT.1
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Dec 2008
    Location
    Charlottesville, VA
    Posts
    31


    Did you find this post helpful? Yes | No

    Post

    Quote Originally Posted by mister_e View Post
    Code:
            PORTB = (LIGHT >>2)
            PORTD.6 = LIGHT.0
            PORTD.7 = LIGHT.1
    Doesn't this line just shift everything two bits to the right:
    Code:
    portb = (light >>2)
    By doing this I'm actually losing two bits right?

    Morris Beasley
    Manufacturing Test Technician
    B.S. Industrial Technology (2007)

    For more information on our robotics, please visit:
    http://www.ish-electronics.webs.com

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    LIGHT is a Word, PORT is a BYTE... this is always hard to fit 16bits in a 8 bit register huh?

    LIGHT>>2 - yes it shift two position to the right... yes you miss bit0 and bit1, but the next lines
    PORTD.6 = LIGHT.0
    PORTD.7 = LIGHT.1

    place them on PORTD.

    no lost at all.

    None of your bit are lost LIGHT>>2 as long as you dont use something like
    LIGHT=LIGHT>>2
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Dec 2008
    Location
    Charlottesville, VA
    Posts
    31


    Did you find this post helpful? Yes | No

    Default

    ok i was thinking that bit 0 and bit 1 would just be moved to where bits 2 and bits 3 are... thus showing bits 0 and 1 twice and losing bits 8 and 9 with the code you provided me with... i'll give it a shot and see what happens...
    Last edited by mcbeasleyjr; - 29th January 2009 at 17:38.

    Morris Beasley
    Manufacturing Test Technician
    B.S. Industrial Technology (2007)

    For more information on our robotics, please visit:
    http://www.ish-electronics.webs.com

Similar Threads

  1. 16F819 ADC problems
    By MUC in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 22nd March 2008, 18:36
  2. PIC18f2423 two 12bit adc input problems
    By Brandon in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th December 2007, 09:47
  3. I have problems with de ADC...
    By jomavilla24 in forum Off Topic
    Replies: 1
    Last Post: - 16th February 2007, 16:24
  4. adc problems
    By MARAD75 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 3rd December 2006, 05:47
  5. Newby with ADC problems.
    By Mark Scotford in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th March 2005, 20:09

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts