Microchip Technology
Welcome to www.microchip.com
Search: Click here to Search Microchip.com
Forums Home Register LoginLog Out Inbox Address Book My Subscription Member List Search My Profile FAQ
ADC reading '0' on 18F1330

ADC reading '0' on 18F1330

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [Microcontroller Discussion Group] >> ADC & Comparators >> ADC reading '0' on 18F1330 Page: [1]
Login
Message << Older Topic   Newer Topic >>
ADC reading '0' on 18F1330 - Jan. 28, 2007 8:34:40 PM   
jrpowers

 

Posts: 3
Joined: Jan. 28, 2007
From: 0
Status: offline
I have a PIC18F1330 running at 8MHz on the internal oscillator, and I'm trying to read analog values on the RA4/T0CKI/AN2/Vref+ pin.  Vdd is 3.7 volts, and the pin is connected to 3.3 volts, yet the readings I get are consistently '0'!

Relevant code:

in main:

TRISAbits.TRISA4 = 1; //RA4 = input
T0CON = 0x00; /* Shut off timer 0, since it could use T0CKI */

the ADC capture code:

ADCON0bits.ADON = 0; // Turn off ADC
ADCON1 = 0b00000100;  // Vref=Vdd, AN2 enabled
ADCON2 = 0b10111001;  // Right-justify, 20 TAD, TOSC=FOSC/8
ADCON0 = 0b00001000; //  SEVTEN=0, CH = 2, still off
ADCON0bits.ADON = 1; // Turn ADC on
ADCON0bits.GO = 1;

while(ADCON0bits.NOT_DONE); //wait for result
adc = ReadADC();  //get ADC result
itoa(adc, val);
putsUSART (val);

Notes:

* ReadADC() is just the normal library function.  At first I was strictly using library code to save time, but I've decomposed everything trying to track this problem down.  I have also directly verified that ADRESH and ADRESL are both coming up 0.
* I'm using the extended instruction set.
* I've also tried configuring to read AN0,AN1, and they come up zero as well.

Help!  If anyone has ideas, I will try them immediately and post the results.

Thanks in advance!

Updates:  Just to be sure this was a problem with my code, I tried another 18F1330, same behavior.  I'm using version 3.02 of the C18 compiler, and I noticed that there were some small fixes for this PIC in newer versions.  However,  I verified that the ADC-related registers all point to the right places.  I'm not sure what else to try.

< Message edited by jrpowers -- Jan. 30, 2007 8:06:49 AM >
Post #: 1
RE: ADC reading '0' on 18F1330 - Feb. 6, 2007 2:50:39 AM   
PhilDys

 

Posts: 2
Joined: Feb. 6, 2007
From: 0
Status: offline
Easy solution to this one. The data sheet is correct for early silicon, but in later silicon the ADCON1 register was changed. You now need to enable the A/D channels with a 0 or select port functions with a 1.

(in reply to jrpowers)
Post #: 2
RE: ADC reading '0' on 18F1330 - Feb. 19, 2007 9:09:01 PM   
jrpowers

 

Posts: 3
Joined: Jan. 28, 2007
From: 0
Status: offline
Thanks, I will give that a try.  I hadn't noticed the response here until just now.

This should also solve my latest nagging problem, which is that my software I2C implementation is constantly reading '0'.

I'll post results, but I suspect this will solve my problems.  Thank you.  By the way, how did you figure this out?  Trial-and-error, or are there new data sheets?

(in reply to PhilDys)
Post #: 3
RE: ADC reading '0' on 18F1330 - Feb. 20, 2007 12:15:54 AM   
jrpowers

 

Posts: 3
Joined: Jan. 28, 2007
From: 0
Status: offline
Just confirmed that this suggestion works!  Thank you again.

(in reply to jrpowers)
Post #: 4
Page:   [1]
All Forums >> [Microcontroller Discussion Group] >> ADC & Comparators >> ADC reading '0' on 18F1330 Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


  Site Index  |  Legal Information  |  microchipDIRECT  |  Samples  |  Technical Support  |  Investor Information  |  Careers at Microchip  |  Contact Us  |  RSS Feeds ©2009 Microchip Technology Inc.  
  Shanghai ICP Recordal No.09049794  
Forum Software © ASPPlayground.NET Advanced Edition 2.5.5 Unicode

0.125