op-amp to pic16f886 problems

Discussion in 'Embedded Systems and Microcontrollers' started by dilanp, Nov 21, 2011.

  1. dilanp

    Thread Starter New Member

    Nov 21, 2011
    5
    0
    I am using a pic16f886's ADC to convert an analog output from a weigh scales load cell. The sense wire from the scale is amplified x100 though a LM741 difference amp. Then the output of the amp is piped though a LM741 line follower. The output ranges from 0-5v when the ADC is not connected to it. However when the ADC is connected to the output of the line follower the voltage output gets capped off at around 600mv to 1v.

    The adc converts the voltages from 0 to 1v although it stops converting after it capps off. I have an LCD module hooked up to display the values of the ADRESH to me. The value of this byte never reaches 11111111 but when the voltage maxes out at 1v the value of the register is about 000110010.

    The adc is left to left justify and is set to use Vdd and Vss as reference also i have made sure to set the appropriate TRIS and ANSEL bits also i have correctly set ANSEL in ADCON0.

    I am assuming that since I have the voltage ref to Vdd(5v) that it should not be capping at 1v. I have no idea why it is not accepting a full 5v input and any help or insight you guys could provide would be of great help and i would really appreciate it.

    A sample of my adc code is below:

    banksel TRISA ;Set the lcd data pins to output
    movwf b'00100000' ;Set RA5 as input
    movwf TRISA

    banksel ANSEL ;Set RA5(AN4) to be analog input
    movlw b'00010000'
    movwf ANSEL
    movlw b'00000000'
    movwf ANSELH

    ;Set up the ADC-----------------------------
    BANKSEL ADCON1 ;
    movlw b'00000000' ;left justify and use Vdd and Vss as ref.
    movwf ADCON1
    movlw b'11010001' ;set frc clock, selecr AN4 to be the channel
    banksel ADCON0
    movwf ADCON0

    RUNADC
    banksel ADCON0
    call SAMPLETIME
    BSF ADCON0,GO ;Start conversion
    BTFSC ADCON0,GO ;Is conversion done?
    GOTO $-1 ;No, test again
    banksel ADRESH ;
    movf ADRESH,W ;Read upper 8 bits
    banksel adBits
    movwf adBits ;store in adbits
    return
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,429
    3,360
    Firstly, you have to show your schematic. We're all in the dark without one.
     
  3. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    The 741 op amp is most likely your problem.

    Look at the input of your ADC with a DMM and report back.
     
  4. dilanp

    Thread Starter New Member

    Nov 21, 2011
    5
    0
    Ok a schematic is on its way. thatoneguy mentioned that the 741 is the problem, is it because it cant drive the adc pin? What other amp might you suggest? We tried replacing the lm741 follower with a tl082 and got the same result.
     
  5. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    TL082 is slightly better, but it is also unable to output rail to rail.

    Look for an op amp in your inventory that has rail to rail outputs, so if your supply is +5V and GND, the output can go to +5V and GND.

    The TL082 and 741 come about a volt or more short of either.

    What do you measure at the ADC pin with a DMM when the output is connected? Is the PIC running on a +5V supply as well? When you say 1V, is that the low or high? I guess I am misunderstanding the question. Is this an op amp as comparator output for a line following sensor?

    Also, you should have a 0.1uF (100nF) cap between Vdd and Vss on the PIC for stability if you don't already, though I don't think that is your problem.
     
  6. dilanp

    Thread Starter New Member

    Nov 21, 2011
    5
    0
    Alright but we have the amps powered by +15v and -15v so it doesn't need to hit the rail doesn't it? When the adc is not connected to the amps they work perfectly fine.

    I can understand why you have trouble with the problem my profs even had trouble understanding it when i explained it to them in person. Even when they understood the problem they could not help me with it.

    When the ADC pin is connected to the follower output the voltage is 0v but when i press down on my scale the voltage rises and it keeps rising as i put more weight on it. The voltage stops rising at about 1v although i keep putting pressure on the scale. The voltage output of the differntal amp keeps rising past 1v all the way to 5v but the output of the buffer that is connected to the pin stays at 1v. (see the schematic).

    The pic is running 5v.
     
    Last edited: Nov 21, 2011
  7. dilanp

    Thread Starter New Member

    Nov 21, 2011
    5
    0
    Schematic here in zip file
     
  8. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    What does the ADC measure if you put a 1k resistor between Vdd and ADC in?

    How many ADC Channels are configured? Is one set up to use a 1V Vref?
     
  9. dilanp

    Thread Starter New Member

    Nov 21, 2011
    5
    0
    Hmm not sure, i will let you know the value tomorrow when i am back in the lab dont have supplies at my house.

    Just one channel is configured RA5(AN4) and i have set ADCON0 so that the ref is Vdd.
     
  10. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Is this on a pre-made demo board, solderless breadboard, or other? Would another component, such as resistor or LED be connected to this port in some path that needs to be disabled by a jumper?

    With the PIC removed, and voltage applied to the board, what does RA5 socket read for voltage on the board?

    With the PIC removed, and no voltage applied, does the diode check function on a DMM show any path from RA4 socket to ground or V+ on the board?

    Permanently add a 0.01uF cap between the ADC port(s) and ground, keep the wire length from the Vin source to the ADC port(s) as short as possible.

    If all of that fails, here's the shotgun approach:

    Are the comparators disabled? CM0CON0.7 and CM1CON0.7 both cleared?
    Timer0 output disabled? OPTION_REG.5 =0
    (The above ports can interfere with RAx)

    ADCON0.7:6 clear for Vss as reference, only enable the port(s) you intend to measure, enabling more than used can cause misreads.

    Lastly, Try AN0/RA0. It is also used for low power wakeup and comparators, so disable comparators and low power wakeup for testing.
     
  11. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    The analog part looks fine. The last op amp buffer probably isn't necessary but doesn't do much harm other then introduce an extra offset error term. It is not the source of the 1V limit problem as the output can go to 5V when the PIC is disconnected, excepting the comments below.

    It is curious that the 110010 (50 decimal) A2D conversion for a 5V reference means the A2D is seeing 50/1023*5V = .244V

    I poked thru your set up and ADCON's and ADSEL look spot on. This pin is also sharing comparator and mMSSP functions but these should be off by default.

    It is possible this pin was damaged by your op amp. As configured it is possible to drive 10 volts or more into this pin from the last stage op amp, and the pin may have been damaged. I really don't like the idea of driving the PIC pin that way. thatoneguy's suggestion about using a 1K resistor as a test will show you if the pin is damaged.
     
  12. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    In light of me missing that, also permanently add a 1k resistor in series with a 5.1v zener to ground from RA4, this would be in parallel with the 0.01uF cap. It may add noise, but the cap should filter most of it out, it will also help prevent destroying the uC.

    The preferred option would be to limit gain on the op amp so the output cannot exceed 5V or go lower than 0V, both of which can ruin the uC. (Actually, 5.5V and -0.5V, but an extra half volt for component tolerances is always best)
     
  13. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Exactly. If I was doing this I would be using a rail to rail op amp powered by 0 to 5V. Since we're already subtracting an offset and applying some gain these could be rescaled to keep the information part of the signal between slightly above ground to slightly below Vcc (minimum).

    To continue to use the current version all I would do to add some protection is add a 1K to 10K series resistor. The zener can introduce errors on the top end, and as RA4 does have protection diodes (don't assume, look: see fig 3-5 of the datasheet) all you need do is limit the current, the voltage will limit itself.
     
Loading...