12F683 ADC problems


Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159

    Default 12F683 ADC problems

    Hi all.

    I'm having an issue that is driving me crazy. I'm trying to use a potentiometer on GPIO4 (10K linear - wiper on GP4, ends on 5V and ground).

    Originally, I tried to use:

    Code:
    duty = adval 'adval is the result of the ADC
    It worked, but it appears that I'm only getting part of the way, as the led (on GP2/CCP1) only varies from off to about half brightness. I then discovered that the result is from 0-1025, not 255 as I had assumed.
    Then I tried:

    Code:
    duty = adval >> 2
    But the led never lights.

    After some more reading, here is what I have now. It still results in the led never lighting, no matter the position of the pot.

    Code:
    ;pic12f683
    #CONFIG
    cfg = _INTOSCIO
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_ON
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _BOD_ON
    cfg&= _IESO_ON
    cfg&= _FCMEN_ON
      __CONFIG cfg
    #ENDCONFIG
    
    DEFINE OSC  8
    ' 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
    
    OSCCON=$70
    CMCON0    = 7
    TRISIO   = %111011      ;gp2= output
    ANSEL = %00111000 ' Set AN3 analog, rest digital
    CMCON0 = 7 ' Analog comparators off
    ADCON0.7 = 1
    
    adval Var word ' Create adval to store result
    duty var byte
    result var word
     
    mainloop:
        ADCIN 3, adval ' Read channel 3 to adval
        pauseus 50 'wait 50us for read to complete 
        result = adval >> 2 'right shift by 2 bits to divide by 4
        if result > 255 then result = 255
        duty = result.BYTE0  
        ' hpwm Channel, Dutycycle, Frequency 
        hpwm     1,duty,600   ; set led brightness at 600hz
        pause 50 ;Pause for 50 milliseconds   
        goto mainloop
    Anyone got any ideas what I'm doing wrong? It's getting a little frustrating. I am planning to do a test for the GO/DONE bit in ADCON0 to make the delay after read less, but I want to get this part working first.

    I would appreciate any help anyone can offer.
    Last edited by andywpg; - 5th April 2024 at 16:48.
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

Similar Threads

  1. ADC on 12F683
    By JakeMend in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th July 2017, 00:44
  2. pic 12f683 adc help please
    By Helgeland in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd February 2012, 14:31
  3. ADC in 12F683; puzzled
    By mikebike in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 23rd September 2010, 20:27
  4. 12f683 ADC help
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 26th November 2009, 21:37
  5. 12F683 Comparator Problems
    By morethanenuf in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 9th September 2005, 15:36

Members who have read this thread : 16

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