PDA

View Full Version : Max31855 Thermocouple Temperature Reading



Lefteris
- 18th September 2012, 11:08
I was looking hard to find a picbasic code for the new MAX31855 from Maxim but I could't find anywhere.
This is a nice chip to read temperature from -210 up to 1300 C for many types of thermocouples with internal ColdJuction and faults report!!.
Here is datasheet for details : http://datasheets.maximintegrated.com/en/ds/MAX31855.pdf

Thermocouples are using for high temperatures, so I am not interesting for negative sign !!!
I send data to PC using Hyperterminal at 9600 bauds.
Brown out detect is disable So I can use 3.3 Volts supply on my pic16f877A
I hope this code is usefull for you as is for me!




define OSC 20
@ DEVICE PIC16F877A,HS_OSC,WDT_ON,MCLR_OFF,BOD_Off,LVP_OFF, PROTECT_OFF
include "modedefs.bas"


'----- Data Output To Pc Without MAX232 at 9600bauds reverse ----

DataTx var portc.6 'TX serial data to PC
BaudTx con 16468 '9600 bauds reverse



'Alias pins - MAX31855 temp sensor
MXSCLK var PORTD.0 'MAX31855 Clock
MXCS var PORTD.1 'MAX31855 Chip Select
MXSO Var PORTD.3 'MAX31855 Serial Data
'--Variables-----------------------
TCtemp var word 'raw data from MAX31855
tempC var word 'temperature in degrees C
tempF var word 'temp C converted to degrees F
CJtemp var word 'raw data from MAX31855
tempcjC var word 'temperature ColdJuction in degrees C
tempcjF var word 'ColdJuction C converted to degrees F



'-----------Read and display temperature from MAX31855-----------

main:

'Read Temp of Thermocouple

LOW MXCS 'chip select low
shiftin MXSO, MXSCLK, 0, [TCtemp\16] 'shift in the data
HIGH MXCS 'chip select high
tempC = TCtemp >> 4 'side shift to ditch the stuff to the right of the decimal point and just show whole degrees)
tempF = ((tempC * 18)/10) + 32 'convert C to F

'--------- Send Temp To PC ------------------
if TempC.bit11 = 0 then 'Positive Sign of Temperature
SEROUT2 DataTx,BaudTx, ["Theromocouple ",dec tempc ," degrees C ",dec tempF," degrees F " ,10,13 ] 'display the data on PC
PAUSE 1000
else
SEROUT2 DataTx,BaudTx, ["OUT of Range ",10,13 ]
pause 1000
endif

'Read Temp of ColdJuction
LOW MXCS 'chip select low
shiftin MXSO, MXSCLK, 0, [CJtemp\32] 'shift in the data
HIGH MXCS 'chip select high
tempcjC = CJtemp>> 8 'side shift to ditch the stuff to the right of the decimal point and just show whole degrees)
tempcjF = ((tempcjC * 18)/10) + 32 'convert C to F



'--------- Send Cj Temp To PC ------------------
SEROUT2 DataTx,BaudTx, ["ColdJuction ",dec tempcjc ," degrees C ",dec tempcjF," degrees F " ,10,13 ] 'display the data on PC
pause 1000


'Check Thermocouple Status
IF CJtemp.bit0=1 THEN
SEROUT2 DataTx,BaudTx, [" NO CONNECTION " ,10,13 ] 'display the data on PC
pause 1000
ENDIF

IF CJtemp.bit1=1 THEN
SEROUT2 DataTx,BaudTx, [" SHORT to GND " ,10,13 ] 'display the data on PC
pause 1000
ENDIF

IF CJtemp.bit2=1 THEN
SEROUT2 DataTx,BaudTx, [" SHORT to VCC " ,10,13 ] 'display the data on PC
PAUSE 1000
ENDIF

goto main
end

gadelhas
- 18th September 2012, 13:44
Thank you! :)

brankobem
- 30th January 2013, 02:35
Thank you, I modify your code to work with PIC16F690 and to display temperature on serial 20x4 LCD and it works great.

CuriousOne
- 10th July 2013, 14:32
I have also tried to modify this code for LCD, but I'm getting very low readings in C. and also, they change strangely - when I heat thermocouple, they start to increase, than at some point (always different), will decrease by 5-10C and then again increase.

tekart
- 21st January 2015, 02:39
Thanks Lefteris - this was very helpful. Not clear why you shift the data right by 4 bits, but it works great. Thanks for posting this! :)

Archangel
- 21st January 2015, 04:20
@ __config _HS_OSC & _WDT_ON & _PWRTE_ON &_BODEN_OFF & _LVP_OFF & _CPD_OFF
Appears orig. config was for PB compiler AND NOT for 16F877a as stated as there is NO MCLR or PROTECT