온도값 측정 완료

master
imbis 4 months ago
parent 84bac81255
commit 0a1356156e

@ -19,10 +19,12 @@ static AK9757W_HANDLER AK9757W_Handler;
static AK9757W_HANDLER* pHandler = &AK9757W_Handler;
const uint8_t default_cntl_reg_data[] = {0x20, 0xFF, 0xFE, 0x4A, 0xE1, 0x00, 0x00, 0x00, 0xDF, 0xE0};
//const uint8_t default_cntl_reg_data[] = {0x20, 0xFF, 0xFE, 0x42, 0xE1, 0x00, 0x00, 0x00, 0xDF, 0xE0};
const uint8_t default_fcoef_reg_data[] = {0x29, 0xF3, 0x57, 0x30, 0x6B, 0xBE, 0x21, 0x61, 0x8D, 0x10, 0x8D, 0xBF, 0x01, 0x0C, 0xFE};
const uint8_t default_gcoef_reg_data[] = {0x37, 0x7D, 0x48, 0x40, 0xF1, 0xB7, 0x33, 0x83, 0x5C, 0x20, 0x40, 0xAB, 0x12, 0x70, 0x40};
const uint8_t default_xcoef_reg_data[] = {0x45, 0xC7, 0xA0, 0x32, 0x78, 0x42, 0x23, 0x75, 0x92, 0x16, 0xC5, 0x42, 0x08, 0x15, 0x60};
const uint8_t default_gir_oir_gts_ots_git_reg_data[] = {0x53, 0xE0, 0x94, 0x12, 0x00, 0x00, 0x0D, 0x14, 0x00, 0x00};
//const uint8_t default_gir_oir_gts_ots_git_reg_data[] = {0x53, 0xE0, 0x94, 0x12, 0x00, 0x00, 0x0D, 0x14, 0x00, 0x00};
const uint8_t default_gir_oir_gts_ots_git_reg_data[] = {0x53, 0xE0, 0x1C, 0x0E, 0x00, 0x00, 0xE1, 0x2F, 0x02, 0x00};
@ -39,6 +41,7 @@ static bool AK9757W_Calc_Parameter(void);
static bool AK9757W_Read_RawData(void);
static bool AK9757W_Process(void);
static void AK9757W_Next_Step(AK9757W_STEP nextStep);
static uint16_t AK9757W_Get_Tout(uint16_t TOUT);
static int16_t AK9757W_14BitTo16Bit(uint16_t Data);
static int16_t AK9757W_12BitTo16Bit(uint16_t Data);
static int8_t AK9757W_6BitTo8it(uint8_t Data);
@ -500,36 +503,71 @@ static bool AK9757W_Read_RawData(void)
{
int error;
uint8_t TxData = AK9757W_REG_RO_STATUS;
uint8_t RxBuff[7];
uint8_t RxBuff[9];
uint16_t uint16_TempValue;
int16_t int16_TempValue;
uint16_t ToutTemp;
float fTs;
float fTout;
error = I2C_Master_WriteRead(TEMP_I2C_ADDRESS, &TxData, 1, &RxBuff[0], 7);
error = I2C_Master_WriteRead(TEMP_I2C_ADDRESS, &TxData, 1, &RxBuff[0], 9);
if(error != E_NO_ERROR)
{
dbg_printf(LOG_LEVEL_DEBUG, "I2C W/R Error %d\r\n", error);
return false;
}
pHandler->RAWDATA.Status.Status = RxBuff[0];
if(pHandler->RAWDATA.Status.Status_Bit.DRDY == true)
{
pHandler->RAWDATA.RAW_TO = (RxBuff[2] << 8) | RxBuff[1];
pHandler->RAWDATA.RAW_TS = RxBuff[4] << 8 | RxBuff[3];
pHandler->RAWDATA.RAW_IR = RxBuff[6] << 8 | RxBuff[5];
pHandler->RAWDATA.RAW_TO = (RxBuff[2] << 8) | RxBuff[1];
pHandler->RAWDATA.RAW_TS = RxBuff[4] << 8 | RxBuff[3];
pHandler->RAWDATA.RAW_IR = RxBuff[6] << 8 | RxBuff[5];
ToutTemp = AK9757W_Get_Tout(pHandler->RAWDATA.RAW_TO);
dbg_printf(LOG_LEVEL_DEBUG, "s = %x, to=%d, ts=%d,ir=%d\r\n", RxBuff[0], pHandler->RAWDATA.RAW_TO, pHandler->RAWDATA.RAW_TS, pHandler->RAWDATA.RAW_IR);
//fTs = (-0.1075 * pow(pHandler->RAWDATA.RAW_TS, 3)) + (0.9811 * pow(pHandler->RAWDATA.RAW_TS, 2)) - (3.0914 * pHandler->RAWDATA.RAW_TS) + 29.404;
//fTs = 26.02 + (pHandler->RAWDATA.RAW_TS * 0.002);
fTs = -0.000000003402565*pHandler->RAWDATA.RAW_TS*pHandler->RAWDATA.RAW_TS+0.001985926*pHandler->RAWDATA.RAW_TS+26.02365;
fTout = ToutTemp / 100.0;
dbg_printf(LOG_LEVEL_DEBUG, "IR = %d, TS = %d, TOUT = %d, Tout = %.2f, Ts = %.2f\r\n", pHandler->RAWDATA.RAW_IR, pHandler->RAWDATA.RAW_TS, pHandler->RAWDATA.RAW_TO, fTout, fTs);
//dbg_printf(LOG_LEVEL_DEBUG, "IR = %X, TS = %X, TOUT = %X, Tout = %.2f, Ts = %.2f\r\n", pHandler->RAWDATA.RAW_IR, pHandler->RAWDATA.RAW_TS, pHandler->RAWDATA.RAW_TO, fTout, fTs);
Oled_SetTemperature(ToutTemp);
}
#if 0
Oled_SetTemperature(pHandler->RAWDATA.RAW_TO/10);
TS = (1.0 + pHandler->calc_gts) * pHandler->RAWDATA.RAW_TS + pHandler->calc_ots;
GIR = pHandler->calc_git * TS;
IR = (pHandler->calc_gir + pHandler->calc_gir * GIR) * pHandler->RAWDATA.RAW_IR + pHandler->calc_oir;
F_TS = pHandler->calc_FC4 * pow(TS, 4) + pHandler->calc_FC3 * pow(TS, 3) + pHandler->calc_FC2 * pow(TS, 2) + pHandler->calc_FC1 * TS + pHandler->calc_FC0;
G_TS = pHandler->calc_GC4 * pow(TS, 4) + pHandler->calc_GC3 * pow(TS, 3) + pHandler->calc_GC2 * pow(TS, 2) + pHandler->calc_GC1 * TS + pHandler->calc_GC0;
IM_IR = (IR - F_TS) * G_TS;
TO = pHandler->calc_XC4 * pow(IM_IR, 4) + pHandler->calc_XC3 * pow(IM_IR, 3) + pHandler->calc_XC2 * pow(IM_IR, 2) + pHandler->calc_XC1 * IM_IR + pHandler->calc_XC0;
dbg_printf(LOG_LEVEL_DEBUG, "%d,%d,%d, %f, %f\r\n", pHandler->RAWDATA.RAW_IR, pHandler->RAWDATA.RAW_TS, pHandler->RAWDATA.RAW_TO, TO, TS);
#endif
return true;
}
static uint16_t AK9757W_Get_Tout(uint16_t TOUT)
{
uint16_t RetTemp = 0;
uint16_t Temp;
double dbTemp;
RetTemp = (TOUT >> 10) * 100;
Temp = TOUT & 0x3FF;
dbTemp = (double)Temp / 1000.0;
RetTemp += (uint16_t)(dbTemp * 100.0);
return RetTemp;
}
static int16_t AK9757W_14BitTo16Bit(uint16_t Data)
{

File diff suppressed because one or more lines are too long

@ -148,40 +148,7 @@
<Name></Name>
</SetRegEntry>
</TargetDriverDllRegistry>
<Breakpoint>
<Bp>
<Number>0</Number>
<Type>0</Type>
<LineNumber>379</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>3906</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\Application\sensor\ak9757w.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\AKM_Temperature_Demo\../Application/sensor/ak9757w.c\379</Expression>
</Bp>
<Bp>
<Number>1</Number>
<Type>0</Type>
<LineNumber>487</LineNumber>
<EnabledFlag>1</EnabledFlag>
<Address>5548</Address>
<ByteObject>0</ByteObject>
<HtxType>0</HtxType>
<ManyObjects>0</ManyObjects>
<SizeOfObject>0</SizeOfObject>
<BreakByAccess>0</BreakByAccess>
<BreakIfRCount>1</BreakIfRCount>
<Filename>..\Application\sensor\ak9757w.c</Filename>
<ExecCommand></ExecCommand>
<Expression>\\AKM_Temperature_Demo\../Application/sensor/ak9757w.c\487</Expression>
</Bp>
</Breakpoint>
<Breakpoint/>
<WatchWindow1>
<Ww>
<count>0</count>
@ -198,6 +165,11 @@
<WinNumber>1</WinNumber>
<ItemText>pHandler</ItemText>
</Ww>
<Ww>
<count>3</count>
<WinNumber>1</WinNumber>
<ItemText>RetTemp,0x0A</ItemText>
</Ww>
</WatchWindow1>
<MemoryWindow1>
<Mm>

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save