Home  |  Contents 

Microcontroller and PC projects
  Forum Index : Microcontroller and PC projects         Section
Subject Topic: K-Type Thermocouple help Please Post ReplyPost New Topic
Page of 3 Next >>
Author
Message << Prev Topic | Next Topic >>
bigmik
Guru
Guru
Avatar

Joined: 20 June 2011
Location: Australia
Online Status: Offline
Posts: 2091
Posted: 07 April 2018 at 4:59pm | IP Logged Quote bigmik

Hi All,

I have struggled with trying to get a reading from a K-Type Thermocouple using a MAX31855 Chip. I know it will be something I am doing wrong and I have tried stripping out the relevant section of `working' code I got from Zonker but damned if I can get a good reading from my K-Types.

I know I am lousy at programming but I think all is right (except the actual calculation of Degrees Celsius as I am not 100% certain how to interpret that as I have seen conflicting methods on the net)

Anyway if someone can see what is wrong I would appreciate it greatly.

' Test MAX31855 read

CS = 15                   ' Pin(15) for CS

SetPin CS, DOUT           ' set CS to DData Out
Pin(15)=1                 ' Disable CS
SPI OPEN 10000, 2 ,32    ' 100KHz Mode 1 32bits


Main:

GoSub ReadTemp
Print Bin$(RAW, 32)             ' Print Raw 32 Bit read
TIP$=Left$(Bin$(RAW, 32),14)    ' Print Thermocouple RAW TEMP read
internal$ = Mid$(Bin$(RAW, 32), 17, 12)
Print TIP$;"  ";Internal$                   '
Print Val("&B"+TIP$), Val("&B"+Internal$)               ' Print in numbers
C=Val("&B"+TIP$)/4-Val("&B"+Internal$)
Print "C= ";c;"Celsius"
Print

Pause 2000

GoTo main



ReadTemp:
Pin(CS)=0                 ' ENABLE CS
Pause 1                   ' allow time to settle
RAW=SPI(0)                ' read in 32 bits
Pause 1                   ' allow time to settle
Pin(CS)=1                 ' DISABLE CS
Return


Here is what I get returned from approx 18deg room temp. (the 2nd Row shows the Thermocouple TIP 14 bits and the Internal `cold' junction 12 bit temperature both in binary)




If I warm up the thermocouple it does change but non-sensibly, The fault bit is always 0 unless I short the thermocouple to GND then I can see it change.

Anyway I would appreciate if someone can see what is wrong or provide a snippet of complete working code for me to try on a 28 pin MM.

I have now tried 3 different Max PCBs and about 5 thermocouples of various shapes but all are K-Type.

Kind Regards,

Mick


EDIT**

