adcon1/ adcin


Closed Thread
Results 1 to 5 of 5

Thread: adcon1/ adcin

  1. #1
    Patrick's Avatar
    Patrick Guest

    Red face adcon1/ adcin

    Why is it that I can only read on portA 2,3
    Program that I used suggested that I use portA,0
    Want an easy explenation on the adcon1 bits and there relationship between adcon and adcin
    please

    Patrick





    '************************************************* ***************
    '* Name : UNTITLED.BAS *
    '* Author : P van Biljon *
    '* Notice : Copyright (c) 2006 Ver:2.44 *
    '* : All Rights Reserved *
    '* Date : 2006/07/07 *
    '* Version : 1.0 *
    '* Notes : *
    '* : *
    '************************************************* ***************
    DEFINE LOADER_USED 1 ' If using bootloader to program pic
    DEFINE LCD_DREG PORTB 'Define PIC port used for LCD Data lines
    DEFINE LCD_DBIT 4 'Define first pin of portc connected to LCD DC4
    DEFINE LCD_RSREG PORTC 'Define PIC port used for RS line of LCD
    DEFINE LCD_RSBIT 1 'Define Portc pin used for RS connection
    DEFINE LCD_EREG PORTC 'Define PIC port used for E line of LCD
    DEFINE LCD_EBIT 0 'Define PortC pin used for E connection
    DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
    DEFINE LCD_LINES 2 'Define using a 2 line LCD
    DEFINE LCD_COMMANDUS 2000 'Define delay time between sending LCD commands
    DEFINE LCD_DATAUS 50 'Define delay time between data sent.
    define osc 4
    define adc_bits 8
    define adc_clock 1
    define adc_sampleus 50


    samples var word
    sample var byte
    temp var byte
    samples = 0
    samples1 var word
    sample1 var byte
    temp1 var byte
    samples1 = 0


    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = 2
    pause 500


    init:
    samples = 0
    samples1 = 0
    gosub loop
    gosub loop1
    gosub loop2
    goto init




    loop:

    for sample = 0 to 20
    adcin 2 ,temp
    samples= samples + temp
    pause 100
    next sample
    temp = samples / 20

    return

    loop1:

    for sample1 = 0 to 20
    adcin 3 ,temp1
    samples1= samples1 + temp1
    pause 100
    next sample1
    temp1 = samples1 / 20

    return
    loop2:
    lcdout $fe,1,"Temp is: " ,DEC(samples/10) ,".",dec2 samples," C"
    lcdout $fe,$C0,"Temp is: " ,DEC(samples1/10) ,".",dec2 samples1," C"

    goto init
    end

  2. #2
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi Patrick,

    It would really help us if we knew which PIC you were using!

    Some PIC's have comparators as well as analog inputs set up on the PortA pins that need to be disabled before the pins will work properly.

    BobK

  3. #3
    Patrick's Avatar
    Patrick Guest


    Did you find this post helpful? Yes | No

    Default pic 16F876

    Hi

    I am using a 16F876
    Read up last night on A/D
    modified to:Stil does not work

    DEFINE LOADER_USED 1 ' If using bootloader to program pic
    DEFINE LCD_DREG PORTB 'Define PIC port used for LCD Data lines
    DEFINE LCD_DBIT 4 'Define first pin of portc connected to LCD DC4
    DEFINE LCD_RSREG PORTC 'Define PIC port used for RS line of LCD
    DEFINE LCD_RSBIT 1 'Define Portc pin used for RS connection
    DEFINE LCD_EREG PORTC 'Define PIC port used for E line of LCD
    DEFINE LCD_EBIT 0 'Define PortC pin used for E connection
    DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
    DEFINE LCD_LINES 2 'Define using a 2 line LCD
    DEFINE LCD_COMMANDUS 2000 'Define delay time between sending LCD commands
    DEFINE LCD_DATAUS 50 'Define delay time between data sent.
    define osc 4
    define adc_bits 8
    define adc_clock 1
    define adc_sampleus 50


    samples var word
    sample var byte
    temp var byte
    samples = 0
    samples1 var word
    sample1 var byte
    temp1 var byte
    samples1 = 0


    TRISA = %11111111 ' Set PORTA to all input
    ADCON1 = %01001001
    pause 100


    init:
    samples = 0
    samples1 = 0
    gosub loop
    gosub loop1
    lcdout $fe,1,"Temp is: " ,DEC(samples/100) ,".",dec2 samples," C"
    lcdout $fe,$C0,"Temp is: " ,DEC(samples1/100) ,".",dec2 samples1," C"

    goto init


    loop:
    adcon0 = $41
    pauseus 50
    adcon0.2 = 1
    pauseus 50
    for sample = 0 to 20
    adcin 0 ,temp
    samples= samples + temp
    pause 100
    next sample
    temp = samples / 20

    return

    loop1:
    adcon0 = $49
    pauseus 50
    adcon0.2 = 1
    pauseus 50
    for sample1 = 0 to 20
    adcin 1 ,temp1
    samples1= samples1 + temp1
    pause 100
    next sample1
    temp1 = samples1 / 20

    return

    end

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    You went from something good like this...

    ADCON1 = 2
    .. ..
    for sample = 0 to 20
    adcin 2 ,temp
    samples= samples + temp
    pause 100
    next sample
    temp = samples / 20

    ...and all you had to do was change ADCIN 2 to ADCIN 0 (PBP Manual!) for it to read from RA0/AN0, to something like your second example which is completely shot.

    For complete definitions of ADCON0 and ADCON1 see your PICs DATASHEET.

  5. #5
    Patrick's Avatar
    Patrick Guest


    Did you find this post helpful? Yes | No

    Talking Adcin adcon1

    Thanks Melanie

    Out of desparation I looked at the sample on the Rentron page where they use the three pots on the inputs of the RA ports of the 16F87X pics,that is where the second example comes from.
    If I program the pic as in example one I have 5volt on pin RA0 and 1 and I want to read from LM34 temp IC
    If I make it Adcon1 = 2 and read on pin 2 and 3 it reads it but I want to know why I cannot get a reading from pin 0 and 1 when the IC is connected.I can also not figure it out on the data sheetsas Adcon1 = 2 makes the pins all analog with no Ref voltage on pins.

    Please if someone can again simplify these settings ,I know that there is being many mails on this subject but,can someone point to a site or mail which makes it simple and just not repeat the data sheet.

    Sometimes I just caun't see the obvious, but then I need help and that is why there is a great forum like this.

    Melanie keep up the good work

    Patrick van Biljon

Similar Threads

  1. ADCIN Problem
    By JavPar in forum General
    Replies: 33
    Last Post: - 20th January 2009, 03:36
  2. ADCIN problems with PIC16F73
    By passion1 in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 26th July 2007, 11:38
  3. Adcin or Pot
    By lerameur in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 11th January 2007, 16:46
  4. help using adcin
    By harryweb in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st January 2006, 07:46
  5. Help with setting adcon1 for 16f877
    By jessey in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 16th August 2005, 11:13

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