Help with ADC &16F628A


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Posts
    130

    Default Help with ADC &16F628A

    Im lost in only six lines of code, I type this on microcode/pbp2.46 (yes I set 16F628A in microcode studio)

    ADCON0 = 1
    lectura var byte
    mainloop:
    Adcin 0, lectura
    Goto mainloop
    End

    and I get errors during compile.

    Its been a while from my last programming, so maybe Im missing something obvious here.

    I would appreciate a working example of ADC for this pic or for 18f pics

    Thanks in advance
    Last edited by peu; - 16th January 2006 at 19:06.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Yeah it's a bit obvious as there's no ADC in the 16F628... only analog comparator.

    OUPS!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    Yeah it's a bit obvious as there's no ADC in the 16F628... only analog comparator.

    OOPS!
    Oops, so whats the correct code or example to read a potentiometer?

    Thanks (that was fast)

  4. #4
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Default

    You might look at the manual for the POT command. This is one option for measuring an analog signal without an ADC module. Another option is to use an external ADC or better yet, use a PIC with an ADC module on it. the 628 only has a comparator module.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

  5. #5
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rhino
    You might look at the manual for the POT command. This is one option for measuring an analog signal without an ADC module. Another option is to use an external ADC or better yet, use a PIC with an ADC module on it. the 628 only has a comparator module.
    ok, I can use 18F6220, so this is the new code:

    adcon0=1
    lectura var byte
    trisa=%00000111


    lectura=0
    mainloop:

    Adcin 0, lectura
    serout porta.3,6,[#lectura,"."]
    Adcin 1, lectura
    serout porta.3,6,[#lectura,"."]
    Adcin 2, lectura
    serout porta.3,6,[#lectura,"."]

    serout porta.3,6,[10,13]
    Goto mainloop
    End


    Im trying to read 3 potentiometers on ra0/1/2

    I use serouts to know if I read something

    [edit] this code is working I missed the # in the serout

    now I want to use the read value to set HPWM

    so I added this

    DEFINE OSC 4
    adcon0=1
    Rval var byte
    Gval var byte
    Bval var byte
    trisa=%00000111

    mainloop:

    Adcin 0, Rval
    serout porta.3,2,[#Rval,"."]
    Adcin 1, Gval
    serout porta.3,2,[#Gval,"."]
    Adcin 2, Bval
    serout porta.3,2,[#Bval,"."]

    serout porta.3,2,[10,13]

    hpwm 3,Rval,300
    hpwm 4,Gval,300
    hpwm 5,Bval,300

    Goto mainloop
    End


    no luck again
    Last edited by peu; - 16th January 2006 at 19:50.

  6. #6
    Join Date
    Mar 2005
    Location
    Iowa, USA
    Posts
    216


    Did you find this post helpful? Yes | No

    Default

    I can't even find a data sheet for 18F6220. Are you sure that is what you have. Also... there are TONS of examples here, and at MELabs website, and rentron.com on how to use the ADC module.
    Wisdom is knowing what path to take next... Integrity is taking it.
    Ryan Miller

Similar Threads

  1. Stable Adc Reading Routine
    By gebillpap in forum General
    Replies: 27
    Last Post: - 13th May 2015, 02:18
  2. 10 bit ADC display on LCD using 16f873
    By pr2don in forum mel PIC BASIC
    Replies: 3
    Last Post: - 6th March 2010, 18:29
  3. Can't get ADC to loop
    By TravisM in forum mel PIC BASIC
    Replies: 2
    Last Post: - 11th October 2009, 15:33
  4. ADC value with 2 decimals on an LCD
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2005, 15:54
  5. 12F675 ADC 'Issues'
    By harrisondp in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 31st March 2005, 01:55

Members who have read this thread : 0

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