Adcon register with P18F4550


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747

    Default Adcon register with P18F4550

    Hi ,

    I am trying to use A/D conversion, but my code compiles but does not even get to main loop when I add ADCON1 AND ADCON2 registers, these are valid registers in this pic, anybody knows why?

    ADCON0 = %11000001 ' AN0, Configure and turn on A/D Module
    'ADCON1 = %10001001 ' Analog input
    'ADCON2 = %10000001 ' Right justified results for 10 bits,Fosc/8

    K

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


    Did you find this post helpful? Yes | No

    Default Re: Adcon register with P18F4550

    ADCON0 and ADCON1 bits 6 and 7 should both be 0.

    Are you using ADCIN or working the registers? Show your code.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: Adcon register with P18F4550

    Ok Thanks , I wiil try it, but the datasheet sheet says: bit 7-6 Unimplemented: Read as ‘0’ .. shouldn't there be no difference as what is there?
    ok work now, but gives me an 8 bit result instead of 10 bit

    K

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: Adcon register with P18F4550

    Ok Thanks , I wiil try it, but the datasheet sheet says: bit 7-6 Unimplemented: Read as ‘0’ .. shouldn't there be no difference as what is there?
    ok work now, but gives me an 8 bit result instead of 10 bit

    I also have these defines in the prog:
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uSec

    K
    Last edited by lerameur; - 24th February 2011 at 14:45.

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


    Did you find this post helpful? Yes | No

    Default Re: Adcon register with P18F4550

    Adcon2.7=1
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: Adcon register with P18F4550

    ya thats what i had before I commented out. See I have 2.23v on pin ANA5 and it reading 93 on the LCD


    K

  7. #7
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: Adcon register with P18F4550

    I change a bit of the program , but i am still getting 8 bit results ( max 255)

    Code:
    Define ADC_BITS 10 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uSec
    
    ADCON0 = %00000001 ' AN0, Configure and turn on A/D Module
    ADCON1 = %00001001 ' Analog input
    ADCON2.7 =1 	   ' Right justified results for 10 bits,Fosc/8
    
    Check_voltage_Low:
    ADCON0 = 00010001 'Start Conversion
    ADCON2.7 =1
    ADCIN 4, voltage_check 'analog pin 4 get the 10 bit result  Check the battery voltage on pin PORTA.5
    
    lcdout $FE,1, "Battery voltage"
    lcdout $FE,$C0, "TempC: ",  dec voltage_check
    pause 1500
    Return

Members who have read this thread : 0

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