Need help with 16f819 10 bit ADC


Closed Thread
Results 1 to 11 of 11
  1. #1
    bannrikae's Avatar
    bannrikae Guest

    Default Need help with 16f819 10 bit ADC

    Hi

    I'm new to forums and pic basic so please forgive if Iv'e missed somthing obvious.

    I have built a battery charger, and I am using the 8 bit ADC on the 16f819 to measure the batt voltage and detect when it is fully charged.
    The resolution for 8 bits was not quite good enough for my requirements so I want to use it in the 10 bit format.

    My circuit and program works when using 8 bit, but when I try to use 10 bit, nothing happens.

    I have a simple test circuit with LED's on the output of port b, and I can get the LED's to light, as a bar graph, in approx 10 mV increments.

    Using the same test circuit and the code below for 10 bits, the leds are coming on as shown

    RB0- on = 0V
    RB1- on = 1.26V
    RB2- on = 2.52V
    RB3- on = 3.78V
    RB4- dosn't come on.

    Iv'e looked at the data sheet and lots of examples of 10 bit code, but can't see anything wrong with my program. I was hopeing for a resolution of about 5 mV.
    I would be very gratefull if sombody could help.

    Test program


    DEFINE adc_bits 10
    DEFINE adc_clock 3
    DEFINE adc_sampleus 50

    adval VAR WORD

    portb=%00000000
    trisb=%00000000

    trisa=%11111111

    adcon1=%100000010

    loop:
    ADCIN 2, adval

    ledtst1:
    IF adval > 0 THEN tst2
    portb = %00000001
    GOTO cont

    tst2:
    IF adval > 1 THEN tst3
    portb = %00000011
    GOTO cont

    tst3:
    IF adval > 2 THEN tst4
    portb = %00000111
    GOTO cont

    tst4:
    IF adval > 3 THEN tst5
    portb = %00001111
    GOTO cont

    tst5:
    portb = %00011111

    cont:
    PAUSE 100
    GOTO loop
    END

  2. #2
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Lightbulb

    You have nine bits in this line.
    adcon1=%100000010
    That's probably the reason for the strange behaviour.

  3. #3
    bannrikae's Avatar
    bannrikae Guest


    Did you find this post helpful? Yes | No

    Default

    Sorry! thats a typing error in my post, actual code is correct.
    It seems so simple I can't understand why it dosen't work.

  4. #4
    Join Date
    Apr 2005
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    Don't you need to change your command to ADCIN 4, adval to get AN4?

    I personally have been using Melanies direct method reading analog values that can be seen in this thread

    http://www.picbasic.co.uk/forum/show...ghlight=adcon0

    Its pretty straight forward and I can understand what is going on.

  5. #5
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Defines should be in uppercase.

    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50

  6. #6
    bannrikae's Avatar
    bannrikae Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks modifyit, I'll try this when I get back to work on Monday and let you know how I get on.

    Ingvar, I didn't think these were case sensitive, it worked OK lower case for 8 bit ADC but I will also try this on Monday.

    Thanks both.

  7. #7
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    Your defines didn't do anything atall since they were the default values.

  8. #8
    bannrikae's Avatar
    bannrikae Guest


    Did you find this post helpful? Yes | No

    Default

    So if they are default values Then shouldn't the prog work?
    The rest of the code works when set up for 8 Bits, can't see what else is wrong, confused!.

    BG

  9. #9
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Post

    It worked before you changed it to 10 bits. 8 bits is default. That's why it worked even though you wrote the defines in lowercase.

  10. #10
    bannrikae's Avatar
    bannrikae Guest


    Did you find this post helpful? Yes | No

    Default

    OK ingvar, see what your saying, will try as soon as I get the time,
    (work gets in the way of projects)

    Thanks

    BG

  11. #11
    bannrikae's Avatar
    bannrikae Guest


    Did you find this post helpful? Yes | No

    Default

    ingvar, just changed defaults to upper case, program now works fine.
    Just knew it had to be somthing stupid I had done.
    Thanks for your help and patience.

    BG

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. 10 bit ADC display on LCD using 16f873
    By pr2don in forum mel PIC BASIC
    Replies: 3
    Last Post: - 6th March 2010, 18:29
  3. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 10:31
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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