I have tried swapping the leads to the Max Thermocouple connector and even tried 5v (yeah that may have killed one of my Max's)

Mick



Edited by bigmik on 07 April 2018 at 5:01pm


__________________
Mick's uMite Stuff can be found HERE




Back to Top View bigmik's Profile Search for other posts by bigmik
 
TassyJim
Guru
Guru
Avatar

Joined: 07 August 2011
Location: Australia
Online Status: Offline
Posts: 2623
Posted: 07 April 2018 at 5:21pm | IP Logged Quote TassyJim

What sort of variable is RAW ?
ie Float or Integer
I think if you are looking at Bin$(RAW, 32), it will need to be an Integer.

Jim

__________________
It all started with the ZX81....
VK7JH
http://www.c-com.com.au/MMedit.htm
Back to Top View TassyJim's Profile Search for other posts by TassyJim Visit TassyJim's Homepage
 
bigmik
Guru
Guru
Avatar

Joined: 20 June 2011
Location: Australia
Online Status: Offline
Posts: 2091
Posted: 07 April 2018 at 5:25pm | IP Logged Quote bigmik

Hi Jim,

Maybe that is my problem.. It is the raw 32 bits of data read from the MAX chip.. Maybe it needs to be defined as a 32bit number (not sure how to do this off hand).. I have no defines in my code..


Kind Regards,

Mick


__________________
Mick's uMite Stuff can be found HERE

Back to Top View bigmik's Profile Search for other posts by bigmik
 
goc30
Regular Member
Regular Member
Avatar

Joined: 12 April 2017
Location: France
Online Status: Offline
Posts: 94
Posted: 07 April 2018 at 6:18pm | IP Logged Quote goc30

hi
for me your pb is in SPI com. may be speed or timing of Chip Select. You don't have default bits, just default value
Back to Top View goc30's Profile Search for other posts by goc30
 
Phil23
Guru
Guru


Joined: 27 March 2016
Location: Australia
Online Status: Offline
Posts: 1509
Posted: 07 April 2018 at 6:45pm | IP Logged Quote Phil23

Dunno if this helps Mick,

Think from memory mine were MAX6675?
Similar but just a few more bits.

It was Geoff that pointed me in this direction.

Quote:
Do

PIN(51) = 1 ' set the pin to inactive
SETPIN 51, DOUT ' pin 10 is the enable signal
SPI OPEN 100000, 2, 16 ' speed is 100KHz, data size is 16 bits
PIN(51) = 0 ' assert the enable line (active low)
d = SPI(0) ' get the whole 16 bits
PIN(51) = 1 ' deselect the chip
SPI CLOSE ' close the SPI channel

Print Chr$(27)+"[f";
Print "Data Returned = ";Bin$(d,16)
Print

Print "Thermocouple reading =";Bin$(d>>3,16)+" "d>>3
Print " "

Print "Temperature =" (d>>3)/4 " degrees C"
Print " ";Bin$(d>>5,16)

Pause 1000
Loop




Phil.

Edit:-

Geoff did make a change on his original suggestion due to something a little obscure in the data sheets..

Still one of those get to it things....
Having the damper on the wood fire automated.

Along with the chopping & stoking.

Edit again..

Might have been mode 1 Vs 2.
Mine worked with mode 2 like you have.

Edited by Phil23 on 07 April 2018 at 6:50pm
Back to Top View Phil23's Profile Search for other posts by Phil23
 
chronic
Guru
Guru


Joined: 21 January 2012
Location: Australia
Online Status: Offline
Posts: 612
Posted: 07 April 2018 at 8:22pm | IP Logged Quote chronic

[don't know if it alters anything - the speed setup is 10k but commented 100k? ]

[edit] the 1 in the msb implies a negative ? I am wondering if the mode is right, the string of 0's look like a miscomm to me

PS if you reverse the thermocouple leads does the MSB bit change ?

Edited by chronic on 07 April 2018 at 9:10pm
Back to Top View chronic's Profile Search for other posts by chronic
 
bigmik
Guru
Guru
Avatar

Joined: 20 June 2011
Location: Australia
Online Status: Offline
Posts: 2091
Posted: 07 April 2018 at 9:27pm | IP Logged Quote bigmik

Hi all,

I have tried various speeds, hence 10k where comment says 100k. ..100k was my first attempt!i also tried 1M. I also tried all four modes of SPI operation.

I also tried without the delays on CS.. I added these as the data sheet mentions a delay (not near my pc at the moment).

I agree it appears to be miscommunication but I now feel that Jim is on the right track re variable type..

I donít know much about variable types.. I need to do a bit of reading of the manual, maybe an undefined variable canít hold a 32bit value..

Will try again with different variable types tomorrow..

Mick

Edited by bigmik on 07 April 2018 at 9:28pm


__________________
Mick's uMite Stuff can be found HERE

Back to Top View bigmik's Profile Search for other posts by bigmik
 
TassyJim
Guru
Guru
Avatar

Joined: 07 August 2011
Location: Australia
Online Status: Offline
Posts: 2623
Posted: 08 April 2018 at 9:12am | IP Logged Quote TassyJim

You probably haven't set the default variable type so any undeclared ones will and up as floats.

Try changing RAW to RAW%
That will make sure it's an integer which will make more sense when you do
Bin$(RAW%, 32)

Jim

__________________
It all started with the ZX81....
VK7JH
http://www.c-com.com.au/MMedit.htm
Back to Top View TassyJim's Profile Search for other posts by TassyJim Visit TassyJim's Homepage
 
bigmik
Guru
Guru
Avatar

Joined: 20 June 2011
Location: Australia
Online Status: Offline
Posts: 2091
Posted: 09 April 2018 at 6:54am | IP Logged Quote bigmik

Thanks Jim, All,

I changed RAW into RAW% and still no better, I have also re-visited the different Modes (0-3) for SPI and I get differing results but nothing sensible.. ie. the returned values fluctuate can wildly with no change in temperature..

At this stage I am thinking I might be better off going down the path of the AD595 chip.. seems much easier to implement (famous last words) or I might try the MAX6675 as there is some working code available and it is only 16bits..

Zonker sent me some code but it was for a MM+ and used Cfunctions which seems over the top for a `simpleí single SPI read..

I tell you seriously that if I had hair I would have pulled it out by now.

It appears that nobody else has used the MAX13855 with a MM using native SPI so just possibly there is some crazy incompatibility.. or more likely.... I am just plain stupid..

Regards,

Mick

PS.

All this is in aid of trying to create a solder oven for SMD work... I have all the bits but thought I would play with getting one going and here I have stalled at the first hurdle.

Mik

Edited by bigmik on 09 April 2018 at 6:56am


__________________
Mick's uMite Stuff can be found HERE

Back to Top View bigmik's Profile Search for other posts by bigmik
 
lew247
Guru
Guru
Avatar

Joined: 23 December 2015
Location: United Kingdom
Online Status: Offline
Posts: 966
Posted: 09 April 2018 at 5:05pm | IP Logged Quote lew247

HI Mik
NOt sure if you've seen this or not but I found Arduino code for this

Maybe you or someone can convert it to MM Basic?

Link here
Back to Top View lew247's Profile Search for other posts by lew247
 
jman
Guru
Guru
Avatar

Joined: 12 June 2011
Location: New Zealand
Online Status: Offline
Posts: 679
Posted: 09 April 2018 at 6:07pm | IP Logged Quote jman

Hi Mick
below some old code I did for this NOT tested on new versions of MMBasic


''''''''''''''''''''''''''''''''''''''''
'Max 31855 
Dim temp(4)

Start:
''''''''''''''''''''''''''''
'Spi Read 32 bits
SetPin 4, Dout
Pin(4) = 1
SPI Open 40000, 0, 8

Pin(4)=0
 Temp(0) = SPI(0)
 Temp(1) = SPI(0)
 Temp(2) = SPI(0)
 Temp(3) = SPI(0)
SPI CLose
Pin(4)=1

error = temp(3) And &B111         'Error check
If error <> 0 Then
  Print "Thermocouple Error"
  Pause 5000
  GoTo Start
EndIf

TempMSB = Temp(0)*16
TempLSB = ShiftR(Temp(1),4)
TempDP = (ShiftR(Temp(1),2) And &B00000011) * .25

Temperature = TempMSB + TempLSB + TempDP

Print "Temperature ";Temperature

TempIntMSB = Temp(2)
TempIntLSB = ShiftR(Temp(3),4)
TempIntDP = TempintLSB * 0.0625
TempInt = TempIntMSB + TempIntDP

Print "Internal Temperature ";TempInt

GoTo Start

Function ShiftR(byte_in, shift)
 If shift <1 Or Shift > 7 Then Error "Invalid shift value"
 ShiftR = (byte_in \ 2 ^ shift)
End Function

Back to Top View jman's Profile Search for other posts by jman
 
bigmik
Guru
Guru
Avatar

Joined: 20 June 2011
Location: Australia
Online Status: Offline
Posts: 2091
Posted: 10 April 2018 at 9:40am | IP Logged Quote bigmik

Hi Jman,

Ok I tried your code but similarly I get incorrect readings (basically the same as my 32 bit SPI code)

I had to change your code to suit my CS of pin(15) and also you used a variable called ERROR which gave me a syntax error so I changed that to ERROR1 I also added a print routine to show what all four SPI reads are and a 2 second delay to see what I received.

Here is the result I see after those changes





Here is the code with my Alterations



''''''''''''''''''''''''''''''''''''''''
'Max 31855 
Dim temp(4)

Start:
''''''''''''''''''''''''''''
'Spi Read 32 bits
SetPin 15, Dout
Pin(15) = 1
SPI Open 40000, 0, 8

Pin(15)=0
 Temp(0) = SPI(0)
 Temp(1) = SPI(0)
 Temp(2) = SPI(0)
 Temp(3) = SPI(0)
SPI CLose
Pin(15)=1
print bin$(Temp(0)); " ";bin$(Temp(1)); " ";bin$(Temp(2)); " ";bin$(Temp(3))

error1 = temp(3) And &B111         'Error check
If error1 <> 0 Then
  Print "Thermocouple Error"
  Pause 5000
  GoTo Start
EndIf

TempMSB = Temp(0)*16
TempLSB = ShiftR(Temp(1),4)
TempDP = (ShiftR(Temp(1),2) And &B00000011) * .25

Temperature = TempMSB + TempLSB + TempDP

Print "Temperature ";Temperature
pause 2000

TempIntMSB = Temp(2)
TempIntLSB = ShiftR(Temp(3),4)
TempIntDP = TempintLSB * 0.0625
TempInt = TempIntMSB + TempIntDP

Print "Internal Temperature ";TempInt

GoTo Start

Function ShiftR(byte_in, shift)
 If shift <1 Or Shift > 7 Then Error "Invalid shift value"
 ShiftR = (byte_in \ 2 ^ shift)
End Function


Something is seriously wrong here.. It surely shouldnt be so difficult..

I tried changing all 4 modes of SPI (0-3) and whilst the results change they are still nonsense. I have tried 4 or 5 K-Types (2 different styles) that work with a cheap temp meter I bought and 3 different MAX31855 modules although they are all the same type (I had to cut the GND from the Thermocouple itself)..

I will have to go back to basics, I will remove the chip from the test board and breadboard the circuit as the Datasheet shows..

Thank you all for your help..

Kind Regards,

Mick

__________________
Mick's uMite Stuff can be found HERE

Back to Top View bigmik's Profile Search for other posts by bigmik
 


Page of 3 Next >>
In the news...
 
Post ReplyPost New Topic
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.8
Copyright ©2001-2004 Web Wiz Guide

This page was generated in 0.1094 seconds.
Privacy Policy     Process times : 0, 0, 0, 0.11