修改浮充为固定一个电压输出(未测试)

This commit is contained in:
起床就犯困 2024-09-20 15:04:41 +08:00
parent fbc0117da7
commit 16e9dbf3a0
22 changed files with 11956 additions and 11706 deletions

View File

@ -52,10 +52,12 @@ typedef struct _config_info{
uint16_t stopSolarOpenCircuitV; /* 太阳能板开路电压高于该(电压 / 100)停止充电 */
uint16_t constantVoltageChargeV; /* 恒压充电时的输出电压 */
uint16_t trickleChargeC; /* 涓流充电电流 */
uint16_t FloatTime; /* 浮充时间(秒) */
// uint16_t FloatTime; /* 浮充时间(秒) */
uint16_t FloatV; /* 浮充电压 */
uint16_t checkSolarOpenCircuitVTime; /* 启动任务中太阳能板开路电压检测时间 */
uint16_t registerRefreshTime; /* 寄存器数据刷新时间 */
uint16_t resRefreshTime; /* 线阻计算间隔时长 */
uint16_t loopImpedance; /* 回路阻抗大小 */
// uint16_t resRefreshTime; /* 回路阻抗计算间隔时长 */
uint16_t sensorEnableBroadcastTime; /* 传感器运行再次注册的间隔 */
uint16_t HighSideMosTemperature_stop; /* 当上桥温度达到该值时,停止输出 */
uint16_t HighSideMosTemperature_end; /* 当上桥温度上升到该值时,降低功率运行 */

View File

@ -228,8 +228,8 @@ typedef struct _SL_Mppt_para{
float_t Battery_Voltage; /* 电池电压 */
float_t Charg_Current; /* 充电电流(流向电池+负载) */
float_t Discharg_Current; /* 放电电流(流向负载) */
float_t Input_Voltage; /* 太阳能开路电压 */
float_t Solar_Open_Circuit_Voltage; /* 太阳能开路电压 */
float_t Input_Voltage; /* 太阳能板输出电压 */
float_t Solar_Open_Circuit_Voltage; /* 太阳能开路电压 */
float_t HighSideMos_Temperature; /* 高端mos的温度 */
uint16_t DischargMos_State; /* 放电mos的状态 */
uint16_t MPPT_Mode; /* 工作模式 */

View File

@ -44,7 +44,7 @@ extern STR_TimeSliceOffset m_wdi;
extern void Task_wdi(void);
#define refreshRegister_reloadVal 1000 /* 任务执行间隔 */
#define refreshRegister_offset 0 /* 任务执行偏移量 */
#define refreshRegister_offset 100 /* 任务执行偏移量 */
extern STR_TimeSliceOffset m_refreshRegister;
extern uint8_t overTemperature;
extern void Task_refreshRegister(void);

View File

@ -11,16 +11,18 @@
config_info g_slConfigInfo = {
.constantCurrentV = 1000,
.constantVoltageV = 1400,
.floatI = 5,
.constantVoltageV = 1420,
.floatI = 20,
.startSolarOpenCircuitV = 1700,
.stopSolarOpenCircuitV = 1500,
.constantVoltageChargeV = 1440,
.trickleChargeC = 100,
.FloatTime = 3,
// .FloatTime = 10,
.FloatV = 1420,
.checkSolarOpenCircuitVTime = 10,
.registerRefreshTime = 1,
.resRefreshTime = 1,
.loopImpedance = 20,
// .resRefreshTime = 1,
.sensorEnableBroadcastTime = 20,
.HighSideMosTemperature_stop = 70,
.HighSideMosTemperature_end = 50,

View File

@ -248,7 +248,65 @@ void mppt_constantVoltage(float InVoltage)
}
/**
* @brief ºã¨Êä³öµçѹ
* @brief ()
* @param
* @retval
*
*/
void mppt_constantVoltageB(float OutVoltage)
{
// static uint8_t ConstantVoltageFlag = 1;
// float PV1_V = get_PV_VOLT_OUT();
//
// if (ConstantVoltageFlag) {
// if (PV1_V > OutVoltage) {
// g_duty_ratio -= step1_pwm;
// Set_duty_ratio(&g_duty_ratio);
// } else {
// g_duty_ratio += step1_pwm;
// Set_duty_ratio(&g_duty_ratio);
// }
//
// if (PV1_V - OutVoltage < 0.1) {
// ConstantVoltageFlag = 0;
// }
// } else {
// if (PV1_V > OutVoltage) {
// g_duty_ratio -= step2_pwm;
// Set_duty_ratio(&g_duty_ratio);
// } else {
// g_duty_ratio += step2_pwm;
// Set_duty_ratio(&g_duty_ratio);
// }
//
// if (PV1_V - OutVoltage > 0.1) {
// ConstantVoltageFlag = 1;
// }
// }
// static float_t kp = 0.0005;
// static float_t ki = 0.000001;
static float_t kp = 0.005;
static float_t ki = 0.00001;
// static float_t kp = 0.1;
// static float_t ki = 0.001;
// float_t outVolt = get_PV_VOLT_OUT();
float_t outVolt = g_Mppt_Para.Battery_Voltage;
// float_t outVolt = voltOut;
// float_t error = outVolt - OutVoltage;
float_t error = OutVoltage - outVolt;
float_t stepPwm = kp * error + ki * outVolt;
g_duty_ratio += stepPwm;
// printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
Set_duty_ratio(&g_duty_ratio);
}
/**
* @brief
* @param
* @retval
*
@ -284,13 +342,15 @@ void mppt_constantVoltageO(float OutVoltage)
// }
// }
static float_t kp = 0.0005;
static float_t ki = 0.000001;
// static float_t kp = 0.0005;
// static float_t ki = 0.000001;
static float_t kp = 0.005;
static float_t ki = 0.00001;
// static float_t kp = 0.1;
// static float_t ki = 0.001;
// float_t outVolt = get_PV_VOLT_OUT();
float_t outVolt = g_Mppt_Para.Battery_Voltage;
float_t outVolt = g_Mppt_Para.Output_Voltage;
// float_t outVolt = voltOut;
// float_t error = outVolt - OutVoltage;
float_t error = OutVoltage - outVolt;
@ -406,7 +466,7 @@ void TrickleCharge(void)
TrickleChargeC = (float_t)g_slConfigInfo.trickleChargeC / 100;
onlyOnce = 0;
}
printf("Trickle\n");
// printf("Trickle\n");
mppt_constantCurrentO(TrickleChargeC + g_Mppt_Para.Discharg_Current);
}
@ -450,22 +510,33 @@ void ConstantVoltageCharge(void)
*/
void FloatingCharge(void)
{
static uint32_t num = 0;
static uint32_t numLenFlag;
// static uint32_t num = 0;
// static uint32_t numLenFlag;
// static uint8_t onlyOnce = 1;
// if (onlyOnce) {
// numLenFlag = g_slConfigInfo.FloatTime * 1000;
// onlyOnce = 0;
// }
// printf("float\n");
// TIM_SetCompare4(TIM4, 0);
// if (numLenFlag == ++num) {
// num = 0;
// for (int var = 0; var < 10; ++var) {
// ConstantVoltageCharge();
// }
// g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
// printf("float\n");
// }
static float_t ConstantVoltageChargeV;
static uint8_t onlyOnce = 1;
if (onlyOnce) {
numLenFlag = g_slConfigInfo.FloatTime * 1000;
ConstantVoltageChargeV = (float_t)g_slConfigInfo.FloatV / 100;
onlyOnce = 0;
}
printf("float\n");
TIM_SetCompare4(TIM4, 0);
if (numLenFlag == ++num) {
num = 0;
ConstantVoltageCharge();
g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
}
mppt_constantVoltageO(ConstantVoltageChargeV);
}
@ -553,6 +624,7 @@ void MpptMode(void)
ConstantCurrentV = (float)g_slConfigInfo.constantCurrentV / 100;
ConstantVoltageV = (float)g_slConfigInfo.constantVoltageV / 100;
FloatI = (float)g_slConfigInfo.floatI / 100;
printf("FloatI: %d / 100 \n", (int)(FloatI * 100));
StopSolarOpenCircuitV = (float)g_slConfigInfo.stopSolarOpenCircuitV / 100;
only_once = 0;
}
@ -643,6 +715,7 @@ void MpptMode(void)
return;
}
// if (((g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < 0.03
// && g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current < 0.03)
// && (g_Mppt_Para.Battery_Voltage < ConstantVoltageV - 1
@ -662,7 +735,8 @@ void MpptMode(void)
|| g_Mppt_Para.Battery_Voltage > 16 || g_Mppt_Para.Battery_Voltage < 8) {
// || g_Mppt_Para.MPPT_Mode == NoBattery) {
// g_Mppt_Para.MPPT_Mode = NoBattery;
g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
// g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
g_Mppt_Para.MPPT_Mode = FLOAT;
return;
}
@ -677,20 +751,29 @@ void MpptMode(void)
// return;
// }
if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage) &&
(FloatI > g_Mppt_Para.Charg_Current))) {
g_Mppt_Para.MPPT_Mode = FLOAT;
// if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage)
// &&(FloatI + 0.1 <= g_Mppt_Para.Charg_Current))
// || (FloatI + 0.1 <= g_Mppt_Para.Discharg_Current)) {
//// || (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < 0.03
//// && g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current < 0.03)) {
//
//// printf("mppt mode \n");
//// printf(" vout : %d/100 \n", (int)(g_Mppt_Para.Battery_Voltage * 100));
// g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
// return;
// }
if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage)
&&(FloatI + 0.1 <= g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current))) {
g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
return;
}
if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage)
&&(FloatI + 0.1 <= g_Mppt_Para.Charg_Current))) {
// || (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < 0.03
// && g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current < 0.03)) {
// printf("mppt mode \n");
// printf(" vout : %d/100 \n", (int)(g_Mppt_Para.Battery_Voltage * 100));
g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
if ((((ConstantVoltageV < g_Mppt_Para.Battery_Voltage)
&& (FloatI > g_Mppt_Para.Charg_Current))
&& (FloatI > g_Mppt_Para.Discharg_Current))
|| g_Mppt_Para.MPPT_Mode == FLOAT) {
g_Mppt_Para.MPPT_Mode = FLOAT;
return;
}
@ -699,7 +782,6 @@ void MpptMode(void)
return;
}
}
void findMiNDutyRatio(void)
@ -747,15 +829,20 @@ void test(void)
// static float_t Volt = 0.7;
// static float_t Curr = 5.5;
static float_t Res = 0.7 / 5.5;
static float_t inBatteryCurr;
inBatteryCurr = g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current;
if (inBatteryCurr > 0.5) {
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage - inBatteryCurr * Res;
static float_t loopImpedance;
static uint8_t onlyone = 1;
if (onlyone) {
loopImpedance = (float_t)g_slConfigInfo.loopImpedance / 100;
}
static float_t inBatteryCurr;
inBatteryCurr = g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current;
if (inBatteryCurr > 0.1) {
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage - inBatteryCurr * loopImpedance;
} else {
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
}
// mppt_constantVoltage(18);

View File

@ -72,7 +72,6 @@ void Task_RunLED(void)
// printf(" 0.没有工作; 1.涓流模式; 2.恒流模式; 3.恒压模式; 4.浮充模式; 5.没有电池 : %d \n", g_Mppt_Para.MPPT_Mode);
//
// printf(" \n");
// uart_sendstr(g_bat485_uart3_handle, " \n");
uart_dev_write(g_bat485_uart3_handle, " \n", sizeof(" \n"));
@ -82,6 +81,10 @@ void Task_RunLED(void)
sprintf(buffer, " duty_ratio : %d/1000 \n", (int)(g_duty_ratio * 1000));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " Input_Voltage : %d/100 \n", (int)(g_Mppt_Para.Input_Voltage * 100));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
memset(buffer, 0, sizeof(buffer));
sprintf(buffer, " vout : %d/100 \n", (int)(g_Mppt_Para.Output_Voltage * 100));
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
@ -191,7 +194,6 @@ void Task_softStart(void)
Set_duty_ratio(&g_duty_ratio);
TimeSliceOffset_Unregister(&m_softStart);
start_mpptWork();
return;
}
@ -251,12 +253,19 @@ void Task_refreshRegister(void)
// g_Mppt_Para.Charg_Current = get_capturedata(get_CHG_CURR);
// g_Mppt_Para.Discharg_Current = get_capturedata(get_DSG_CURR);
// g_Mppt_Para.HighSideMos_Temperature = get_capturedata(get_MOSFET_Temper);
g_Mppt_Para.Battery_Voltage = get_PV_VOLT_OUT();
// g_Mppt_Para.Battery_Voltage = get_PV_VOLT_OUT();
g_Mppt_Para.Output_Voltage = get_PV_VOLT_OUT();
g_Mppt_Para.Charg_Current = get_CHG_CURR();
g_Mppt_Para.Discharg_Current = get_DSG_CURR();
g_Mppt_Para.HighSideMos_Temperature = get_MOSFET_Temper();
g_Mppt_Para.DischargMos_State = GPIO_ReadOutputDataBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN)
&& GPIO_ReadInputDataBit(DSG_PROT_GPIO, DSG_PROT_PIN);
if (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < -0.1) {
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage
- (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current)
* (float_t)g_slConfigInfo.loopImpedance / 100;
}
// g_Mppt_Para.DischargMos_State = GPIO_ReadOutputDataBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN);
// g_Mppt_Para.Solar_Open_Circuit_Voltage = get_capturedata(get_PV1_VOLT_IN);
g_Mppt_Para.Solar_Open_Circuit_Voltage = get_PV1_VOLT_IN();
@ -404,6 +413,9 @@ void Task_impedanceCalculation(void)
num = 0;
TIM_Cmd(TIM3, DISABLE);
TIM_SetCompare4(TIM4, 300);
Delay_Ms(500);
TIM_SetCompare4(TIM4, 420);
Delay_Ms(5);
// currOne = get_capturedata(get_CHG_CURR) - get_capturedata(get_DSG_CURR);
@ -411,8 +423,6 @@ void Task_impedanceCalculation(void)
currOne = get_CHG_CURR() - get_DSG_CURR();
voltOne = get_PV_VOLT_OUT();
TIM_SetCompare4(TIM4, 300);
Delay_Ms(5);
// currTwo = get_capturedata(get_CHG_CURR) - get_capturedata(get_DSG_CURR);
// voltTwo = get_capturedata(get_PV_VOLT_OUT);
currTwo = get_CHG_CURR() - get_DSG_CURR();
@ -424,7 +434,7 @@ void Task_impedanceCalculation(void)
printf("currTwo = %d/1000, voltTwo = %d/100 \n", (int)(currTwo * 1000), (int)(voltTwo * 100));
printf("Res = %d/1000, E = %d/100 \n", (int)(g_impedance * 1000), (int)((voltTwo - currTwo * g_impedance) * 100));
TIM_Cmd(TIM3, ENABLE);
// TIM_Cmd(TIM3, ENABLE);
}
return;
@ -573,6 +583,6 @@ void hardware_Init(void)
// Set_duty_ratio(&g_duty_ratio);
uart_dev_write(g_bat485_uart3_handle, " hello world \n", sizeof(" hello world \n"));
TIM3_Init(1);
TIM3_Init(10);
}

