A/D conversion problem with pic16F88


Closed Thread
Results 1 to 10 of 10
  1. #1
    Tapio Linkosalo's Avatar
    Tapio Linkosalo Guest

    Default A/D conversion problem with pic16F88

    I'm trying to get temperature readings from a thermocouple, using INA128 op.amp. connected to pic16f88. The problem is that although I get readings that seem to be valid, every now and then (10 to 20% of the reading, with irregular intervals) are erratic. The erronous readings are always smaller than the correct ones, typically about 1/4 of the real values (i.e. if I should get values around 400, I get every now and then values of about 100). The op.amp. is connected to the porta.2 pin.

    My configuration is like this:

    Code:
            OPTION_REG.7 = 0     'enable portb pullups
            TRISA = %00000100    'set porta pin 2 as inputs
            TRISB = %01110011    'set portb pins 2,3,7 as output
            OSCCON =%01101100    'set internal osc at 4 mhz w/freq stable
            OSCTUNE = 0          'internal osc. running at factory calibration
            CMCON = 7            'comparators off
            ANSEL = 4            'porta.2 AD-input, others digital
            ADCON0 = %01010000
            ADCON1 = %10000000  
            PIE1 = 0             'disable all interrupts
            INTCON = 0           ' -"-
    And the code that reads A/D looks like this:

    Code:
    readAD:                                'Do the AD-conversion
            adcon0.0 = 1                   'turn on AD-converter
            pauseus 20
            ADCON0.2 = 1                   'Start AD-conversion
    notdone:
            if ADCON0.2 = 1 then notdone   'wait for low on bit-2 of ADCON0, 
                                           ' = conversion finished
            ADresult.highbyte = ADRESH     'move HIGH byte of result to ADresult
            ADresult.lowbyte  = ADRESL     'move LOW byte of result to ADresult
            return
    Is there something wrong in my configuration/code? Thanks!

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Hi, Tapio

    Did you verify the minimum acquisition time, ( 16F88 Datasheet p. 219 ... looks you did !!! ), line impedance between INA out and ADC in, and ref voltage ( or 5v supply ) stability ???

    Hope also there's no relay nor "heavy load" driven from the Pic supply ...

    Note Thermocouple and INA inputs shielding also have to be really care-treated not to be a spike-antenna.

    Need a portion of scheme for further analysis ...

    As first trail, try 50 or 100 µS as an acquisition time ... and try to scope the INA output for glitches.
    Second trail : a Very-low pass filter between INA and ADC

    Third trail : a softw. non-linear-change value rejection !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Tapio Linkosalo
    Code:
            OSCCON =%01101100    'set internal osc at 4 mhz w/freq stable
    I don't think you SET the frequency stable bit; you loop until the MCU sets it.
    Code:
    OSCCON =%01101000
    While OSCCON.2=0:Wend
    Last edited by dhouston; - 28th July 2006 at 19:19.

  4. #4
    Tapio Linkosalo's Avatar
    Tapio Linkosalo Guest


    Did you find this post helpful? Yes | No

    Default

    There are some heavy loads involved. The circuitry is a thermostat, that sets heating power of a resistor by cutting power on and off via a N-fet. The fet, however, is connected directly to 12V input, while the PIC is powered with a 78L05 regulator. I guess I need to scope the power to the PIC to be sure.

    I tried to chech the output from the INA with a data logger. Did not see any ripple there, however the logger had acquisition time of 1ms, so I suppose I'm better off scoping that part, too.

    Software measurement rejection is indeed one option, I just wanted to make sure that there is no error in the A/D configuration before taking that route. Thanks for your comments!

  5. #5
    Tapio Linkosalo's Avatar
    Tapio Linkosalo Guest


    Did you find this post helpful? Yes | No

    Default

    Ok, tried increasing the acquisition time up to 1000us - no help. Then checked the voltage with PC-scope. Input voltage to PIC is stable (also used as Vref), and the ripple on the output from op.amp. is just a few percent, nothing like the error readings in the AD. Still looks like there is a configuration problem in my software?

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default

    Hi,Tapio

    Could also come from an unwanted 10 to 8 Bits truncature ( indexed EEPROM transfer bug i.e. )... I do not see why, but it is possible ... so, to be checked !!! .

    Alain.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Tapio,

    Another thing to try ....

    Remove the thermocouple input from RA2 and replace it with a known voltage input (from a voltage divider or pot). With this, you should be able to determine if the problem is from the software side or the hardware side. Just a thought ...
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  8. #8
    Tapio Linkosalo's Avatar
    Tapio Linkosalo Guest


    Did you find this post helpful? Yes | No

    Default

    Alain,

    truncation is a possibility that came also to my mind. I tried adding "define adcbits 10" to the software yesterday, at that time it started to work, but it could be also that re-soldering one lead of the thermocouple at the same time was the real reason. I tried to remove the define, even erase the chip and reprogram in case that the define did a change in the configuration that was not reversable by removing it, but could not return to the erraneous state of affairs.

    I wonder if the reason could be in the input. I checked the output from the op. amp. with oscilloscope, and it seems to be stable within around 5%, nothing like 4-fold variation in the input values.

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Smile

    Hi, Tapio

    Glad to hear it works ...

    As the Define Adcbits deal with adcin ... I'd bet the thermocouple was the trustable reason ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  10. #10
    Tapio Linkosalo's Avatar
    Tapio Linkosalo Guest


    Did you find this post helpful? Yes | No

    Default

    Actually, it did not work, but now I think it does.

    The problem was not in the A/D configuration, but the op-amp. The datasheets tell to add a resistor for bias current return path which I had not added (and also had to tinkle around as ref ground and opamp power ground must be different). So the erronous readings were due to thermocouple drifting towards V+ref end of the input.

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01:48
  2. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 16:26
  3. A/D conversion problem with 18F2455
    By abdy37 in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 7th May 2007, 14:53
  4. A/D conversion problem on 18F4431
    By ttease in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 10th April 2007, 23:03
  5. A/D converter fails?
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2006, 18:57

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