Shop OBEX P1 Docs P2 Docs Learn Events
1-Wire Thermocouple Amplifier - MAX31850K — Parallax Forums

1-Wire Thermocouple Amplifier - MAX31850K

I have a Stamp 2PX24 and would like to add a 1-Wire Thermocouple Amplifier - MAX31850K with K-Type temp probe. I have tried the sample code I could find but nothing specific. The only code I have is for Arduino. I'm not proficient enough with PBasic to translate it. Does anyone have some code I can reuse? I just need to read the temp and display to 4x20 LCD or DEBUG window is fine as I can take it from there.
Any help from forum members is greatly appreciated.

Comments

  • PublisonPublison Posts: 12,366
    edited 2016-06-11 16:57
  • Yes. This is what I was looking for. Not sure why I could not find it. I think my problem was I did not have a level shifter. I ordered 2 of them. Thanks! This forum is awesome.
  • Question: I have the MAX31855 wired up and is reading accurately and output to 4 line LCD. Problem now is as the temp is rising (monitoring temp up to 1400deg F); the temp suddenly jumps from around 600 to 9000 (some random number) and fluctuates there. If I restart the stamp, temp is accurate again. It seems as if the temp is rising fast, the scale changes or something. I did try putting a .01mf cap on the probe leads to the MAX31855 but this didn't change anything. Do I need to lowing the polling rate? Anyone seen anything like this? Below is the code I'm using:

    TX PIN 0 ' serial output to LCD
    so PIN 1 ' serial-out/data pin
    Clk PIN 2 ' clock pin
    CS PIN 3 ' chip select


    '
    [ Constants ]

    LcdBaud CON 188
    LcdBkSpc CON $08 ' move cursor left
    LcdRt CON $09 ' move cursor right
    LcdLF CON $0A ' move cursor down 1 line
    LcdCls CON $0C ' clear LCD (use PAUSE 5 after)
    LcdCR CON $0D ' move pos 0 of next line
    LcdBLon CON $11 ' backlight on
    LcdBLoff CON $12 ' backlight off
    LcdOff CON $15 ' LCD off
    LcdOn1 CON $16 ' LCD on; cursor off, blink off
    LcdOn2 CON $17 ' LCD on; cursor off, blink on
    LcdOn3 CON $18 ' LCD on; cursor on, blink off
    LcdOn4 CON $19 ' LCD on; cursor on, blink on
    LcdLine1 CON $80 ' move to line 1, column 0
    LcdLine2 CON $94 ' move to line 2, column 0
    LcdLine3 CON $A8 ' move to line 2, column 0
    LcdLine4 CON $BC ' move to line 2, column 0

    LcdCC0 CON $F8 ' define custom char 0
    LcdCC1 CON $F9 ' define custom char 1
    LcdCC2 CON $FA ' define custom char 2
    LcdCC3 CON $FB ' define custom char 3
    LcdCC4 CON $FC ' define custom char 4
    LcdCC5 CON $FD ' define custom char 5
    LcdCC6 CON $FE ' define custom char 6
    LcdCC7 CON $FF ' define custom char 7

    '
    [ Variables ]
    MAX_T VAR Word ' MAX31855 C` result
    F_temp VAR Word ' Buffer for C` to F` conversion.

    '
    [ EEPROM Data ]


    '
    [ Initialization ]

    Init_LCD:
    PAUSE 1000 ' allow LCD to self-initialize first
    LCDCMD 0, %00110000 ' send wakeup sequence to LCD
    PAUSE 5 ' pause required by LCD specs
    LCDCMD 0, %00110000
    PAUSE 0 ' pause required by LCD specs
    LCDCMD 0, %00110000
    PAUSE 0 ' pause required by LCD specs
    LCDCMD 0, %00100000 ' set data bus to 4-bit mode
    LCDCMD 0, %00101000 ' set to 2-line mode with 5x8 font
    LCDCMD 0, %00001100 ' display on without cursor
    LCDCMD 0, %00000110 ' auto-increment cursor

    '
    [ Program Code ]

    Setup:
    HIGH CS ' set to conversion mode. MAX6675
    PAUSE 250 ' time to start first conversion. (250 mS)

    Main:
    SEROUT TX, LcdBaud, [LcdBLoff, LcdOn1, LcdCls]
    PAUSE 250

    SEROUT 0, LcdBaud, TX, [LcdLine1, $82, "RPM="]
    SEROUT 0, LcdBaud, TX, [LcdLine2, $96, "OIL="]
    SEROUT 0, LcdBaud, TX, [LcdLine2, $9F, "EGT="]
    SEROUT 0, LcdBaud, TX, [LcdLine3, "FUEL1="]
    SEROUT 0, LcdBaud, TX, [LcdLine3, $B3, "INT="]
    SEROUT 0, LcdBaud, TX, [LcdLine4, "FUEL2="]

    DO
    LOW CS ' set the MAX31855 to write mode, Stops all conversions
    SHIFTIN so, Clk, MSBPOST, [MAX_T\11] ' shift in the data, MSB first on the falling clock pulse\16 bits of data only 11 are needed.
    HIGH CS ' Restart conversion mode
    F_temp = (ABS MAX_T) * 9 / 5 + 32 ' Convert C` to F` This is far easier than using C * 1.8 + 32 !!!
    ' DEBUG CLS
    ' DEBUG BIN ? MAX_T ' Show BIN%
    ' DEBUG DEC ? MAX_T ' Show C`
    ' DEBUG DEC ? F_temp ' show conversion result
    SEROUT 0, LcdBaud, TX, [$A3, DEC F_temp]
    PAUSE 1000 ' Allow a second for the MAX31855 to read the T/C and do the conversion.
    ' This PAUSE value could be less but the flash on the DEBUG screen is annoying.
    IF F_temp > 3000 THEN GOSUB Fault

    LOOP ' repeat
    END

    Fault:
    DEBUG CLS, "T/C fault " ' The MAX31855 has a fault bit(2) for this, But the simple "IF-Then" is so much easier to use.
    PAUSE 5000 ' The fault is either OPEN T/C, OVER TEMP (above 1025`C), or BELOW ZERO C`.
    RETURN
  • Shouldn't you be reinitializing MAX_T to zero each time before shifting in the bits?
  • Nope:
    Don't see where it says so in the manual, but shiftin definitely clears the variable.
    maxt   var    word
    cnt    var   byte
    
    for cnt = 1 to 16
      maxt = $5a5a
      shiftin datapin, clkpin, mode [maxt \cnt]
      debug cr, bin16 maxt
      next
    

    Tie datapin high and try it. You'll like it.
  • So I understand what we're saying Tom- below is what I have for this section. Does the example above replace the shiftin that i currently have along with the 2 variables added? Note that i changed the values to binary (the REM (x) is the decimal value. What is meant by "Tie datapin high"?

    DO
    LOW CS ' select SPI
    SHIFTIN so, Clk, MSBPRE, [MAX_T\16] ' shift in the data, MSB first, MSBPRE for sign bit.
    HIGH CS ' SPI for Xfer
    IF MAX_T.BIT0 = %0001 THEN Fault ' 3 fault conditons (1).
    MAX_T = MAX_T >> %0011 ' drop bits 0, 1, 2 to isolate the 12 bit + sign result (3).
    MAX_T.NIB3 = -MAX_T.BIT12 ' extend the sign to bits 13, 14 and 15.
    MAX_T = MAX_T * %0101 ' resolution is 0.5 degC per bit (5)
    ' DEBUG CR,"degC=",REP "-"\MAX_T.BIT15, DEC ABS MAX_T/10,".",DEC1 ABS MAX_T ' display as sxxxx.x +/-0.5 degC.
    MAX_T = MAX_T + %000110010000 ' add 40.0 degC to make it + (400).
    F_temp = MAX_T ** %0010111000010100 - %00101000 ' convert to whole degF, multiply * .18, remove offset -72 add 32 (11796-40)
    ' DEBUG CR,"degF=",SDEC F_temp ' display as sxxxx +/-1 degF.
    SEROUT 0, LcdBaud, TX, [$A3, " "] ' Refresh F_Temp.
    SEROUT 0, LcdBaud, TX, [$A3, SDEC F_temp] ' display as sxxxx degF.
    PAUSE 1000
    LOOP
    END

    Fault:
    'DEBUG CLS, "T/C fault" ' MAX31855 fault bit(2).
    SEROUT 0, LcdBaud, TX, [$A3, "*ERR*"]
    PAUSE 5000
    RETURN
  • Um, I was responding to Sandy's suggestion about initializing your variable MAX_T prior to the shiftin instruction. The code fragment is just a little example that demonstrates it is not needful. Sorry for the confusion; I should have quoted his comment.
  • Got it Tom. Have a good 4th!
Sign In or Register to comment.