pic 12f683 adc help please


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2012
    Posts
    3

    Default pic 12f683 adc help please

    Hello i try to understand the use of the adc converter in 12f683.
    i have found som code on the internet but i dont know how to modify.

    i have testet this code and it works . this give me a 8bit result from AN3
    and present the result as a stream of pulses on GPIO.1 just to monitor the funktion of the adc.

    can someone help me modify the code for this so i can read AN0 + AN1 and store them as adval1 and adval2.
    the rest of the ports are digital i/o.

    the workin example code.

    ' Define ADCIN parameters
    Define ADC_BITS 8 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS
    ANSEL = %00111000 ' Set AN3 analog, rest digital
    CMCON0 = 7 ' Analog comparators off

    adval Var byte ' Create adval to store result
    GPIO.1=0
    Pause 500 ' Wait .5 second for LCD to init
    mainloop:
    ADCIN 3, adval ' Read channel 3 to adval

    Pulsut: 'pulses
    high GPIO.1
    pause 5
    low GPIO.1
    pause 5
    adval=adval - 1
    if adval>0 then pulsut
    pause 100
    Goto mainloop ' new reading.
    End

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


    Did you find this post helpful? Yes | No

    Default Re: pic 12f683 adc help please

    here is an example of reading an AD input on a 12F683... you will have to adapt it to your needs.

    don't forget that pin RA4 is analog input 3. also don't forget that RA3 defaults to MCLR and also can ONLY be an input, never an Output.

    Code:
    '12F683
    '****************************************************************
    '*  Name    : UNTITLED.BAS                                      *
    '*  Author  : [select VIEW...EDITOR OPTIONS]                    *
    '*  Notice  : Copyright (c) 2007 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 12/24/2007                                        *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
     DEFINE DEBUG_REGG GPIO        'set debug port to gpio
     DEFINE DEBUG_BIT 0             'use pin 0 for debug
     DEFINE DEBUG_BAUD 2400         'set baud rate to 2400
     DEFINE DEBUG_MODE 0            'communicate in true mode
    ' -----[ Initialization ]--------------------------------------------------
    Reset:
    TRISIO = %11001100    'configure GPIO.0,1,4,5 as outputs, gpio.2 as input
    ansel  = %00000100    'and set gpio.2 as analog
    cmcon0 = %00000111    'turn off the comparator
    adcon0 = %00001011   'left jstfied,vdd,x,x,an2,an2,start,adc on
    define adc_bits 8            'set up the a/d converter
    define adc_clock 3
    define adc_sampleus 50
    adval var byte
    ' -----[ Program Code ]----------------------------------------------------
     
    main:
    adcin 2,adval
    if adval=0 then main
    debug "ad val= ",#adval,$0D,$0A
    'pause 500
    goto main
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  3. #3
    Join Date
    Apr 2008
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: pic 12f683 adc help please

    Hello Helgeland

    In order to configure the analog pins you have to write to som internal pic registers ADCON0 , ANSEL and TRISIO registers.

    Here is a link to a very useful document describing PIC12F675 and 12F683 settings.
    Look to page 10 to 14

    http://members.shaw.ca/picgroup/Reso...Cadilly-13.pdf

    Hope this helps you

  4. #4
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: pic 12f683 adc help please

    Wow, that link is the shiznits. I wish that link was around about a year ago when I started using the 12f683 for a few projects. Great info.

Members who have read this thread : 2

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