View previous topic :: View next topic |
Author |
Message |
soymoe
Joined: 04 Aug 2014 Posts: 13
|
How to get thermocouple temperature ? |
Posted: Mon Aug 04, 2014 2:09 pm |
|
|
Re: MAX31855 thermocouple-to-digital converter Example/Driver
http://www.ccsinfo.com/forum/viewtopic.php?t=49599
Hi, thanks for this library, can you show me which one method call to get thermocouple temperature? I will show temperature in 7 segments display. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Aug 04, 2014 7:11 pm |
|
|
The code looks very well commented.
and the datasheet for the part explains the rest to me.
This is a CCS code forum, and i don't see your code.
I also don't see what it is that you don't understand.
try to explain your problem better. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Aug 04, 2014 11:13 pm |
|
|
This section of his code shows how to read the thermocouple.
1. Call readMAX() in a loop, until the tempFault() function returns 0.
2. Call readExtTemp() and display the result as a signed 16-bit integer
value. This is the Thermocouple temperature in degrees C.
Code: |
while(TRUE)
{
do{
readMAX();
}while(tempFault()!=0);
printf("\n\n Thermocouple: %Ld, Ambient: %Ld\n\r",readExtTemp(),readIntTemp());
delay_ms(500);
}
|
He also displays the internal temperature of the MAX31855 chip, by calling
the readIntTemp() function. |
|
|
soymoe
Joined: 04 Aug 2014 Posts: 13
|
|
Posted: Thu Sep 11, 2014 2:19 pm |
|
|
I'm try to view the temperature using this code, but don't work.
Code: | #include <16F88.h>
#device adc=16
#FUSES NOWDT // No Watch Dog Timer
#FUSES INTRC_IO // >>> Oscilador interno, no CLKOUT
#FUSES PUT // Power Up Timer
#FUSES NOMCLR // Master Clear pin used for I/O
#FUSES BROWNOUT // Reset when brownout detected
#FUSES PROTECT // Code not protected from reading
#FUSES NOCPD // No EE protection
int8 TempBin=15;
#use delay(int=8000000) // Especifica al compilador que hace uso del OSC interno
//#USE SPI (MASTER, SPI1, CLOCK_HIGH=100, CLOCK_LOW=100, MODE=0, LOAD_ACTIVE=1, ENABLE_ACTIVE=0, STREAM=SPI_1, MSB_FIRST,FORCE_HW)
#use rs232(baud=9600, xmit=PIN_B2,rcv=PIN_B3,bits=8, parity=N))
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
#define SS PIN_B0
int8 spival[4];
int16 Temp=25;
int1 Error=0;
/*******************************************************************************
//Read SPI data
*******************************************************************************/
void readMAX()
{
output_low(SS);
delay_us(10);
spival[3]=spi_read(0);
spival[2]=spi_read(0);
spival[1]=spi_read(0);
spival[0]=spi_read(0);
delay_us(10);
output_high(SS);
}
/*******************************************************************************
//Fault detection.
//Returns >0 if FAULT. If necessary do a bitwise analisys to check fault source
*******************************************************************************/
int tempFault()
{
int1 Fvdd=0,Fgnd=0,Fopen=0,fault=0;
fault=spival[2]&0x01; // pelos menos uma falha
Fvdd=(spival[0]>>2)&0x01;
Fgnd=(spival[0]>>1)&0x01;
Fopen=spival[0]&0x01;
return (fault*1+Fvdd*2,Fgnd*4,Fopen*8);
}
/*******************************************************************************
//Read thermocouple temperature
//Returns returns signed temperature in ºC approximately
*******************************************************************************/
int16 readExtTemp()
{
int8 aux;
int16 temp1;
aux=spival[2]>>2;
temp1=spival[3];
temp1<<=6;
temp1+=aux;
return temp1/=4;
}
/*******************************************************************************
//Read internal temperature
//Returns returns signed temperature in ºC approximately
*******************************************************************************/
int16 readIntTemp()
{
int8 aux;
int16 temp2;
temp2=spival[1];
temp2<<=4;
aux=spival[0]>>4;
temp2=spival[1]<<4;
temp2+=aux;
return temp2/=16;
}
void main()
{
setup_oscillator(OSC_8MHZ|OSC_INTRC);
setup_spi(SPI_MASTER | SPI_MODE_1 | SPI_CLK_DIV_64);
setup_comparator(NC_NC_NC_NC);
//set_tris_b(0xfB);
delay_ms(500);
while(TRUE){
printf("@"); // send alive message
printf("%d",TempBin);
printf("@"); // send alive message
readMAX();
Error=tempFault();
if(Error==1)printf("error");
delay_ms(500);
}
} |
if spi is enable, port show nothing. Please help me! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 11, 2014 2:37 pm |
|
|
You are missing the printf statement to print the results. You are also
missing the while() loop to display the results every 500m.
The following code is from the MAX13855 driver in the code library:
http://www.ccsinfo.com/forum/viewtopic.php?t=49599
Code: | while(TRUE)
{
do{
readMAX();
}while(tempFault()!=0);
printf("\n\n Thermocouple: %Ld, Ambient: %Ld\n\r",readExtTemp(),readIntTemp());
delay_ms(500);
}
} |
If that still doesn't work, then check your SPI connections. The SO pin
on the MAX31855 must connect to the SDI pin on the PIC. It's possible
that you have this connection reversed by accident.
The SCK pin on the PIC must go to the SCK pin on the MAX31855.
Also, Pin B0 on the PIC must go to \CS on the MAX31855. |
|
|
soymoe
Joined: 04 Aug 2014 Posts: 13
|
|
Posted: Thu Sep 11, 2014 4:12 pm |
|
|
Thanks, im remove the printf statement to print the results to try if fault result is detected, but dont print any message on port. if spi is enable rs232 its seems dont work. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 11, 2014 7:02 pm |
|
|
The comments in the driver say this:
Quote: | //Returns >0 if FAULT. If necessary do a bitwise analisys to check fault source |
It doesn't say to check for a return value of 1. It says to check the
complete byte. For example, if you just want to look at the tempFault
value, then your while() loop should do this:
Code: |
while(TRUE)
{
readMAX();
printf("tempFault = %x \n\r", tempFault);
delay_ms(500);
}
|
Run that code and post the results. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 11, 2014 9:01 pm |
|
|
Another important issue:
The MAX31855 is a 3.3 volt chip. The 16F88 won't run at 3.3 volts,
according to the data sheet. The "LF" version, 16LF88 will work at 3.3v.
Which PIC do you have ?
The 16F88 is normally used with a 5v Vdd voltage. Is that what you have ?
If you insist on using the 16F88 at 5v, then you will need logic level
converter chips between the PIC and the MAX31855.
Also, is this a Proteus project or is a real hardware board ? Proteus
probably doesn't care about any of this stuff, but real hardware does care. |
|
|
soymoe
Joined: 04 Aug 2014 Posts: 13
|
|
Posted: Thu Sep 11, 2014 9:19 pm |
|
|
is a real hardware, running on pic 16f88 at 5v.The max31855 is powered for 3.3v regulator. The logic level dont compatible? 3.3v is high level for pic working at 5v. The ploblem maybe is CS pin, that in high level is 5v. do you think? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 11, 2014 9:34 pm |
|
|
The MAX31855 data sheet says the maximum voltage on the input pins
(SDI and CS) should be Vdd +0.3v. So if the MAX31855 is running at
3.3v, the maximum logic high level should be 3.6v. But the PIC running
at 5v will put about 4.9v to 5v on those two pins, which violates the spec.
The SDO pin from the MAX31855 will output a signal with a logic high level
of about 3.3v. This is not high enough to drive the SDI pin on hardware
SPI on a PIC running at 5v. The PIC requires a minimum of 4.0v on the
SDI pin to see the incoming signal. So it won't work.
You could fix this by using software SPI on PortB, which has a Vih of
only 2.0v. That would solve the SDI pin problem. But you would still
have a problem with the SDO and CS pins. Their output voltage is too
high. You could solve this by using voltage dividers on those two pins.
This would reduce the output to safe levels going to the MAX31855.
It would take a total of 4 resistors to do this.
Or you could use level shifter chips.
It would be easier if you got a PIC that could run with a Vdd of 3.3v.
Then it would be compatible with the MAX31855. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 12, 2014 8:04 am |
|
|
I edited my post above to show the correct, easy way to reduce the
voltage levels from the PIC to the MAX31855. Here are schematics
of the voltage divider circuits. You need to use software SPI for this.
Code: |
From PIC 1.8K
pin --/\/\/\----o------> To \CS pin on MAX31855
(5v levels) | (3.3v CMOS levels)
<
> 3.3K
<
|
---
- GND
From PIC 1.8K
pin --/\/\/\----o------> To SCK pin on MAX31855
(5v levels) | (3.3v CMOS levels)
<
> 3.3K
<
|
---
- GND
To a PIC pin
on PortB <--------------- From SDO pin on MAX31855
(TTL compatible (3.3v CMOS output levels)
input pin)
|
|
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri Sep 12, 2014 12:56 pm |
|
|
Hi,
If you are interested in lowering your parts count, and don't mind working with SMT components, I've used the TI TXB0104 level translator IC extensively with the MAX31855 device in +5V designs. When you factor in assembly costs, it may be cheaper too!
John |
|
|
soymoe
Joined: 04 Aug 2014 Posts: 13
|
|
Posted: Fri Sep 12, 2014 1:17 pm |
|
|
ezflyr wrote: | Hi,
If you are interested in lowering your parts count, and don't mind working with SMT components, I've used the TI TXB0104 level translator IC extensively with the MAX31855 device in +5V designs. When you factor in assembly costs, it may be cheaper too!
John |
Thanks john, i will think about this, but i from argentine and is not so easy buy this components here. I try not use smd components, the assembly is manually. |
|
|
soymoe
Joined: 04 Aug 2014 Posts: 13
|
|
Posted: Fri Sep 12, 2014 1:29 pm |
|
|
PCM programmer wrote: | I edited my post above to show the correct, easy way to reduce the
voltage levels from the PIC to the MAX31855. Here are schematics
of the voltage divider circuits. You need to use software SPI for this.
Code: |
From PIC 1.8K
pin --/\/\/\----o------> To \CS pin on MAX31855
(5v levels) | (3.3v CMOS levels)
<
> 3.3K
<
|
---
- GND
From PIC 1.8K
pin --/\/\/\----o------> To SCK pin on MAX31855
(5v levels) | (3.3v CMOS levels)
<
> 3.3K
<
|
---
- GND
To a PIC pin
on PortB <--------------- From SDO pin on MAX31855
(TTL compatible (3.3v CMOS output levels)
input pin)
|
|
i can have a output temperature un serial port, but it is always zero and do not detect termocouple default, in other words not work, but i have a output. The problem which rs232 was that spi protocolol share some pins. To solve this, i change rs232 pins. may be max31855 was destroyed for over voltage |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 12, 2014 2:02 pm |
|
|
What pins do you think are shared between the serial port and the SPI pins ?
The serial port (RS-232) Tx pin is on RB5. There is SPI pin for hardware
SPI Master used there. There is the \SS pin for hardware SPI, but that is
only used with a PIC as an SPI slave. You are not doing that. Your PIC
is an SPI master.
The Rx pin is shared with SDO. So there is a conflict there. But with the
MAX31855, you do not send data from the PIC to the MAX31855. So the
SDO pin on the PIC is not needed. However, if you use setup_spi(), it
will be configured for use by the SPI port.
With the Software SPI method that I proposed, you can set it up with
the #use spi() statement and use any free pins on PortB, except for
RB6 and RB7, because those pins are used by the ICD programmer.
Use the #use spi() method to enable the SPI port. Don't use setup_spi().
Some free pins on PortB would be RB0, RB1, RB3, and RB4. |
|
|
|