MAX6675

#41
Morning all, below is the code I use in a little temp measure project and have a question.

Code:
; Picaxe 08M2 to Max6675 thermocouple

Symbol CS = C.2           ' connect pin6 to pin 6 MAX6675
Symbol SCK = C.1          ' connect pin4 to pin 5 MAX6675
Symbol MISO = PinC.3         ' connect pin5  to pin 7 MAX6675
Symbol CONF = C.4            ' output pin for flame confirmed
Symbol Val = W1
Symbol I = B1

' Directives

#COM 31                'specify serial port
#picaxe 08M2            'specify procesor
#no_data                'reduces download time
#terminal 4800            'specify terminal baud rate


init:
    pause 2000
    High CONF

Main:
GoSub MeasTemp
GoSub DisplayTemp
GoSub ControlOut


Pause 500        ' allow Max6675 to finish

Goto Main

MeasTemp:
High CS        ' deselect the 6675
Low SCK
Low CS            ' start conversion
Val = 0        ' initialize temperature variable
For I = 1 to 16    ' serial clock in 16 bits
High SCK
Val = Val * 2 + MISO 'clock in the bits into a word
Low SCK
Next I
High CS        ' deselect the 6675
Val = Val / 32    ' use only the 11 most sig bits (val = deg Celsius)

    Return


DisplayTemp:
    sertxd("Temp=",#val,"  ",13,10)        'display text

Return


ControlOut:
    if val <= 120 then LockOut            'flame not confirmed
    if val >= 130 then Confirmed           'flame confirmed

    Return


LockOut:
    sertxd("Lock_Out"," ",13,10)        'display text
    Pause 100                   'wait for period
    High CONF                          'turn on output
    Pause 100                   'wait for period

    Return

Confirmed:
    sertxd("Flame_Confirmed", " ",13,10)    'display text
    Pause 100                       'wait for period
    Low CONF                             'turn off output
    Pause 100                       'wait for period

    Return

The data sheet on the internet talks about bit D2 from the MAX6675 is used to detect if the thermocouple has gone Open as at the moment all my code does is return its max temp of 1024. I could do with monitoring this bit as well as the temp as I already have but can't work out how to go about it. Any help appreciated.
 

hippy

Technical Support
Staff member
#42
The MAX6675 returns a single 16-bit value which includes the D2 bit. So before you do your 'val = val / 32' to get a temperature you need something which extracts the D2 from that. Change -
Code:
High CS        ' deselect the 6675
Val = Val / 32    ' use only the 11 most sig bits (val = deg Celsius)
to -
Rich (BB code):
High CS        ' deselect the 6675
valid = val / 4 & 1 ^ 1
Val = Val / 32    ' use only the 11 most sig bits (val = deg Celsius)
Your 'valid' variable will be 1 when the probe is not open, that is when D2 is low, will be 0 when it is open / not connected.
 
#43
Hi Hippy, thanks again for you support. I've written that into the code with a few other bits to use it and it complies ok so that's halfway there. Shame I don't really understand from what you've written how it works but I'm sure it will do.
 

hippy

Technical Support
Staff member
#44
Code:
                                Probe connected    Disconnected

Your initial 'val' reading is : -tttttttttttt0--   -tttttttttttt1--

Dividing by 4                 : ---tttttttttttt0   ---tttttttttttt1

Anding with 1                 : ---------------0   ---------------1

Exclusive oring with 1        : ---------------1   ---------------0
 
#45
So its all about getting the bit you want to look at into the correct place, in this instance over to right (dividing by 4) and then does the add 1 or Adding with 1 if different get rid of what you don't want? The Exclusive ORing with 1 looks to invert the final result.
Any of that right or am I miles off?
 
#47
Well that's a start, now I just need to get to a point that when I look at a data sheet knowing what combinations of dividing and Anding ect is needed.
 

hippy

Technical Support
Staff member
#48
Well that's a start
It seems you are well on your way already. Your 'val=val/32' does that bit-shifting to align the integer temperature as you desire, it doesn't need any anding because it is usable as it is after the shift -
Code:
Your initial 'val' reading is : -ttttttttttffv--  t=temp, f=fractional

Dividing by 32                : ------tttttttttt
The /32 throws away bits D4 down to D0. If you wanted to keep the fractional temperature part, D4 and D3, you could divide by 8 then and with 3, binary %11 -
Code:
Your initial 'val' reading is : -ttttttttttffv--  t=temp, f=fractional

Dividing by 8                 : ----ttttttttttff

Anding with 3                 ; --------------ff
Then you could have -
Code:
High CS        ' deselect the 6675
valid = val / 4 & 1 ^ 1
fractional = val / 8 & 3
Val = Val / 32    ' use only the 11 most sig bits (val = deg Celsius)

Select Case fractional 
  Case %00 : SerTxd( "Temp = ", #val, ".0"  ) ; 0
  Case %01 : SerTxd( "Temp = ", #val, ".25" ) ; 1
  Case %10 : SerTxd( "Temp = ", #val, ".5"  ) ; 2
  Case %11 : SerTxd( "Temp = ", #val, ".75" ) ; 3
End Select
As always, the more you do, the easier it becomes in figuring out how to do things, even with things you have never seen before..
 
#49
I didn't know you could do the decimal point part of the temp reading even if it just in quarter jumps.

How do you get it to select the individual Case% from the fractional=
 
Top