1. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    i want to implement A to D conversion for PIC 18f67J90 (which has 10 bit ADC converter)

    I am using 3.5V battery

    I need to vary the voltage from 1.25 to 2.0 V in steps of 0.075V using the potentiometer and 3.5 V source

    When I read 1.25V from multimeter, counter should display 1
    1.25+0.075 = 1.325V from multimeter counter should display 2

    1.325+ 0.075=1.4V from multimeter counter should display 3 and so on upto 2V
    _________________________________________________________________________________________
    I have implemented a code but it gives inaccurate results.

    for 2V I see the correct counter value

    but that value stays until 1.6V reading from the multimeter

    Also for 1.25 V counter shows 1 which is correct

    But there is no uniformity between the other multimeter readings and counter value

    That is, I am not getting the counter value corresponding to the multimeter readings which increase in steps of 0.075V


    How do I go about fixing this issue?



    If anyone has an idea please let me know
    Thanks
     
    Last edited: Aug 2, 2012
  2. RG23

    Thread Starter Active Member

    Dec 6, 2010
    301
    2
    I have included part of the code related to ADC

    MOVLW 0x41
    MOVWF ADCON0
    CLRF ADCON1

    label_battery://////subroutine to display count after analyzing the voltage

    call Batt_A_D
    movf BV,0
    sublw 0x7D
    btfss CARRY
    incf count1////display count1 subroutine not included here
    movf BV,0
    sublw 0x7A
    btfss CARRY
    incf count1
    movf BV,0
    sublw 0x77
    btfss CARRY
    incf count1
    movf BV,0
    sublw 0x74
    btfss CARRY
    incf count1
    movf BV,0
    sublw 0x71
    btfss CARRY
    incf count1
    movf BV,0
    sublw 0x6E
    btfss CARRY
    incf count1
    movf BV,0
    sublw 0x6B
    btfss CARRY
    incf count1
    movf BV,0
    sublw 0x68
    btfss CARRY
    incf count1
    movf BV,0
    sublw 0x65
    btfss CARRY
    incf count1

    return


    Batt_A_D://////Subroutine for A to D conversion

    bsf ADCON0,2 ; select Battery Voltage input (AN1)
    clrf DELAY3
    incfsz DELAY3,1
    goto $-1
    clrf DELAY3
    incfsz DELAY3,1
    goto $-1
    clrf DELAY3
    incfsz DELAY3,1
    goto $-1
    clrf DELAY3
    incfsz DELAY3,1
    goto $-1
    clrf DELAY3
    incfsz DELAY3,1
    goto $-1
    clrf DELAY3
    incfsz DELAY3,1
    goto $-1
    clrf DELAY3
    incfsz DELAY3,1
    goto $-1
    clrf DELAY3
    incfsz DELAY3,1
    goto $-1
    clrf DELAY3
    incfsz DELAY3,1
    goto $-1
    BSF ADCON0,1 ;START A/D
    btfsc ADCON0,1 ; wait for A/D result to be done
    GOTO $-1
    bcf ADCON0,2
    nop
    nop
    movf ADRESH,0 ; get A/D result
    movwf BV ; save in BV
    return
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,606
    A schematic would help, or just a sketch showing how the power and references get into your PIC.

    How do you know the data the A2D is returning?
     
  4. nigelwright7557

    Senior Member

    May 10, 2008
    487
    71
    I cant see where count1 is initialsed.
    It is only incremented.

    You can get rid of some of those numerous delay routines by nesting a delay routine.
     
Loading...