2024-07-11 06:58:55 +00:00
|
|
|
|
/*
|
|
|
|
|
* mppt_control.c
|
|
|
|
|
*
|
|
|
|
|
* Created on: 2024<EFBFBD><EFBFBD>6<EFBFBD><EFBFBD>29<EFBFBD><EFBFBD>
|
|
|
|
|
* Author: psx
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "mppt_control.h"
|
|
|
|
|
#include "collect_Conversion.h"
|
|
|
|
|
#include "pwm.h"
|
|
|
|
|
#include "inflash.h"
|
2024-07-22 06:20:24 +00:00
|
|
|
|
#include "gpio.h"
|
2024-08-29 02:50:22 +00:00
|
|
|
|
#include "sl_protocol.h"
|
|
|
|
|
#include "task.h"
|
2024-07-11 06:58:55 +00:00
|
|
|
|
|
2024-08-17 03:14:19 +00:00
|
|
|
|
#include "uart_dev.h"
|
|
|
|
|
|
2024-07-12 09:02:26 +00:00
|
|
|
|
static void TrickleCharge(void);
|
|
|
|
|
static void ConstantCurrentCharge(void);
|
|
|
|
|
static void ConstantVoltageCharge(void);
|
|
|
|
|
static void FloatingCharge(void);
|
2024-09-18 01:47:44 +00:00
|
|
|
|
//static void NoBatteryCharge(void);
|
2024-08-29 02:50:22 +00:00
|
|
|
|
|
2024-07-12 09:02:26 +00:00
|
|
|
|
|
2024-08-05 02:35:10 +00:00
|
|
|
|
/* ռ<>ձ<EFBFBD> */
|
2024-09-28 08:07:51 +00:00
|
|
|
|
float g_duty_ratio = 0.75;
|
2024-08-05 02:35:10 +00:00
|
|
|
|
/* <20><><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ */
|
2024-08-29 02:50:22 +00:00
|
|
|
|
//static uint8_t modeFlag = 2;
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
2024-07-11 06:58:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval OutputPower <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
static float Get_OutputPower(void)
|
|
|
|
|
{
|
|
|
|
|
static float OutputPower;
|
|
|
|
|
static float V_out, I_out;
|
|
|
|
|
|
|
|
|
|
V_out = get_PV_VOLT_OUT();
|
|
|
|
|
I_out = get_CHG_CURR();
|
|
|
|
|
|
|
|
|
|
OutputPower = V_out * I_out;
|
|
|
|
|
|
|
|
|
|
printf(" V = %d/100, I = %d/10000, OutputPower = %d/10000 \r\n",
|
|
|
|
|
(int)(V_out*100), (int)(I_out * 10000), (int)(OutputPower * 10000));
|
|
|
|
|
|
|
|
|
|
return OutputPower;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ʹ<EFBFBD>õ<EFBFBD>Ϊ<EFBFBD>Ŷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŷ<EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ,ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*/
|
|
|
|
|
/* pwmռ<6D>ձȵ<D5B1><C8B5>ڲ<EFBFBD><DAB2><EFBFBD> */
|
|
|
|
|
const float step1_pwm = 0.01;
|
2024-08-05 02:35:10 +00:00
|
|
|
|
const float step2_pwm = 0.005;
|
2024-07-11 06:58:55 +00:00
|
|
|
|
//#define array_num 10
|
|
|
|
|
void mppt_readJust(void)
|
|
|
|
|
{
|
2024-07-24 08:57:38 +00:00
|
|
|
|
// static float last_duty_ratio = 0.5;
|
|
|
|
|
// static float now_duty_ratio;
|
|
|
|
|
// static float last_OutputPower;
|
|
|
|
|
// static float now_OutputPower;
|
|
|
|
|
// static float step_pwm = step1_pwm;
|
|
|
|
|
//
|
|
|
|
|
// last_OutputPower = Get_OutputPower();
|
|
|
|
|
//
|
|
|
|
|
// printf(" duty_ratio = %d/1000 \r\n", (int)(last_duty_ratio * 1000));
|
|
|
|
|
//
|
|
|
|
|
// /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ鿴<DAB2><E9BFB4><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
// now_duty_ratio = last_duty_ratio + step_pwm;
|
|
|
|
|
// if (now_duty_ratio > 1) {
|
|
|
|
|
// now_duty_ratio = 1;
|
|
|
|
|
// }
|
|
|
|
|
// Set_duty_ratio(now_duty_ratio);
|
|
|
|
|
// now_OutputPower = Get_OutputPower();
|
|
|
|
|
// if (now_OutputPower > last_OutputPower) {
|
|
|
|
|
// printf(" now_OutputPower > last_OutputPower1 \r\n");
|
|
|
|
|
// last_duty_ratio = now_duty_ratio;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ鿴<DAB2><E9BFB4><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
// now_duty_ratio = last_duty_ratio - step_pwm;
|
|
|
|
|
// if (now_duty_ratio < 0) {
|
|
|
|
|
// now_duty_ratio = 0;
|
|
|
|
|
// }
|
|
|
|
|
// Set_duty_ratio(now_duty_ratio);
|
|
|
|
|
// now_OutputPower = Get_OutputPower();
|
|
|
|
|
// if (now_OutputPower > last_OutputPower) {
|
|
|
|
|
// printf(" now_OutputPower > last_OutputPower2 \r\n");
|
|
|
|
|
// last_duty_ratio = now_duty_ratio;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹ<EFBFBD><DAB9>ʾ<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>Ϊԭ<CEAA><D4AD><EFBFBD>ĵ<EFBFBD> */
|
|
|
|
|
// Set_duty_ratio(last_duty_ratio);
|
2024-08-05 02:35:10 +00:00
|
|
|
|
// step_pwm = step2_pwm;
|
2024-07-24 08:57:38 +00:00
|
|
|
|
|
2024-07-11 06:58:55 +00:00
|
|
|
|
static float last_duty_ratio = 0.5;
|
|
|
|
|
static float last_OutputPower;
|
|
|
|
|
static float now_OutputPower;
|
|
|
|
|
static float step_pwm = step1_pwm;
|
|
|
|
|
|
|
|
|
|
last_OutputPower = Get_OutputPower();
|
|
|
|
|
|
|
|
|
|
printf(" duty_ratio = %d/1000 \r\n", (int)(last_duty_ratio * 1000));
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ鿴<DAB2><E9BFB4><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
2024-08-05 02:35:10 +00:00
|
|
|
|
g_duty_ratio = last_duty_ratio + step_pwm;
|
|
|
|
|
|
|
|
|
|
Set_duty_ratio(&g_duty_ratio);
|
2024-07-11 06:58:55 +00:00
|
|
|
|
now_OutputPower = Get_OutputPower();
|
|
|
|
|
if (now_OutputPower > last_OutputPower) {
|
|
|
|
|
printf(" now_OutputPower > last_OutputPower1 \r\n");
|
2024-08-05 02:35:10 +00:00
|
|
|
|
last_duty_ratio = g_duty_ratio;
|
2024-07-11 06:58:55 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ鿴<DAB2><E9BFB4><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
2024-08-05 02:35:10 +00:00
|
|
|
|
g_duty_ratio = last_duty_ratio - step_pwm;
|
|
|
|
|
Set_duty_ratio(&g_duty_ratio);
|
2024-07-11 06:58:55 +00:00
|
|
|
|
now_OutputPower = Get_OutputPower();
|
|
|
|
|
if (now_OutputPower > last_OutputPower) {
|
|
|
|
|
printf(" now_OutputPower > last_OutputPower2 \r\n");
|
2024-08-05 02:35:10 +00:00
|
|
|
|
last_duty_ratio = g_duty_ratio;
|
2024-07-11 06:58:55 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹ<EFBFBD><DAB9>ʾ<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ù<EFBFBD><C3B9><EFBFBD>Ϊԭ<CEAA><D4AD><EFBFBD>ĵ<EFBFBD> */
|
2024-08-05 02:35:10 +00:00
|
|
|
|
g_duty_ratio = last_duty_ratio;
|
|
|
|
|
Set_duty_ratio(&g_duty_ratio);
|
|
|
|
|
step_pwm = step2_pwm;
|
2024-07-11 06:58:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void printf_data(void)
|
|
|
|
|
{
|
|
|
|
|
printf("\n");
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// get_CHG_CURR();
|
|
|
|
|
// get_PV_VOLT_OUT();
|
|
|
|
|
// get_DSG_CURR();
|
2024-08-17 03:14:19 +00:00
|
|
|
|
// get_PV1_VOLT_IN();
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// get_PV_VOLT_IN1();
|
|
|
|
|
// get_MOSFET_Temper();
|
|
|
|
|
// get_PV2_VOLT_IN();
|
|
|
|
|
|
2024-07-11 06:58:55 +00:00
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 01:47:44 +00:00
|
|
|
|
//float_t get_capturedata(float_t (*fun)(void))
|
|
|
|
|
//{
|
|
|
|
|
// float_t temp1;
|
|
|
|
|
// float_t temp[3];
|
|
|
|
|
//
|
|
|
|
|
// for (int i = 0; i < 3; ++i) {
|
|
|
|
|
// temp[i] = fun();
|
|
|
|
|
//// Delay_Us(1);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (temp[0] > temp[1]) {
|
|
|
|
|
// temp1 = temp[0];
|
|
|
|
|
// temp[0] = temp[1];
|
|
|
|
|
// temp[1] = temp1;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (temp[0] > temp[2]) {
|
|
|
|
|
// temp1 = temp[0];
|
|
|
|
|
// temp[0] = temp[2];
|
|
|
|
|
// temp[2] = temp1;
|
|
|
|
|
// if (temp[1] > temp[2]) {
|
|
|
|
|
// temp1 = temp[1];
|
|
|
|
|
// temp[1] = temp[2];
|
|
|
|
|
// temp[2] = temp1;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// return temp[1];
|
|
|
|
|
//}
|
2024-08-29 02:50:22 +00:00
|
|
|
|
|
|
|
|
|
//uint16_t get_mpptMode(void)
|
|
|
|
|
//{
|
|
|
|
|
// return (uint16_t)modeFlag;
|
|
|
|
|
//}
|
|
|
|
|
|
2024-07-12 09:34:47 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD>㶨<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void mppt_constantVoltage(float InVoltage)
|
2024-07-11 06:58:55 +00:00
|
|
|
|
{
|
2024-08-17 03:14:19 +00:00
|
|
|
|
// static uint8_t ConstantVoltageFlag = 1;
|
|
|
|
|
// float PV1_V = get_PV1_VOLT_IN();
|
|
|
|
|
//
|
|
|
|
|
// if (ConstantVoltageFlag) {
|
|
|
|
|
// if (PV1_V > InVoltage) {
|
|
|
|
|
// 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 - InVoltage < 0.1) {
|
|
|
|
|
// ConstantVoltageFlag = 0;
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// if (PV1_V > InVoltage) {
|
|
|
|
|
// 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 - InVoltage > 0.1) {
|
|
|
|
|
// ConstantVoltageFlag = 1;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2024-07-12 09:34:47 +00:00
|
|
|
|
|
2024-08-23 08:50:34 +00:00
|
|
|
|
static float_t kp = 0.005;
|
|
|
|
|
static float_t ki = 0.00001;
|
2024-08-17 03:14:19 +00:00
|
|
|
|
// static float_t allError = 0;
|
2024-07-11 06:58:55 +00:00
|
|
|
|
|
2024-08-17 03:14:19 +00:00
|
|
|
|
// float_t error = (get_PV1_VOLT_IN()) - InVoltage;
|
|
|
|
|
// float_t error = InVoltage - (get_PV2_VOLT_IN());
|
|
|
|
|
// allError += error;
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// printf("111\n");
|
2024-07-22 06:20:24 +00:00
|
|
|
|
|
2024-09-18 01:47:44 +00:00
|
|
|
|
// float_t pv1Volt = get_capturedata(get_PV1_VOLT_IN);
|
|
|
|
|
|
|
|
|
|
// float_t pv1Volt = get_PV1_VOLT_IN();
|
|
|
|
|
float_t pv1Volt = g_Mppt_Para.Input_Voltage;
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// printf("volt in : %d \n", pv1Volt);
|
2024-08-17 03:14:19 +00:00
|
|
|
|
float_t error = pv1Volt - InVoltage;
|
|
|
|
|
// float_t error = InVoltage - pv1Volt;
|
|
|
|
|
float_t stepPwm = kp * error + ki * pv1Volt;
|
|
|
|
|
g_duty_ratio += stepPwm;
|
|
|
|
|
|
|
|
|
|
// printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
|
|
|
|
|
// printf("g_duty_ratio : %d/10000 \n", (int)(g_duty_ratio * 10000));
|
2024-07-22 06:20:24 +00:00
|
|
|
|
|
2024-08-17 03:14:19 +00:00
|
|
|
|
Set_duty_ratio(&g_duty_ratio);
|
2024-07-11 06:58:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 02:35:10 +00:00
|
|
|
|
/**
|
2024-09-20 07:04:41 +00:00
|
|
|
|
* @brief <EFBFBD>㶨<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ(<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
2024-08-05 02:35:10 +00:00
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-09-20 07:04:41 +00:00
|
|
|
|
void mppt_constantVoltageB(float OutVoltage)
|
2024-08-05 02:35:10 +00:00
|
|
|
|
{
|
2024-08-17 03:14:19 +00:00
|
|
|
|
// 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;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
2024-09-20 07:04:41 +00:00
|
|
|
|
// static float_t kp = 0.0005;
|
|
|
|
|
// static float_t ki = 0.000001;
|
|
|
|
|
static float_t kp = 0.005;
|
|
|
|
|
static float_t ki = 0.00001;
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// static float_t kp = 0.1;
|
|
|
|
|
// static float_t ki = 0.001;
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// float_t outVolt = get_PV_VOLT_OUT();
|
|
|
|
|
float_t outVolt = g_Mppt_Para.Battery_Voltage;
|
2024-08-29 09:24:57 +00:00
|
|
|
|
// float_t outVolt = voltOut;
|
2024-08-17 03:14:19 +00:00
|
|
|
|
// float_t error = outVolt - OutVoltage;
|
|
|
|
|
float_t error = OutVoltage - outVolt;
|
|
|
|
|
float_t stepPwm = kp * error + ki * outVolt;
|
|
|
|
|
g_duty_ratio += stepPwm;
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
|
2024-08-17 03:14:19 +00:00
|
|
|
|
|
|
|
|
|
Set_duty_ratio(&g_duty_ratio);
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-20 07:04:41 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD>㶨<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void mppt_constantVoltageO(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.Output_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);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 02:35:10 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD>ǯλ<EFBFBD><EFBFBD><EFBFBD>㶨<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void mppt_constantCurrentO(float outCurrent)
|
|
|
|
|
{
|
2024-08-17 03:14:19 +00:00
|
|
|
|
// static uint8_t ConstantCurrent = 1;
|
|
|
|
|
// float out_I = get_CHG_CURR();
|
|
|
|
|
//
|
|
|
|
|
// if (ConstantCurrent) {
|
|
|
|
|
// if (out_I > outCurrent) {
|
|
|
|
|
// g_duty_ratio -= step1_pwm;
|
|
|
|
|
// Set_duty_ratio(&g_duty_ratio);
|
|
|
|
|
// } else {
|
|
|
|
|
// g_duty_ratio += step1_pwm;
|
|
|
|
|
// Set_duty_ratio(&g_duty_ratio);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (out_I - outCurrent < 0.1) {
|
|
|
|
|
// ConstantCurrent = 0;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// else {
|
|
|
|
|
// if (out_I > outCurrent) {
|
|
|
|
|
// g_duty_ratio -= step2_pwm;
|
|
|
|
|
// Set_duty_ratio(&g_duty_ratio);
|
|
|
|
|
// } else {
|
|
|
|
|
// g_duty_ratio += step2_pwm;
|
|
|
|
|
// Set_duty_ratio(&g_duty_ratio);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (out_I - outCurrent > 0.1) {
|
|
|
|
|
// ConstantCurrent = 1;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
2024-08-23 08:50:34 +00:00
|
|
|
|
static float_t kp = 0.005;
|
|
|
|
|
static float_t ki = 0.00005;
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
2024-08-17 03:14:19 +00:00
|
|
|
|
// static float_t last_CHG_CURR = 0;
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// static float_t flag = 1;
|
|
|
|
|
// static float_t last_OutputPower = 0;
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// float_t outCurr = get_CHG_CURR();
|
|
|
|
|
|
|
|
|
|
float_t outCurr = g_Mppt_Para.Charg_Current;
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// float_t OutputPower = outCurr * get_PV_VOLT_OUT();
|
2024-08-17 03:14:19 +00:00
|
|
|
|
float_t error = outCurrent - outCurr;
|
|
|
|
|
// float_t error = outCurr - outCurrent;
|
|
|
|
|
float_t stepPwm = kp * error + ki * outCurr;
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// if (flag) {
|
|
|
|
|
// if (OutputPower > last_OutputPower) {
|
|
|
|
|
// g_duty_ratio += stepPwm;
|
|
|
|
|
// flag = 1;
|
|
|
|
|
// } else {
|
|
|
|
|
// g_duty_ratio -= stepPwm;
|
|
|
|
|
// flag = 0;
|
|
|
|
|
// }
|
2024-08-17 03:14:19 +00:00
|
|
|
|
// } else {
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// if (OutputPower > last_OutputPower) {
|
|
|
|
|
// g_duty_ratio -= stepPwm;
|
|
|
|
|
// flag = 0;
|
|
|
|
|
// } else {
|
|
|
|
|
// g_duty_ratio += stepPwm;
|
|
|
|
|
// flag = 1;
|
|
|
|
|
// }
|
2024-08-17 03:14:19 +00:00
|
|
|
|
// }
|
2024-08-23 08:50:34 +00:00
|
|
|
|
//
|
|
|
|
|
// last_OutputPower = OutputPower;
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
2024-08-23 08:50:34 +00:00
|
|
|
|
g_duty_ratio += stepPwm;
|
|
|
|
|
|
|
|
|
|
// printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
|
|
|
|
|
// printf("g_duty_ratio : %d/10000 \n", (int)(g_duty_ratio * 10000));
|
2024-08-17 03:14:19 +00:00
|
|
|
|
|
|
|
|
|
Set_duty_ratio(&g_duty_ratio);
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
2024-08-17 03:14:19 +00:00
|
|
|
|
// last_CHG_CURR = outCurr;
|
|
|
|
|
// if (stepPwm > 0 && (last_CHG_CURR > outCurr)) {
|
|
|
|
|
// flag = 1;
|
|
|
|
|
// } else {
|
|
|
|
|
// flag = 0;
|
|
|
|
|
// }
|
2024-08-05 02:35:10 +00:00
|
|
|
|
}
|
2024-07-22 06:20:24 +00:00
|
|
|
|
|
2024-07-12 09:02:26 +00:00
|
|
|
|
/**
|
2024-07-12 09:34:47 +00:00
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2024-07-12 09:02:26 +00:00
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void TrickleCharge(void)
|
|
|
|
|
{
|
2024-09-18 01:47:44 +00:00
|
|
|
|
static float_t TrickleChargeC;
|
|
|
|
|
static uint8_t onlyOnce = 1;
|
|
|
|
|
if (onlyOnce) {
|
|
|
|
|
TrickleChargeC = (float_t)g_slConfigInfo.trickleChargeC / 100;
|
|
|
|
|
onlyOnce = 0;
|
|
|
|
|
}
|
2024-09-20 07:04:41 +00:00
|
|
|
|
// printf("Trickle\n");
|
2024-09-18 01:47:44 +00:00
|
|
|
|
mppt_constantCurrentO(TrickleChargeC + g_Mppt_Para.Discharg_Current);
|
2024-07-12 09:02:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2024-07-12 09:34:47 +00:00
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>磨<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>磩<EFBFBD><EFBFBD>mppt<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʳ<EFBFBD><EFBFBD><EFBFBD>
|
2024-07-12 09:02:26 +00:00
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void ConstantCurrentCharge(void)
|
|
|
|
|
{
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// mppt_readJust();
|
|
|
|
|
mppt_constantVoltage(18);
|
2024-09-18 01:47:44 +00:00
|
|
|
|
// printf("ConstantCurrent\n");
|
2024-08-23 08:50:34 +00:00
|
|
|
|
|
2024-07-12 09:02:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD>ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void ConstantVoltageCharge(void)
|
|
|
|
|
{
|
2024-09-18 01:47:44 +00:00
|
|
|
|
static float_t ConstantVoltageChargeV;
|
|
|
|
|
static uint8_t onlyOnce = 1;
|
|
|
|
|
if (onlyOnce) {
|
|
|
|
|
ConstantVoltageChargeV = (float_t)g_slConfigInfo.constantVoltageChargeV / 100;
|
|
|
|
|
onlyOnce = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mppt_constantVoltageO(ConstantVoltageChargeV);
|
2024-07-12 09:02:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void FloatingCharge(void)
|
|
|
|
|
{
|
2024-09-20 07:04:41 +00:00
|
|
|
|
// 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");
|
|
|
|
|
// }
|
|
|
|
|
|
2024-09-21 03:00:09 +00:00
|
|
|
|
static float_t FloatChargeV;
|
2024-08-29 02:50:22 +00:00
|
|
|
|
static uint8_t onlyOnce = 1;
|
|
|
|
|
if (onlyOnce) {
|
2024-09-21 03:00:09 +00:00
|
|
|
|
FloatChargeV = (float_t)g_slConfigInfo.FloatV / 100;
|
2024-08-29 02:50:22 +00:00
|
|
|
|
onlyOnce = 0;
|
|
|
|
|
}
|
2024-09-21 03:00:09 +00:00
|
|
|
|
mppt_constantVoltageO(FloatChargeV);
|
2024-08-23 08:50:34 +00:00
|
|
|
|
|
2024-07-12 09:02:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-29 02:50:22 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief û<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>㶨<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
|
|
|
|
|
* @param
|
|
|
|
|
* @retval
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void NoBatteryCharge(void)
|
|
|
|
|
{
|
2024-09-18 01:47:44 +00:00
|
|
|
|
// static float_t NoBatteryChargeV;
|
|
|
|
|
// static uint8_t onlyOnce = 1;
|
|
|
|
|
// if (onlyOnce) {
|
|
|
|
|
// NoBatteryChargeV = (float_t)g_slConfigInfo.noBatteryChargeV / 100;
|
|
|
|
|
// onlyOnce = 0;
|
|
|
|
|
// }
|
2024-08-29 02:50:22 +00:00
|
|
|
|
|
2024-09-18 01:47:44 +00:00
|
|
|
|
mppt_constantVoltageO(14.2);
|
2024-08-29 02:50:22 +00:00
|
|
|
|
|
2024-08-29 09:24:57 +00:00
|
|
|
|
// if ((g_Mppt_Para.Battery_Voltage - NoBatteryChargeV > 0.2 && g_Mppt_Para.Charg_Current < 0.1)
|
|
|
|
|
// || (NoBatteryChargeV - g_Mppt_Para.Battery_Voltage > 0.1 && g_Mppt_Para.Charg_Current > 0.5)) {
|
|
|
|
|
// ConstantCurrentCharge();
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = CONSTANTCURRENT;
|
|
|
|
|
// }
|
|
|
|
|
|
2024-09-18 01:47:44 +00:00
|
|
|
|
// if (!overTemperature) {
|
|
|
|
|
// if (!(g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < 0.3
|
|
|
|
|
// && g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current < 0.3)) {
|
|
|
|
|
// ConstantCurrentCharge();
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = CONSTANTCURRENT;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2024-08-29 09:24:57 +00:00
|
|
|
|
|
2024-08-29 02:50:22 +00:00
|
|
|
|
}
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
2024-07-12 09:02:26 +00:00
|
|
|
|
void MpptContorl(void)
|
|
|
|
|
{
|
2024-08-29 02:50:22 +00:00
|
|
|
|
switch(g_Mppt_Para.MPPT_Mode) {
|
2024-07-24 08:57:38 +00:00
|
|
|
|
case TRICKLE:
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// printf("111\n");
|
2024-07-12 09:02:26 +00:00
|
|
|
|
TrickleCharge();
|
2024-07-24 08:57:38 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CONSTANTCURRENT:
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// printf("222222\n");
|
2024-07-12 09:02:26 +00:00
|
|
|
|
ConstantCurrentCharge();
|
2024-09-18 01:47:44 +00:00
|
|
|
|
// ConstantVoltageCharge();
|
2024-07-24 08:57:38 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CONSTANTVOLTAGE:
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// printf("333333333\n");
|
2024-07-12 09:02:26 +00:00
|
|
|
|
ConstantVoltageCharge();
|
2024-07-24 08:57:38 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case FLOAT:
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// printf("444444444444\n");
|
2024-07-12 09:02:26 +00:00
|
|
|
|
FloatingCharge();
|
2024-07-24 08:57:38 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2024-09-18 01:47:44 +00:00
|
|
|
|
// case NoBattery:
|
|
|
|
|
//// printf("555555555555555\n");
|
|
|
|
|
// NoBatteryCharge();
|
|
|
|
|
// break;
|
2024-08-29 02:50:22 +00:00
|
|
|
|
|
2024-07-24 08:57:38 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MpptMode(void)
|
|
|
|
|
{
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// printf("vout : %d /100 \n", (int)(g_Mppt_Para.Battery_Voltage * 100));
|
|
|
|
|
// printf("iout : %d /1000 \n", (int)(g_Mppt_Para.Charg_Current * 1000));
|
|
|
|
|
// printf("in checkSolarOpenCircuitVoltage v: %d/100 \n", (int)(g_Mppt_Para.Solar_Open_Circuit_Voltage * 100));
|
|
|
|
|
|
|
|
|
|
static float ConstantCurrentV;
|
|
|
|
|
static float ConstantVoltageV;
|
|
|
|
|
static float FloatI;
|
|
|
|
|
static float StopSolarOpenCircuitV;
|
|
|
|
|
|
|
|
|
|
/* <20><>ֵ<EFBFBD><D6B5>ִ<EFBFBD><D6B4>һ<EFBFBD><D2BB> */
|
|
|
|
|
static uint8_t only_once = 1;
|
|
|
|
|
if (only_once) {
|
|
|
|
|
ConstantCurrentV = (float)g_slConfigInfo.constantCurrentV / 100;
|
|
|
|
|
ConstantVoltageV = (float)g_slConfigInfo.constantVoltageV / 100;
|
|
|
|
|
FloatI = (float)g_slConfigInfo.floatI / 100;
|
2024-09-20 07:04:41 +00:00
|
|
|
|
printf("FloatI: %d / 100 \n", (int)(FloatI * 100));
|
2024-08-29 02:50:22 +00:00
|
|
|
|
StopSolarOpenCircuitV = (float)g_slConfigInfo.stopSolarOpenCircuitV / 100;
|
|
|
|
|
only_once = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//// if (g_Mppt_Para.Battery_Voltage > 16 || g_Mppt_Para.Battery_Voltage < 8
|
|
|
|
|
//// || modeFlag == NoBattery) {
|
|
|
|
|
//// modeFlag = NoBattery;
|
|
|
|
|
// if (g_Mppt_Para.Battery_Voltage > 16 || g_Mppt_Para.Battery_Voltage < 8
|
|
|
|
|
// || g_Mppt_Para.MPPT_Mode == NoBattery) {
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = NoBattery;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
//// if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage) &&
|
|
|
|
|
//// (FloatI > g_Mppt_Para.Charg_Current)) || modeFlag == FLOAT) {
|
|
|
|
|
//// modeFlag = FLOAT;
|
|
|
|
|
// if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage) &&
|
|
|
|
|
// (FloatI > g_Mppt_Para.Charg_Current)) || g_Mppt_Para.MPPT_Mode == FLOAT) {
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = FLOAT;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (((ConstantCurrentV + 0.4) < g_Mppt_Para.Battery_Voltage) &&
|
|
|
|
|
// ((ConstantVoltageV - 0.4) >= g_Mppt_Para.Battery_Voltage)) {
|
|
|
|
|
//// modeFlag = CONSTANTCURRENT;
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = CONSTANTCURRENT;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if ((ConstantVoltageV < g_Mppt_Para.Battery_Voltage) &&
|
|
|
|
|
// (FloatI + 0.1 <= g_Mppt_Para.Charg_Current)) {
|
|
|
|
|
//// modeFlag = CONSTANTVOLTAGE;
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (ConstantCurrentV > g_Mppt_Para.Battery_Voltage) {
|
|
|
|
|
//// modeFlag = TRICKLE;
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = TRICKLE;
|
|
|
|
|
// return;
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// if (g_Mppt_Para.Battery_Voltage > 16 || g_Mppt_Para.Battery_Voltage < 8
|
|
|
|
|
// || g_Mppt_Para.MPPT_Mode == NoBattery) {
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = NoBattery;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < 0.05
|
|
|
|
|
// || g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current < 0.05) {
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = NoBattery;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage) &&
|
|
|
|
|
// (FloatI > g_Mppt_Para.Charg_Current)) || g_Mppt_Para.MPPT_Mode == FLOAT) {
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = FLOAT;
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
//
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// if (((ConstantCurrentV + 0.4) < g_Mppt_Para.Battery_Voltage) &&
|
|
|
|
|
// ((ConstantVoltageV - 0.4) >= g_Mppt_Para.Battery_Voltage)) {
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = CONSTANTCURRENT;
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
//
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// if ((ConstantVoltageV < g_Mppt_Para.Battery_Voltage) &&
|
|
|
|
|
// (FloatI + 0.1 <= g_Mppt_Para.Charg_Current)) {
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// return;
|
|
|
|
|
// }
|
2024-08-29 02:50:22 +00:00
|
|
|
|
//
|
|
|
|
|
// if (ConstantCurrentV > g_Mppt_Para.Battery_Voltage) {
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = TRICKLE;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-09-21 03:00:09 +00:00
|
|
|
|
if (g_Mppt_Para.Input_Voltage < StopSolarOpenCircuitV
|
2024-08-29 02:50:22 +00:00
|
|
|
|
&& (g_Mppt_Para.Discharg_Current >= g_Mppt_Para.Charg_Current
|
|
|
|
|
|| g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < 0.05)) {
|
|
|
|
|
g_Mppt_Para.MPPT_Mode = NoWork;
|
2024-09-21 03:00:09 +00:00
|
|
|
|
printf("nowork \n");
|
2024-08-29 02:50:22 +00:00
|
|
|
|
stop_mpptWork();
|
|
|
|
|
TimeSliceOffset_Register(&m_startMpptControl, Task_startMpptControl
|
|
|
|
|
, startMpptControl_reloadVal, startMpptControl_offset);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-08-23 08:50:34 +00:00
|
|
|
|
|
2024-09-20 07:04:41 +00:00
|
|
|
|
|
2024-09-18 01:47:44 +00:00
|
|
|
|
// 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
|
|
|
|
|
// || g_Mppt_Para.Battery_Voltage > ConstantVoltageV + 1))
|
|
|
|
|
// || g_Mppt_Para.MPPT_Mode == NoBattery) {
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = NoBattery;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage) &&
|
|
|
|
|
// (FloatI > g_Mppt_Para.Charg_Current)) || g_Mppt_Para.MPPT_Mode == FLOAT) {
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = FLOAT;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
if ((g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < 0.05
|
|
|
|
|
&& g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current < 0.05)
|
|
|
|
|
|| g_Mppt_Para.Battery_Voltage > 16 || g_Mppt_Para.Battery_Voltage < 8) {
|
|
|
|
|
// || g_Mppt_Para.MPPT_Mode == NoBattery) {
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = NoBattery;
|
2024-09-20 07:04:41 +00:00
|
|
|
|
// g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
|
|
|
|
|
g_Mppt_Para.MPPT_Mode = FLOAT;
|
2024-09-21 03:00:09 +00:00
|
|
|
|
|
|
|
|
|
// printf("Charg_Current : %d/100 \n", (int)(g_Mppt_Para.Charg_Current * 100));
|
|
|
|
|
// printf("Discharg_Current : %d/100 \n", (int)(g_Mppt_Para.Discharg_Current * 100));
|
|
|
|
|
// printf("Battery_Voltage : %d/100 \n", (int)(g_Mppt_Para.Battery_Voltage * 100));
|
|
|
|
|
|
|
|
|
|
g_batteryState = 0;
|
|
|
|
|
|
2024-08-29 09:24:57 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 01:47:44 +00:00
|
|
|
|
if ((((ConstantCurrentV + 0.2) < g_Mppt_Para.Battery_Voltage)
|
|
|
|
|
&&((ConstantVoltageV - 0.2) >= g_Mppt_Para.Battery_Voltage))
|
|
|
|
|
&&(g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current > 0.1)) {
|
|
|
|
|
g_Mppt_Para.MPPT_Mode = CONSTANTCURRENT;
|
2024-08-23 08:50:34 +00:00
|
|
|
|
return;
|
2024-07-24 08:57:38 +00:00
|
|
|
|
}
|
2024-09-18 01:47:44 +00:00
|
|
|
|
// if ((g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current > 4)) {
|
|
|
|
|
// g_Mppt_Para.MPPT_Mode = CONSTANTCURRENT;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
2024-07-24 08:57:38 +00:00
|
|
|
|
|
2024-09-20 07:04:41 +00:00
|
|
|
|
// 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;
|
|
|
|
|
// }
|
2024-07-24 08:57:38 +00:00
|
|
|
|
|
2024-09-18 01:47:44 +00:00
|
|
|
|
if (((ConstantVoltageV < g_Mppt_Para.Battery_Voltage)
|
2024-09-20 07:04:41 +00:00
|
|
|
|
&&(FloatI + 0.1 <= g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current))) {
|
2024-08-29 02:50:22 +00:00
|
|
|
|
g_Mppt_Para.MPPT_Mode = CONSTANTVOLTAGE;
|
2024-07-24 08:57:38 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-20 07:04:41 +00:00
|
|
|
|
if ((((ConstantVoltageV < g_Mppt_Para.Battery_Voltage)
|
|
|
|
|
&& (FloatI > g_Mppt_Para.Charg_Current))
|
2024-09-28 08:07:51 +00:00
|
|
|
|
&& (FloatI > g_Mppt_Para.Discharg_Current))) {
|
|
|
|
|
// || g_Mppt_Para.MPPT_Mode == FLOAT) {
|
2024-09-20 07:04:41 +00:00
|
|
|
|
g_Mppt_Para.MPPT_Mode = FLOAT;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-29 02:50:22 +00:00
|
|
|
|
if (ConstantCurrentV > g_Mppt_Para.Battery_Voltage) {
|
|
|
|
|
g_Mppt_Para.MPPT_Mode = TRICKLE;
|
2024-07-24 08:57:38 +00:00
|
|
|
|
return;
|
2024-07-12 09:02:26 +00:00
|
|
|
|
}
|
2024-07-24 08:57:38 +00:00
|
|
|
|
|
2024-07-12 09:02:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 02:35:10 +00:00
|
|
|
|
void findMiNDutyRatio(void)
|
|
|
|
|
{
|
|
|
|
|
static uint8_t num = 100;
|
|
|
|
|
if (0.05 < get_CHG_CURR()) {
|
|
|
|
|
num -= 1;
|
|
|
|
|
TIM_SetCompare4(TIM4, num);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
printf("min duty ratio : %d/200 \n", num);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-07-11 06:58:55 +00:00
|
|
|
|
void test(void)
|
|
|
|
|
{
|
|
|
|
|
// mppt_readjust();
|
|
|
|
|
// Get_OutputPower();
|
2024-08-17 03:14:19 +00:00
|
|
|
|
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// mppt_constantVoltage(18);
|
2024-08-17 03:14:19 +00:00
|
|
|
|
|
2024-08-05 02:35:10 +00:00
|
|
|
|
// findMiNDutyRatio();
|
2024-07-24 08:57:38 +00:00
|
|
|
|
// MpptContorl();
|
2024-07-11 06:58:55 +00:00
|
|
|
|
|
2024-08-05 02:35:10 +00:00
|
|
|
|
// printf_data();
|
2024-07-22 06:20:24 +00:00
|
|
|
|
// void MpptContorl();
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// mppt_constantVoltageO(12);
|
|
|
|
|
|
2024-08-05 02:35:10 +00:00
|
|
|
|
// FloatingCharge();
|
2024-08-17 03:14:19 +00:00
|
|
|
|
// mppt_readJust();
|
|
|
|
|
|
2024-08-23 08:50:34 +00:00
|
|
|
|
// mppt_constantCurrentO(1);
|
2024-08-29 02:50:22 +00:00
|
|
|
|
|
2024-09-21 03:00:09 +00:00
|
|
|
|
|
|
|
|
|
// if (g_interruptNum < 5) {
|
|
|
|
|
// g_interruptNum++;
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
2024-09-18 01:47:44 +00:00
|
|
|
|
// g_Mppt_Para.Charg_Current = get_capturedata(get_CHG_CURR);
|
|
|
|
|
// g_Mppt_Para.Discharg_Current = get_capturedata(get_DSG_CURR);
|
|
|
|
|
// g_Mppt_Para.Output_Voltage = get_capturedata(get_PV_VOLT_OUT);
|
|
|
|
|
// g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
|
|
|
|
|
g_Mppt_Para.Charg_Current = get_CHG_CURR();
|
|
|
|
|
g_Mppt_Para.Discharg_Current = get_DSG_CURR();
|
|
|
|
|
g_Mppt_Para.Output_Voltage = get_PV_VOLT_OUT();
|
|
|
|
|
g_Mppt_Para.Input_Voltage = get_PV1_VOLT_IN();
|
2024-09-21 03:00:09 +00:00
|
|
|
|
|
2024-09-24 09:44:41 +00:00
|
|
|
|
// mppt_constantVoltage(18);
|
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
|
2024-09-21 03:00:09 +00:00
|
|
|
|
if (g_Mppt_Para.Discharg_Current == 0 && g_Mppt_Para.Charg_Current == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-09-18 01:47:44 +00:00
|
|
|
|
// g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
|
|
|
|
|
|
|
|
|
|
// static float_t Volt = 0.7;
|
|
|
|
|
// static float_t Curr = 5.5;
|
2024-09-21 03:00:09 +00:00
|
|
|
|
// static float_t loopImpedance;
|
|
|
|
|
// static uint8_t onlyone = 1;
|
|
|
|
|
// if (onlyone) {
|
|
|
|
|
// loopImpedance = (float_t)g_slConfigInfo.loopImpedance / 100;
|
|
|
|
|
// }
|
2024-09-18 01:47:44 +00:00
|
|
|
|
|
|
|
|
|
|
2024-09-20 07:04:41 +00:00
|
|
|
|
static float_t inBatteryCurr;
|
2024-09-28 08:07:51 +00:00
|
|
|
|
static float_t outBatteryCurr;
|
2024-09-20 07:04:41 +00:00
|
|
|
|
inBatteryCurr = g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current;
|
2024-09-28 08:07:51 +00:00
|
|
|
|
outBatteryCurr = g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current;
|
2024-09-20 07:04:41 +00:00
|
|
|
|
if (inBatteryCurr > 0.1) {
|
2024-09-21 03:00:09 +00:00
|
|
|
|
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage - inBatteryCurr * g_impedance;
|
2024-09-20 07:04:41 +00:00
|
|
|
|
} else {
|
|
|
|
|
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
|
|
|
|
|
}
|
2024-09-18 01:47:44 +00:00
|
|
|
|
|
2024-09-28 08:07:51 +00:00
|
|
|
|
if (g_batteryState == 0 && (inBatteryCurr > 0.1 || outBatteryCurr > 0.1) && g_Mppt_Para.Output_Voltage < 14.2) {
|
|
|
|
|
// printf("int g_batteryState : %d\n", g_batteryState);
|
2024-09-21 03:00:09 +00:00
|
|
|
|
g_batteryState = 1;
|
2024-09-28 08:07:51 +00:00
|
|
|
|
// TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
|
|
|
|
// , impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
|
2024-09-21 03:00:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-09-18 01:47:44 +00:00
|
|
|
|
// mppt_constantVoltage(18);
|
2024-08-29 02:50:22 +00:00
|
|
|
|
|
2024-08-29 09:24:57 +00:00
|
|
|
|
// if (g_Mppt_Para.MPPT_Mode == CONSTANTCURRENT
|
|
|
|
|
// || g_Mppt_Para.MPPT_Mode == CONSTANTVOLTAGE) {
|
|
|
|
|
//
|
|
|
|
|
// g_Mppt_Para.Battery_Voltage = get_capturedata(get_PV_VOLT_OUT)
|
|
|
|
|
// - g_impedance * (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current);
|
|
|
|
|
// } else {
|
2024-09-18 01:47:44 +00:00
|
|
|
|
// g_Mppt_Para.Battery_Voltage = get_capturedata(get_PV_VOLT_OUT);
|
2024-08-29 09:24:57 +00:00
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// voltOut = get_capturedata(get_PV_VOLT_OUT);
|
|
|
|
|
// g_Mppt_Para.Battery_Voltage = voltOut - g_impedance * (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current);
|
|
|
|
|
|
|
|
|
|
|
2024-09-18 01:47:44 +00:00
|
|
|
|
// ConstantVoltageCharge();
|
|
|
|
|
// return;
|
|
|
|
|
|
2024-08-29 02:50:22 +00:00
|
|
|
|
if (!overTemperature) {
|
|
|
|
|
MpptMode();
|
2024-09-18 01:47:44 +00:00
|
|
|
|
MpptContorl();
|
2024-08-29 02:50:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-08-05 02:35:10 +00:00
|
|
|
|
|
2024-08-29 02:50:22 +00:00
|
|
|
|
// mppt_constantVoltageO(12);
|
|
|
|
|
|
2024-08-05 02:35:10 +00:00
|
|
|
|
// static uint32_t run_num = 0;
|
|
|
|
|
// if (1000 < run_num++) {
|
|
|
|
|
// FloatingCharge();
|
|
|
|
|
// run_num = 1200;
|
|
|
|
|
// printf("in floatcharge \n");
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// mppt_readJust();
|
|
|
|
|
// mppt_constantCurrentO(1.2);
|
2024-08-17 03:14:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// int16_t var = 0;
|
|
|
|
|
// char buff[4];
|
|
|
|
|
// for (var = 0; var < 100; ++var) {
|
|
|
|
|
// sprintf(buff, "%3d:", var);
|
|
|
|
|
// uart_dev_write(g_gw485_uart4_handle, buff, sizeof(buff));
|
|
|
|
|
// uart_dev_write(g_gw485_uart4_handle, "1234567890\n", sizeof("1234567890\n"));
|
|
|
|
|
// Delay_Ms(1);
|
|
|
|
|
// }
|
|
|
|
|
// uart_dev_write(g_gw485_uart4_handle, "\n\n\n\n\n\n", sizeof("\n\n\n\n\n\n"));
|
2024-07-11 06:58:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|