CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to use Max6675 with PIC
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Bee
Guest







How to use Max6675 with PIC
PostPosted: Tue Feb 01, 2005 2:18 am     Reply with quote

Hi all. I'm begin on ccs c programming. I have ploblem.I don't know how to use IC MAX6675 with PIC . MAX6675 is cold-junction-compensated K-thermocouple-to-Digital Converter. Please suggestion for me
/ THANK YOU Idea Idea Idea
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Feb 01, 2005 8:48 am     Reply with quote

1) Read data sheet for MAX6675. Discover it uses SPI to communicate with a host processor. Shocked
2) Read data sheet for PIC processor you intend to use or at least prototype with. Pay special attention to references to SPI. Shocked
3) Use search feature of forum to search for SPI. Realize this will get you way to many hits to read but at least read a few to get a feel for what is happening. Shocked
4) Read CCS documentation with special attention to references to SPI and the example code. Shocked

At this point your eyes are probably going to fall out of your head. Cool

Once you have figured out what SPI is and have a general idea of how to do it, the MAX6675 is pretty simple. The MAX6675 doesn't use the 4th pin for data IN because it doesn't accept any commands. Just lower the chip select line with the clock low. Each rising edge of the clock for the next 16 clocks will produce a single bit of output. You will be receiving the data MSbit first. After you get that 16th bit clocked out, return the chip select line high. Look at the diagrams on page 6 of the datasheet. The table on page 6 tells you how to interpret the 16 bits.

Bit 15 is always 0
Bit 14 down to Bit 3 is a 12 bit temperature reading
Bit 2 indicates if the termocouple is present
Bit 1 is a device ID, always 1
Bit 0 will be either high or low depending on how the pin drifts when it tri-states or if you include pull-up or pull-down resistor.

The MAX6675 reports temperatures between 0 and nearly 1024C in 1/4 degree increments. Treat the value as a fixed-point number with 2 decimal places (the lowest 2 bits). Temperature in degrees is in the upper 10 bits.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Bee
Guest







thank you
PostPosted: Tue Feb 01, 2005 10:03 pm     Reply with quote

u can suggestion for example code ?
JPH



Joined: 02 Feb 2005
Posts: 9
Location: Finland

View user's profile Send private message

PostPosted: Wed Feb 02, 2005 10:42 am     Reply with quote

Hello

Here is uncommented source code for reading 16-bit data from MAX6675.


#define MAX_CS PIN_B0
#define MAX_DO PIN_C4
#define MAX_CLK PIN_C3

void init_temp()
{

output_low(MAX_CLK);
output_low(MAX_DO);
output_low(MAX_CS);
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
output_high(MAX_CS);

}

int16 read_temp()
{

BYTE datah, datal=0;
int16 data=0;

output_low(MAX_CS);
delay_cycles(1);
datah=SPI_READ(0);
datal=SPI_READ(0);
output_high(MAX_CS);

if( bit_test(datal,2))
{
bit_set(data,15);

return(data);
}


data = datah<<8;
data = data | datal;

return(data);
}

You have to manipulate retuned data in the program to get 12-bit temperature data out from 16-bit data.
Bee
Guest







thank you JPH
PostPosted: Fri Feb 04, 2005 1:48 am     Reply with quote

thank you JPH. I have question. why result non stable

This result
64
72
48
96
64
72
112
56
48
64
128
64
80
80
80
112
144
48
80
80
64
64
72

Plesae check this code

MAX6675.C is source code from JPH

++++++++++++++++++++++++++++++++++++++++++++
#include <16F877.h>
#include <max6675.c>
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7)

void main() {
BYTE value;
init_temp();
do {
value = read_temp();
printf("%u\r\n",value);
delay_ms(500);
} while (TRUE);
}
++++++++++++++++++++++++++++++++++++++++++++++++++
JPH



Joined: 02 Feb 2005
Posts: 9
Location: Finland

View user's profile Send private message

PostPosted: Fri Feb 04, 2005 12:34 pm     Reply with quote

Hi

First hardware question. Is the thermouple (-) pole in the same ground with MAX6675? Datasheet says they should be.

Second MAX6675.C return data(int 16) and you are storing it to value(BYTE).

TRY THIS

#include <16F877.h>
#include <max6675.c>
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7)

main() {
int16 value;
init_temp();
do {
value = read_temp();
value = value>>3;
value = value*0.25;
printf("%d\r\n",value);
delay_ms(500);
} while (TRUE);
}


-JPH
Bee
Guest







Thank you -JPH
PostPosted: Mon Feb 07, 2005 2:19 am     Reply with quote

Hi JPH. Thank you so much.You interesting in my problem.
I'm check hardware.The thermocouple (-) pole in the same ground.
Value from thermometer is 58 'C . But value from Thermocouple is


47 'C
47 'C
47 'C
47 'C
48 'C
47 'C
47 'C
47 'C
47 'C
46 'C
46 'C
47 'C
46 'C
46 'C
46 'C
46 'C
47 'C
46 'C
47 'C
47 'C
46 'C
47 'C


What happen? explain please.

This is code
+++++++++++++++++++++++++++++++++++++++++++++
#include <16F877.h>
#include <max6675.c>
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP,NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7)

main() {
int16 value;
init_temp();
do {
value = read_temp();
value = value>>3;
value = (value*0.25);
printf("%ld 'C\r\n",value);
delay_ms(3000);
} while (TRUE);
}

