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]


Reply With Quote
