LTC2943具温度电压和电流测量功能的多节电池电量测量芯片教程文件Word格式文档下载.docx
《LTC2943具温度电压和电流测量功能的多节电池电量测量芯片教程文件Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《LTC2943具温度电压和电流测量功能的多节电池电量测量芯片教程文件Word格式文档下载.docx(31页珍藏版)》请在冰豆网上搜索。
14位无延迟增量累加
(NoLatencyΔΣTM)ADC
来测量。
测量结果被存储于可通过内置
I2C/SMBus
接口进行存取的内部寄存器中。
LTC2943
具有针对所有
4
种测量物理量的可编程高门限和低门限。
如果超过了某个编程门限,则该器件将采用
SMBus
警报协议或通过在内部状态寄存器中设定一个标记来传送警报信号。
仅需采用单个低阻值检测电阻器以设定测量电流范围。
应用
∙电动工具
∙电动自行车
∙便携式医疗设备
∙视频摄像机
程序:
#include<
Arduino.h>
stdint.h>
#include"
Linduino.h"
LT_I2C.h"
UserInterface.h"
QuikEval_EEPROM.h"
LTC2943.h"
Wire.h>
//FunctionDeclaration
voidprint_title();
//Printthetitleblock
voidprint_prompt();
//PrintthePrompt
voidstore_alert_settings();
//StorethealertsettingstotheEEPROM
int8_trestore_alert_settings();
//ReadthealertsettingsfromEEPROM
#defineAUTOMATIC_MODE_DISPLAY_DELAY1000//!
<
Thedelaybetweenreadingsinautomaticmode
#defineSCAN_MODE_DISPLAY_DELAY10000//!
Thedelaybetweenreadingsinscanmode
constfloatresistor=.100;
//!
resistorvalueondemoboard
//Errorstring
constcharack_error[]="
Error:
NoAcknowledge.CheckI2CAddress."
;
Errormessage
//Globalvariables
staticint8_tdemo_board_connected;
Setto1iftheboardisconnected
staticuint8_talert_code=0;
ValuestoredorreadfromALERTregister.Sharedbetweenloop()andrestore_alert_settings()
//!
InitializeLinduino
voidsetup()
{
chardemo_name[]="
DC1812"
DemoBoardNamestoredinQuikEvalEEPROM
quikeval_I2C_init();
ConfiguretheEEPROMI2Cportfor100kHz
quikeval_I2C_connect();
ConnectstomainI2Cport
Serial.begin(115200);
InitializetheserialporttothePC
print_title();
demo_board_connected=discover_demo_board(demo_name);
if(demo_board_connected)
{
print_prompt();
}
else
demo_board_connected=true;
Serial.println("
DidnotreadIDString,attemptingtoproceedanyway...\nPleaseensureI2ClinesofLinduinoareconnectedtotheLTCdevice"
);
}
RepeatsLinduinoloop
voidloop()
int8_tack=0;
I2Cacknowledgeindicator
staticuint8_tuser_command;
Theuserinputcommand
staticuint8_tmAh_or_Coulombs=0;
staticuint8_tcelcius_or_kelvin=0;
staticuint16_tprescalar_mode=LTC2943_PRESCALAR_M_4096;
staticuint16_tprescalarValue=4096;
staticuint16_talcc_mode=LTC2943_ALERT_MODE;
if(demo_board_connected)//!
Donothingifthedemoboardisnotconnected
if(Serial.available())//!
Donothingifserialisnotavailable
user_command=read_int();
Readuserinputcommand
if(user_command!
='
m'
)
Serial.println(user_command);
Serial.println();
ack=0;
switch(user_command)//!
Printstheappropriatesubmenu
case1:
ack|=menu_1_automatic_mode(mAh_or_Coulombs,celcius_or_kelvin,prescalar_mode,prescalarValue,alcc_mode);
AutomaticMode
break;
case2:
ack|=menu_2_scan_mode(mAh_or_Coulombs,celcius_or_kelvin,prescalar_mode,prescalarValue,alcc_mode);
ScanMode
case3:
ack|=menu_3_manual_mode(mAh_or_Coulombs,celcius_or_kelvin,prescalar_mode,prescalarValue,alcc_mode);
ManualMode
case4:
ack|=menu_4_sleep_mode(mAh_or_Coulombs,prescalar_mode,prescalarValue,alcc_mode);
SleepMode
case5:
ack|=menu_5_shutdown_mode();
ShutdownMode
case6:
ack|=menu_6_settings(&
mAh_or_Coulombs,&
celcius_or_kelvin,&
prescalar_mode,&
prescalarValue,&
alcc_mode);
SettingsMode
if(ack!
=0)//!
Ifackisnotrecievedprintanerror.
Serial.println(ack_error);
Serial.print(F("
*************************"
));
//FunctionDefinitions
Printthetitleblock
voidprint_title()
Serial.println(F("
\n*****************************************************************"
*DC1812ADemonstrationProgram*\n"
**\n"
*ThisprogramcommunicateswiththeLTC2943MulticellCoulomb*\n"
*CounterfoundontheDC1812Ademoboard.*\n"
*Setthebaudrateto115200andselectthenewlineterminator.*\n"
*****************************************************************\n"
PrintthePrompt
voidprint_prompt()
\n1-AutomaticMode\n"
2-ScanMode\n"
3-ManualMode\n"
4-SleepMode\n"
5-ShutdownMode\n"
6-Settings\n"
Enteracommand:
"
AutomaticMode.
int8_tmenu_1_automatic_mode(int8_tmAh_or_Coulombs,int8_tcelcius_or_kelvin,uint16_tprescalar_mode,uint16_tprescalarValue,uint16_talcc_mode)
@returnReturnsthestateoftheacknowledgebitaftertheI2Caddresswrite.0=acknowledge,1=noacknowledge.
int8_tLTC2943_mode;
LTC2943_mode=LTC2943_AUTOMATIC_MODE|prescalar_mode|alcc_mode;
SetthecontrolregisteroftheLTC2943toautomaticmodeaswellassetprescalarandAL#/CC#pinvalues.
ack|=LTC2943_write(LTC2943_I2C_ADDRESS,LTC2943_CONTROL_REG,LTC2943_mode);
WritesthesetmodetotheLTC2943controlregister
do
*************************\n\n"
uint8_tstatus_code,hightemp_code,lowtemp_code;
uint16_tcharge_code,current_code,voltage_code,temperature_code;
ack|=LTC2943_read_16_bits(LTC2943_I2C_ADDRESS,LTC2943_ACCUM_CHARGE_MSB_REG,&
charge_code);
ReadMSBandLSBAccumulatedChargeRegistersfor16bitchargecode
ack|=LTC2943_read_16_bits(LTC2943_I2C_ADDRESS,LTC2943_VOLTAGE_MSB_REG,&
voltage_code);
ReadMSBandLSBVoltageRegistersfor16bitvoltagecode
ack|=LTC2943_read_16_bits(LTC2943_I2C_ADDRESS,LTC2943_CURRENT_MSB_REG,&
current_code);
ReadMSBandLSBCurrentRegistersfor16bitcurrentcode
ack|=LTC2943_read_16_bits(LTC2943_I2C_ADDRESS,LTC2943_TEMPERATURE_MSB_REG,&
temperature_code);
ReadMSBandLSBTemperatureRegistersfor16bittemperaturecode
ack|=LTC2943_read(LTC2943_I2C_ADDRESS,LTC2943_STATUS_REG,&
status_code);
ReadStatusRegisterfor8bitstatuscode
floatcharge,current,voltage,temperature;
if(mAh_or_Coulombs)
charge=LTC2943_code_to_coulombs(charge_code,resistor,prescalarValue);
ConvertchargecodetoCoulombsifCoulombunitsaredesired.
Serial.print("
Coulombs:
Serial.print(charge,4);
C\n"
charge=LTC2943_code_to_mAh(charge_code,resistor,prescalarValue);
ConvertchargecodetomAhifmAhunitsaredesired.
mAh:
mAh\n"
current=LTC2943_code_to_current(current_code,resistor);
ConvertcurrentcodetoAmperes
voltage=LTC2943_code_to_voltage(voltage_code);
ConvertvoltagecodetoVolts
Current"
Serial.print(current,4);
A\n"
Voltage"
Serial.print(voltage,4);
V\n"
if(celcius_or_kelvin){
temperature=LTC2943_code_to_kelvin_temperature(temperature_code);
Converttemperaturecodetokelvin
Temperature"
Serial.print(temperature,4);
K\n"
temperature=LTC2943_code_to_celcius_temperature(temperature_code);
Converttemperaturecodetocelcius
checkAlerts(status_code);
CheckstatuscodeforAlerts.IfanAlerthasbeenset,printoutappropriatemessageintheSerialPrompt.
m-MainMenu\n\n"
Serial.flush();
delay(AUTOMATIC_MODE_DISPLAY_DELAY);
Delayfor1sbeforenextpolling
while(Serial.available()==false||(ack));
ifSerialisnotavailableandanNACKhasnotbeenrecieved,keeppollingtheregisters.
read_int();
//clearstheSerial.available
return(ack);
int8_tmenu_2_scan_mode(int8_tmAh_or_Coulombs,int8_tcelcius_or_kelvin,uint16_tprescalar_mode,uint16_tprescalarValue,uint16_talcc_mode)
@returnReturnsthestateoftheacknowledgebitaftertheI2Caddresswrite.0=acknowledge,1=noacknowledge
LTC2943_mode=LTC2943_SCAN_MODE|prescalar_mode|alcc_mode;
SetthecontrolmodeoftheLTC2943toscanmodeaswellassetprescalarandAL#/CC#pinvalues.
uint8_tstatus_code;