00001 /* 00002 * LTC2943.h 00003 * 00004 * Created on: Oct 20, 2015 00005 * Author: veli 00006 */ 00007 00008 #ifndef LIB_LTC2943_H_ 00009 #define LIB_LTC2943_H_ 00010 00011 #include "IMI2C.h" 00012 00013 /* LTC2943 donanım adres tanımlamaları */ 00014 #define LTC2943_HARDWARE_ADDRESS 0x64 00015 #define LTC2943_ALERT_RESPONSE_ADDRESS 0x0C 00016 00017 /* LTC2943 yazmaç haritası tanımlamaları */ 00018 #define STATUS 0x00 00019 #define CONTROL 0x01 00020 #define ACC_CHARGE_MSB 0x02 00021 #define ACC_CHARGE_LSB 0x03 00022 #define CHARGE_THRESH_HIGH_MSB 0x04 00023 #define CHARGE_THRESH_HIGH_LSB 0x05 00024 #define CHARGE_THRESH_LOW_MSB 0x06 00025 #define CHARGE_THRESH_LOW_LSB 0x07 00026 #define VOLTAGE_MSB 0x08 00027 #define VOLTAGE_LSB 0x09 00028 #define VOLTAGE_THRESH_HIGH_MSB 0x0A 00029 #define VOLTAGE_THRESH_HIGH_LSB 0x0B 00030 #define VOLTAGE_THRESH_LOW_MSB 0x0C 00031 #define VOLTAGE_THRESH_LOW_LSB 0x0D 00032 #define CURRENT_MSB 0x0E 00033 #define CURRENT_LSB 0x0F 00034 #define CURRENT_THRESH_HIGH_MSB 0x10 00035 #define CURRENT_THRESH_HIGH_LSB 0x11 00036 #define CURRENT_THRESH_LOW_MSB 0x12 00037 #define CURRENT_THRESH_LOW_LSB 0x13 00038 #define TEMPERATURE_MSB 0x14 00039 #define TEMPERATURE_LSB 0x15 00040 #define TEMPERATURE_THRESH_HIGH 0x16 00041 #define TEMPERATURE_THRESH_LOW 0x17 00042 00043 /* Kontrol yazmacı komut kodlaro tanımlamaları 00044 * 00045 * B[7:6] - ADC mode 00046 * B[5:3] - Prescaler 00047 * B[2:1] - ALCC Configure 00048 * B[0] - Shut down 00049 * */ 00050 00051 #define AUTOMATIC_MODE 0xC0 00052 #define SCAN_MODE 0x80 00053 #define MANUAL_MODE 0x40 00054 #define SLEEP_MODE 0x00 00055 00056 #define PRESCALER_1 0x00 00057 #define PRESCALER_4 0x08 00058 #define PRESCALER_16 0x10 00059 #define PRESCALER_64 0x18 00060 #define PRESCALER_256 0x20 00061 #define PRESCALER_1024 0x28 00062 #define PRESCALER_4096 0x30 00063 #define PRESCALER_4096_2 0x31 00064 00065 #define ALERT_MODE 0x04 00066 #define CHARGE_COMPLETE_MODE 0x02 00067 #define DISABLE_ALCC_PIN 0x00 00068 00069 #define SHUTDOWN_MODE 0x01 00070 00071 /* Dönüşüm sabitleri */ 00072 const float CHARGE_LEAST = 0.00034; // 0.34 mAh 00073 const float VOLTAGE_LEAST = 0.00144; // 1.44 mV 00074 const float CURRENT_LEAST = 0.0000293; // 29.3 uV 00075 const float TEMPERATURE_LEAST = 0.25; // 0.25 C 00076 const float FULLSCALE_VOLTAGE = 23.6; // 23.6 V 00077 const float FULLSCALE_CURRENT = 0.06; // 60 mV 00078 const float FULLSCALE_TEMPERATURE = 510; // 510 K 00079 00080 00081 class LTC2943 00082 { 00083 00084 public: 00085 float senseResistorValue; 00086 uint16_t prescalerValue; 00087 uint16_t prescalerMode; 00088 uint16_t alccMode; 00089 00090 00091 float readAccumulatedCharge(); 00092 float readVoltage(); 00093 float readCurrent(); 00094 float readTemperature(); 00095 00096 int readStatusRegister(); 00097 00098 void setChargeThresholdHigh(uint16_t _maxCharge); 00099 void setChargeThresholdLow(uint16_t _minCharge); 00100 void setVoltageThresholdHigh(float _maxVoltage); 00101 void setVoltageThresholdLow(float _minVoltage); 00102 00103 00104 void setCurrentThresholdHigh(uint16_t _maxCurrent); 00105 void setCurrentThresholdLow(uint16_t _minCurrent); 00106 void setTemperatureThresholdHigh(uint16_t _maxTemp); 00107 void setTemperatureThresholdLow(uint16_t _minTemp); 00108 00109 int getVoltageThresholdLow(); 00110 00111 void resetAlertStatus(); 00112 00113 void setControlRegister(unsigned char _mode, unsigned char _prescaler, unsigned char _alccConfiguration); 00114 00115 void readRegisters(); 00116 LTC2943(unsigned char u_c_device_address, 00117 string str_i2c_file_name, 00118 sem_t * mutex); 00119 00120 virtual ~LTC2943(); 00121 00122 private: 00123 IMI2C * batteryReader; 00124 char c_register_data[24]; 00125 00126 float calculateAccumulatedChargeFromADCCode(uint16_t _accumulatedChargeADCCode); 00127 float calculateVoltageFromADCCode(uint16_t _voltageCode); 00128 float calculateCurrentFromADCCode(uint16_t _currentCode); 00129 float calculateTemperatureFromADCCode(uint16_t _temperatureCode); 00130 }; 00131 00132 #endif /* LIB_LTC2943_H_ */