ADC not working - I'm a new member


Closed Thread
Results 1 to 13 of 13

Hybrid View

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

    Default ADC not working - I'm a new member

    I've migrated from the Parallax sx but I'm new to PICs and PicBasic Pro

    How do I use ADCIN

    The following program is meant to display the binary value of a pot on AN2 on 8 LEDs on port RC. It doesn't work!!!

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

    ' Name : LearningADC.bas
    LEDs var PORTC

    ' Allocate variables

    PotVal Var Byte

    ANSEL = %00000100 ' Set PORTA.1 analog, rest digital
    ANSELH = %00000000

    mainloop:
    Adcin 2, x ' Read ADC value on AN2 (PORTA.2)
    LEDs = potval
    Pause 100 ' Do it about 10 times a second
    Goto mainloop

    End

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

    Thanks from Kwa Dukuza, lost somewhere in South Africa
    John Bond

  2. #2
    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!

  3. #3
    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 )

  4. #4
    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!

  5. #5
    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

  6. #6
    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!

Members who have read this thread : 2

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