+ Reply to Thread
Results 1 to 3 of 3

Thread: 18F66J16 A/D operates only without ADIN

  1. #1
    Licensed User Pictester's Avatar
    Join Date
    Nov 2006
    Location
    Winnipeg, Canada
    Posts
    12

    Default 18F66J16 A/D operates only without ADIN

    Hello,

    Here's a bit of feedback on my experience using the compiler to implement the analog to digital controller using the ADIN command with an 18F66J16.

    The ADIN command worked fine with channel AD0 (pin 0 of port A) but for whatever reason it would not work on the pin 2 of Port A. Anyway, I used the assembler method given in the Microchip manuals and got it working. Maybe it's because the ANCON0 and ADCON0 registers, and the ANCON1 and ADCON1 registers share the same locations? This makes the sequence of things to do a bit different, vs. most other chips where there are ADCON0, ADCON1 and ADCON2 registers to cover all parameters without having to have two different registers occupy the same physical memory location. Note that I call each bit directly in these registers; calling the whole 8 bits at once still didn't work.

    Anyway, here's the code that worked. And thanks to Mark Rodgers for helping me get the chip operating in the first place - your help is appreciated!

    Any comments? Is this a problem with the chip or is there a way to get ADIN to work with the second channel AD2?

    Hi, its great to see you visiting our forum. Why not try Proton Compiler for FREE?

    Download the FREE version of Proton Compiler, Its called Amicus18 and its available from HERE

    Already using proton Compiler??? Get rid of these pesky messages... get LICENSED USER STATUS




    -Tom
    ************************************************** **
    Device = 18F66j16

    CONFIG_START XT_OSC, WDT_OFF, PWRTE_ON, BODEN_ON, LVP_OFF, CP_OFF, CPD_OFF, DEBUG_OFF

    CONFIG_END

    OSCCON.6=1 'INTOSC is 8mhz
    OSCCON.5=1
    OSCCON.4=1
    OSCTUNE.6=0 'switch off PLL for INT OSC
    Declare XTAL 8
    Symbol Get_Vbatt=PORTA.1 'get battery voltage signal
    Symbol Debug_out=PORTB.5 'debug output line


    Dim CR As Byte
    CR = $0D
    Declare ADIN_RES 10 ' 10-bit result required
    Declare ADIN_TAD 32_FOSC ' RC OSC chosen
    Declare ADIN_STIME 50 ' Allow 50us sample time
    Dim VAR1 As Word
    Dim X As Float
    Dim Y As Float
    Dim DEG As Float

    TRISA = %00001101 ' Configure PORTA pins As inputs And outputs
    WDTCON.4 = 1
    ANCON0 = %11010010 ' Configure pins as digital or analog, AN0-AN7
    WDTCON.4 = 0
    ADCON0.7 = 0 'neg ref is AVss
    ADCON0.6 = 0 'pos ref is AVdd
    ADCON0.0 = 0 'A/D off
    ADCON1.7 = 1 ' right justify
    ADCON1.6 = 0 ' normal A/D operation
    '******************************* Battery V*****************
    WDTCON.4 = 0 ' choose ADCON location
    ADCON0.2 = 0 ' pick channel 0 bit 1
    ADCON0.3 = 0 ' pick channel 0 bit 2
    ADCON0.4 = 0 ' pick channel 0 bit 3
    ADCON0.5 = 0 ' pick channel 0 bit 4
    ADCON0.0 = 1 ' turn on the A/D
    DelayUS 100 ' Delay to allow A/D to stabilize
    ADCON0.1 = 1 ' Start A/D - GO
    DelayMS 1 ' Throw in amply delay to allow A/D to stabilize
    VAR1 = (ADRESH << 8) + ADRESL 'put A/D variables into word
    SerOut Debug_out, 84, ["Battery V level = ",HEX4 VAR1, CR]
    Get_Vbatt = 0
    '********************************************** Temperature
    WDTCON.4 = 0
    ADCON0.2 = 0 ' pick channel 2
    ADCON0.3 = 1
    ADCON0.4 = 0
    ADCON0.5 = 0
    ADCON0.0 = 1 ' turn on the A/D
    DelayUS 500 ' Delay to allow A/D to stabilize
    ADCON0.1 = 1 ' Start A/D - GO
    DelayMS 1
    VAR1 = (ADRESH << 8) + ADRESL 'put A/D variables into word - ADIN didn't work here
    SerOut Debug_out, 84, ["Temp level = ",HEX4 VAR1, CR]


  2. If you're a Licensed user of PROTON DEVELOPMENT SUITE, apply for Licensed User Status to remove these pesky messages
     and get access to additional forum areas, Beta test downloads and more!

  3. #2
    Licensed User Tim's Avatar
    Join Date
    Jan 2003
    Location
    london
    Posts
    6,950


    Default

    So to clarify what your saying, your having a problem with the ADin on a as yet unsupported device that you added the .lpb etc files for your self. The chip its self seems to be different in its configuration and will not even support the writing to a register in one go? (the way Proton would do it)

    Now your wanting ADin to work on the higher channels despite you calming that you have it going already? Why?

    BTW I see an issue with your code

    VAR1 = (ADRESH << 8) + ADRESL 'put A/D variables into word

    Its producing a lot of code for so little

    All you need to do is

    dim ADRESULT as ADRESL.word

    VAR1 = ADRESULT

    Thanks for point out a potential problem

    BTW were is the ASM?
    Tim

  4. #3
    Licensed User Pictester's Avatar
    Join Date
    Nov 2006
    Location
    Winnipeg, Canada
    Posts
    12


    Default

    Hi Tim,

    Thank you for the reply. You are right, I'm not posting to ask for the solution to a problem and I'm not asking ADIN be implemented. I put in the submission to the group to provide the workaround I worked out for anyone else who will work with this chip in the future. I chose the "feedback" forum in case you are working on adding the 18F66J16 to the list of supported chips. If this is so, I would hope my message serves as a helpful observation. On another note, I've received so much help from this group that I feel I should contribute what I can when possible.

    Of course, using ADIN is much simpler to use with fewer details to go wrong, so I prefer to use it over having a whack of register definitions to set up and change each time. So if ADIN is implemented for this chip, that would result in much fewer code lines (and the associated chance for error) for me and my people.

    Regarding the assembler code - well, I described this as an "assembler" method but it isn't really the right term, I meant I was addressing each register bit individually rather than being able to use ADIN's much quicker functionality. The methods were derived by reading assembler examples from Microchip.

    And thank you for the comment on the code.

    -Tom

+ Reply to Thread

Similar Threads

  1. adding 18F66J16
    By Pictester in forum Wish List / Product Feedback
    Replies: 12
    Last Post: 26th October 2007, 13:34
  2. Problem adin 0
    By ralf2 in forum Proton Plus Compiler v3
    Replies: 9
    Last Post: 25th October 2007, 13:38
  3. Adin
    By Richard in forum Proton Plus Compiler v3
    Replies: 5
    Last Post: 9th October 2005, 13:23

Members who have read this thread since 2nd May 2012, 22:28 : 0

Actions :  (Set Date)  (Clear Date)

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