T_ADC.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:30k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * T_ADC.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * ADC calibration source
- *
- * Author:
- * -------
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- #include <assert.h>
- #include <math.h>
- #pragma hdrstop
- // common
- #ifndef _METAAPP_COMMON_H_
- #include "metaapp_common.h"
- #endif
- #ifndef _T_META_FACTORY_CALIBRATION_H_
- #include "T_META_factory_calibration.H"
- #endif
- #ifndef _CAL_COMMON_H_
- #include "cal_common.h"
- #endif
- // form
- #ifndef _META_FACTORY_H_
- #include "META_Factory.h"
- #endif
- #ifndef _FORM_MAIN_H_
- #include "form_Main.h"
- #endif
- // callback
- #ifndef _META_FACTORY_BB_CB_H_
- #include "meta_factory_bb_cb.h"
- #endif
- #ifndef _META_FACTORY_NVRAM_CB_H_
- #include "meta_factory_nvram_cb.h"
- #endif
- // misc
- #ifndef _FT_UTILS_H_
- #include "ft_utils.h"
- #endif
- #ifndef _TIME_UTILS_H_
- #include "time_utils.h"
- #endif
- //----------------------------------------------------------------------------
- extern bool is_suspend_cal; // in T_META_factory_calibration.cpp
- // ADC calibration
- extern ADCMeaData_Cnf *BBCnf_ADC;
- extern ADCMeaData_Req* MF_BB_ADC_Req;
- extern ADCMeaData_Req *BBReq_ADC;
- extern CBBADC* MF_BB_ADC_ptr;
- extern TfrmFatcory *frmFatcory;
- //extern TfrmMainSel *frmMainSel;;
- //----------------------------------------------------------------------------
- bool __fastcall T_META_factory_calibration::ADCCal( void )
- {
- ViReal64 measvoltage;
- char tempbuf[256];
-
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " ====================== ADC calibration begin ===================== "
- );
- PostMessage(
- ctrl.hPostMsgDestHandle,
- WM_MF_ADC_BEGIN,
- 0,
- 0
- );
- if (!m_dcs_ctrl.DCS_Init(m_pDcs))
- {
- CalErrorHandler(WM_MF_ADC_DCS_INIT_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: Power supply initialize ");
- return false;
- }
- // set output voltage = V1
- if (!m_dcs_ctrl.DCS_outputVoltCurr( m_pDcs, i_ADC_V1/1000.0, i_CURRENT_LIMIT/1000.0))
- {
- CalErrorHandler(WM_MF_ADC_DCS_SET_VOLTAGE_CURRENT_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: Agilent 661x set vlotage = " +
- Double_To_AnsiString(i_ADC_V1/1000.0)
- );
- return false;
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " Set power supply vlotage = " +
- Double_To_AnsiString(1.0*i_ADC_V1/1000.0)
- );
- /* Measure the dc voltage level at the output terminals */
- Sleep (50);
- if (!m_dcs_ctrl.DCS_measureVolt(m_pDcs, measvoltage))
- {
- return false;
- }
- ADC_Measure_Voltage[0] = (float)measvoltage;
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " Power supply measure vlotage = " +
- Double_To_AnsiString(measvoltage)
- );
- //////////////// V1 : measure ADC value of Battery channel begin ///////////
- MF_BB_ADC_Req->channel = i_BATTERY_CHANNEL;
- MF_BB_ADC_Req->Meacount = i_ADC_MEASUREMENT_COUNT;
- MetaResult = META_BB_ADCGetMeaSumData_r(m_pCal->i_MainMETAHandle, MF_BB_ADC_Req, ::MF_MeasureADC_cnf_cb, &BBID_ADC, NULL);
- if (MetaResult != META_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure fail (V1) "
- );
- return false;
- }
- RestartTimerADCCal(WM_MF_ADC_MEASURE_FAIL);
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (BBCnf_ADC->status != BB_STATUS_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_CNF_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure cnf fail (V1) ");
- return false;
- }
- BATTERY_ADC_Output[0] = ((float)BBCnf_ADC->value*1.0) / ((float) (MF_BB_ADC_Req->Meacount*1.0));
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " BATTERY_ADC_Output[0] = " +
- Double_To_AnsiString(BATTERY_ADC_Output[0])
- );
- ///////////////////////////// V1 : measure ADC value of Charger channel begin ///////////////////////////////////////////
- MF_BB_ADC_Req->channel = i_CHARGER_CHANNEL;
- MF_BB_ADC_Req->Meacount = i_ADC_MEASUREMENT_COUNT;
- MetaResult = META_BB_ADCGetMeaSumData_r(m_pCal->i_MainMETAHandle, MF_BB_ADC_Req, MF_MeasureADC_cnf_cb, &BBID_ADC, NULL);
- if (MetaResult != META_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure fail (V1) ");
- return false;
- }
- RestartTimerADCCal(WM_MF_ADC_MEASURE_FAIL);
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (BBCnf_ADC->status != BB_STATUS_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_CNF_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure cnf fail (V1) "
- );
- return false;
- }
- CHARGER_ADC_Output[0] = ((float)BBCnf_ADC->value*1.0) / ((float) (MF_BB_ADC_Req->Meacount*1.0));
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " CHARGER_ADC_Output[0] = " +
- Double_To_AnsiString(CHARGER_ADC_Output[0])
- );
- ///////////////////////////// measure ADC value end ///////////////////////////////////////////
- if (this->Terminated)
- {
- this->OnTerminate = neByUser;
- return false;
- }
- // set output voltage = V2
- if (!m_dcs_ctrl.DCS_outputVoltCurr(m_pDcs, i_ADC_V2/1000.0, i_CURRENT_LIMIT/1000.0))
- {
- return false;
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " Set power supply vlotage = " +
- Double_To_AnsiString(i_ADC_V2/1000.0)
- );
- /* Measure the dc voltage level at the output terminals */
- Sleep (50);
- if (!m_dcs_ctrl.DCS_measureVolt(m_pDcs, measvoltage))
- {
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " Power supply measure vlotage = " +
- Double_To_AnsiString(measvoltage)
- );
- ADC_Measure_Voltage[1] = (float)measvoltage;
- ///////////////////////////// V2 : measure ADC value of Battery channel begin ///////////////////////////////////////////
- MF_BB_ADC_Req->channel = i_BATTERY_CHANNEL;
- MF_BB_ADC_Req->Meacount = i_ADC_MEASUREMENT_COUNT;
- MetaResult = META_BB_ADCGetMeaSumData_r( m_pCal->i_MainMETAHandle, MF_BB_ADC_Req, MF_MeasureADC_cnf_cb, &BBID_ADC, NULL );
- if (MetaResult != META_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure fail (V2) ");
- return false;
- }
- RestartTimerADCCal(WM_MF_ADC_MEASURE_FAIL);
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (BBCnf_ADC->status != BB_STATUS_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_CNF_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure cnf fail (V2) ");
- return false;
- }
- BATTERY_ADC_Output[1] = BBCnf_ADC->value / ((float) (MF_BB_ADC_Req->Meacount*1.0));
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " BATTERY_ADC_Output[1] = " +
- Double_To_AnsiString(BATTERY_ADC_Output[1])
- );
- if (this->Terminated)
- {
- this->OnTerminate = neByUser;
- return false;
- }
- ///////////////////////////// V2 : measure ADC value of CHARGER channel begin ///////////////////////////////////////////
- MF_BB_ADC_Req->channel = i_CHARGER_CHANNEL;
- MF_BB_ADC_Req->Meacount = i_ADC_MEASUREMENT_COUNT;
- MetaResult = META_BB_ADCGetMeaSumData_r(m_pCal->i_MainMETAHandle, MF_BB_ADC_Req, MF_MeasureADC_cnf_cb, &BBID_ADC, NULL);
- if( MetaResult != META_SUCCESS )
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure fail (V2) ");
- return false;
- }
- RestartTimerADCCal(WM_MF_ADC_MEASURE_FAIL);
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (BBCnf_ADC->status != BB_STATUS_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_CNF_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure cnf fail (V2) ");
- return false;
- }
- CHARGER_ADC_Output[1] = BBCnf_ADC->value / ((float) (MF_BB_ADC_Req->Meacount*1.0));
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " CHARGER_ADC_Output[1] = " +
- Double_To_AnsiString(CHARGER_ADC_Output[1])
- );
- if (this->Terminated)
- {
- this->OnTerminate = neByUser;
- return false;
- }
- ////////////////////////////// Calculate BATTERY ADC slope and offset /////////////////////////
- bmt_adcdata adc_data;
- float y0 = ADC_Measure_Voltage[0]*1000000.0;
- float y1 = ADC_Measure_Voltage[1]*1000000.0;
- float x0 = BATTERY_ADC_Output[0];
- float x1 = BATTERY_ADC_Output[1];
- float fdata = 0.0;
- if( (x1-x0) != 0)
- {
- fdata = 1.0*(y1-y0)/(x1-x0);
- fdata += (fdata>=0) ? 0.5 : -0.5 ;
- adc_data.i_ADCSlope[i_BATTERY_CHANNEL] = (int)fdata;
- fdata = y0 - 1.0*(y1-y0)/(x1-x0)*x0;
- fdata += (fdata>=0) ? 0.5 : -0.5 ;
- adc_data.i_ADCOffset[i_BATTERY_CHANNEL] = (int)fdata;
- MF_BB_ADC_ptr->Set_AdcData( adc_data );
- sprintf( tempbuf, "%d", adc_data.i_ADCSlope[i_BATTERY_CHANNEL] );
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- sprintf( tempbuf, "%d", adc_data.i_ADCOffset[i_BATTERY_CHANNEL] );
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- }
- else
- {
- CalErrorHandler(WM_MF_ADC_EVALUATE_SLOPE_OFFSET_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: ADC calibration evaluate battery slope and offset fail = ");
- return false;
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " BATTERY_ADC_Slope = " +
- IntToStr(adc_data.i_ADCSlope[i_BATTERY_CHANNEL])
- );
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " BATTERY_ADC_Offset = " +
- IntToStr(adc_data.i_ADCOffset[i_BATTERY_CHANNEL])
- );
- //////////////////// set slope and offset of other channel to same as battery channel ////////
- int i;
- int total_adc_num;
- //BBCHIP_TYPE bb_chip = frmMainSel->Get_FinalBBChip();
- if ((MT6205 == m_pCal->e_bb_chip) || (MT6205B == m_pCal->e_bb_chip))
- {
- total_adc_num = TOTAL_6205B_ADC_NUM;
- }
- else
- {
- total_adc_num = TOTAL_6218_ADC_NUM;
- }
- for (i=0; i<total_adc_num; i++)
- {
- if ((i != i_BATTERY_CHANNEL) && (i!= i_CHARGER_CHANNEL))
- {
- adc_data.i_ADCSlope[i] = adc_data.i_ADCSlope[i_BATTERY_CHANNEL];
- adc_data.i_ADCOffset[i] = adc_data.i_ADCOffset[i_BATTERY_CHANNEL];
- }
- }
- ////////////////////////////// Calculate CHARGER ADC slope and offset /////////////////////////
- y0 = ADC_Measure_Voltage[0]*1000000.0;
- y1 = ADC_Measure_Voltage[1]*1000000.0;
- x0 = CHARGER_ADC_Output[0];
- x1 = CHARGER_ADC_Output[1];
- fdata = 0.0;
- if( (x1-x0) != 0)
- {
- fdata = 1.0*(y1-y0)/(x1-x0);
- fdata += (fdata>=0) ? 0.5 : -0.5 ;
- adc_data.i_ADCSlope[i_CHARGER_CHANNEL] = (int)fdata;
- fdata = y0 - 1.0*(y1-y0)/(x1-x0)*x0;
- fdata += (fdata>=0) ? 0.5 : -0.5 ;
- adc_data.i_ADCOffset[i_CHARGER_CHANNEL] = (int)fdata;
- sprintf(tempbuf, "%d", adc_data.i_ADCSlope[i_CHARGER_CHANNEL] );
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- sprintf(tempbuf, "%d", adc_data.i_ADCOffset[i_CHARGER_CHANNEL] );
- m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
- MF_BB_ADC_ptr->Set_AdcData( adc_data );
- }
- else
- {
- CalErrorHandler( WM_MF_ADC_EVALUATE_SLOPE_OFFSET_FAIL );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL: ADC calibration evaluate charger slope and offset fail = "
- );
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " CHARGER_ADC_Slope = " +
- IntToStr(adc_data.i_ADCSlope[i_CHARGER_CHANNEL])
- );
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " CHARGER_ADC_Offset = " +
- IntToStr(adc_data.i_ADCOffset[i_CHARGER_CHANNEL])
- );
- //////////////////// save ADC slope and offset to flash //////////////////////////////////////
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " Start writting ADC slope and offset to flash"
- );
- MF_BB_ADC_ptr->ConfirmCallback = ::ccb_write_ADC_to_nvram;
- MF_BB_ADC_ptr->REQ_Write_To_NVRAM_Start();
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- RestartTimerADCCal(WM_MF_NVRAM_ADC_WRITE_FAIL);
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- E_METAAPP_RESULT_T state = MF_BB_ADC_ptr->Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
- {
- CalErrorHandler(WM_MF_NVRAM_EF_ADC_LID_VERNO_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL : NVRAM_EF_ADC_LID version is not support, please update META to latest version. "
- );
- }
- else
- {
- CalErrorHandler(WM_MF_NVRAM_ADC_WRITE_FAIL);
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " FAIL: Target< Write ADC slope and offset to flash "
- );
- }
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " Target< Write ADC slope and offset to flash "
- );
- if ( this->Terminated )
- {
- this->OnTerminate = neByUser;
- return false;
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " ======================= ADC calibration end ====================== "
- );
- WriteADCCalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath);
- ///////////////////////// ADC current limit check /////////////////////////////////////////////
- log->Add( "n" + DateToStr(Date()) + " " + CurrentTimeStr() +
- " ================== ADC current limit check begin ================= "
- );
- //******************************** evaluate BATTERY channel input voltage ***************************************
- ADC_Measure_Voltage[2] = (float)measvoltage;
- MF_BB_ADC_Req->channel = i_BATTERY_CHANNEL;
- MF_BB_ADC_Req->Meacount = i_ADC_MEASUREMENT_COUNT;
- MetaResult = META_BB_ADCGetMeaSumData_r(m_pCal->i_MainMETAHandle, MF_BB_ADC_Req, MF_MeasureADC_cnf_cb, &BBID_ADC, NULL);
- if (MetaResult != META_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure fail (evaluate battery channel input voltage) ");
- return false;
- }
- RestartTimerADCCal(WM_MF_ADC_MEASURE_FAIL);
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (BBCnf_ADC->status != BB_STATUS_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_CNF_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure cnf fail (evaluate battery channel input voltage) ");
- return false;
- }
- BATTERY_ADC_Output[2] = BBCnf_ADC->value / ((float) (MF_BB_ADC_Req->Meacount*1.0));
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " BATTERY_ADC_Output[2] = " +
- Double_To_AnsiString(BATTERY_ADC_Output[2])
- );
- BATTERY_ADC_Predict_Voltage = (adc_data.i_ADCOffset[i_BATTERY_CHANNEL] + adc_data.i_ADCSlope[i_BATTERY_CHANNEL]*BATTERY_ADC_Output[2])/1000000.0 ;
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " BATTERY_ADC_Predict_Voltage = " +
- Double_To_AnsiString(BATTERY_ADC_Predict_Voltage)
- );
- //******************************** evaluate CHARGER channel input voltage ***************************************
- MF_BB_ADC_Req->channel = i_CHARGER_CHANNEL;
- MF_BB_ADC_Req->Meacount = i_ADC_MEASUREMENT_COUNT;
- MetaResult = META_BB_ADCGetMeaSumData_r(m_pCal->i_MainMETAHandle, MF_BB_ADC_Req, MF_MeasureADC_cnf_cb, &BBID_ADC, NULL);
- if (MetaResult != META_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure fail (evaluate charger channel input voltage) ");
- return false;
- }
- RestartTimerADCCal(WM_MF_ADC_MEASURE_FAIL);
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (BBCnf_ADC->status != BB_STATUS_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_CNF_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure cnf fail (evaluate charger channel input voltage) ");
- return false;
- }
- CHARGER_ADC_Output[2] = BBCnf_ADC->value / ((float) (MF_BB_ADC_Req->Meacount*1.0));
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " CHARGER_ADC_Output[2] = " +
- Double_To_AnsiString(CHARGER_ADC_Output[2])
- );
- CHARGER_ADC_Predict_Voltage = (adc_data.i_ADCOffset[i_CHARGER_CHANNEL] + adc_data.i_ADCSlope[i_CHARGER_CHANNEL]*CHARGER_ADC_Output[2])/1000000.0 ;
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " CHARGER_ADC_Predict_Voltage = " +
- Double_To_AnsiString(CHARGER_ADC_Predict_Voltage)
- );
- //********************************** check BATTERY and CHARGER ADC current difference *******
- double current_difference;
- if (CHARGER_ADC_Predict_Voltage > BATTERY_ADC_Predict_Voltage)
- {
- current_difference = (double) ((CHARGER_ADC_Predict_Voltage - BATTERY_ADC_Predict_Voltage)/d_ADC_RESISTANCE);
- }
- else
- { current_difference = (double) ((BATTERY_ADC_Predict_Voltage - CHARGER_ADC_Predict_Voltage)/d_ADC_RESISTANCE);
- }
- if (current_difference >= d_MAX_CURRENT_DIFFERENCE)
- {
- CalErrorHandler(WM_MF_ADC_CHECK_CURRENT_DIFFERENCE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL : ADC calibration check current difference, difference = " +
- Double_To_AnsiString(current_difference)
- );
- return false;
- }
- else
- {
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " PASS : ADC calibration check current difference, difference = " +
- Double_To_AnsiString(current_difference)
- );
- }
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
- " =================== ADC current limit check end =================== "
- );
- ///////////////////////// ADC voltage limit check /////////////////////////////////////////////
- /* Set output voltage and current levels, turn output on*/
- log->Add( "n" + DateToStr(Date()) + " " + CurrentTimeStr() +
- " =================== ADC voltage limit check begin ================= "
- );
- // set output voltage = check voltage
- if (!m_dcs_ctrl.DCS_outputVoltCurr(m_pDcs, i_ADC_CHECK_VOLTAGE/1000.0, i_CURRENT_LIMIT/1000.0))
- {
- return false;
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " Set power supply vlotage = " +
- Double_To_AnsiString(i_ADC_CHECK_VOLTAGE /1000.0)
- );
- /* Measure the dc voltage level at the output terminals */
- Sleep (50);
- if (!m_dcs_ctrl.DCS_measureVolt(m_pDcs, measvoltage))
- {
- return false;
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " Power supply measure vlotage = " +
- Double_To_AnsiString(measvoltage)
- );
- //**************** evaluate BATTERY channel input voltage *****************
- ADC_Measure_Voltage[2] = (float)measvoltage;
- MF_BB_ADC_Req->channel = i_BATTERY_CHANNEL;
- MF_BB_ADC_Req->Meacount = i_ADC_MEASUREMENT_COUNT;
- MetaResult = META_BB_ADCGetMeaSumData_r(m_pCal->i_MainMETAHandle, MF_BB_ADC_Req, MF_MeasureADC_cnf_cb, &BBID_ADC, NULL );
- if (MetaResult != META_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure fail (evaluate battery channel voltage) "
- );
- return false;
- }
- RestartTimerADCCal(WM_MF_ADC_MEASURE_FAIL);
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (BBCnf_ADC->status != BB_STATUS_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_CNF_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure cnf fail (evaluate battery channel input voltage) ");
- return false;
- }
- BATTERY_ADC_Output[2] = BBCnf_ADC->value / ((float) (MF_BB_ADC_Req->Meacount*1.0));
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " BATTERY_ADC_Output[2] = " +
- Double_To_AnsiString(BATTERY_ADC_Output[2])
- );
- BATTERY_ADC_Predict_Voltage = (adc_data.i_ADCOffset[i_BATTERY_CHANNEL] + adc_data.i_ADCSlope[i_BATTERY_CHANNEL]*BATTERY_ADC_Output[2])/1000000.0 ;
- log->Add( DateToStr(Date()) + " " + CurrentTimeStr() + " BATTERY_ADC_Predict_Voltage = " +
- Double_To_AnsiString(BATTERY_ADC_Predict_Voltage)
- );
- //******************************** evaluate CHARGER channel input voltage ***************************************
- MF_BB_ADC_Req->channel = i_CHARGER_CHANNEL;
- MF_BB_ADC_Req->Meacount = i_ADC_MEASUREMENT_COUNT;
- MetaResult = META_BB_ADCGetMeaSumData_r(m_pCal->i_MainMETAHandle, MF_BB_ADC_Req, MF_MeasureADC_cnf_cb, &BBID_ADC, NULL);
- if (MetaResult != META_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure fail (evaluate charger voltage) "
- );
- return false;
- }
- RestartTimerADCCal(WM_MF_ADC_MEASURE_FAIL);
- is_suspend_cal = true;
- this->Suspend();
- is_suspend_cal = false;
- if (BBCnf_ADC->status != BB_STATUS_SUCCESS)
- {
- CalErrorHandler(WM_MF_ADC_MEASURE_CNF_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " ADC measure cnf fail (evaluate charger channel input voltage) ");
- return false;
- }
- CHARGER_ADC_Output[2] = BBCnf_ADC->value / ((float) (MF_BB_ADC_Req->Meacount*1.0));
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " CHARGER_ADC_Output[2] = " +
- Double_To_AnsiString(CHARGER_ADC_Output[2])
- );
- CHARGER_ADC_Predict_Voltage = (adc_data.i_ADCOffset[i_CHARGER_CHANNEL] + adc_data.i_ADCSlope[i_CHARGER_CHANNEL]*CHARGER_ADC_Output[2])/1000000.0 ;
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " CHARGER_ADC_Predict_Voltage = " +
- Double_To_AnsiString(CHARGER_ADC_Predict_Voltage)
- );
- //********************* check BATTERY input voltage ************************
- float difference;
- if (BATTERY_ADC_Predict_Voltage > ADC_Measure_Voltage[2])
- {
- difference = BATTERY_ADC_Predict_Voltage - ADC_Measure_Voltage[2];
- }
- else
- {
- difference = ADC_Measure_Voltage[2] - BATTERY_ADC_Predict_Voltage;
- }
- if (difference > (float)d_MAX_VOLTAGE_DIFFERENCE)
- {
- CalErrorHandler(WM_MF_ADC_CHECK_CURRENT_DIFFERENCE_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " FAIL : ADC calibration check battery channel vlotage difference, difference = " +
- Double_To_AnsiString(ADC_Measure_Voltage[2] - BATTERY_ADC_Predict_Voltage)
- );
- return false;
- }
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() + " Pass : ADC calibration check battery channel vlotage difference = " +
- Double_To_AnsiString(ADC_Measure_Voltage[2] - BATTERY_ADC_Predict_Voltage)
- );
- cfg->get_MAX_BATTERY_ADC_SLOPE(i_MAX_BATTERY_ADC_SLOPE);
- cfg->get_MIN_BATTERY_ADC_SLOPE(i_MIN_BATTERY_ADC_SLOPE);
- cfg->get_MAX_BATTERY_ADC_OFFSET(i_MAX_BATTERY_ADC_OFFSET);
- cfg->get_MIN_BATTERY_ADC_OFFSET(i_MIN_BATTERY_ADC_OFFSET);
- //******************** check BATTERY ADC slope and offset ********************
- if ((adc_data.i_ADCSlope[i_BATTERY_CHANNEL] >= i_MIN_BATTERY_ADC_SLOPE) &&
- (adc_data.i_ADCSlope[i_BATTERY_CHANNEL] <= i_MAX_BATTERY_ADC_SLOPE) &&
- (adc_data.i_ADCOffset[i_BATTERY_CHANNEL] >= i_MIN_BATTERY_ADC_OFFSET) &&
- (adc_data.i_ADCOffset[i_BATTERY_CHANNEL] <= i_MAX_BATTERY_ADC_OFFSET)
- )
- {
- CalErrorHandler(WM_MF_ADC_CHECK_SLOPE_OFFSET_PASS);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Pass: ADC calibration check slope and offset ." +
- " BATTERY ADC slope = " + adc_data.i_ADCSlope[i_BATTERY_CHANNEL] + "n" +
- " min battery ADC slope = " + IntToStr(i_MIN_BATTERY_ADC_SLOPE) + "n" +
- " max battery ADC slope = " + IntToStr(i_MAX_BATTERY_ADC_SLOPE) + "n" +
- " BATTERY ADC offset = " + adc_data.i_ADCOffset[i_BATTERY_CHANNEL] + "n" +
- " min BATTERY ADC offset = " + IntToStr(i_MIN_BATTERY_ADC_OFFSET) + "n" +
- " max BATTERY ADC offset = " + IntToStr(i_MAX_BATTERY_ADC_OFFSET)
- );
- }
- else
- {
- CalErrorHandler(WM_MF_ADC_CHECK_SLOPE_OFFSET_FAIL);
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " Fail: ADC calibration check slope and offset ." +
- " BATTERY ADC slope = " + adc_data.i_ADCSlope[i_BATTERY_CHANNEL] + "n" +
- " min BATTERY ADC slope = " + IntToStr(i_MIN_BATTERY_ADC_SLOPE) + "n" +
- " max BATTERY ADC slope = " + IntToStr(i_MAX_BATTERY_ADC_SLOPE) + "n" +
- " BATTERY ADC offset = " + adc_data.i_ADCOffset[i_BATTERY_CHANNEL] + "n" +
- " min BATTERY ADC offset = " + IntToStr(i_MIN_BATTERY_ADC_OFFSET) + "n" +
- " max BATTERY ADC offset = " + IntToStr(i_MAX_BATTERY_ADC_OFFSET)
- );
- return false;
- }
- PostMessage(ctrl.hPostMsgDestHandle,
- WM_MF_ADC_CALIBRATION_DONE,
- 0,
- 0
- );
- log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
- " =================== ADC voltage limit check end ================= "
- );
- frmFatcory->DisableAllCalTimer();
- return true;
- }