下载文件
ZMD推出温度传感器 快速响应时间达到0.8s:
TSic具有快速响应时间(63%温度范围内为0.8s,采用SOP-8或e-line封装),3s之内可精确测出水温。用户定制的TSic COF器件测试周期仅为4ms。
http://www.mikrocontroller.net/attachment/27605/tsic.c
德国资料:
TSic 506 FeatureSheet
TSic 506 DataSheet
http://www.zmdi.com/index.php?id=127&L=4
/*!
* \file tsic.c
* \brief ZMD TSic Temperatursensor lesen
* \author Joerg S
* \date 7.2007
*/
#include "treiber_import.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
/*!
* \brief Temperatur von TSic Sensor empfangen
* \param temp R�ckgabepointer f�r Temperatur (Vorkommastellen). MSB ist negativ Bit. Wenn MSB 1,
dann ist Tempertaur negativ.
* \param nachkomma R�ckgabepointer f�r Temperatur (Nachkommastellen)
* \return temp_float Temperatur in float-Variable
*/
float Read_Temp_TSic ( unsigned char *temp, unsigned int *nachkomma)
{
unsigned int temp_value;
float Temp_float;
INIT_TA_SMCLK_500KHZ;
// VCC fuer Sensor einschalten
TSIC_ON;
// Warten bis Spannung satbil
delay_100us(1);
if (getTSicTemp(&temp_value))
{
// Temp_float = (((float)temp_value / 2047) * 200) - 50; // conversion equation from TSic's data sheet
Temp_float = (temp_value * 0.097704) -50;
}
// VCC fuer Sensor ausschalten
TSIC_OFF;
*temp = (unsigned int) Temp_float;
return Temp_float;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
unsigned char getTSicTemp (unsigned int *temp_value16)
{
unsigned int temp_value1 = 0;
unsigned int temp_value2 = 0;
unsigned char i;
unsigned int Temperature;
unsigned char parity;
// Sensor benoetigt 65-85ms nach Power-Up bis zum senden
TAR = 0;
while (ZWIRE_IN_H && (TAR < ZWIRE_TIMEOUT_START)); // Warten auf Start-Bit
if (TAR >= ZWIRE_TIMEOUT_START) return FALSE;
// Start-Bit (TStrobe) abwarten
TAR = 0;
while (ZWIRE_IN_L && (TAR < ZWIRE_TIMEOUT_BIT));
if (TAR >= ZWIRE_TIMEOUT_BIT) return FALSE;
// Start-Bit = 62,5�s low und 62,5�s high
// Logisch 1 = 31,25�s low und 93,75�s high
// Logisch 0 = 93,75�s low und 31,25�s high
// Erstes Byte lesen (8Bit + 1Bit Parity)
for (i = 0; i < 9; i++)
{
TAR = 0;
while (ZWIRE_IN_H && (TAR < ZWIRE_TIMEOUT_BIT)); // Auf fallende Flanke warten
if (TAR >= ZWIRE_TIMEOUT_BIT) return FALSE;
TAR = 0;
while (TAR < ZWIRE_HALFBIT_TIMER);
if (ZWIRE_IN_H)
temp_value1 |= 1 << (8-i); // Wenn high, dann logisch 1
TAR = 0;
while (ZWIRE_IN_L && (TAR < ZWIRE_TIMEOUT_BIT)); // Auf steigende Flanke warten
if (TAR >= ZWIRE_TIMEOUT_BIT) return FALSE;
}
// Auf naechtes Start-Bit warten
TAR = 0;
while (ZWIRE_IN_H && (TAR < ZWIRE_TIMEOUT_START)); // Warten auf Start-Bit
if (TAR >= ZWIRE_TIMEOUT_START) return FALSE;
// Start-Bit (TStrobe) abwarten
TAR = 0;
while (ZWIRE_IN_L && (TAR < ZWIRE_TIMEOUT_BIT));
if (TAR >= ZWIRE_TIMEOUT_BIT) return FALSE;
// Zweites Byte lesen (8Bit + 1Bit Parity)
for (i = 0; i < 9; i++)
{
TAR = 0;
while (ZWIRE_IN_H && (TAR < ZWIRE_TIMEOUT_BIT)); // Auf fallende Flanke warten
if (TAR >= ZWIRE_TIMEOUT_BIT) return FALSE;
TAR = 0;
while (TAR < ZWIRE_HALFBIT_TIMER);
if (ZWIRE_IN_H)
temp_value2 |= 1 << (8-i); // Wenn high, dann logisch 1
TAR = 0;
while (ZWIRE_IN_L && (TAR < ZWIRE_TIMEOUT_BIT)); // Auf steigende Flanke warten
if (TAR >= ZWIRE_TIMEOUT_BIT) return FALSE;
}
// Parity Byte 1
parity = 0;
for (i = 0; i < 9; i++)
if (temp_value1 & (1 << i))
parity++;
if (parity % 2)
return FALSE;
// Parity Byte 2
parity = 0;
for (i = 0; i < 9; i++)
if (temp_value2 & (1 << i))
parity++;
if (parity % 2)
return FALSE;
temp_value1 >>= 1; // delete parity bit
temp_value2 >>= 1; // delete parity bit
Temperature = (temp_value1 << 8) | temp_value2;
*temp_value16 = Temperature;
return TRUE; // parity is OK
}
///////////////////////////////////////////////////////////////////////////////////////////////////
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/2848/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2010-3-26 22:56
评论列表