16F876 ADC problem


+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Douwe's Avatar
    Douwe Guest

    Default 16F876 ADC problem

    Hallo,

    I have an problem with measure two values with the 16F876.
    First i measure current (stroom) with 3,50 Volt on AN3, the value
    then is correct and works fine.
    Then i program thereafter basic for reading the voltage of an solar panel.
    (zonnepaneel)
    I use now the 5 Volt as Vref (no use of AN3)
    The reading of the current from the first part is now different and not correct,
    it changes to about 10% to 15 % higher.......
    I have inserted pauses on different places etc. but have the same problem.
    What are i doing wrong ???

    this is de code i wroted:


    ================================================
    ' Connect analog input to channel-0 (RA0)
    ' Meet de stroom.

    meten: ADCON1 = %01000001 ' Set PORTA analog and LEFT justify result
    ' and make Vref on AN3 = 3.50 Volt.
    ADCON0 = %11000001 ' Configure and turn on A/D Module RA0
    ADCON0.2 = 1 ' Start conversion (bit 2 = 1)
    Pause 50 ' Wait .5 second
    If ADCON0.2 = 1 Then meten ' Wait for low on bit-2 of ADCON0, conversion finished
    adval = ADRESH ' Move high byte of result to adval
    dummy = adval * 240 ' scaling
    adval = div32 100 ' scaling
    st1 = abs adval ' max. waarde is 600 (600 mA)
    goto display ' Display current.

    ' Meet de spanning van zonnepaneel.

    meetpnl: ADCON1 = %01000000 ' Reset AN3 Vref. (is nu weer 5 Volt)
    ADCON0 = %11001001 ' Configure and turn on A/D Module RA1
    ADCON0.2 = 1 ' Start conversion (bit 2 = 1)
    Pause 50 ' Wait .5 second
    If ADCON0.2 = 1 Then meetpnl ' Wait for low on bit-2 of ADCON0, conversion finished
    adval = ADRESH ' Move high byte of result to adval
    dummy = adval * 976 ' x 400 en 32 bits result in dummy lees bldz. 33
    adval = div32 1000 ' : 255 en 32 bits divide scaling 150/255
    adval = abs adval ' max. waarde is 400 (40 Volt)
    pnl1 = adval /10 ' eerste digit scaling
    pnl2 = adval // 10 ' de rest.
    goto display ' Display Solar Voltage.

  2. #2
    Douwe's Avatar
    Douwe Guest

    Smile It is now working......

    Quote Originally Posted by Douwe
    Hallo,

    I have an problem with measure two values with the 16F876.
    First i measure current (stroom) with 3,50 Volt on AN3, the value
    then is correct and works fine.
    Then i program thereafter basic for reading the voltage of an solar panel.
    (zonnepaneel)
    I use now the 5 Volt as Vref (no use of AN3)
    The reading of the current from the first part is now different and not correct,
    it changes to about 10% to 15 % higher.......
    I have inserted pauses on different places etc. but have the same problem.
    What are i doing wrong ???

    this is de code i wroted:


    ================================================
    ' Connect analog input to channel-0 (RA0)
    ' Meet de stroom.

    meten: ADCON1 = %01000001 ' Set PORTA analog and LEFT justify result
    ' and make Vref on AN3 = 3.50 Volt.
    ADCON0 = %11000001 ' Configure and turn on A/D Module RA0
    ADCON0.2 = 1 ' Start conversion (bit 2 = 1)
    Pause 50 ' Wait .5 second
    If ADCON0.2 = 1 Then meten ' Wait for low on bit-2 of ADCON0, conversion finished
    adval = ADRESH ' Move high byte of result to adval
    dummy = adval * 240 ' scaling
    adval = div32 100 ' scaling
    st1 = abs adval ' max. waarde is 600 (600 mA)
    goto display ' Display current.

    ' Meet de spanning van zonnepaneel.

    meetpnl: ADCON1 = %01000000 ' Reset AN3 Vref. (is nu weer 5 Volt)
    ADCON0 = %11001001 ' Configure and turn on A/D Module RA1
    ADCON0.2 = 1 ' Start conversion (bit 2 = 1)
    Pause 50 ' Wait .5 second
    If ADCON0.2 = 1 Then meetpnl ' Wait for low on bit-2 of ADCON0, conversion finished
    adval = ADRESH ' Move high byte of result to adval
    dummy = adval * 976 ' x 400 en 32 bits result in dummy lees bldz. 33
    adval = div32 1000 ' : 255 en 32 bits divide scaling 150/255
    adval = abs adval ' max. waarde is 400 (40 Volt)
    pnl1 = adval /10 ' eerste digit scaling
    pnl2 = adval // 10 ' de rest.
    goto display ' Display Solar Voltage.

    In the program i checked the ADCON0.2 bit for low and if it is not low, jump to
    label meten: thats the problem.
    label meten: starts with initialize the AD converter again etc. thats no good, i can't explane why, but now i jump to ADCON0.2 = 1 (start conversion) and it works fine.

    ------------------------------------------------------------------------
    summary, wrong code:


    meten: ADCON1 = %01000001
    ADCON0 = %11000001
    ADCON0.2 = 1
    Pause 50
    If ADCON0.2 = 1 Then meten
    etc.
    etc.


    Now, with good results:

    meten: ADCON1 = %01000001
    ADCON0 = %11000001
    Again: ADCON0.2 = 1
    Pause 50
    If ADCON0.2 = 1 Then again
    etc.
    etc.
    ----------------------------------------------------------------------

    Douwe (The Netherlands)

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

    Default

    It would be better like so...

    Code:
    meten:
    	ADCON0=%01000001		' Set Fosc, Select Channel, Turn-On A/D
    	Pauseus 50			' Wait for channel to setup
    	ADCON0.2 = 1			' Start conversion
    	While ADCON0.2=1:Wend		' Wait for conversion

  4. #4
    Douwe's Avatar
    Douwe Guest

    Default thats right

    Quote Originally Posted by Melanie
    It would be better like so...

    Code:
    meten:
    	ADCON0=%01000001		' Set Fosc, Select Channel, Turn-On A/D
    	Pauseus 50			' Wait for channel to setup
    	ADCON0.2 = 1			' Start conversion
    	While ADCON0.2=1:Wend		' Wait for conversion
    O.K. Melanie,
    nice programming, and it works o.k. thanks for the tip.

    Douwe.

Similar Threads

  1. ADC or ADCIN "bias" problem?
    By RussMartin in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th February 2010, 19:39
  2. pic12f675 ADC problem
    By radu022003 in forum mel PIC BASIC
    Replies: 3
    Last Post: - 1st September 2009, 10:13
  3. PIC18F2423, ADC problem
    By mistergh in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th March 2009, 01:31
  4. Mutliple ADC problem with PIC16F877
    By andyto in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd October 2007, 17:47
  5. ADC problem with PIC16F917
    By eetech in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th March 2007, 21:22

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts