A/D conversion with PIC18F67J50


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Thanks mister_e ! I have flipped to page 299 to 302 so many times but never noticed the "D" to "N" change. Doh!

    Do you think it is edited out because it is a shared address, only distinguished by the address share bit ADSHR in the WDTCON register?

    Currently I have to:
    @ bsf WDTCON,ADSHR 'flag address share bit
    ADCON0 = %11111000 ' channels with a 0 is analog input, all others digital
    @ bcf WDTCON,ADSHR
    (or should I say I think? I have to....)

    to set the aNcon0 register

    (Despite all my mistakes, I am now getting valid conversion results, as of post 4)
    Last edited by ScaleRobotics; - 6th May 2009 at 22:34.
    http://www.scalerobotics.com

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


    Did you find this post helpful? Yes | No

    Default

    Holly crap, yeah, that make sense indeed. Yet another stupidity from Microchip

    So my example will need some changes...
    Code:
            '
            '       Configure ADC
            '       =============
            ANCON0  VAR BYTE EXT    ' not included in PBP2.50c
            ANCON1  VAR BYTE EXT    ' not included in PBP2.50c
            
            WDTCON.4 = 1    ' Switch to Alternate SFR
            ANCON0 = %10011110
                   '  -xx------ Not Implemented
                   '  1--1111-- AN7, & AN<4:1> = Digital
                   '  -------0- AN0 = Analog
                   
            ANCON1 = %11111111
                   '  11111111- AN<15:10> = Digital
                                         
            WDTCON.4 = 0    ' Back to Default SFR
    or
    Code:
            '
            '       Configure ADC
            '       =============
            WDTCON.4 = 1    ' Switch to Alternate SFR
            
            ADCON1 = %10011110  ' alternate ANCON0
                   '  -xx------ Not Implemented
                   '  1--1111-- AN7, & AN<4:1> = Digital
                   '  -------0- AN0 = Analog
                   
            ADCON0 = %11111111  ' alternate ANCON1 
                   '  11111111- AN<15:10> = Digital
                                         
            WDTCON.4 = 0    ' Back to Default SFR
    By far, i prefer the first, easier to read

    However, yours work.. keep it like that. If it's not broken, don't fix it!
    Last edited by mister_e; - 6th May 2009 at 23:00.
    Steve

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

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


    Did you find this post helpful? Yes | No

    Default

    Side note... there's no real need to redefine ANCON1, ANCON0 as i did if you use ANCON1_ALT, ANCON0_ALT within your code. Those two are defined in PIC18EXT.BAS.

    Having _ALT written at the right of the register name, may remember you to set/clear WDTCON.4 bit? Maybe
    Steve

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

  4. #4
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Side note... there's no real need to redefine ANCON1, ANCON0 as i did if you use ANCON1_ALT, ANCON0_ALT within your code. Those two are defined in PIC18EXT.BAS.

    Having _ALT written at the right of the register name, may remember you to set/clear WDTCON.4 bit? Maybe
    Sweet! I did not see that either. May be time for glasses. And a lot cleaner than the way I was doing it, and I like the way you wrote the registry bits in the code. That would have kept me from having to divert my attention to and from tfm a lot!

    Thanks for all the help.

    Walter
    http://www.scalerobotics.com

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


    Did you find this post helpful? Yes | No

    Default

    To me, comments are really important. So, on the long run... coding like that
    Code:
            ADCON0 = %00000001
                   '  0-------- VCFG1, Vref- 0 = AVss (1=AN2)
                   '  -0------- VCFG2, Vref+ 0 = AVdd (1=AN3) 
                   '  --0000--- CHS<3:0>, Channel select -- 0
                   '  ------0-- Go/Done, don't care for now
                   '  -------1- ADON, Enable ADC
    May indeed avoid to open the datasheet all the time, one thing is sure, it's easier to modify/understand later.
    Last edited by mister_e; - 8th May 2009 at 02:03.
    Steve

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

Similar Threads

  1. Fast / low resolution A/D conversion
    By AndrewC in forum General
    Replies: 7
    Last Post: - 7th April 2009, 12:18
  2. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 16:26
  3. A/D conversion problem on 18F4431
    By ttease in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th April 2007, 23:03
  4. A/D converter fails?
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2006, 18:57
  5. Strange A/D conversion...
    By Christos_K in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th June 2005, 01:35

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