Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MAX6675 interfacing code error

Status
Not open for further replies.

garg29

Advanced Member level 1
Joined
Nov 17, 2004
Messages
451
Helped
25
Reputation
50
Reaction score
9
Trophy points
1,298
Activity points
3,605
max6675 project

Hi friends,
As discussed and suggested by all of you in my previous question "" "temperture controller for J & K type temperature sensors" I think what "Ianp" suggested was one of the best methods. Ianp suggested to use MAX6675 ( Cold-Junction-Compensated K-Thermocoupleto-Digital Converter 0°C to +1024°C) with 89c51 for reading temperature from k-type thermocouple. I tried to build a starting code to read values from MAX6675, but the code is showing only 0 (zero) on the screen. I know the code isn't complete as the 12-bit data is comprised only of D3 bit - to - D14 bit as shown in picture below, But still some non-zero value should be read from MAX6675. I'couldn't understand the mistake. Please help me, in finding out my mistake.

Thanks

With best regards,
Garg


Code:
;*********************** READ MAX6675 **********************************************

READ_MAX6675:

	SETB CS
	NOP
	CLR CS
	
	MOV HIGH_A, #00H	; upper byte
	MOV LOW_A, #00H		; lower byte
	
	MOV A, #00H
	MOV B, #08H
	CLR C
	
MAX6675_LOOP:		
		
	SETB CLK
	CLR CLK
	
	MOV C, DO
	
	RRC A
	DJNZ B, MAX6675_LOOP
		
	MOV HIGH_A, A
	
	
	MOV A, #00H
	MOV B, #08H
	CLR C
	
MAX6675_LOOP2:		
	
	SETB CLK
	CLR CLK
	
	MOV C, DO
	
	RRC A
	DJNZ B, MAX6675_LOOP2
	
	MOV LOW_A, A	
	
	SETB CS
	
	
	RET


;***************************************************************************************
 

silvio

Advanced Member level 3
Joined
Dec 31, 2001
Messages
716
Helped
105
Reputation
210
Reaction score
16
Trophy points
1,298
Location
Romania
Activity points
11,495
Hi Garg29

Bear in mind that the time required for conversion is typical 0,17 seconds (guaranteed by design) starting from rising edge of /CS (immediatelly after previously forced low).
I don't see in your code waiting for EOC

Code:
MOV C, DO

D0 is assigned to which 8051 bit ? Hope it's not among ones of port P0, otherwise you must use pullup resistor (especially for bit D0, last from 16bit data stream which is TSL)

Bits D14–D3 contains the converted temperature in the order of MSB to LSB. Thus you should use "RLC A" rather "RRC A'for proper left hand justification.
 

garg29

Advanced Member level 1
Joined
Nov 17, 2004
Messages
451
Helped
25
Reputation
50
Reaction score
9
Trophy points
1,298
Activity points
3,605
Thanks silvio for replying. first of all i'll tell you about the bits.

Code:
DO		.EQU	P2.0
CS		.EQU	P2.1
CLK		.EQU	P2.2

DO is "DATA OUT"
CS is "CHIP SELECT"
clk is "SERIAL CLOCK"

As you said i'm not waiting for EOC, i requet you to please tell me how to do that, i'm new in programming line. you said the conversion time required is 0.17 seconds, so should i give some delay between


Code:
   SETB CS
	NOP		;instead of nop should i add 0.17 seconds delay  ???????
	CLR CS


Bits D14–D3 contains the converted temperature in the order of MSB to LSB. Thus you should use "RLC A" rather "RRC A'for proper left hand justification.

and the last thing, I wasn't able to understand from data sheet which bit (D15 or D0) of max6675 comes out first, please tell me.

Thanks once again,

With best regards,
Garg
 

silvio

Advanced Member level 3
Joined
Dec 31, 2001
Messages
716
Helped
105
Reputation
210
Reaction score
16
Trophy points
1,298
Location
Romania
Activity points
11,495
Hi Garg,

Asssuming your 8051 driven by 11.0592 XTAL, one machine cycle is 1 us.
Every DJNZ takes 2 machine cycles, means "DJNZ R3, $" spent in 256 x 2 us = 512 us
You need a delay of 170 ms. Thus 170 ms / 512 us = 332.
You need to repeat instruction "DJNZ R3, $" 332 times to get a delay of 170 ms.
Since an 8 bit register can take a value greater than 255 you need R5 too.

Code:
          MOV R3,#00h
          MOV R4,#00h
          MOV R5,#0AAh
LOOP: DJNZ R3,$
          DJNZ R4,$
          DJNZ R5,LOOP
          RET

You can use either timer 0 or 1 if you want and have something to do during 170 ms.

Bit D15 is coming out first.

Force CS low and apply a clock signal at SCK to read
the results at SO. Forcing CS low immediately stops
any conversion process. Initiate a new conversion
process by forcing CS high.

Code:
CLR CS       ;start a dummy read
SETB CLK    ;with a clock pulse
CLR CLK
SETB CS     ;initiate conversion
CALL LOOP  ;170 ms delay
CLR CS       ;start reading at SO
 

    garg29

    Points: 2
    Helpful Answer Positive Rating

garg29

Advanced Member level 1
Joined
Nov 17, 2004
Messages
451
Helped
25
Reputation
50
Reaction score
9
Trophy points
1,298
Activity points
3,605
hi silvio
thanks a lot. i m done with this project.i have clicked on "helped me" for you:D
but after doing one change which i couldnot understand
Code:
   MOV A, #00H 
   MOV B, #07H                ;replaced #08h with #07h
   CLR C 
    
MAX6675_LOOP:       
       
   SETB CLK 
   CLR CLK 
    
   MOV C, DO 
    
   RRC A 
   DJNZ B, MAX6675_LOOP 
       
   MOV HIGH_A, A 
    
    
   MOV A, #00H 
   MOV B, #08H                       [b] ;did not replace this #08h [/b]
   CLR C 
    
MAX6675_LOOP2:       
    
   SETB CLK 
   CLR CLK 
    
   MOV C, DO 
    
   RRC A 
   DJNZ B, MAX6675_LOOP2 
    
   MOV LOW_A, A    
    
   SETB CS 
    
    
   RET

can you explain me how is it happening?
regards

garg
 

silvio

Advanced Member level 3
Joined
Dec 31, 2001
Messages
716
Helped
105
Reputation
210
Reaction score
16
Trophy points
1,298
Location
Romania
Activity points
11,495
Hi Garg,

If you succeed to read the data conversion in 15 steps (first 7 + last 8 ) then I believe that you can blame my first dummy bit read. Thus remove the lines SETB CLK and CLR CLK and keep the MOV B, #08H for both loops.

Code:
CLR CS       ;start a dummy read and clear any conversion in progress
SETB CS     ;initiate conversion 
CALL LOOP  ;170 ms delay 
CLR CS       ;start reading at SO

If the MSB in HIGH_A is "0" and LSB in LOW_A is "1" then it's OK.

You can even go further and type the code:
Code:
MOV A, LOW_A
ANL A, #04H
JNZ ERROR
; continue with appropiate code if you have no errors
;
;
ERROR:
;you're here because your thermocouple is open
;
;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top