DIY编程器网

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 6167|回复: 3
打印 上一主题 下一主题

Using the MAX6675 Thermocouple-to-Digital Converter

  [复制链接]
跳转到指定楼层
楼主
发表于 2012-1-12 22:37:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Using the MAX6675 Thermocouple-to-Digital Converter
by Andrew on 27 Jun 2009
I've been asked for the code used to read the MAX6675 Thermocouple-to-Digital Converter used to measure the temperature in my ongoing SMD Reflow Oven project.  The following is based on an Arduino (with a home built SPI helper library) but is fairly generic and should be applicable to most platforms.
Maxim's MAX6675 8-pin SOIC chip is a compact and simple to use solution for converting the output of a type K thermocouple to a digital temperature value read over SPI.  It provides Digital to Analogue conversion of the voltage produced by the thermocouple, cold-junction compensation, noise reduction and processing of the result into a binary temperature value at a precision of 0.25°C.
SO - MISO (Arduino D12), SCK (Arduino D13), CS (Arduino D8)

Circuit used (from the datasheet sheet) is shown to the right.  I used a breadboard for the circuit but created a [url=]breakout board[/url] for the (SMD) MAX6675 chip and decoupling capacitor with BatchPCB.
The thermocouple is connected to pins 2 and 3 - if connected the wrong way around the temperature output from the MAX6675 will go down as the end of the thermocouple is heated.  Connecting the MAX6675 to the Arduino is straightforward - just power and the SPI MISO and SCK (clock) and chip select line (^CS).  Pin D8 was used to select the device.
SPI SetupFrom the datasheet we see that the MAX6675 transmits the temperature in 2 bytes - most significant bit first.  The clock is expected to be idle low and data can be read when it is falling (SPI mode 1).  The MAX6675 can take a maximum SPI clock rate of 4.3MHz - as the Arduino was running at 16MHz a SPI data rate of Clock/8 (2MHz) was specified so the device was operating well within its tolerances.The following sets up up the MAX6675 chip select pin (Arduino Pin D8) control pin, SPI and the Arduino Serial line:
#define MAX6675_SELECT_PIN 8#define DESELECT_MAX6675 digitalWrite(MAX6675_SELECT_PIN, HIGH)#define SELECT_MAX6675 digitalWrite(MAX6675_SELECT_PIN, LOW)void setup(){  pinMode(MAX6675_SELECT_PIN, OUTPUT);  DESELECT_MAX6675;  setup_spi(SPI_MODE_1, SPI_MSB, SPI_NO_INTERRUPT, SPI_MSTR_CLK8);  Serial.begin(19200);}
Reading the TemperatureReading the temperature value is equally straightforward.  Select the device, wait atleast 100ns (this is close to the time that it will take the AVR to start sending data on the SPI bus anyway but I put in a microsecond delay to be certain), read the two bytes from SPI, and deselect the device.
SELECT_MAX6675; delayMicroseconds(1); unsigned char highByte = send_spi(0); unsigned char lowByte = send_spi(0); DESELECT_MAX6675;
The 16-bits read from the device in two bytes need to be processed slightly:
Bit 2 in the 2nd byte will be high if the device cannot detect an attached thermocouple, otherwise the 12 temperature value bits spread across the 2 bytes (6-0 of the hight byte, and 7-3 of the low byte) need to be shifted into a single numeric value (highByte << 5 | lowByte>>3).
The program simply prints the bytes received on an error and the temperature (divided by 4 to get the value in degrees) if it has been read successfully.
if (lowByte & (1<<2)) {   Serial.print("Not connected ");   Serial.print(highByte, HEX); Serial.print(" ");   Serial.println(lowByte, HEX); } else {   short value = (highByte << 5 | lowByte>>3);   Serial.print(value/4); Serial.print(".");   Serial.println(value%4 *25); }
The MAX6675 has a maximum conversion time of 0.22 seconds. If the device is sampled faster than this it will continue to output the temperature that was first read without any indication that it is being read too fast - I found a delay of atleast 250ms between readings the device worked well.
The complete sampling code is shown below:
#include <spi.h>// MAX6675 connected to pin D9#define MAX6675_SELECT_PIN 8#define DESELECT_MAX6675 digitalWrite(MAX6675_SELECT_PIN, HIGH)#define SELECT_MAX6675 digitalWrite(MAX6675_SELECT_PIN, LOW)void setup(){ pinMode(MAX6675_SELECT_PIN, OUTPUT); DESELECT_MAX6675; setup_spi(SPI_MODE_1, SPI_MSB, SPI_NO_INTERRUPT, SPI_MSTR_CLK8); Serial.begin(19200);}void loop(){ delay(500); // select the device, wait > 100nS, read two bytes, deselect SELECT_MAX6675; delayMicroseconds(1); unsigned char highByte = send_spi(0); unsigned char lowByte = send_spi(0); DESELECT_MAX6675; // if bit 3 is high thermocouple is unconnected if (lowByte & (1<<2)) {   Serial.print("Not connected ");   Serial.print(highByte, HEX); Serial.print(" ");   Serial.println(lowByte, HEX); } else {   // temperature value is in bits 6-0 of highByte and 7-2 of lowByte   short value = (highByte << 5 | lowByte>>3);   // 1 bit is 0.25 degree 'divide' by 4 to show degrees   Serial.print(value/4); Serial.print("."); Serial.println(value%4 *25); }}
ConclusionsCompared with manual reading and conversion of the thermocouple voltage to temperature the MAX6675 is a delight to use.  Although it is not a cheap device it is comparable to other thermocouple processing devices (for example the AC1226 and LTK001) but is fairly unique in having a digital/SPI output rather than a cleaned up voltage per Centigrade value that also requires a D/A converter.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏1 分享分享 支持支持 反对反对
沙发
发表于 2012-4-21 08:15:56 | 只看该作者
看看吧,大家都会支持你
板凳
发表于 2012-6-1 23:20:38 | 只看该作者
谢谢楼主了,楼主辛苦了,呵呵
地板
发表于 2015-10-28 22:18:24 | 只看该作者
这个很好,学习学习
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|文字版|手机版|DIY编程器网 ( 桂ICP备14005565号-1 )

GMT+8, 2024-11-26 15:09 , 耗时 0.089921 秒, 18 个查询请求 , Gzip 开启.

各位嘉宾言论仅代表个人观点,非属DIY编程器网立场。

桂公网安备 45031202000115号

DIY编程器群(超员):41210778 DIY编程器

DIY编程器群1(满员):3044634 DIY编程器1

diy编程器群2:551025008 diy编程器群2

QQ:28000622;Email:libyoufer@sina.com

本站由桂林市临桂区技兴电子商务经营部独家赞助。旨在技术交流,请自觉遵守国家法律法规,一旦发现将做封号删号处理。

快速回复 返回顶部 返回列表