View previous topic :: View next topic |
Author |
Message |
Bee Guest
|
How to use Max6675 with PIC |
Posted: Tue Feb 01, 2005 2:18 am |
|
|
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](images/smiles/icon_idea.gif) |
|
![](templates/subSilver/images/spacer.gif) |
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Tue Feb 01, 2005 8:48 am |
|
|
1) Read data sheet for MAX6675. Discover it uses SPI to communicate with a host processor.
2) Read data sheet for PIC processor you intend to use or at least prototype with. Pay special attention to references to SPI.
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.
4) Read CCS documentation with special attention to references to SPI and the example code.
At this point your eyes are probably going to fall out of your head.
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! |
|
![](templates/subSilver/images/spacer.gif) |
Bee Guest
|
thank you |
Posted: Tue Feb 01, 2005 10:03 pm |
|
|
u can suggestion for example code ? |
|
![](templates/subSilver/images/spacer.gif) |
JPH
Joined: 02 Feb 2005 Posts: 9 Location: Finland
|
|
Posted: Wed Feb 02, 2005 10:42 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Bee Guest
|
thank you JPH |
Posted: Fri Feb 04, 2005 1:48 am |
|
|
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);
}
++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
![](templates/subSilver/images/spacer.gif) |
JPH
Joined: 02 Feb 2005 Posts: 9 Location: Finland
|
|
Posted: Fri Feb 04, 2005 12:34 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Bee Guest
|
Thank you -JPH |
Posted: Mon Feb 07, 2005 2:19 am |
|
|
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);
}
+++++++++++++++++++++++++++++++++++++++++++++++ |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Feb 07, 2006 3:46 pm |
|
|
rwyoung wrote: | 1) Read data sheet for MAX6675. Discover it uses SPI to communicate with a host processor.
2) Read data sheet for PIC processor you intend to use or at least prototype with. Pay special attention to references to SPI.
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.
4) Read CCS documentation with special attention to references to SPI and the example code.
At this point your eyes are probably going to fall out of your head.
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. |
|
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Feb 07, 2006 3:47 pm |
|
|
Read data sheet for MAX6675. Discover it uses SPI to communicate with a host processor.
2) Read data sheet for PIC processor you intend to use or at least prototype with. Pay special attention to references to SPI.
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.
4) Read CCS documentation with special attention to references to SPI and the example code.
At this point your eyes are probably going to fall out of your head.
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. |
|
![](templates/subSilver/images/spacer.gif) |
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Tue Feb 07, 2006 6:37 pm |
|
|
To quote Monty Python...
"Spam, spam, spam, spam, spam......" |
|
![](templates/subSilver/images/spacer.gif) |
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Wed Feb 08, 2006 8:32 am |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
Re: How to use Max6675 with PIC |
Posted: Sat Jun 17, 2006 6:34 pm |
|
|
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](images/smiles/icon_idea.gif) |
|
|
![](templates/subSilver/images/spacer.gif) |
Gast Guest
|
Re: How to use Max6675 with PIC |
Posted: Fri Sep 15, 2006 3:16 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 15, 2006 5:13 pm |
|
|
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). |
|
![](templates/subSilver/images/spacer.gif) |
DENNIS Guest
|
|
Posted: Sat Sep 16, 2006 2:21 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|