1-Wire Thermocouple Amplifier - MAX31850K
anaxcontrol
Posts: 23
in BASIC Stamp
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.
Any help from forum members is greatly appreciated.
Comments
http://forums.parallax.com/discussion/158615/thermocouple-interface-with-bs2p
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
Don't see where it says so in the manual, but shiftin definitely clears the variable.
Tie datapin high and try it. You'll like it.
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