12Bit ADC with PIC18F2523


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Apr 2008
    Posts
    25

    Default 12Bit ADC with PIC18F2523

    Hello,
    I have code for 10 bit ADC which is normally working with PIC18F2455 and I want to use this code for 12 bit ADC with PIC18F2523.
    I changed Define ADC_BITS 10 to ADC_BITS 12, but results are sill 10 Bits.
    I using 20 MHz external oscillator.
    How to configure this code for 12 bit ADC with PIC18F2523 ?

    Thank you


    Here is my code:

    Define LOADER_USED 1
    DEFINE OSC 48

    ' Define LCD registers and bits
    Define LCD_DREG PORTB
    Define LCD_DBIT 4
    Define LCD_RSREG PORTC
    Define LCD_RSBIT 7
    Define LCD_EREG PORTC
    Define LCD_EBIT 6
    DEFINE LCD_BITS 4 ' 4-bit data bus
    DEFINE LCD_LINES 2 ' LCD - 2 lines


    ' Define ADCIN parameters

    Define ADC_BITS 12 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS


    adval var word ' Create adval to store result

    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %00001010 ' Set PORTA analog...
    ADCON2 = %10000000 ' ...and right justify result

    Pause 500 ' Wait .5 second

    loop: ADCIN 0, adval ' Read channel 0 to adval
    Lcdout $fe, 1 ' Clear LCD
    Lcdout "Value: ", DEC adval ' Display the decimal value
    Pause 100 ' Wait .1 second
    Goto loop ' Do it forever
    End

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,636


    Did you find this post helpful? Yes | No

    Default Re: 12Bit ADC with PIC18F2523

    ADCON2 = %10000000 ' ...and right justify result
    how many times do we see this totally wrong statement

    ADCON2 = %10000000 ' ...and right justify result and set the conversion clock to fosc/2
    which is way out of limits for a 48mhz osc and contradicts the define
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    why not just
    ADCON2.7=1
    or
    ADCON2 = ADCON2 | %10000000 ' ...and right justify result


    other than that i have nothing , never tried a 12 bit adc chip.
    you may need to do it manually

  3. #3
    Join Date
    Apr 2008
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: 12Bit ADC with PIC18F2523

    Hello richard,
    I configured my code for 12 Bit AD, now I get 12 Bits results, but it is working only with 4MHz external oscillator.
    When I replace extenal oscillator wit 20MHz and DEFINE OSC 20, it is not working, what is wrong?


    Define LOADER_USED 1
    DEFINE OSC 4

    ' Define LCD registers and bits
    Define LCD_DREG PORTB
    Define LCD_DBIT 4
    Define LCD_RSREG PORTC
    Define LCD_RSBIT 7
    Define LCD_EREG PORTC
    Define LCD_EBIT 6
    DEFINE LCD_BITS 4 ' 4-bit data bus
    DEFINE LCD_LINES 2 ' LCD - 2 lines


    ' Define ADCIN parameters

    Define ADC_BITS 12 ' Set number of bits in result
    Define ADC_CLOCK 3 ' Set clock source (3=rc)
    Define ADC_SAMPLEUS 50 ' Set sampling time in uS


    adval var word ' Create adval to store result

    advalLow VAR WORD ' make it available to use in PBP
    advalHigh VAR WORD ' make it available to use in PBP
    advalLow = ADRESL
    advalHigh = ADRESH


    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %00001010 ' Set PORTA analog...
    ADCON2.7=1 ' ...and right justify result

    Pause 500 ' Wait .5 second

    loop: ADCIN 0, adval ' Read channel 0 to adval
    adval = ADRESL + (ADRESH * 256)
    Lcdout $fe, 1 ' Clear LCD
    Lcdout "Value: ", DEC adval ' Display the decimal value
    Pause 100 ' Wait .1 second
    Goto loop ' Do it forever
    End

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,636


    Did you find this post helpful? Yes | No

    Default Re: 12Bit ADC with PIC18F2523

    in what way does it not work ?
    where and what are your config settings

    advalLow and advalHigh only need to be bytes

    advalLow VAR byte ' make it available to use in PBP
    advalHigh VAR byte ' make it available to use in PBP


    since ADRESH and ADRESHL are sequential in memory for that chip its possible to save a bit of typing by :-
    Code:
    @my_adresult =ADRESHL
    my_adresult var word ext
    
    ;.............
    
    
    ADCIN 0, adval ' Read channel 0 to dummy adval
     adval = my_adresult

  5. #5
    Join Date
    Apr 2008
    Posts
    25


    Did you find this post helpful? Yes | No

    Default Re: 12Bit ADC with PIC18F2523

    Ok,
    I directly saving the ADRESL and ADRESH register which is used to store the end results of an analog-to-digital conversion (ADC) to results adval and sending LCD. My problem is, the code is working properly only with 4MHz oscillator, when I define 20MHz occillator, the conversion is very slow, waiting few second, when start conversion.
    Whay the conversion is fast for 4Mhz oscillator and very slow for 20MHz oscillator

    adval = ADRESL + (ADRESH * 256)

    and sending LCD

    Lcdout $fe, 1 ' Clear LCD
    Lcdout "Value: ", DEC adval ' Display the decimal value

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,636


    Did you find this post helpful? Yes | No

    Default Re: 12Bit ADC with PIC18F2523

    where and what are your config settings ?

    the default osc is 1mhz which may be the problem

Similar Threads

  1. ADC values above 4095 for 12 bit ADC
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 1st February 2015, 22:24
  2. 12bit Power Supply
    By ztoti in forum Adverts
    Replies: 19
    Last Post: - 15th October 2014, 23:29
  3. 6ch 12bit adc pic16c771
    By pigglet in forum Adverts
    Replies: 0
    Last Post: - 23rd September 2012, 15:37
  4. ADC problem on 18F46K22 device using all 28 ADC pins
    By JimAvanti in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 23rd February 2012, 20:22
  5. PIC18f2423 two 12bit adc input problems
    By Brandon in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th December 2007, 09:47

Members who have read this thread : 1

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