2024-12-06 09:38:25 +00:00
|
|
|
|
|
|
|
|
|
#include "parameter.h"
|
2024-12-07 09:52:46 +00:00
|
|
|
|
#include "FM_TIM.h"
|
|
|
|
|
#include "FM_GPIO.h"
|
|
|
|
|
#include "capture.h"
|
2024-12-26 03:48:54 +00:00
|
|
|
|
#include "bl_chargControl.h"
|
2024-12-07 09:52:46 +00:00
|
|
|
|
|
2024-12-06 09:38:25 +00:00
|
|
|
|
config_parameter g_cfgParameter = {0};
|
2024-12-07 09:52:46 +00:00
|
|
|
|
static otherParameter g_otherParameter = {0};
|
|
|
|
|
|
2025-01-03 09:25:26 +00:00
|
|
|
|
static BOOL batteryState = FALSE; /* 有无电池(估计) */
|
|
|
|
|
static float dutyRatio = 0; /* 占空比 */
|
2025-01-08 09:50:37 +00:00
|
|
|
|
static uint8_t mosTemperState = mosTemperFull; /* mos管温度状态 */
|
2025-01-03 09:25:26 +00:00
|
|
|
|
static BOOL checkImpedanceState = FALSE; /* 启动后是否进行了回路阻抗检测 */
|
|
|
|
|
static timeInfo lastTime = {0}; /* 上次读取充放电量参数的时间 */
|
2024-12-07 09:52:46 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 获取电池状态
|
|
|
|
|
* @param
|
|
|
|
|
* @retval batteryState电池状态 FALSE:无
|
|
|
|
|
* TRUE: 有
|
|
|
|
|
*/
|
|
|
|
|
BOOL getBatteryState(void)
|
|
|
|
|
{
|
|
|
|
|
return batteryState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置电池状态
|
|
|
|
|
* @param state 电池状态
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void setBatteryState(BOOL state)
|
|
|
|
|
{
|
|
|
|
|
if (state != TRUE && state != FALSE) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
batteryState = state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 获取占空比大小
|
|
|
|
|
* @param
|
|
|
|
|
* @retval dutyRatio 占空比
|
|
|
|
|
*/
|
|
|
|
|
float getDutyRatio(void)
|
|
|
|
|
{
|
|
|
|
|
return dutyRatio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置占空比大小,在一个范围内,不能设置为0,1等
|
|
|
|
|
* @param dutyRatio 占空比
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setDutyRatio(float DutyRatio)
|
|
|
|
|
{
|
2024-12-24 06:43:20 +00:00
|
|
|
|
if (DutyRatio > 0.95f) {
|
|
|
|
|
dutyRatio = 0.95f;
|
2024-12-07 09:52:46 +00:00
|
|
|
|
}
|
|
|
|
|
else if (DutyRatio < 0.05f) {
|
|
|
|
|
dutyRatio = 0.05f;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
dutyRatio = DutyRatio;
|
2024-12-24 06:43:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 09:52:46 +00:00
|
|
|
|
set_pwmDutyRatio(dutyRatio);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置占空比大小为0,同时关闭pwm下桥的输出
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setDutyRatioToZero(void)
|
|
|
|
|
{
|
|
|
|
|
EN_PWMOUT_Diseable();
|
|
|
|
|
dutyRatio = 0;
|
|
|
|
|
set_pwmDutyRatio(dutyRatio);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-11 09:51:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 获取mos管温度状态
|
|
|
|
|
* @param
|
|
|
|
|
* @retval mosTemperState mos管温度状态
|
|
|
|
|
*/
|
|
|
|
|
uint8_t getMosTemperState(void)
|
|
|
|
|
{
|
|
|
|
|
return mosTemperState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置mos管温度状态
|
|
|
|
|
* @param state 需要设置的mos管状态
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setMosTemperState(uint8_t state)
|
|
|
|
|
{
|
2025-01-08 09:50:37 +00:00
|
|
|
|
if (state == mosTemperFull || state == mosTemperReduce || state == mosTemperStop) {
|
2024-12-11 09:51:48 +00:00
|
|
|
|
mosTemperState = state;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 获取回路阻抗检测状态
|
|
|
|
|
* @param
|
|
|
|
|
* @retval checkImpedanceState FALSE:未检测或检测失败
|
|
|
|
|
* TRUE: 检测成功
|
|
|
|
|
*/
|
|
|
|
|
BOOL getCheckImpedanceState(void)
|
|
|
|
|
{
|
|
|
|
|
return checkImpedanceState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 回路阻抗检测成功后设置回路阻抗检测状态
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void setCheckImpedanceState(void)
|
|
|
|
|
{
|
|
|
|
|
checkImpedanceState = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 06:43:20 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置上次读取充放电量参数的时间
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void setLastTime(timeInfo time)
|
|
|
|
|
{
|
|
|
|
|
lastTime = time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置上次读取充放电量参数的时间
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
timeInfo getLastTime(void)
|
|
|
|
|
{
|
|
|
|
|
return lastTime;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-07 09:52:46 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 得到电池电压
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 电池电压
|
|
|
|
|
*/
|
|
|
|
|
float getBatteryVoltage(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.Battery_Voltage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置电池电压
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setBatteryVoltage(void)
|
|
|
|
|
{
|
|
|
|
|
g_otherParameter.Battery_Voltage = g_otherParameter.Output_Voltage
|
2025-01-08 09:50:37 +00:00
|
|
|
|
- getChargBatteryCurrent() * getLoopImpedance();
|
2024-12-07 09:52:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 得到输出电压
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 输出电压
|
|
|
|
|
*/
|
|
|
|
|
float getOutputVoltage(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.Output_Voltage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置输出电压
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setOutputVoltage(void)
|
|
|
|
|
{
|
|
|
|
|
g_otherParameter.Output_Voltage = get_PV_VOLT_OUT() ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 得到充电电流
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 充电电流
|
|
|
|
|
*/
|
|
|
|
|
float getChargCurrent(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.Charg_Current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置充电电流
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setChargCurrent(void)
|
|
|
|
|
{
|
|
|
|
|
g_otherParameter.Charg_Current = get_CHG_CURR();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 得到放电电流
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 放电电流
|
|
|
|
|
*/
|
|
|
|
|
float getDischargCurrent(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.Discharg_Current;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置放电电流
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setDischargCurrent(void)
|
|
|
|
|
{
|
|
|
|
|
g_otherParameter.Discharg_Current = get_DSG_CURR();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 得到系统输入电压
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 系统输入电压
|
|
|
|
|
*/
|
|
|
|
|
float getInputVoltage(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.Input_Voltage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置系统输入电压
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setInputVoltage(void)
|
|
|
|
|
{
|
2024-12-11 09:51:48 +00:00
|
|
|
|
g_otherParameter.Input_Voltage = get_PV_VOLT_IN1();
|
2024-12-07 09:52:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 返回太阳能开路电压(不具备实时性)
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 太阳能开路电压
|
|
|
|
|
*/
|
|
|
|
|
float getSolarOpenCircuitVoltage(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.Solar_Open_Circuit_Voltage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置太阳能开路电压(特定情况下才能测量)
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setSolarOpenCircuitVoltage(void)
|
|
|
|
|
{
|
|
|
|
|
g_otherParameter.Solar_Open_Circuit_Voltage = get_PV1_VOLT_IN();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 返回mos管的温度
|
|
|
|
|
* @param
|
|
|
|
|
* @retval mos管的温度
|
|
|
|
|
*/
|
|
|
|
|
float getHighSideMosTemperature(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.HighSideMos_Temperature;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置mos管温度
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setHighSideMosTemperature(void)
|
|
|
|
|
{
|
|
|
|
|
g_otherParameter.HighSideMos_Temperature = get_MOSFET_Temper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 返回太阳能板输出电压
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 太阳能板输出电压
|
|
|
|
|
*/
|
|
|
|
|
float getSolarInCircuitVoltage(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.Solar_In_Circuit_Voltage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置太阳能板输出电压
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setSolarInCircuitVoltage(void)
|
|
|
|
|
{
|
|
|
|
|
g_otherParameter.Solar_In_Circuit_Voltage = get_PV1_VOLT_IN();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 得到总用电量
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 总用电量
|
|
|
|
|
*/
|
|
|
|
|
float getTotalElectricityConsumption(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.totalElectricityConsumption;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置总用电量
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setTotalElectricityConsumption(void)
|
|
|
|
|
{
|
2024-12-14 09:52:26 +00:00
|
|
|
|
g_otherParameter.totalElectricityConsumption += g_otherParameter.Discharg_Current / 3600000.0f;
|
2024-12-07 09:52:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 初始化总用电量
|
|
|
|
|
* @param totalPower 初始值
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void totalElectricityConsumptionInt(float totalPower)
|
|
|
|
|
{
|
|
|
|
|
g_otherParameter.totalElectricityConsumption = totalPower;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 得到总充电量
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 总用电量
|
|
|
|
|
*/
|
|
|
|
|
float getTotalChargCapacity(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.totalChargCapacity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置总充电量
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setTotalChargCapacity(void)
|
|
|
|
|
{
|
2024-12-14 09:52:26 +00:00
|
|
|
|
g_otherParameter.totalChargCapacity += g_otherParameter.Charg_Current / 3600000.0f;
|
2024-12-07 09:52:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 初始化总充电量
|
|
|
|
|
* @param totalPower 初始值
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void totalChargCapacityInt(float totalPower)
|
|
|
|
|
{
|
|
|
|
|
g_otherParameter.totalChargCapacity = totalPower;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 得到电池电量
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 电池电量
|
|
|
|
|
*/
|
|
|
|
|
float getSOC(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.SOC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置电池电量
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setSOC(void)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 得到工作模式
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 工作模式
|
|
|
|
|
*/
|
|
|
|
|
int getMPPT_Mode(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.MPPT_Mode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置工作模式
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setMPPT_Mode(int MPPT_Mode)
|
|
|
|
|
{
|
|
|
|
|
g_otherParameter.MPPT_Mode = MPPT_Mode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 得到流向电池的电流
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 流向电池的电流
|
|
|
|
|
*/
|
|
|
|
|
float getChargBatteryCurrent(void)
|
|
|
|
|
{
|
|
|
|
|
return (g_otherParameter.Charg_Current - g_otherParameter.Discharg_Current);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 得到充电开关状态
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 充电开关状态
|
|
|
|
|
*/
|
|
|
|
|
BOOL getChargMosState(void)
|
|
|
|
|
{
|
|
|
|
|
if (getDutyRatio() > 0 && getDutyRatio() < 1) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置充电开关状态
|
|
|
|
|
* @param state 开关状态,FALSE 关闭
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setChargMosState(BOOL state)
|
|
|
|
|
{
|
|
|
|
|
if (state == FALSE) {
|
|
|
|
|
/* 关闭充电 */
|
2024-12-24 06:43:20 +00:00
|
|
|
|
stopChargWork();
|
2024-12-07 09:52:46 +00:00
|
|
|
|
} else if (state == TRUE) {
|
|
|
|
|
/* 打开充电 */
|
2024-12-24 06:43:20 +00:00
|
|
|
|
beginChargWork();
|
2024-12-07 09:52:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 得到放电状态
|
|
|
|
|
* @param
|
|
|
|
|
* @retval state 状态,FALSE 关闭
|
|
|
|
|
*/
|
|
|
|
|
BOOL getDischargMosState(void)
|
|
|
|
|
{
|
2025-01-08 09:50:37 +00:00
|
|
|
|
if (g_cfgParameter.powerBoxType) {
|
2024-12-07 09:52:46 +00:00
|
|
|
|
return readOnlyPowerOutputState();
|
|
|
|
|
} else {
|
|
|
|
|
return readOutputState();
|
2024-12-11 09:51:48 +00:00
|
|
|
|
}
|
2024-12-07 09:52:46 +00:00
|
|
|
|
}
|
2024-12-06 09:38:25 +00:00
|
|
|
|
|
2024-12-07 09:52:46 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 得到软件版本号
|
|
|
|
|
* @param
|
|
|
|
|
* @retval softVer 软件版本号
|
|
|
|
|
*/
|
2025-01-08 09:50:37 +00:00
|
|
|
|
uint8_t *getVersionnInformation(void)
|
2024-12-07 09:52:46 +00:00
|
|
|
|
{
|
|
|
|
|
return softVer;
|
|
|
|
|
}
|
2024-12-06 09:38:25 +00:00
|
|
|
|
|
2025-01-08 09:50:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief 得到回路阻抗大小
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 回路阻抗大小
|
|
|
|
|
*/
|
|
|
|
|
float getLoopImpedance(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.loopImpedance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置回路阻抗大小
|
|
|
|
|
* @param loopImpedance 回路阻抗大小
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
BOOL setLoopImpedance(float loopImpedance)
|
|
|
|
|
{
|
|
|
|
|
/* 读取的回路阻抗偏差过大则不使用 */
|
|
|
|
|
if (loopImpedance < 0 || loopImpedance > 0.3f) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_otherParameter.loopImpedance = loopImpedance;
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 得到注册状态
|
|
|
|
|
* @param
|
|
|
|
|
* @retval 注册状态
|
|
|
|
|
*/
|
|
|
|
|
uint16_t getRegistrationStatus(void)
|
|
|
|
|
{
|
|
|
|
|
return g_otherParameter.Registration_Status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 设置注册状态
|
|
|
|
|
* @param 注册状态
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
void setRegistrationStatus(uint16_t status)
|
|
|
|
|
{
|
|
|
|
|
if (status == UNREGISTER || status == REGISTER_FAIL || status == REGISTER_SUCCESS) {
|
|
|
|
|
g_otherParameter.Registration_Status = status;
|
|
|
|
|
}
|
|
|
|
|
}
|