ML5238

Files at this revision

API Documentation at this revision

Comitter:
gscuttari
Date:
Mon Apr 15 10:20:43 2019 +0000
Commit message:
ML5238

Changed in this revision

bms.h Show annotated file Show diff for this revision Revisions of this file
main_def.h Show annotated file Show diff for this revision Revisions of this file
main_ext.h Show annotated file Show diff for this revision Revisions of this file
main_struct.h Show annotated file Show diff for this revision Revisions of this file
measure.h Show annotated file Show diff for this revision Revisions of this file
ml5238_reg.h Show annotated file Show diff for this revision Revisions of this file
param.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bms.h	Mon Apr 15 10:20:43 2019 +0000
@@ -0,0 +1,181 @@
+/*****************************************************************************
+    bms.h
+
+    Copyright (C) 2019 SQC Systems s.r.l.
+    All rights reserved.
+
+    SQC Systems shall not be liable for any direct, indirect, 
+    consequential or incidental damages arising from using or modifying this 
+    program.
+
+    History
+    2019.03.19  ver.1.00
+
+******************************************************************************/
+#ifndef _BMS_H_
+#define _BMS_H_
+
+
+/**********************************
+           STATE OF BMS
+**********************************/
+// Define State of BMS
+#define START_MODE 1
+#define RUN_MODE 2
+#define STANDBY_MODE 3
+#define ERROR_MODE 4
+#define CHARGING_MODE 5
+#define RESTORE_MODE 6
+#define LOW_BATTERY_MODE 7
+#define POWER_DOWN_MODE 8
+#define SHORT_CIRCUIT_MODE 9
+#define HIGH_TEMPERATURE_CUTOFF 10
+#define LOW_TEMPERATURE_CUTOFF 11
+
+/**********************************
+           EVENTS
+**********************************/
+
+// Define Events
+#define EVENT_POWER_ON 0
+#define EVENT_SHORT_CIRCUIT 1
+#define EVENT_OVER_TEMP 2
+#define EVENT_START_BMS 3
+#define EVENT_LOAD_DISCONNECTED 4
+#define EVENT_LOAD_RECONNECTED 5
+#define EVENT_CHARGER_DISCONNECTED 6
+#define EVENT_CHARGER_RECONNECTED 7
+#define EVENT_BATTERY_TOO_LOW 8
+#define EVENT_BATTERY_DOWN 9
+#define EVENT_BATTERY_IS_FULL 10
+#define EVENT_BATTERY_IS_OK 11
+#define EVENT_GOTO_RUN_FROM_RESTORE 12
+
+/**********************************
+           TALK and DONE
+**********************************/
+#define TALK (SS_PIN = 0);              // Chip Select
+#define DONE (SS_PIN = 1);              // Chip Deselect
+
+#define SET_CAN_IN_HIGH_SPEED_MODE (RS = 0);   // Set Can Bus in high speed mode
+#define SET_CAN_BUS_IN_LISTEN_MODE (RS = 1);   // Set Can Bus in Listen Only Mode
+
+char VMON_DATA_WRITE[] = {0x00, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A , 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
+int STATE_OF_BMS;
+double VIM0;
+double VIM1;
+double VR; 
+double Gim;
+double Vimz;
+double Vimon;
+double Isense;
+double V_ref = 3.4f;
+double Rsense = 0.003f;
+bool schort_circuit_detection = false;
+double instant_current_detected;
+
+float LOWVOLTAGEWARNING = 34.0;         // Define low voltage warning
+float LOWVOLTAGECUTOFF = 33.0;          // Define low voltage cut off
+float HIVOLTAGESHUNT = 3.8;             // Define high voltege limit for balancing
+float VOLTAGEALLOWANCE = 0.009;         // Define the accuracy the balancing algorithm can balance it to.
+float HIGHVOLTAGECUTOFF = 39.0;         // Define high voltage cut off
+int TOTALCELLS = 16;                      // Number Of cells
+
+
+float voltageHighest;
+float voltageLowest;
+int highestCellNumber;
+int lowestCellNumber;
+
+
+float cellVoltage[17];
+float difference[17];
+
+float voltageTotal;
+float voltageAverage;
+float temp_read = 0; 
+float temp_min = -5;
+float temp_warning = 40;
+float temp_cutoff = 60;
+float thr_val=0, thr_res=0, temperature=0;
+unsigned char read_buf,read_buf2,read_fet, read_power, rdata;
+double gain_correction = 0;
+
+
+// Status flags READ ONLY
+bool DF_STATUS = false; // Mosfet OUT
+bool CF_STATUS = false; // Mosfet CHARGER
+bool PSW_STATUS = false; // Power safe mode
+bool INT_STATUS = false; // INT bit indicates the /INTO pin output status.
+bool RPSL_STATUS = false; // RPSL bit indicates interrupt status of charger disconnecting interrupt if charge over-current detected.
+bool RPSH_STATUS = false; // RPSH bit indicates interrupt status of charger disconnecting interrupt if the status is power down.
+bool RRS_STATUS = false; // RRS bit indicates interrupt status of load disconnecting interrupt
+bool RSC_STATUS = false; // RSC bit indicates interrupt status of short current detecting interrupt.
+
+
+
+// status flags of power status
+bool PSV_STATUS = false; 
+bool PDWN_STATUS = false; 
+bool PUPIN_STATUS = false; 
+
+
+
+// Setup ML5238
+void START_UP_ML5238();
+bool SET_ENABLE = true;
+bool SET_DISABLE = false;
+bool SET_RUN = true;
+bool SET_STOP = false;
+
+
+void handle_interrupt();
+void read_instant_current();
+float read_temperature_of_battery();
+void events_of_bms();
+void actions();
+float vTotal();
+int highestCell();
+int lowestCell();
+float average_voltage();
+
+
+
+typedef struct _Register_Map_structure {
+    float Cell_1_voltage;
+    float Cell_2_voltage;
+    float Cell_3_voltage;
+    float Cell_4_voltage;
+    float Cell_5_voltage;
+    float Cell_6_voltage;
+    float Cell_7_voltage;
+    float Cell_8_voltage;
+    float Cell_9_voltage;
+    float Cell_10_voltage;
+    float Cell_11_voltage;
+    float Cell_12_voltage;
+    float Cell_13_voltage;
+    float Cell_14_voltage;
+    float Cell_15_voltage;
+    float Cell_16_voltage;
+    char Bms_uptime[32];
+    uint32_t Estimated_time_left;
+    float Battery_voltage;
+    float Battery_current;
+    float Min_cell_voltage;
+    float Max_cell_voltage;
+    float External_temp_sensor_1;
+    float External_temp_sensor_2;
+    uint16_t Distance_left;
+    uint32_t State_of_charge;
+    float On_board_temperature_sensor;
+    uint16_t Battery_status;
+    float Voltageaverage;
+    float InstantPower;
+    float Speed;
+} Register_Map_structure;
+Register_Map_structure Register_Map;
+
+
+
+#endif /*_BMS_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_def.h	Mon Apr 15 10:20:43 2019 +0000
@@ -0,0 +1,81 @@
+/*****************************************************************************
+    main_def.h
+
+    Copyright (C) 2013 LAPIS Semiconductor Co., Ltd.
+    All rights reserved.
+
+    LAPIS Semiconductor shall not be liable for any direct, indirect, 
+    consequential or incidental damages arising from using or modifying this 
+    program.
+
+    History
+    2013.02.20  ver.3.00
+    2012.11.20  ver.2.00
+    2012.09.13  ver.1.00
+******************************************************************************/
+#ifndef _MAIN_DEF_H_
+#define _MAIN_DEF_H_
+
+#define CELL_NUM_MAX                    (16u)
+#define THERMISTOR_NUM_MAX              (8u)
+#define T_END                           (85u+40u+1u)
+
+
+#define SET_FLAG        (0x01u)
+#define CLR_FLAG        (0x00u)
+
+#define ST_NORMAL                       (0x0000u)
+#define ST_OVRCHRG_VOL                  (0x0001u)
+#define ST_OVRDISCHRG_VOL               (0x0002u)
+#define ST_OVRCHRG_DISCHRG_VOL          (0x0004u)
+#define ST_SHORT_CUR                    (0x0008u)
+
+#define ST_CHRG_CUR                     (0x0010u)
+#define ST_DISCHRG_CUR                  (0x0020u)
+#define ST_OVRCHRG_CUR                  (0x0040u)
+#define ST_OVRDISCHRG_CUR               (0x0080u)
+
+#define ST_TOTAL_CHRG                   (0x0100u)
+#define ST_CELLDIFF_CHRG                (0x0200u)
+#define ST_PSAVE                        (0x0400u)
+#define ST_PDOWN                        (0x0800u)
+
+#define ST_UDR_TEMPE_CHRG               (0x1000u)
+#define ST_UDR_TEMPE_DISCHRG            (0x2000u)
+#define ST_OVR_TEMPE_CHRG               (0x4000u)
+#define ST_OVR_TEMPE_DISCHRG            (0x8000u)
+#define ST_TEMPE_DETECT                 (ST_OVR_TEMPE_DISCHRG|ST_UDR_TEMPE_DISCHRG)
+
+#define UART_SEND_BUF_SZ                (40u)
+
+#define STX (0x02u)
+
+#define MAIN_R_OK               (0)
+#define MAIN_R_ERR_PARAM        (-1)
+
+#define MAIN_EEPROM_ADR         (0x0200u)   //Top Addr
+#define MAIN_EEPROM_SIZE        (0x0060u)   //size of one data
+#define MAIN_EEPROM_TIMES_ADR   (0x002Cu)   //Times Addr
+#define MAIN_EEPROM_ENERGY_ADR  (0x0058u)   //Enegy Addr
+#define MAIN_EEPROM_PAGE_SIZE   (10u)
+
+#define GAIN10_SUB          (1u)            //(Vim1-Vim0)/VR-0.1
+#define GAIN50_SUB          (5u)            //(Vim1-Vim0)/VR-0.5
+#define GAIN10F             (100u-GAIN10_SUB)           //x10(Fixed)-0.1
+#define GAIN50F             (500u-GAIN50_SUB)           //x50(Fixed)-0.5
+
+#define ST_EEP_ABNRDATA     (2u)
+#define ST_EEP_ALL_ERASE    (1u)
+#define ST_EEP_OK           (0u)
+
+#define EEP_INS_ABNRDATA        ((unsigned char*)"x")
+#define EEP_INS_ALL_ERASE       ((unsigned char*)"y")
+#define EEP_INS_OK              ((unsigned char*)"z")                           //CopyParamEEPROM()= EEP_R_NODATA, EEP_R_DATADIFF, EEP_ALL_ERASE
+
+//using drv_ctrl_flag
+#define DRVST_ON_BIT    (0x80u)
+#define DRVST_OFF_BIT   (0x40u)
+
+#define VREF_VAL            (3300u)
+
+#endif /*_MAIN_DEF_H_*/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_ext.h	Mon Apr 15 10:20:43 2019 +0000
@@ -0,0 +1,151 @@
+/*****************************************************************************
+    main_ext.h
+
+    Copyright (C) 2012 LAPIS Semiconductor Co., Ltd.
+    All rights reserved.
+
+    LAPIS Semiconductor shall not be liable for any direct, indirect, 
+    consequential or incidental damages arising from using or modifying this 
+    program.
+
+    History
+    2012.11.20  ver.2.00
+    2012.09.13  ver.1.00
+******************************************************************************/
+#ifndef _MAIN_EXT_H_
+#define _MAIN_EXT_H_
+
+#include "main_struct.h"
+#include "main_def.h"
+#include "measure.h"
+
+#define PRODUCT_ID_NUM      (3)
+
+extern MainSt process;
+extern CurDetSt curResult;
+extern CellDetSt cellResult;
+extern TempeSt tempState;
+extern TempeDetSt tempeResult[THERMISTOR_NUM_MAX];
+extern DetectTimes times;
+extern EnergyLevel level;
+
+extern unsigned short Work_State;
+extern unsigned char uart_send_buf[UART_SEND_BUF_SZ];
+
+extern unsigned short Vinl10;
+extern unsigned short Vinl50;
+extern unsigned short Vinh10;
+extern unsigned short Vinh50;
+extern unsigned short Vioc10;
+extern unsigned short Vioc50;
+extern unsigned short Viod_stg110;
+extern unsigned short Viod_stg150;
+extern unsigned short Viod_stg210;
+extern unsigned short Viod_stg250;
+extern unsigned short Vut_c[THERMISTOR_NUM_MAX];
+extern unsigned short Vutr_c[THERMISTOR_NUM_MAX];
+extern unsigned short Vut_d[THERMISTOR_NUM_MAX];
+extern unsigned short Vutr_d[THERMISTOR_NUM_MAX];
+extern unsigned short Vot_c[THERMISTOR_NUM_MAX];
+extern unsigned short Votr_c[THERMISTOR_NUM_MAX];
+extern unsigned short Vot_d[THERMISTOR_NUM_MAX];
+extern unsigned short Votr_d[THERMISTOR_NUM_MAX];
+
+
+extern unsigned short Vov;
+extern unsigned short Vovr;
+extern unsigned short Vuv;
+extern unsigned short Vuvr;
+
+extern unsigned short Vbsv;
+extern unsigned short gvbs;
+extern unsigned short gvbe;
+
+extern unsigned long Vdown;
+extern unsigned short Vec;
+
+
+extern unsigned short D_ov;
+extern unsigned short D_uv;
+
+
+//extern unsigned short Rsense;
+
+extern unsigned short Vcen;
+extern unsigned short Vden;
+extern unsigned short D_Vcen;
+extern unsigned short D_Vden;
+
+extern unsigned short D_Psave;
+
+extern unsigned short Psave_time;
+
+extern unsigned short Viod_stg1;
+extern unsigned short Viod_stg2;
+extern unsigned short Vioc;
+
+extern unsigned char D_iod_stg1;
+extern unsigned char D_iod_stg2;
+
+extern unsigned char D_iovc;
+
+//extern unsigned char TempeNum;
+extern unsigned long Tempe25;
+extern unsigned long TempeB;
+extern unsigned long DivR;
+extern unsigned short TempeTime;
+
+
+extern unsigned short D_Temp;
+extern unsigned short differential_voltage;
+extern unsigned long TotalCellVol_ChargerEna;
+extern unsigned short Ah_Val;
+extern unsigned short Veint;
+extern unsigned char Product_Id[PRODUCT_ID_NUM];
+extern unsigned char ShortC;
+extern unsigned char eepUpTime;         //1[min] to 10[min]
+
+extern unsigned short differential_voltage_rel;
+extern unsigned long TotalCellVol_ChargerEna_rel;
+
+extern char ut_c[THERMISTOR_NUM_MAX];
+extern char utr_c[THERMISTOR_NUM_MAX];
+extern char ut_d[THERMISTOR_NUM_MAX];
+extern char utr_d[THERMISTOR_NUM_MAX];
+extern char ot_c[THERMISTOR_NUM_MAX];
+extern char otr_c[THERMISTOR_NUM_MAX];
+extern char ot_d[THERMISTOR_NUM_MAX];
+extern char otr_d[THERMISTOR_NUM_MAX];
+
+extern unsigned char ut_c_th_target;
+extern unsigned char ut_d_th_target;
+extern unsigned char ot_c_th_target;
+extern unsigned char ot_d_th_target;
+
+extern unsigned long Energy;
+
+extern unsigned short uart_rw_size;
+extern unsigned short uart_r_size;
+extern unsigned char eep_count_Flag;
+
+extern unsigned char threshold_mode_status;
+extern volatile unsigned char Thres_req0_flg;
+extern volatile unsigned char Thres_req1_flg;
+extern volatile unsigned char Thres_req2_flg;
+extern volatile unsigned char senddata_cont_flg;
+extern volatile unsigned char WDT_flag;
+extern volatile unsigned char eeprom_read_state;        //0:there ara parameters to eeprom, else:there are no parameters.
+
+extern unsigned char shortDet_flag; //Add 14.07.10
+extern volatile unsigned char External0_en_flag;
+
+extern void clk_wait1ms(void);
+extern void main_clrWDT( void );
+extern void uart_send_param(unsigned char* uart_buf);
+extern int _eeprom_write_data(unsigned int address, unsigned char* buff, unsigned int size);
+extern int _eeprom_read_data(unsigned int address, unsigned char* buff, unsigned int size);
+extern void Uart_SendString(unsigned char* buf, unsigned short len);
+void ltoa_hex(unsigned char* str_buff, unsigned char* data_buff, int byte_size);
+extern void EnergyCalcCur(void);
+
+#endif /*_MAIN_EXT_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_struct.h	Mon Apr 15 10:20:43 2019 +0000
@@ -0,0 +1,67 @@
+/*****************************************************************************
+    main_struct.h
+
+    Copyright (C) 2012 LAPIS Semiconductor Co., Ltd.
+    All rights reserved.
+
+    LAPIS Semiconductor shall not be liable for any direct, indirect, 
+    consequential or incidental damages arising from using or modifying this 
+    program.
+
+    History
+    2012.11.20  ver.2.00
+    2012.09.13  ver.1.00
+******************************************************************************/
+#ifndef _MAIN_STRUCT_H_
+#define _MAIN_STRUCT_H_
+
+typedef struct{
+    unsigned char cellNum;          //Cell Instruction number(0 cell to 15cell)
+    unsigned char tempeNum;         //Thermister Instruction number(0 cell to 15cell)
+    unsigned char CellNumCon;
+    unsigned char ThermisNumCon;
+
+    unsigned short TempCount;       //the count number of 10ms(10000ms-60000ms)
+    unsigned char VcellAllMeasFlag;     //Task_Vflag
+    unsigned char TempeOneMeasFlag;     //Finished the basic cycle
+
+    unsigned short BalanceNow;
+    unsigned short BalanceCount;        //0.1s to 1s
+
+    unsigned char BalanceStartFlag;
+    unsigned char PsaveTransFlag;
+    unsigned char PsaveReturnFlag;
+    unsigned char PsaveEepromFlag;
+
+    unsigned long PsaveDelayCount;          //Use at interval time and delay time.
+
+    unsigned long eepUpCount;
+
+    unsigned short Count_LED;
+    unsigned short BalanceFlag;
+}MainSt;
+
+typedef struct{
+    unsigned long Charge_Num;
+    unsigned long Discharge_Num;
+    unsigned long OvCh_Num;
+    unsigned long OvDis_Num;
+    unsigned long OvCharge_Num;
+    unsigned long OvDischarge_Num;
+    unsigned long Short_Num;
+    unsigned long UdTempeCh_Num;
+    unsigned long UdTempeDis_Num;
+    unsigned long OvTempeCh_Num;
+    unsigned long OvTempeDis_Num;
+}DetectTimes;
+
+typedef struct{
+    unsigned long Energy100;
+    unsigned long Energy80;
+    unsigned long Energy60;
+    unsigned long Energy40;
+    unsigned long Energy20;
+    unsigned long Energy10min;
+}EnergyLevel;
+
+#endif /*_MAIN_STRUCT_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/measure.h	Mon Apr 15 10:20:43 2019 +0000
@@ -0,0 +1,159 @@
+/*****************************************************************************
+    measure.h
+
+    Copyright (C) 2012 LAPIS Semiconductor Co., Ltd.
+    All rights reserved.
+
+    LAPIS Semiconductor shall not be liable for any direct, indirect, 
+    consequential or incidental damages arising from using or modifying this 
+    program.
+
+    History
+    2012.11.20  ver.2.00
+    2012.09.13  ver.1.00
+******************************************************************************/
+#ifndef _MEASURE_H_
+#define _MEASURE_H_
+
+/*############################################################################*/
+/*#                                Struct                                    #*/
+/*############################################################################*/
+typedef struct{
+    unsigned short Visense10;
+    unsigned short Visense50;
+    unsigned short Vim010;
+    unsigned short Vim050;
+/*
+    unsigned short Vim110;
+    unsigned short Vim150;
+    unsigned short VR10;
+    unsigned short VR50;
+*/
+    unsigned short Rsense;
+    unsigned short Count_DC;
+
+    unsigned char Count_ODC;
+    unsigned char Count_OD2;
+    unsigned char curState;
+    unsigned char DetectForbitFlag;         //bit0:charge over current detection, bit1:discharge over current1 detection, bit2:discharge over current2 detection
+    
+}CurDetSt;
+
+typedef struct{
+    unsigned long Vsum;
+    unsigned short OvChDelaytime;
+    unsigned short OvChstate;
+    unsigned short OvDisDelaytime;
+    unsigned short OvDisstate;
+}CellDetSt;
+
+typedef struct {
+    unsigned short Vt_pcb;
+    unsigned short UChDelayCount;
+    unsigned short UDisDelayCount;
+    unsigned short OChDelayCount;
+    unsigned short ODisDelayCount;
+    unsigned char  Tadr;
+    unsigned char  DetectForbitFlag;    //bit0:under tempe charge forbit, bit1:under tempe discharge forbit, bit2:over tempe charge forbit, bit3:over tempe discharge forbit
+}TempeDetSt;
+
+typedef struct{
+    unsigned char UChState;
+    unsigned char UDisState;
+    unsigned char OChState;
+    unsigned char ODisState;
+//  unsigned short delayCount;
+    TempeDetSt* res;
+    unsigned char TempFlag;
+}TempeSt;
+
+
+/*############################################################################*/
+/*#                                Variable                                  #*/
+/*############################################################################*/
+
+/*############################################################################*/
+/*#                                define                                    #*/
+/*############################################################################*/
+
+/*############################################################################*/
+/*#                                Return                                    #*/
+/*############################################################################*/
+#define MEAS_R_OK           (0)
+#define MEAS_R_ERR_NULL     (-1)
+
+#define CUR_NOR             (0x00u)
+#define CUR_CHRG            (0x01u)
+#define CUR_DISCHRG         (0x02u)
+#define CUR_OVCHRG          (0x04u)
+#define CUR_OVDISCHRG1      (0x08u)
+#define CUR_OVDISCHRG2      (0x10u)
+
+#define CELL_VOL_NOR        (0x00u)
+#define CELL_VOL_OVD        (0x02u)
+#define CELL_VOL_OVC        (0x01u)
+#define CELL_VOL_OVCD       (0x04u)
+#define CELL_VOL_PD         (0x05u)
+
+#define CFET_OFF_DFET_OFF               (0x00u)
+#define CFET_ON_DFET_OFF                (0x02u)
+#define CFET_OFF_DFET_ON                (0x01u)
+#define CFET_ON_DFET_ON                 (0x03u)
+
+#define EEP_TEMPE_TABLE_ADR     (0x200u)
+#define VMON_OUT_EN     (0x10u)
+
+#define CURRENT_AD_FULL     (0xFF00u)
+#define CURRENT_AD_NULL     (0x0100u)
+
+#define CURRENT50_AD_FULL       (0xC000u)
+#define CURRENT10_AD_FULL       (CURRENT_AD_FULL)
+
+#define CUR_OVCH_DETEC_FORBIT       (0x01u)
+#define CUR_OVDISCH1_DETEC_FORBIT   (0x02u)
+#define CUR_OVDISCH2_DETEC_FORBIT   (0x04u)
+
+#define TEMPE_UDCH_DETEC_FORBIT     (0x01u)
+#define TEMPE_UDDISCH_DETEC_FORBIT  (0x02u)
+#define TEMPE_OVCH_DETEC_FORBIT     (0x04u)
+#define TEMPE_OVDISCH_DETEC_FORBIT  (0x08u)
+
+#define IMON_SET_NUM        (2u)
+
+extern const unsigned char Imon_set_table[IMON_SET_NUM];
+
+/*############################################################################*/
+/*#                                Prototype                                  #*/
+/*############################################################################*/
+void currentInit(CurDetSt* res);
+
+void currentGetParam(CurDetSt* res, unsigned short* param10,unsigned short* param50, 
+    unsigned short Im, unsigned char discharge_en,
+    unsigned long* param10tmp, unsigned long* param50tmp);
+
+void meas_current(CurDetSt* res);
+void UpdateCurrentParamCC(CurDetSt* res,
+    unsigned short* param10, unsigned short* param50,
+    unsigned long param10tmp, unsigned long param50tmp);
+
+void UpdateCurrentParamDC(CurDetSt* res,
+    unsigned short* param10, unsigned short* param50,
+    unsigned long param10tmp, unsigned long param50tmp);
+
+void judgeCurrent(CurDetSt* res);
+int meas_one_cell_volt(unsigned char cell_num, unsigned short* Vcell);
+void meas_all_cell_volt(unsigned char con_cell_num, unsigned short* Vcell);
+unsigned char JudgeCellAll(unsigned char cellNum , unsigned short* Vcell, CellDetSt* res);
+
+void Temperature_init(TempeDetSt* res);
+void getTemperature(unsigned char thNo, TempeDetSt* res);
+void JudgeOneTemperature(unsigned char thNum, TempeSt* res);
+unsigned short JudgeTemperature(TempeSt* res);
+void fet_control(unsigned char* fetState ,unsigned short workState);
+
+void Gas_storeVisense(CurDetSt* res);
+void Gas_aveVisense(unsigned short* cvisens, unsigned short* dvisens);
+void Gas_aveVisenseClear(void);
+
+
+#endif /*_MEASURE_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ml5238_reg.h	Mon Apr 15 10:20:43 2019 +0000
@@ -0,0 +1,149 @@
+/*****************************************************************************
+    ml5238_reg.h
+
+    Copyright (C) 2019 SQC Systems s.r.l.
+    All rights reserved.
+
+    SQC Systems shall not be liable for any direct, indirect, 
+    consequential or incidental damages arising from using or modifying this 
+    program.
+
+    History
+    2019.03.19  ver.3.00
+    2012.11.20  ver.2.00
+    2012.09.13  ver.1.00
+******************************************************************************/
+#ifndef _ML5238_REG_H_
+#define _ML5238_REG_H_
+
+#define ML5238_NOOP         (0x00u)
+#define ML5238_VMON         (0x01u)
+#define ML5238_IMON         (0x02u)
+#define ML5238_FET          (0x03u)
+#define ML5238_PSENSE       (0x04u)
+#define ML5238_RSENSE       (0x05u)
+#define ML5238_POWER        (0x06u)
+#define ML5238_STATUS       (0x07u)
+#define ML5238_CBALH        (0x08u)
+#define ML5238_CBALL        (0x09u)
+#define ML5238_SETSC        (0x0Au)
+
+/**********************************
+           NOOP(0x00)
+**********************************/
+#define NOOP_NO0    (0x01u)
+#define NOOP_NO1    (0x02u)
+#define NOOP_NO2    (0x04u)
+#define NOOP_NO3    (0x08u)
+#define NOOP_NO4    (0x10u)
+#define NOOP_NO5    (0x20u)
+#define NOOP_NO6    (0x40u)
+#define NOOP_NO7    (0x80u)
+
+/**********************************
+           VMON(0x01)
+**********************************/
+#define VMON_CN0    (0x01u)
+#define VMON_CN1    (0x02u)
+#define VMON_CN2    (0x04u)
+#define VMON_CN3    (0x08u)
+#define VMON_OUT    (0x10u)
+
+/**********************************
+           IMON(0x02)
+**********************************/
+#define IMON_GIM    (0x01u)
+#define IMON_ZERO   (0x02u)
+#define IMON_GCAL0  (0x04u)
+#define IMON_GCAL1  (0x08u)
+#define IMON_OUT    (0x10u)
+
+
+/**********************************
+           FET(0x03)
+**********************************/
+#define FET_DF          (0x01u)
+#define FET_CF          (0x02u)
+#define FET_DRV         (0x10u)
+#define RESET_ALL_FET   (0x00u)
+
+
+
+/**********************************
+           PSENSE(0x04)
+**********************************/
+#define PSENSE_PSL  (0x01u)
+#define PSENSE_RPSL (0x02u)
+#define PSENSE_IPSL (0x04u)
+#define PSENSE_EPSL (0x08u)
+#define PSENSE_PSH  (0x10u)
+#define PSENSE_RPSH (0x20u)
+#define PSENSE_IPSH (0x40u)
+#define PSENSE_EPSH (0x80u)
+
+/**********************************
+           RSENSE(0x05)
+**********************************/
+#define RSENSE_RS   (0x01u)
+#define RSENSE_RRS  (0x02u)
+#define RSENSE_IRS  (0x04u)
+#define RSENSE_ERS  (0x08u)
+#define RSENSE_SC   (0x10u)
+#define RSENSE_RSC  (0x20u)
+#define RSENSE_ISC  (0x40u)
+#define RSENSE_ESC  (0x80u)
+
+/**********************************
+           POWER(0x06)
+**********************************/
+#define POWER_PSV   (0x01u)
+#define POWER_PDWN  (0x10u)
+#define POWER_PUPIN (0x80u)
+
+/**********************************
+           STATUS(0x07)
+**********************************/
+#define STATUS_DF   (0x01u)
+#define STATUS_CF   (0x02u)
+#define STATUS_PSV  (0x04u)
+#define STATUS_INT  (0x08u)
+#define STATUS_RPSL (0x10u)
+#define STATUS_RPSH (0x20u)
+#define STATUS_RRS  (0x40u)
+#define STATUS_RSC  (0x80u)
+
+/**********************************
+           CBALH(0x08)
+**********************************/
+#define CBALH_SW9   (0x01u)
+#define CBALH_SW10  (0x02u)
+#define CBALH_SW11  (0x04u)
+#define CBALH_SW12  (0x08u)
+#define CBALH_SW13  (0x10u)
+#define CBALH_SW14  (0x20u)
+#define CBALH_SW15  (0x40u)
+#define CBALH_SW16  (0x80u)
+
+/**********************************
+           CBALL(0x09)
+**********************************/
+#define CBALL_SW1   (0x01u)
+#define CBALL_SW2   (0x02u)
+#define CBALL_SW3   (0x04u)
+#define CBALL_SW4   (0x08u)
+#define CBALL_SW5   (0x10u)
+#define CBALL_SW6   (0x20u)
+#define CBALL_SW7   (0x40u)
+#define CBALL_SW8   (0x80u)
+
+/**********************************
+           SETSC(0x0A)
+**********************************/
+//0x00=33.3A 0x01=66.6A 0x10=100A 0x11=133.3A
+#define SETSC_SC0   (0x00u)
+#define SETSC_SC1   (0x01u)
+#define SETSC_SC2   (0x10u)
+#define SETSC_SC3   (0x11u)
+
+
+#endif /*_ML5238_REG_H_*/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/param.h	Mon Apr 15 10:20:43 2019 +0000
@@ -0,0 +1,129 @@
+/*****************************************************************************
+    param.h
+
+    Copyright (C) 2012 LAPIS Semiconductor Co., Ltd.
+    All rights reserved.
+
+    LAPIS Semiconductor shall not be liable for any direct, indirect, 
+    consequential or incidental damages arising from using or modifying this 
+    program.
+
+    History
+    2012.11.20  ver.2.00
+    2012.09.13  ver.1.00
+******************************************************************************/
+#ifndef _PARAM_H_
+#define _PARAM_H_
+
+#include "main_ext.h"
+
+#define CELL_NUM_CON        16u
+#define THER_NUM_CON        4u
+#if (TESTMODE==85)
+#define RSENSE_VAL          50u     //0.5[mOhm]
+#elif (TESTMODE==86)
+#define RSENSE_VAL          1000u       //10[mOhm]
+#else
+#define RSENSE_VAL          300u        //3[mOhm]
+#endif
+#define AH_VAL              215u        //2.15[Ah]
+
+const static unsigned char CellNum=CELL_NUM_CON;
+
+//Over Voltage, Over Voltage Release, Under Voltage, Under Voltage Release
+
+const static unsigned short p_Vov=(unsigned short)((double)16*4095*(4200/2)/VREF_VAL);
+const static unsigned short p_Vovr=(unsigned short)((double)16*4095*(4000/2)/VREF_VAL);
+const static unsigned short p_Vuv=(unsigned short)((double)16*4095*(2800/2)/VREF_VAL);
+const static unsigned short p_Vuvr=(unsigned short)((double)16*4095*(3000/2)/VREF_VAL);
+
+const static unsigned short p_Vbsv=(unsigned short)((double)16*4095*(3600/2)/VREF_VAL);
+const static unsigned short p_gvbs=(unsigned short)((double)16*4095*(100/2)/VREF_VAL);
+const static unsigned short p_gvbe=(unsigned short)((double)16*4095*(70/2)/VREF_VAL);
+
+const static unsigned long p_Vdown=(unsigned long)((double)CELL_NUM_CON*16*4095*(2750/2)/VREF_VAL);
+const static unsigned short p_Vec =(unsigned short)((double)16*4095*(1400/2)/VREF_VAL);
+
+
+const static unsigned short p_D_ov = 50u;                   //500ms
+const static unsigned short p_D_uv = 60u;                   //600ms
+#define D_CBAL_VAL      (1u)
+
+const static unsigned short p_Rsense = RSENSE_VAL;
+
+const static unsigned short p_Vcen = 2u;                        //200[mA]
+const static unsigned short p_Vden = 2u;                        //200[mA]
+const static unsigned short p_D_Vcen = 20u;                 //200[ms]
+const static unsigned short p_D_Vden = 20u;                 //200[ms]
+
+const static unsigned short p_D_Psave = 60u;                //1[min]
+
+const static unsigned short p_Psave_time = 1000u;           //10[s]
+
+const static unsigned short p_Viod_stg1 =200u;              //20[A]
+const static unsigned short p_Viod_stg2 =500u;              //50[A]
+const static unsigned short p_Vioc =40u;                        //4[A]
+
+const static unsigned char p_D_iod_stg1 =4u;                    //40[ms]
+const static unsigned char p_D_iod_stg2 =2u;                    //20[ms]
+
+const static unsigned char p_D_iovc = 40u;                  //400[ms]
+
+const static unsigned char p_TempeNum= THER_NUM_CON;
+const static unsigned long p_Tempe25=10000u;
+const static unsigned long p_TempeB=3435u;
+const static unsigned long p_DivR=10000u;
+const static unsigned short p_TempeTime =1000u;             //10[s]
+
+const static char p_ut_c[THERMISTOR_NUM_MAX] = {  -5,  -5,  -5,  -5,  -5,  -5,  -5,  -5};
+const static char p_utr_c[THERMISTOR_NUM_MAX]= {   5,   5,   5,   5,   5,   5,   5,   5};
+const static char p_ut_d[THERMISTOR_NUM_MAX] = { -20, -20, -20, -20, -20, -20, -20, -20};
+const static char p_utr_d[THERMISTOR_NUM_MAX]= { -10, -10, -10, -10, -10, -10, -10, -10};
+const static char p_ot_c[THERMISTOR_NUM_MAX] = {  60,  60,  60,  60,  60,  60,  60,  60};
+const static char p_otr_c[THERMISTOR_NUM_MAX]= {  50,  50,  50,  50,  50,  50,  50,  50};
+const static char p_ot_d[THERMISTOR_NUM_MAX] = {  80,  80,  80,  80,  80,  80,  80,  80};
+const static char p_otr_d[THERMISTOR_NUM_MAX]= {  70,  70,  70,  70,  70,  70,  70,  70};
+
+const static unsigned short p_D_Temp=3u;
+
+const static unsigned short p_differential_voltage=0u;
+
+const static unsigned short p_differential_voltage_rel=(unsigned short)((double)16*4095*(50/2)/VREF_VAL);
+
+const static unsigned long p_TotalCellVol_ChargerEna=0u;
+
+const static unsigned long p_TotalCellVol_ChargerEna_rel=(unsigned long)((double)16*4095*(60000/2)/VREF_VAL);
+
+const static unsigned short p_Ah_Val=AH_VAL;
+
+const static unsigned short p_Veint=(unsigned short)((double)16*4095*(3600/2)/VREF_VAL);
+
+const static unsigned char p_Product_Id[PRODUCT_ID_NUM] = {'M','3','8'};            //Product ID
+
+const static unsigned char p_ShortC= 2u;                                            //0.3[V]
+
+const static unsigned char p_eepUpTime= 1u;                                         //1[min]-10[min]
+
+//
+//#define ENERGY_X      (0x00015D17)                //(  X x 1000 x 3600 / ((3300x1000)/(4096/*xRSENSExGim*/))  ) x (1000 / 50)
+#define SELFDCHG_VALUE      (625u)
+//#define Energy_All        ((double)AH_VAL*ENERGY_X*RSENSE_VAL/100/100u)
+#define Energy_All      ((double)AH_VAL*36*4095*20*RSENSE_VAL/3300/100u)
+
+const static unsigned long p_Energy_100 = (unsigned long)(Energy_All);
+const static unsigned long p_Energy_80 = (unsigned long)(Energy_All * 0.80);
+const static unsigned long p_Energy_60 = (unsigned long)(Energy_All * 0.60);
+const static unsigned long p_Energy_40 = (unsigned long)(Energy_All * 0.40);
+const static unsigned long p_Energy_20 = (unsigned long)(Energy_All * 0.20);
+const static unsigned long p_Energy_10min = Energy_All / (24u * 6u) / SELFDCHG_VALUE;       //(X * 1000 * 3600 / 32.227) * (1000 / 10)
+
+
+const static unsigned char p_waitTimes = 1u;
+const static unsigned char p_ImonInit_waitTimes = 1u;
+const static unsigned char p_Imon_waitTimes = 1u;
+const static unsigned char p_fDrv_waitTimes = 3u;
+const static unsigned char p_pd_waitTimes = 3u;
+const static unsigned char psl_waitTimes = 10u;
+const static unsigned char p_psl_waitTimes = 10u;
+
+#endif //_PARAM_H_