+++++++++++++++++++++++++++++++++++++++++++++++
Guest








PostPosted: Tue Feb 07, 2006 3:46 pm     Reply with quote

rwyoung wrote:
1) Read data sheet for MAX6675. Discover it uses SPI to communicate with a host processor. Shocked
2) Read data sheet for PIC processor you intend to use or at least prototype with. Pay special attention to references to SPI. Shocked
3) Use search feature of forum to search for SPI. Realize this will get you way to many hits to read but at least read a few to get a feel for what is happening. Shocked
4) Read CCS documentation with special attention to references to SPI and the example code. Shocked

At this point your eyes are probably going to fall out of your head. Cool

Once you have figured out what SPI is and have a general idea of how to do it, the MAX6675 is pretty simple. The MAX6675 doesn't use the 4th pin for data IN because it doesn't accept any commands. Just lower the chip select line with the clock low. Each rising edge of the clock for the next 16 clocks will produce a single bit of output. You will be receiving the data MSbit first. After you get that 16th bit clocked out, return the chip select line high. Look at the diagrams on page 6 of the datasheet. The table on page 6 tells you how to interpret the 16 bits.

Bit 15 is always 0
Bit 14 down to Bit 3 is a 12 bit temperature reading
Bit 2 indicates if the termocouple is present
Bit 1 is a device ID, always 1
Bit 0 will be either high or low depending on how the pin drifts when it tri-states or if you include pull-up or pull-down resistor.

The MAX6675 reports temperatures between 0 and nearly 1024C in 1/4 degree increments. Treat the value as a fixed-point number with 2 decimal places (the lowest 2 bits). Temperature in degrees is in the upper 10 bits.
Guest








PostPosted: Tue Feb 07, 2006 3:47 pm     Reply with quote

Read data sheet for MAX6675. Discover it uses SPI to communicate with a host processor. Shocked
2) Read data sheet for PIC processor you intend to use or at least prototype with. Pay special attention to references to SPI. Shocked
3) Use search feature of forum to search for SPI. Realize this will get you way to many hits to read but at least read a few to get a feel for what is happening. Shocked
4) Read CCS documentation with special attention to references to SPI and the example code. Shocked

At this point your eyes are probably going to fall out of your head. Cool

Once you have figured out what SPI is and have a general idea of how to do it, the MAX6675 is pretty simple. The MAX6675 doesn't use the 4th pin for data IN because it doesn't accept any commands. Just lower the chip select line with the clock low. Each rising edge of the clock for the next 16 clocks will produce a single bit of output. You will be receiving the data MSbit first. After you get that 16th bit clocked out, return the chip select line high. Look at the diagrams on page 6 of the datasheet. The table on page 6 tells you how to interpret the 16 bits.

Bit 15 is always 0
Bit 14 down to Bit 3 is a 12 bit temperature reading
Bit 2 indicates if the termocouple is present
Bit 1 is a device ID, always 1
Bit 0 will be either high or low depending on how the pin drifts when it tri-states or if you include pull-up or pull-down resistor.

The MAX6675 reports temperatures between 0 and nearly 1024C in 1/4 degree increments. Treat the value as a fixed-point number with 2 decimal places (the lowest 2 bits). Temperature in degrees is in the upper 10 bits.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Feb 07, 2006 6:37 pm     Reply with quote

To quote Monty Python...

"Spam, spam, spam, spam, spam......"
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Wed Feb 08, 2006 8:32 am     Reply with quote

This time it was a little bit different.

Usually the Phantom Guest posts as a complete quote but now we have both a complete quote and what looks like a botched copy-and-paste.

Darren made a comment in the forum poll that he thought it was a software glitch but I have my doubts. I subscribe to a couple of other forums that use this same (or at least similiar revision) forum software and they don't seem to be having the Phantom Guest posting problem.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Guest








Re: How to use Max6675 with PIC
PostPosted: Sat Jun 17, 2006 6:34 pm     Reply with quote

Bee wrote:
Hi all. I'm begin on ccs c programming. I have ploblem.I don't know how to use IC MAX6675 with PIC . MAX6675 is cold-junction-compensated K-thermocouple-to-Digital Converter. Please suggestion for me
/ THANK YOU Idea Idea Idea
Gast
Guest







Re: How to use Max6675 with PIC
PostPosted: Fri Sep 15, 2006 3:16 am     Reply with quote

I have just one question to. I use your programm and it works great. But if i use this:
printf("Temperatur: %ld\r\n", value);
it don't works. Some letters or value are not more present.

What is my mistake? Can somebody help me?

Regards. Dennis

PCHW 3.249
PIC16F877A
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Sep 15, 2006 5:13 pm     Reply with quote

Quote:
Some letters or value are not more present.

There is probably something wrong with your serial port setup,
either hardware or software.

I suggest that you make a small test program, that doesn't get
data from reading the temperature. Instead, just set 'value'
to some number, such as 12345, and try to display it with printf().

In other words, you should test that your serial port code (and the
connection to the PC) is working correctly. If the test program
doesn't work, then post it. (Possibly in a new thread, because a
serial port problem is not related to the MAX6675).
DENNIS
Guest







PostPosted: Sat Sep 16, 2006 2:21 am     Reply with quote

Thank you, PCM programmer. I have changed my quarz and #use(rs 232...)and it works. Now i am using a 4MHz and it works great. With a 20 or 16 MHz one i have recieved just rubbish. I don't now, whats happend. Can you explain me?

Regards. Dennis
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group