本帖最后由 hzy41y 于 2020-3-25 20:13 编辑
MCU通过INA219检测18650的电流与电压后,用PWM1控制Buck对18650进行恒流充电,用PWM2控制358对18650进行恒流放电,最后经计算得电池的充放电容量。
Buck电路参考tanzhi963的已调试通用,现在正在调INA219。
/******************* 刷新数据*******************/
void RefreshData(void) //刷新数据
{
unsigned short BusVolt, Current, Power;
unsigned short OffsetCurrent, OffsetPower;
unsigned char Ascii[6];
BusVolt = INA219_GetBusVolt(); //获取总线电压
Ascii[0]= BusVolt/10000+48; //加48(0x30)转为0到9的ASCII码
Ascii[1]=(BusVolt%10000)/1000+48; //加48(0x30)转为0到9的ASCII码
Ascii[2]='.'; //显示小数点
Ascii[3]=(BusVolt%1000)/100+48; //加48(0x30)转为0到9的ASCII码
Ascii[4]=(BusVolt%100)/10+48;
Ascii[5]=BusVolt%10+48;
SendString("\r\n\r\n电压");
SendString(Ascii); //发送数据字符串
OffsetCurrent = (BusVolt >> 9) + 2;
Current = INA219_GetCurrent(); //获取电流
if(Current > OffsetCurrent)
Current -= OffsetCurrent;
else
Current = 0;
if(Current & 0x8000) //最高位为1表示为负电流
{ Current=~Current+1; //补码转原码
SendString("-"); //负电流
}
Ascii[0]=Current/1000+48;
Ascii[1]='.'; //显示小数点
Ascii[2]=(Current%1000)/100+48;
Ascii[3]=(Current%100)/10+48;
Ascii[4]= Current%10+48;
Ascii[5]=0; //0为字符结束
SendString("\r\n电流");
SendString(Ascii); //发送数据字符串
OffsetPower = ((BusVolt >> 3) * OffsetCurrent)/125 + 6;
Power = INA219_GetPower(); //获取功率
if(Power > OffsetPower)
Power -= OffsetPower;
else
Power = 0;
Ascii[0]=Power/10000+48;
Ascii[1]=(Power%10000)/1000+48;
Ascii[2]='.'; //显示小数点
Ascii[3]=(Power%1000)/100+48;
Ascii[4]=(Power%100)/10+48;
Ascii[5]=Power%10+48;
SendString("\r\n功率");
SendString(Ascii); //发送数据字符串
}
普通IO模拟I2C读写INA219数据串口发送源码
|