Shop OBEX P1 Docs P2 Docs Learn Events
K type thermocouple, MAX31855K, Basic Stamp = stability/decoding issues. — Parallax Forums

K type thermocouple, MAX31855K, Basic Stamp = stability/decoding issues.

CuriousOneCuriousOne Posts: 931
edited 2014-08-22 21:22 in Accessories
Hello.

I wanted to interface K type thermocouple with the basic stamp. The quick googling showed this page: http://emesystems.com/OL2therm.htm

It was using MAX6675, which is no longer made, and being replaced with MAX31855. So, I ordered that IC, assembled as indicated and started testing. To get idea what data is being forwarded, I've removed this line:

debug dec THC/100,".",dec2 THC,cr

and replaced it with

debug dec result, CR

The code appears to be running properly and result changes when I heat or cool down the thermocouple, but it has very strong fluctuation. For example, thermocouple now lies on the table, and variable RESULT changes from 360 to 420 on it's own. If I touch the shield of thermocouple cable (which is connected to Vss of "stamps in class" board), the reading will jump to from 480 to 510, and very slowly (about 30 minutes) will come back to the initial values. Or it will come to initial values instantly if I cycle the power. Same happens if I put my finger on the USB connector on the board, just this time RESULT will jump to 440-460 range. Wiring is all correct and according to datasheet. Thermocouple is working, checked with factory made thermometer.
«1

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-07-04 09:29
    A quote from the EMESystems page: "Isolate the thermocouple from noise sources. For example, if you pinch the bare thermocouple junction with your fingers, you may induce a huge 60hz signal into the circuit that it is not able to compensate, and you will see fluctuations in the readings. The fluctuations will be much less if you insulate the thermocouple tip. Other means may be necessary for different situations, for example, to put the thermocouple inside a grounded, shielded thermo-well."

    Look at the evaluation kit designs, how they're laid out, how the MAX32855 is bypassed and the inputs are filtered. Look at your own setup and how the grounds are wired. Your ground wires may be too long. How are you wiring the MAX31855? How is it shielded if at all? Thermocouples are very low voltage devices and it doesn't take much for environmental noise to be coupled into the sensing circuitry.
  • CuriousOneCuriousOne Posts: 931
    edited 2013-07-04 22:22
    The thermocouple is factory made, and junction is sealed in metal box, all wires are shielded and short, where opened. I'll check the wiring again but...
  • Mike GreenMike Green Posts: 23,101
    edited 2013-07-04 22:32
    It's not just the thermocouple, it's all the high gain stuff between the thermocouple and the inside of the MAX31855 and how that interacts with the Stamp.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2013-07-05 08:54
    Have you accounted for the differences in the serial interface? The newer chip is more sophisticated, 13 bits + sign versus 12 bits positive only (but with a dummy sign bit). Also, the newer chip can return 32 bits of data in one SPI transaction, with both thermocouple and reference temperatures, plus fault bits, whichindicate thermocouple open or shorts to the power supplies.

    That said, it seems to me the original MAX6675 code should still work up to a point and with small tweaks. Each bit still resolves to 0.25°C.

    Are you saying your readings in that instance were jumping from 360 to 420 with nothing in between, or were those the extreme values in a scatter?
  • CuriousOneCuriousOne Posts: 931
    edited 2013-07-05 12:15
    These were the extreme values. On monday I will re-do the PCB, and mount whole assembly into shielded metal box. I even tried another chip. thinking that this one is faulty, but no luck.
  • CuriousOneCuriousOne Posts: 931
    edited 2013-07-08 03:39
    Just for verification, I've re-assembled the circuit using different power supply, different IC, different thermocouple and different stamp module. Even breadboard was the brand new one.

    "own" fluctuation remains, but changes when touching Vss or Vdd now gone. So now I'm thinking, since I'm reading once in 250ms, let's do 4 readings, average them and feed to output?
  • CuriousOneCuriousOne Posts: 931
    edited 2013-07-09 05:47
    I believe, there's an error in program code, since when I rapidly increase the temperature, the actual readings will start to decrease!
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2013-07-09 08:05
    Do you have the polarity correct? The red wire is the negative side, yellow positive, and that often throws people off. We are so used to thinking of red as positive.
    red=alumel (-)
    yellow=chromel (+)

    You should be shifting the result two right for printing.
    DEBUG result >> 2
    The temperature is in the high most significant 14 bits, and the 2 least significant bits do other things. By including them you are accentuating the noise. The most significant bit is the sign, so at sub-zero temperatures you'd have to deal with that too.
  • CuriousOneCuriousOne Posts: 931
    edited 2013-07-09 10:08
    Yes polarity is correct, but I suspect I need to adjust SHIFTIN command, since it has /16 switch, as in code above.
  • CuriousOneCuriousOne Posts: 931
    edited 2013-07-11 07:34
    I think a almost solved the problem. In fact, there were two problems.

    Read fluctuation problem:

    The line

    THC=result>>5*/3200

    Should look like

    THC=result>>4

    Then readings are stable and realistic.

    And the temperature change sign change is caused by rapid heating I think. I was using hot air gun for heating, tried to heat with hands, it works much stable.
  • ercoerco Posts: 20,255
    edited 2013-10-16 11:21
    Kids have it too easy these days. $21.58 for a complete K-type thermocouple system. We didn't have free shipping back in my day!

    http://www.ebay.com/itm/Digital-Thermometer-K-Type-Thermocouple-2-Probe-Sensor-Metal-1300-C-2372-F-New-/200935431980?pt=LH_DefaultDomain_0&hash=item2ec8af5f2c&ssPageName=RSS:B:SHOP:US:101
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-10-16 13:02
    erco, they didn't have robots back in our day either!!! Only tin toy ones.
  • GenetixGenetix Posts: 1,747
    edited 2013-10-16 17:06
    Show them that real men use slide rules.
  • CuriousOneCuriousOne Posts: 931
    edited 2014-08-13 07:37
    The problem is still there.

    I've modified the read procedure to look like this:
     LOW MXCS 'chip select low 
     shiftin MXSO, MXSCLK, 0, [TCtemp\32] 'shift in the data
     HIGH MXCS 'chip select high 
    

    And sending the value of TCtemp to debug in the binary mode.

    I'm getting the 13 bit reading, when according to datasheet, I should get 32 bits!

    The bits D0, D1, D2, D3 work as they should do (i.e. detecting thermocouple absence, short to ground or vcc), but above them, I'm getting the "digital moise". Thermocouple is verified and works on factory made thermostat.

    What might be the reason?
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2014-08-13 08:26
    SHIFTIN can't do 32 bits at once, you have to break it into two 16 bit words:
    [SIZE=1][FONT=courier new]LOW MXCS 'chip select low 
     shiftin MXSO, MXSCLK, MSBPRE, [TCtemp1\16,TCtemp0\16] 'shift in the data
    HIGH MXCS 'chip select high[/FONT][/SIZE]
    
    Then according to the data sheet (my inference)
    [SIZE=1][FONT=courier new]degCouple = TCtemp1 >> 2 + (-TCtemp1.bit31 << 14)   ' the last term extends the sign bit
    degCinternal = TCtemp0 >> 4 + (-TCtemp0.bit31 << 12)
    faults = TCtemp1.bit0
    SCVfault = TCtemp0.bit2
    SCGfault = TCtemp0.bit1
    OCfault = TCtemp0.bit0
    
    [/FONT][/SIZE]
  • CuriousOneCuriousOne Posts: 931
    edited 2014-08-13 09:25
    Thanks a lot, I've modified the code according to your suggestions, but (-TCtemp1.bit31 << 14) this part gives error, so for test I've omitted it. So I'm debugging both these variables, and reading of internal thermocouple seems to be working properly - when I heat up the chip, the raw reading increases, when cooled, decreases. However, with the external thermocouple I have a problem. Raw reading is always around 16380 at room temperature, and when I put thermocouple into say boiling water glass, the reading changes to 163xxx or some 2 digit numbers, rapidly changing between them, until it reaches some reading. The just two or 3 digit numbers appear randomly, say 21-49-34-112-30-63 and so on. I've connected same thermocouple to industrial PLC - it shows the temperature just fine. Might be the reason in fact that MAX31855 is 3.3v device, and I'm feeding it via 78L33, while BS2 itself is 5v device? but if that was the reason, then why internal thermocouple works fine? I've tried 3 different MAX31855 -s, all display same behavior.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2014-08-13 09:52
    Sorry, that should be

    degCouple = TCtemp1 >> 2 + (-TCtemp1.bit15 << 14)

    Not 31. Too much Propeller-think! Not important for temperatures>0.

    The internal reference temperature of the chip is measured with a bandgap circuit, not a thermocouple.

    Try short circuiting the thermocouple inputs, pin 2 to pin 3 right at the chip. That simulates a thermocouple with its temperature equal to the reference. The two readings should be the same.




  • CuriousOneCuriousOne Posts: 931
    edited 2014-08-13 10:13
    What will happen if I'll remove this part at all: (-TCtemp1.bit15 << 14) It is the part that gives error during compile. I've removed thermocouple and shorted the input right on the chip. Now the thermocouple reads average 131 and internal reads 543.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2014-08-13 11:16
    The following compiles. The statement you asked about + (-TCtemp1.BIT15 << 14) is only there to handle temperatures below zero. Not important if you are measuring room temperatures. Are you using WORD variables where called for?
    [SIZE=1][FONT=courier new]' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    
    MXCS PIN 0
    MXSO PIN 1
    MXSCLK PIN 2
    degCouple VAR WORD
    degCinternal VAR WORD
    TCtemp1 VAR WORD
    TCtemp0 VAR WORD
    faults VAR NIB
    
    
    SCVfault VAR faults.BIT2
    SCGfault VAR faults.BIT1
    OCfault VAR faults.BIT0
    
    DO
      LOW MXCS 'chip select low 
        SHIFTIN MXSO, MXSCLK, MSBPRE, [TCtemp1\16,TCtemp0\16] 'shift in the data
      HIGH MXCS 'chip select high
      degCouple = TCtemp1 >> 2 + (-TCtemp1.BIT15 << 14)   ' the last term extends the sign bit
      degCinternal = TCtemp0 >> 4 + (-TCtemp0.BIT15 << 12)
      faults = TCtemp0.NIB0
      DEBUG SDEC degCouple, TAB, SDEC degCinternal, TAB, BIN3 faults
      PAUSE 1000
    LOOP[/FONT][/SIZE]
    

    Caveat: I don't have one of those sensors, so I'm talking through my hat!
  • CuriousOneCuriousOne Posts: 931
    edited 2014-08-13 12:51
    Yes I want to use it in DIY reflow oven, so below zero is absolutely not important.
  • CuriousOneCuriousOne Posts: 931
    edited 2014-08-15 04:13
    After long tries with different power supplies, etc. I got the working solution. But it seems like MAX31855 is not the best choice for this task? I place thermocouple into electric kettle. As long as I connect it to AC, the temperature sign changes to minus! also it changes to minus if I touch braid shield of the thermocouple. If I ground the shield of thermocouple, then temperature reading becomes positive, but reads 320 at 100C. But also, at the same time, short to gnd byte becomes active. So have no idea what to do next.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2014-08-16 09:38
    Sounds like a wiring error. Can you post photo showing how the K is connected to the chip? Also the full program as you have it? As a sanity check I fired up an old max6675, and it was nice and stable as stable as I remembered it.
    CuriousOne wrote: »
    After long tries with different power supplies, etc. I got the working solution. But it seems like MAX3185 is not the best choice for this task? I place thermocouple into electric kettle. As long as I connect it to AC, the temperature sign changes to minus! also it changes to minus if I touch braid shield of the thermocouple. If I ground the shield of thermocouple, then temperature reading becomes positive, but reads 320 at 100C. But also, at the same time, short to gnd byte becomes active. So have no idea what to do next.
  • CuriousOneCuriousOne Posts: 931
    edited 2014-08-18 23:35
    max318.jpg
    max319.jpg
    Here it is. There's a little PCB with MAX31855 and LM78L33 mounted on it. Connection is visible on the picture. I've tried another PCB design, no difference in readings. I've also ordered ADS1148 from TI and AD7793 from Analog, they appear to have more robust(?) and noise shielded hw design.
    818 x 403 - 110K
    916 x 523 - 147K
  • CuriousOneCuriousOne Posts: 931
    edited 2014-08-18 23:41
    Forgot to mention, the code is latest one you've provided.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2014-08-19 08:46
    Focusing in on the fact that the MAX31855 is a 3.3V part, as you mentioned above, the Stamp interface is driving it with 5V levels. It does not have 5V tolerant inputs. It would be worthwhile to do it right, to see if that could explain the odd results. I know you said that the internal temperature seems to be coming across okay, but you never know...

    With the SPI it takes only a voltage divider between the Stamp outputs and the MAX' CS\ and CLK inputs.
    [SIZE=1]Stamp output -----/\/\/\-------o-------/\/\/\----- Vss
                         R         |          2R
                                MAX' input
    [/SIZE]
    

  • CuriousOneCuriousOne Posts: 931
    edited 2014-08-19 08:58
    I will try that, but don't think it will help, since error bits all come out nice and clear.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2014-08-19 10:34
    Perhaps, albeit current flowing in the substrate diodes is more likely to affect the analog rather than the digital circuits in the sensor/adc.

    The high-res ADC interfaces are a good option. TThe ADS1118 is another one to consider. It is bit simpler than the ones you mentioned, 8-pin tssop (msop) package, accommodates 2 thermocouples and has an internal temperature reference. There is a nice TI app note, sbaa189. I use the ADS1115 with the Propeller, which is the same chip but with an i2c interface (sans the internal temperature sensor).
  • CuriousOneCuriousOne Posts: 931
    edited 2014-08-20 01:52
    tried 510 ohm and 1kohm resistors as suggested. No change.

    Thermocouple is working properly, verified by connecting to industrial temp meter.
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2014-08-20 09:18
    Okay, that's good to check off.

    Have you tried shorting the T+ to T-? That is not an error condition. Zero volts at the input is what is expected when the thermocouple temperature equals the reference temperature. So, both of the readings should be the same. That is a quick check on operation. It should be stable.

    The MAX31855 data sheet suggests that you include a differential capacitor of about 10nF between the thermocouple inputs, especially under conditions of electrical noise. That may help, or it may take more than that to filter noise at the inputs. Take a look at the app note I linked to in #28 for the ADS1118.

    I understand that your thermocouple is working okay with the industrial temperature meter. The meter probably has a lot of filtering both analog and digital. The analog issue is fundamental and has to do with the limited common mode range of the measuring circuit. If external noise pickup exceedsthe common mode range, the readings will be crazy.

    Are you operating from a battery, or from a power adapter? Looking back up in your description, you describe "not working" in relation to crazy readings when you dip the thermocouple in a kettle of boiling water. The kettle may increase the pickup of noise, so it is essential that the tip be insulated from direct conductive contact with the water. What about when the thermocouple is just sitting out in the open air? Still the same crazy readings? Your reflow oven will not have a kettle of boiling water, but the thermocouples will be immersed in a fairly intense AC electrical field.
  • CuriousOneCuriousOne Posts: 931
    edited 2014-08-21 01:07
    First of all, I'd like to thank you for your help and support!

    I've soldered 10nf capacitor between thermocouple inputs and problem is gone! Previously, if I just touch the braid of thermocouple, readings were jumping all around, now they are stable. The electronic kettle problem was caused probably by stray current flowing trough the ground path. I've connected the kettle via extender which has no GND pin, so now kettle on/off does not affects reading. The boiling water measures 408-412, based on code you've provided and melting ice in water measures 24-26. How should I convert this to C ?
Sign In or Register to comment.