?? cmx_fttherm.c
字號:
//*****************************************************************************
//*****************************************************************************
// FILENAME: CMX_FTTHERM.c
// Version: 1.1, Updated on 2008/6/23 at 14:7:12, Updated on 2007/05/18 at 22:47:55
//
//
// DESCRIPTION:
// This container Driver gets the voltage values from the thermistor circuit (by two MVolts subdrivers), calculates and returns the value of temperature.
//
//-----------------------------------------------------------------------------
// Copyright (c) Cypress MicroSystems 2005. All Rights Reserved.
//*****************************************************************************
//*****************************************************************************
#include "CMX.h"
#include "CMX_FTTHERM.h"
#define MIN -101
#define MAX 551
#define COUNT_VALUES 23
const int arTherm[2][COUNT_VALUES] =
{
{2301, 2505, 2725, 2960, 3211, 3477, 3757, 4051, 4358, 4675, 5000, 5331, 5664, 5998, 6328, 6652, 6967, 7269, 7557, 7829, 8083, 8317, 8462},
{5500, 5200, 4900, 4600, 4300, 4000, 3700, 3400, 3100, 2800, 2500, 2200, 1900, 1600, 1300, 1000, 700, 400, 100, -200, -500, -800, -1000} // array of temperature values (in hundredths of a deg C)
// 1 3 5 7 9 11 13 15 17 19 21 23
};
//-----------------------------------------------------------------------------
// FUNCTION NAME: FTTHERM_Instantiate(const CMX_NFTHERM_ParameterBlock * thisBLK)
//
// DESCRIPTION:
// This function doesn't do anything at this time, but is placed here
// for forward compatibility.
//
//-----------------------------------------------------------------------------
//
// ARGUMENTS:
// thisBLK => Pointer to ParameterBlock for this instance.
//
// RETURNS: None
//
// SIDE EFFECTS:
//
// THEORY of OPERATION or PROCEDURE:
//
//-----------------------------------------------------------------------------
void CMX_FTTHERM_Instantiate(const CMX_FTTHERM_ParameterBlock * thisBLK)
{
// Blank function
}
//-----------------------------------------------------------------------------
// FUNCTION NAME: FTTHERM_GetValue(const CMX_NFTHERM_ParameterBlock * thisBLK)
//
// DESCRIPTION:
// This function gets the Vexc and Vthermistor voltages (from MVOLTS subdrivers) and returns the calculated value of temperature.
//
//-----------------------------------------------------------------------------
//
// ARGUMENTS:
// thisBLK => Pointer to ParameterBlock for this instance.
//
// RETURNS:
// int lVtherm => signed integer value of temperature.
//
// SIDE EFFECTS:
//
// THEORY of OPERATION or PROCEDURE: This function gets the Vexc and Vthermistor voltages, calculates it's relation, and calculates the value of temperature by the method of piece-linear approximation.
//
//-----------------------------------------------------------------------------
int CMX_FTTHERM_GetValue(const CMX_FTTHERM_ParameterBlock * thisBLK)
{
BYTE bPointIndex;
long lVtherm;
int ivalue1,ivalue2,itemp1,itemp2;
ivalue1 = CMX_mVolts_GetValue(thisBLK->ptrEXC);
lVtherm = CMX_mVolts_GetValue(thisBLK->ptrTHERM);
lVtherm *= 10000;
lVtherm /= ivalue1;
if ((int)lVtherm < arTherm[0][0])
{
// The voltage ratio is too low, so the temperature is greater than what can be measured
lVtherm = MAX;
}
else if((int)lVtherm > arTherm[0][COUNT_VALUES-1])
{
// The voltage ratio is too high, so the temperature is less than what can be measured.
lVtherm = MIN;
}
else
{
// Scan through the voltage ratio values in the piecewise linear curve fit data to find
// the appropriate line to interpolate
for(bPointIndex = 0; bPointIndex < (COUNT_VALUES-2); bPointIndex++)
{
if (lVtherm < arTherm[0][bPointIndex+1]) break;
}
// Retrieve the voltage ratios for interpolation
ivalue1 = arTherm[0][bPointIndex];
ivalue2 = arTherm[0][bPointIndex + 1];
// Retrieve the temperatures for interpolation
itemp1 = arTherm[1][bPointIndex];
itemp2 = arTherm[1][bPointIndex + 1];
// Interpolate to find the temperature in hundredths of a deg C
lVtherm = (((long) ivalue2 - lVtherm) * (itemp1 - itemp2)) / (ivalue2 - ivalue1) + itemp2;
// Divide the result by 10 in order to get the temperature in tenths of a deg C.
// Round to the nearest tenth rather than truncating
// First, get the temperature value as an integer
ivalue1 = lVtherm;
// Next, get the sign and absolute value of the temperature
if (ivalue1 < 0)
{
bPointIndex = 1;
ivalue1 = 0 - ivalue1;
}
else
{
bPointIndex = 0;
}
// Calculate the truncated form
ivalue2 = ivalue1 / 10;
// Multiply the truncated form by 10 and add 5
// If the result is less than or equal to the original undivided number, then the
// Truncated value must be incremented by 1.
if ((ivalue2 * 10 + 5) <= ivalue1)
{
ivalue2++;
}
// Change the sign to negative if necessary
if (bPointIndex)
{
ivalue2 = 0 - ivalue2;
}
// Store the temperature to the return value
lVtherm = ivalue2;
}
return (int) lVtherm;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -