ADC not working - I'm a new member


Closed Thread
Results 1 to 13 of 13

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

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

    Here is another example of a small test program that will read the AN2 a/d converter and send it to a debug window.

    one thing to remember is that the a/d converter names do not always match the pin #. example... AN2 does match PortA.2 but AN3 is actually on PortA.4.

    If you have not used the debug feature of the PICkit programmer, you program the chip, power it up and then goto the Tools Menu and choose UART Tool. This will open up another Terminal window where you choose 2400 baud in the upper left and then click on Connect.


    Code:
    ' 16F690
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 12/4/2007                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    ' 10-bit A/D conversion 
    ' Connect analog input to channel-2 (RA2)
    ' -----[ I/O Definitions ]-------------------------------------------------
     DEFINE DEBUG_REGG PORTA        'set debug port to porta
     DEFINE DEBUG_BIT 0             'use pin a0 of porta for debug
     DEFINE DEBUG_BAUD 2400         'set baud rate to 2400
     DEFINE DEBUG_MODE 0            'communicate in true mode
     
    ' Define ADCIN parameters
    ' Set number of bits in result
    DEFINE  ADC_BITS        10 
    ' Set clock source (3=rc)
    DEFINE  ADC_CLOCK       3   
    ' Set sampling time in microseconds
    DEFINE  ADC_SAMPLEUS    50     
    adcVar  VAR WORD ' Create variable to store result
    ' Set PORTA to all input
    'TRISA = %11111111     
    ' Set up AD
    ANSEL  = %00000100  'enable AN2, ALL THE REST DIGITAL
    ANSELH = %00000000  'AN8-11 DIGITAL
    ADCON0 = %10001000   ' RIGHT JUSTIFIED
    ADCON1 = %00010000  'fOSC/8     
    Pause 500               ' Wait .5 second
    main:  
      ADCIN 2, adcVar ' Read channel 0
      ' do something with adVar here
      debug DEC adcvar,"  ",BIN adcVar,$0D,$0A
      Pause 100              ' Wait.01 second
    GoTo main                   ' Do it forever
    Good Luck
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  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

    Thanks Dwight - that will sort me out once I've got my Microchip PICKit 2 dongle to start working again. The fault with the dongle seems like it may be electronic, not software.

    When I started this thread, I didn't have a MAX232 rigged up but I do now so from now on I can use the debug

    Kind regards from Kwa Dukuza

    John Bond
    Last edited by johnbond; - 19th June 2011 at 13:02.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

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

    Check out the PBP manual under DEBUG.
    Then look at
    DEFINE DEBUG_MODE X 'X being 0 or 1 - TRUE or INVERTED
    Dave
    Always wear safety glasses while programming.

  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 that "Heads-Up" Dave. I am scared of PC Com Ports after I got a 100V shock from one (half our 220V phase). I prefer using a MAX232 to a fried PCB. We tend to get Kong Fu PCs here and you never know what fascinating undocumented features are included. Maybe it's just Chinese revenge

    Regards form the dark continent - Africa
    John Bond

  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

    OK Dwight, so you're a Gentleman! Thanks for that neat code. I works like clockwork

    I now understand both ADC and DEBUG!

    Regards from Kwa Dukuza on the dark continent of Africa
    John Bond

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