10 bits ADCIN with 18F2520


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2010
    Posts
    7

    Default 10 bits ADCIN with 18F2520

    Hello, I hope my question is not something stupid...
    I tryed to check in the old posts but I found not one answer....

    I was using ADCIN (8 Bits) with this code:

    TRISA=255
    ADCON1=0
    DEFINE OSC 40
    DEFINE ADC_BITS 8
    DEFINE ADC_SAMPLEUS 50

    and:

    ADCIN 0, STORE_0

    where STORE_0 is a byte sized variable, and it works perfet.

    Now I tryed to perform a 10 bit conversion, I used a word sized variable and the define was modified in:

    DEFINE ADC_BITS 10

    ...but it store again one value large one byte, no more...

    Can someone help me posting a piece of working code for 18F2520?
    Thanks
    Stefano

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default Re: 10 bits ADCIN with 18F2520

    I'm not sure if this is the problem, but try:

    ADCON2.7=1
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  3. #3
    Join Date
    Apr 2011
    Location
    Kent, UK
    Posts
    52


    Did you find this post helpful? Yes | No

    Default Re: 10 bits ADCIN with 18F2520

    I never had any luck with DEFINE ADC_BITS 8 it allways wanted to work in 10 bit. But if you only need 8 bit, do an ADCIN with DEFINE_BITS 10 to a word variable then divide the answere by 4.

  4. #4
    Join Date
    Oct 2010
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: 10 bits ADCIN with 18F2520

    Quote Originally Posted by Kamikaze47 View Post
    I'm not sure if this is the problem, but try:

    ADCON2.7=1
    I tryed... should be someting else becouse it dont works...
    thanks
    Stefano

  5. #5
    Join Date
    Oct 2010
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: 10 bits ADCIN with 18F2520

    Quote Originally Posted by timmers View Post
    I never had any luck with DEFINE ADC_BITS 8 it allways wanted to work in 10 bit. But if you only need 8 bit, do an ADCIN with DEFINE_BITS 10 to a word variable then divide the answere by 4.
    Thanks but my problem is the opposite... it works with DEFINE ADC_BITS 8 and give me a byte value... but I need more precision and DEFINE_BITS 10 dont works in my code! :-(
    Bye
    Stefano

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: 10 bits ADCIN with 18F2520

    where STORE_0 is a byte sized variable, and it works perfet.

    Now I tryed to perform a 10 bit conversion, I used a word sized variable and the define was modified in:

    DEFINE ADC_BITS 10

    ...but it store again one value large one byte, no more...
    Try a WORD size variable.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Oct 2010
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: 10 bits ADCIN with 18F2520

    Quote Originally Posted by mackrackit View Post
    Try a WORD size variable.
    I did it.

    The value is stored in one word size variable but the value never come bigger than 255 (the same value I had when I used the 8 bits define).

    stefano

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: 10 bits ADCIN with 18F2520

    This is for a different chip but it might help. I like dealing with the registers directly, an example of both are here.
    http://www.picbasic.co.uk/forum/show...9694#post79694
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: 10 bits ADCIN with 18F2520

    This works for 10-bit A/D on an 18F2520, using 9600 baud serial to a PC to view the results.
    Code:
    DEFINE OSC 40
    
    SerPin VAR PORTC.6
    
    DEFINE ADC_BITS 10  ; 10-bit results
    ADCON2.7 = 1        ; right justify
    
    ADval  VAR WORD
    
    Main:
        ADCIN 0, ADval
        SEROUT2 SerPin, 84,[DEC ADval,13,10]
        PAUSE 500
    GOTO Main
    DT

  10. #10
    Join Date
    Oct 2010
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: 10 bits ADCIN with 18F2520

    Thanks to all...
    I will try the code and I will reply!
    Stefano

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts