Microchip

 ADC reading '0' on 18F1330

Author Message
jrpowers

  • Total Posts : 3
  • Reward points : 0
  • Joined: 1/28/2007
  • Location: 0
  • Status: offline
ADC reading '0' on 18F1330 Sunday, January 28, 2007 8:34 PM (permalink)
0
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 on Tuesday, January 30, 2007 8:06 AM>
 
#1
    PhilDys

    • Total Posts : 2
    • Reward points : 0
    • Joined: 2/6/2007
    • Location: 0
    • Status: offline
    RE: ADC reading '0' on 18F1330 Tuesday, February 06, 2007 2:50 AM (permalink)
    0
    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.
     
    #2
      jrpowers

      • Total Posts : 3
      • Reward points : 0
      • Joined: 1/28/2007
      • Location: 0
      • Status: offline
      RE: ADC reading '0' on 18F1330 Monday, February 19, 2007 9:09 PM (permalink)
      0
      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?
       
      #3
        jrpowers

        • Total Posts : 3
        • Reward points : 0
        • Joined: 1/28/2007
        • Location: 0
        • Status: offline
        RE: ADC reading '0' on 18F1330 Tuesday, February 20, 2007 12:15 AM (permalink)
        0
        Just confirmed that this suggestion works!  Thank you again.
         
        #4
          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • 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
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2013 ASPPlayground.NET Forum Version 3.9