ADC not working - I'm a new member


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: ADC not working - I'm a new member

    I think your problem is here:
    Code:
    Adcin 2, x ' Read ADC value on AN2 (PORTA.2)
    you are reading the value of AN2, then storing in x
    You should be storing in potval

    And WELCOME to the forum!!
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  2. #2
    Join Date
    Jun 2011
    Location
    Kwa Dukuza, South Africa
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: ADC not working - I'm a new member

    Sorry, I spotted that after I posted but this is still not working...

    I've added

    =========================================

    ADCON1 = %10000100 ' Set PORTA analog and RIGHT justify result
    ADCON0 = %01000001 ' Configure and turn on A/D Module channel o Fosc 8

    =========================================

    and changed

    =========================================

    Adcin 0, PotVal

    =========================================

    I don't understand registers. I've read the PIC16F690 DATASHEET a couple of times. I seem to handle these issues best using the "Monkey see... monkey do" philosophy when trying to grasp complex problems. (Maybe the Monkey see, monkey do is part of my African heritage )

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: ADC not working - I'm a new member

    I don't have my book handy, but if you look at the ADCIN section of the PBP manual, there are several DEFINES you need in order to use the ADCIN command. Also to post code in the cool code box, you need to use tags. Really simple:
    [code[ <----should be the other, but then you won't see the tag
    All your code here
    [/code[ <----Again the second bracket should be } without the shift key.

    Maje sense?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Jun 2011
    Location
    Kwa Dukuza, South Africa
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: ADC not working - I'm a new member

    Thanks for your help Bert,

    Bert said "[code[ <----should be the other, but then you won't see the tag
    All your code here
    [/code[ <----Again the second bracket should be } without the shift key."

    Ja dit maak sense, dis cool! (Afrikaans response to Bert's last question - For English, replace "this" for "dit" and "dis")

    I've tried the various DEFINE and REGISTER options but I really don't know what I am doing. Nothing happens. I haven't linked up a UART/USART yet so I can't debug and I am in the dark. Hardware RS232 is my next exercise and I think I'll need to understand REGISTERS for that.

    Kind regards from Kwa Dukuza, lost somewhere in darkest Africa
    John Bond

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: ADC not working - I'm a new member

    Well now we need the basic stuff - lol. What pic? what version PBP? MPLAB or MCS? PM or MPASM? Internal osc or external? Some of it we don't need for this problem, but its a good idea to let us know what you are working with.

    What doesn't work? do any led's work? Can you make them blink? Is the value just wrong?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  6. #6
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: ADC not working - I'm a new member

    I've just glanced at an old 16f690 program, which was unfeasibly huge so I've hacked it down & hopefully not missed anything during the slimming process...

    Code:
    '-------------------------------------------------------------------------
    DEFINE ADC_BITS  8     ' ADCIN resolution  (Bits)
    DEFINE ADC_CLOCK 1     ' ADC clock source  (Fosc/8)
    DEFINE ADC_SAMPLEUS 11 ' ADC sampling time (uSec)
    ADCON1 = %0100000 ' FOSC/4
    ' 
    CM1CON0 = 0  'turn the pesky comparators off
    CM1CON1 = 0  'turn the pesky comparators off
    CM2CON0 = 0 'turn the pesky comparators off
    CM2CON1 = 0 'turn the pesky comparators off
    ' 
    ANSEL       = %0000010        'RA1 (pin 18) AN1 analogue 
    ' 
    PotVal Var Byte
    '
     
    '********program starts......
    ' 
    adcin 1, PotVal
    '
     
    '[do cool stuff with contents of PotVal here, then have a cup of tea & a nap]
    You don't need to worry about ADCON0 (since the ADCIN command selects the ADC channel for you) *unless* you start wanting to use 10 bits, then you need to modify ADCON0.7 to suit (LH or RH Justify)
    Last edited by HankMcSpank; - 16th June 2011 at 20:31.

  7. #7
    Join Date
    Jun 2011
    Location
    Kwa Dukuza, South Africa
    Posts
    19


    Did you find this post helpful? Yes | No

    Default Re: ADC not working - I'm a new member

    Thanks Bert and Hank

    No time for tea or a nap but I'm sure this will solve my ADC problem. I now have a problem with the compiler. It crashes after a couple of downloads and only works again after reloading both PBP and MPLAB. I will make a new post on these issues

    Hank - Thanks for that warning on 10 bit (LH or RH Justify) because I will be using 10 bit to measure piezo pressure sensor and I will discarding the upper 1 or 2 bits to reduce the span to 8 bits. I am looking for a 0.05 Bar (peak to peak pressure fluctuation) to determine the speed of an air motor running at between 5 bar and 6 bar. 8 bit, without reducing the span, makes it a bit tight!

    Thanks again and kind regards

    John

Members who have read this thread : 0

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

Tags for this Thread

Posting Permissions

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