149 lines
3.3 KiB
C
149 lines
3.3 KiB
C
|
/*
|
|||
|
* 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"
|
|||
|
|
|||
|
SL_Mppt_para g_Mppt_Para = {0};
|
|||
|
|
|||
|
/**
|
|||
|
* @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;
|
|||
|
// float V_out_array[array_num];
|
|||
|
// float I_out_array[array_num];
|
|||
|
// float V_temp = 0;
|
|||
|
// float I_temp = 0;
|
|||
|
|
|||
|
// for (int var = 0; var < array_num; ++var) {
|
|||
|
// I_out_array[var] = get_CHG_CURR();
|
|||
|
// V_out_array[var] = get_PV_VOLT_OUT();
|
|||
|
// Delay_Ms(1);
|
|||
|
// }
|
|||
|
//
|
|||
|
// for (int var = 0; var < array_num; ++var) {
|
|||
|
// I_temp += I_out_array[var];
|
|||
|
// V_temp += V_out_array[var];
|
|||
|
// }
|
|||
|
|
|||
|
// for (int var = 0; var < array_num; ++var) {
|
|||
|
// I_temp += get_CHG_CURR();
|
|||
|
// V_temp += get_PV_VOLT_OUT();
|
|||
|
// Delay_Ms(1);
|
|||
|
// }
|
|||
|
// V_out = V_temp / array_num;
|
|||
|
// I_out = I_temp / array_num;
|
|||
|
|
|||
|
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;
|
|||
|
const float step2_pwm = 0.001;
|
|||
|
//#define array_num 10
|
|||
|
void mppt_readJust(void)
|
|||
|
{
|
|||
|
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);
|
|||
|
// step_pwm = step2_pwm;
|
|||
|
}
|
|||
|
|
|||
|
void printf_data(void)
|
|||
|
{
|
|||
|
printf("\n");
|
|||
|
get_CHG_CURR();
|
|||
|
get_PV_VOLT_OUT();
|
|||
|
get_DSG_CURR();
|
|||
|
get_PV1_VOLT_IN();
|
|||
|
get_PV_VOLT_IN1();
|
|||
|
get_MOSFET_Temper();
|
|||
|
get_PV2_VOLT_IN();
|
|||
|
printf("\n");
|
|||
|
}
|
|||
|
|
|||
|
void mppt_constantVoltage(void)
|
|||
|
{
|
|||
|
float temp = get_PV_VOLT_OUT();
|
|||
|
Set_duty_ratio(0);
|
|||
|
Delay_Ms(500);
|
|||
|
float PV1_V = get_PV1_VOLT_IN();
|
|||
|
|
|||
|
float constant_V = 0.78 * PV1_V;
|
|||
|
|
|||
|
temp = temp / constant_V;
|
|||
|
|
|||
|
Set_duty_ratio(temp);
|
|||
|
}
|
|||
|
|
|||
|
void test(void)
|
|||
|
{
|
|||
|
// mppt_readjust();
|
|||
|
// Get_OutputPower();
|
|||
|
|
|||
|
// mppt_constantVoltage();
|
|||
|
printf_data();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|