View File

@ -66,4 +66,10 @@ void DSG_PROT_Init(void);
#define EnPowerSupply_PIN GPIO_Pin_3
void EnPowerSupply_Init(void);
/* 电压低于11V进入中断 */
/* WORK_VOLT_INT --> PA12 */
#define WORK_VOLT_INT_GPIO GPIOA
#define WORK_VOLT_INT_PIN GPIO_Pin_12
void WORK_VOLT_INT_Init(void);
#endif /* HARDWARE_INC_GPIO_H_ */

View File

@ -132,5 +132,37 @@ void EnPowerSupply_Init(void)
GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, RESET);
}
void EXTI1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void WORK_VOLT_INT_Init(void)
{
RCC_PB2PeriphClockCmd(RCC_PB2Periph_AFIO | RCC_PB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = WORK_VOLT_INT_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
GPIO_Init(WORK_VOLT_INT_GPIO, &GPIO_InitStructure);
/* GPIOA ----> EXTI_Line1 */
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource12); //指定中断/事件线的输入源实际上是设定外部中断配置寄存器AFIO_EXTICRx的值此处为PA12
EXTI_InitStructure.EXTI_Line = EXTI_Line1; //EXTI中断/事件线选择此处选择EXTI_Line1
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //EXTI模式选择此处选择为产生中断模式
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //EXTI边沿触发事件此处选择为下降沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能EXTI线
EXTI_Init(&EXTI_InitStructure);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn; //使能EXTI2中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //设置抢占优先级为1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //设置子优先级为2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
NVIC_Init(&NVIC_InitStructure); //中断优先级分组初始化
}
void EXTI1_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line1)==SET) { //EXTI_GetITStatus用来获取中断标志位状态如果EXTI线产生中断则返回SET否则返回RESET
}
}

View File

@ -52,8 +52,8 @@ void PWM_TIM_Configuration(void)
void Set_duty_ratio(float *duty_ratio)
{
if (*duty_ratio < 0.1) {
*duty_ratio = 0.1;
if (*duty_ratio < 0.05) {
*duty_ratio = 0.05;
// return;
} else if (*duty_ratio > 0.9) {
*duty_ratio = 0.9;

View File

@ -23,7 +23,7 @@ void TIM3_Init(uint16_t delay_ms)
/* 分频系数 */
uint16_t psc = (SystemCoreClock / 10000) - 1;
/* 周期数 */
uint16_t arr = delay_ms * 10 - 1;
uint16_t arr = delay_ms * 1 - 1;
TIM3_Int_Init(arr, psc);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff