AD problems


Closed Thread
Results 1 to 4 of 4

Thread: AD problems

  1. #1
    Join Date
    Jan 2006
    Location
    Slovenia EU
    Posts
    32

    Default AD problems

    Hello,

    I use two AD channel on PIC 16F877. Until interrupt pulse measure value on channel 0 and channel 1 with 2 ms delay. On AD pins have voltage divider with resistor.(from 9V to 4,5V). Problem is similar without divider.

    Major problem is:
    When tied pin2 from AD channel 0 to VCC (5V) shown value 294 (2,6V in my case). Channel 1 is on GND
    and then tied channel 1 to VCC (5V) value on CH0 is now 511 (4,5V in my case).
    I not understand why don't must be each channel separated for correct result. Is my ADCON setting correct?

    TNX,
    Samo

    Part of my routine is:

    @ DEVICE PIC16F877, HS_OSC



    DEFINE OSC 20

    DEFINE LCD_DREG PORTD
    DEFINE LCD_DBIT 4
    DEFINE LCD_RSREG PORTC
    DEFINE LCD_RSBIT 6
    DEFINE LCD_EREG PORTC
    DEFINE LCD_EBIT 7
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 4
    DEFINE LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50

    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK_2
    DEFINE ADC_SAMPLEUS 3

    TRISA=%11111111
    ADCON1=%10010111

    T1CON=%00110100 ' Set TIMER1


    ANALOG1 VAR PORTA.0 'ANALOGNI VHOD1
    ANALOG2 VAR PORTA.1 'ANALOGNI VHOD2
    ANALOG3 VAR PORTA.3 'ANALOGNI VHOD3
    INTER VAR PORTB.0 'INTERRUPT
    IZHOD2 VAR PORTA.2 'IZHOD2
    IZHOD1 VAR PORTB.4 'IZHOD1
    IZHOD5 VAR PORTB.1 'IZHOD5
    IZHOD4 VAR PORTB.2 'IZHOD4
    IZHOD3 VAR PORTB.3 'IZHOD3
    IZHOD1A VAR PORTA.4 'IZHOD1A
    IZHOD2A VAR PORTA.5 'IZHOD2A
    SCL VAR PORTA.6 'I2C CLOCK
    SDA VAR PORTA.7 'I2C DATA
    TSET VAR PORTB.5 'TIPKA SET
    TUP VAR PORTB.6 'TIPKA UP
    TDN VAR PORTB.7 'TIPKA DOWN
    LED1A VAR PORTC.4 'LED1A



    MERITEV1 VAR WORD
    MERITEV2 VAR WORD
    MER1 VAR WORD
    MER2 VAR WORD
    MER2A VAR WORD
    MER2B VAR WORD
    MER2X VAR WORD
    MER1A VAR WORD
    MER1B VAR WORD
    MER1X VAR WORD
    MER2Y VAR WORD
    MER1Y VAR WORD


    LCDOUT $FE,$40,$10,$10,$08,$04,$02,$01,$01,$01 '\
    LCDOUT $FE,$48,$01,$01,$01,$01,$01,$01,$01,$01 'I
    LCDOUT $FE,$50,$00,$00,$00,$00,$00,$00,$00,$1F 'I

    LCDOUT $FE,1


    On Interrupt Goto SAMPLE ' Define interrupt handler
    INTCON = $90 ' Enable INTE interrupt


    MAIN: MER1=MERITEV1/112
    MER1Y=MERITEV1//112
    MER1X=(MER1Y*10)/112

    MER2=MERITEV2/112
    MER2Y=MERITEV2//112
    MER2X=(MER1Y*10)/112

    LCDOut $FE,2,1,0,#MER1,".",#MER1X,"V"
    LCDOut $FE, $C0,1,1,2,2,#MERITEV1
    LCDOut $FE, $90,1," ",1,#MER2,".",#MER2X,"V"
    LCDOut $FE, $D0,1," ",1,#MERITEV2
    LOW LED1A
    GOTO MAIN




    Disable
    SAMPLE: ADCIN 0,MERITEV1
    PAUSE 2
    ADCIN 1,MERITEV2

    HIGH LED1A


    INTCON.1 = 0 ' Clear interrupt flag
    Resume
    Enable
    GOTO MAIN
    END

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    we don't know much about your external analog source but assuming a 10K, the ADC sampling time is way too low. Use my PicMultiCalc to know the right value for your actual setup.

    Here if i use 10K, the DEFINEs will be...
    Code:
    DEFINE ADC_BITS 10     ' ADCIN resolution  (Bits)
    DEFINE ADC_CLOCK 2     ' ADC clock source  (Fosc/32)
    DEFINE ADC_SAMPLEUS 11 ' ADC sampling time (uSec)
    now...
    Code:
    MER1=MERITEV1/112
    MER1Y=MERITEV1//112
    MER1X=(MER1Y*10)/112
    
    MER2=MERITEV2/112
    MER2Y=MERITEV2//112
    MER2X=(MER1Y*10)/112
    to me it's suppose to be MER2Y

    Code:
    ADCON1=%10010111
    i don't see this setting in the datasheet... for now, it make all pins to digital.

    i did the test with ADCON1=%10000000
    and it works.. well here
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    And, based on your analog pin assignments;
    Code:
    ANALOG1 VAR PORTA.0 'ANALOGNI VHOD1
    ANALOG2 VAR PORTA.1 'ANALOGNI VHOD2
    ANALOG3 VAR PORTA.3 'ANALOGNI VHOD3
    If you change ADCON1=%10010111 to ADCON1=%10000100, that would
    set RA0, RA1 and RA3 up as analog inputs to match. Assuming analog Vref
    is Vdd & Vss.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Jan 2006
    Location
    Slovenia EU
    Posts
    32


    Did you find this post helpful? Yes | No

    Default

    Thank you for your help. It is working now.

    Samo

Similar Threads

  1. 16F876 AD comparisation help needed
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th April 2008, 18:41
  2. Problem with AD inputs at PIC16f873a
    By wurm in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th April 2008, 10:01
  3. I neat some help on 12F675 ad
    By Kmt in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd November 2007, 18:48
  4. PLEASE HELP ME! pic16f876a and AD tlc4541
    By luca_sheva in forum mel PIC BASIC
    Replies: 1
    Last Post: - 1st February 2005, 17:32
  5. ADC problem
    By NacNud in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th December 2004, 02:27

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