恒定电流电压,改为pi控制(作用于mppt点的左端)

This commit is contained in:
起床就犯困 2024-08-17 11:14:19 +08:00
parent ad8afd3845
commit 6b9e8fae9c
24 changed files with 8880 additions and 9293 deletions

View File

@ -35,6 +35,13 @@ typedef enum
FLOAT = 4, /* ¸¡³äģʽ */ FLOAT = 4, /* ¸¡³äģʽ */
}SL_MPPT_MODE; }SL_MPPT_MODE;
///* 恒定电流或者电压时PI调节器参数 */
//typedef struct PIconstV {
// float_t kp;
// float_t ki;
// float_t allError;
//};
extern float g_duty_ratio; extern float g_duty_ratio;
void mppt_readJust(void); void mppt_readJust(void);

View File

@ -17,7 +17,7 @@
extern STR_TimeSliceOffset m_runled; extern STR_TimeSliceOffset m_runled;
void Task_RunLED(void); void Task_RunLED(void);
#define mpptControl_reloadVal 10 /* 任务执行间隔 */ #define mpptControl_reloadVal 2000 /* 任务执行间隔 */
#define mpptControl_offset 0 /* 任务执行偏移量 */ #define mpptControl_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset m_mpptControl; extern STR_TimeSliceOffset m_mpptControl;
void Task_mpptControl(void); void Task_mpptControl(void);
@ -47,10 +47,10 @@ extern uint8_t g_recvBroadcastRegisterNumber; /*
extern STR_TimeSliceOffset m_recvbroadcast; extern STR_TimeSliceOffset m_recvbroadcast;
void Task_recvbroadcast(void); void Task_recvbroadcast(void);
#define CapCharg_reloadVal 500 /* 任务执行间隔 */ #define EnPowerSupply_reloadVal 100 /* 任务执行间隔 */
#define CapCharg_offset 0 /* 任务执行偏移量 */ #define EnPowerSupply_offset 0 /* 任务执行偏移量 */
extern STR_TimeSliceOffset m_CapCharg; extern STR_TimeSliceOffset m_EnPowerSupply;
extern void Task_CapCharg(void); extern void Task_EnPowerSupply(void);
void task_Init(void); void task_Init(void);
void hardware_Init(void); void hardware_Init(void);

View File

@ -18,24 +18,58 @@
#define MOSFET_Temper ADC_Channel_6 #define MOSFET_Temper ADC_Channel_6
#define PV2_VOLT_IN ADC_Channel_7 #define PV2_VOLT_IN ADC_Channel_7
//#define enable_Printf_VI #define enable_Printf_VI
/* 光伏充电输出电流比例,放大倍数*电阻 */ /* 光伏充电输出电流比例,放大倍数*电阻 */
const float P_CHG_CURR = (1.0 / (50 * 0.005)); const float P_CHG_CURR = (1.0 / (50 * 0.005));
/* 光伏充电输出电压比例,分压系数(放电时采集不准) */ /* 光伏充电输出电压比例,分压系数(放电时采集不准) */
const float P_PV_VOLT_OUT = (47 + 4.7) / 4.7; const float P_PV_VOLT_OUT = (47.0 + 10.0) / 10.0;
/* 放电电流采集电流倍数 */ /* 放电电流采集电流倍数 */
const float P_DSG_CURR = (1.0 / (50 * 0.005)); const float P_DSG_CURR = (1.0 / (50 * 0.005));
///* 光伏1开路输出电压比例 */ ///* 光伏1开路输出电压比例 */
//const float P_PV1_VOLT_IN = (100 + 4.7) / 4.7; //const float P_PV1_VOLT_IN = (100 + 4.7) / 4.7;
/* 光伏1开路输出电压比例 */ /* 光伏1开路输出电压比例 */
const float P_PV1_VOLT_IN = (100 + 10) / 10; const float P_PV1_VOLT_IN = (47 + 4.7) / 4.7;
/* 系统电源电压比例 */ /* 系统电源电压比例 */
const float P_PV_VOLT_IN1 = (47 + 4.7) / 4.7; const float P_PV_VOLT_IN1 = (47 + 4.7) / 4.7;
/* 温度采集比例 */ /* 温度采集比例 */
const float P_MOSFET_TEMPER = 0; //const float P_MOSFET_TEMPER = 0;
/* 光伏2开路输出电压比例 */ /* 光伏2开路输出电压比例 */
const float P_PV2_VOLT_IN = (100 + 4.7) / 4.7; const float P_PV2_VOLT_IN = (47 + 4.7) / 4.7;
/* 温度的adc值的个数 */
#define mosTemperADCLen 241
/* 温度 */
const uint16_t mosTemperADC[mosTemperADCLen] = {
3707, 3697, 3687, 3676, 3665, 3654, 3643, 3632, 3620, 3608, /* -20 - -15.5 ℃ */
3596, 3584, 3571, 3559, 3546, 3533, 3519, 3506, 3492, 3478, /* -15 - -10.5 ℃ */
3464, 3449, 3434, 3419, 3404, 3389, 3373, 3358, 3341, 3325, /* -10 - -5.5 ℃ */
3309, 3292, 3275, 3258, 3241, 3223, 3205, 3187, 3169, 3151, /* -5 - -0.5 ℃ */
3132, 3114, 3095, 3075, 3056, 3037, 3017, 2997, 2977, 2957, /* 0 - 4.5 ℃ */
2936, 2916, 2895, 2874, 2854, 2832, 2811, 2790, 2768, 2747, /* 9 - 9.5 ℃ */
2725, 2703, 2681, 2659, 2637, 2615, 2592, 2570, 2548, 2525, /* 10 - 14.5 ℃ */
2503, 2480, 2457, 2435, 2412, 2389, 2366, 2343, 2321, 2298, /* 15 - 19.5 ℃ */
2275, 2252, 2229, 2207, 2184, 2161, 2138, 2116, 2093, 2071, /* 20 - 24.5 ℃ */
2048, 2026, 2003, 1981, 1959, 1937, 1914, 1893, 1871, 1849, /* 25 - 29.5 ℃ */
1827, 1806, 1784, 1763, 1742, 1721, 1700, 1679, 1658, 1638, /* 30 - 34.5 ℃ */
1617, 1597, 1577, 1557, 1537, 1518, 1498, 1479, 1460, 1441, /* 35 - 39.5 ℃ */
1422, 1403, 1385, 1366, 1348, 1330, 1312, 1295, 1277, 1260, /* 40 - 44.5 ℃ */
1243, 1226, 1209, 1192, 1176, 1160, 1144, 1128, 1112, 1097, /* 45 - 49.5 ℃ */
1081, 1066, 1051, 1036, 1022, 1007, 993, 979, 965, 951, /* 50 - 54.5 ℃ */
938, 924, 911, 898, 885, 872, 860, 848, 835, 823, /* 55 - 59.5 ℃ */
811, 800, 788, 777, 765, 754, 743, 732, 722, 711, /* 60 - 64.5 ℃ */
701, 691, 681, 671, 661, 651, 642, 632, 623, 614, /* 65 - 69.5 ℃ */
605, 596, 588, 579, 571, 562, 554, 546, 538, 530, /* 70 - 74.5 ℃ */
522, 515, 507, 500, 493, 486, 478, 471, 465, 458, /* 75 - 79.5 ℃ */
451, 445, 438, 432, 426, 420, 414, 408, 402, 396, /* 80 - 84.5 ℃ */
390, 385, 379, 374, 368, 363, 358, 353, 348, 343, /* 85 - 89.5 ℃ */
338, 333, 328, 324, 319, 315, 310, 306, 301, 297, /* 90 - 94.5 ℃ */
293, 289, 285, 281, 277, 273, 269, 266, 262, 258, /* 95 - 99.5 ℃ */
255 /* 100 ℃ */
};
static uint16_t get_adc(uint8_t ADC_Channel); static uint16_t get_adc(uint8_t ADC_Channel);
@ -82,7 +116,7 @@ float get_CHG_CURR(void)
I_ADC = Get_ConversionVal(get_adc(CHG_CURR)); I_ADC = Get_ConversionVal(get_adc(CHG_CURR));
// I_ADC = get_adc(CHG_CURR); // I_ADC = get_adc(CHG_CURR);
I = (float)(I_ADC) / 4095 * 3.3 * P_CHG_CURR; I = (float)(I_ADC) / 4095 * 3.3 * P_CHG_CURR * 2;
// printf(" CHG_CURR I : %d /10000 \n", (int)(I * 10000)); // printf(" CHG_CURR I : %d /10000 \n", (int)(I * 10000));
#ifdef enable_Printf_VI #ifdef enable_Printf_VI
@ -129,7 +163,7 @@ float get_DSG_CURR(void)
I_ADC = Get_ConversionVal(get_adc(DSG_CURR)); I_ADC = Get_ConversionVal(get_adc(DSG_CURR));
// I_ADC = get_adc(DSG_CURR); // I_ADC = get_adc(DSG_CURR);
I = (float)(I_ADC) / 4095 * 3.3 / P_DSG_CURR; I = (float)(I_ADC) / 4095 * 3.3 * P_DSG_CURR;
#ifdef enable_Printf_VI #ifdef enable_Printf_VI
printf("\n DSG_CURR ADC : %d \n", I_ADC); printf("\n DSG_CURR ADC : %d \n", I_ADC);
@ -149,10 +183,10 @@ float get_PV1_VOLT_IN(void)
float V; float V;
uint16_t V_ADC; uint16_t V_ADC;
GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, SET); // GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, SET);
V_ADC = Get_ConversionVal(get_adc(PV1_VOLT_IN)); V_ADC = Get_ConversionVal(get_adc(PV1_VOLT_IN));
// V_ADC = get_adc(PV1_VOLT_IN); // V_ADC = get_adc(PV1_VOLT_IN);
GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, RESET); // GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, RESET);
V = (float)(V_ADC) / 4095 * 3.3 * P_PV1_VOLT_IN; V = (float)(V_ADC) / 4095 * 3.3 * P_PV1_VOLT_IN;
@ -188,10 +222,10 @@ float get_PV_VOLT_IN1(void)
} }
const float Rp=10000.0; //10K const float Rp = 10000.0; //10K
const float T2 = (273.15+25.0);;//T2 const float T2 = (273.15+25.0);//T2
//const float Bx = 3950.0;//B const float Bx = 3950.0;//B
const float Bx = 3435.0;//B //const float Bx = 3435.0;//B
const float Ka = 273.15; const float Ka = 273.15;
/** /**
* @brief * @brief
@ -200,27 +234,37 @@ const float Ka = 273.15;
*/ */
float get_MOSFET_Temper(void) float get_MOSFET_Temper(void)
{ {
float T; float T = 0;
uint16_t T_ADC; uint16_t T_ADC;
T_ADC = Get_ConversionVal(get_adc(MOSFET_Temper)); T_ADC = Get_ConversionVal(get_adc(MOSFET_Temper));
// T_ADC = get_adc(MOSFET_Temper); // T_ADC = get_adc(MOSFET_Temper);
float V = (float)(T_ADC) / 4095 * 3.3; // float V = (float)(T_ADC) / 4095 * 3.3;
float R = (float)(10 * V) / (3.3 - V); // float R = (float)(10 * V) / (3.3 - V);
//
// T = R / Rp;
// T = log(T);//ln(Rt/Rp)
// T /= Bx;//ln(Rt/Rp)/B
// T += (1.0 / T2);
// T = 1.0 / (T);
// T -= Ka;
T = R / Rp; float Res = 10.0 * T_ADC / (4094 - T_ADC);
T = log(T);//ln(Rt/Rp)
T /= Bx;//ln(Rt/Rp)/B for (int i = 0; i < mosTemperADCLen; ++i) {
T += (1.0 / T2); if (T_ADC >= mosTemperADC[i]) {
T = 1.0 / (T); T = -20 + i * 0.5;
T -= Ka; break;
}
}
// T = (float)(T_ADC) / 4095 * 3.3 * P_MOSFET_TEMPER; // T = (float)(T_ADC) / 4095 * 3.3 * P_MOSFET_TEMPER;
#ifdef enable_Printf_VI #ifdef enable_Printf_VI
printf("\n MOSFET_Temper ADC : %d \n", T_ADC); printf("\n MOSFET_Temper ADC : %d \n", T_ADC);
printf(" MOSFET_Temper T : %d /100 \n", (int)(T * 100)); printf(" MOSFET_Temper T : %d /10 \n", (int)(T * 10));
printf(" MOSFET_Temper Res : %d /10000 \n", (int)(Res * 10000));
#endif #endif
return T; return T;
@ -236,10 +280,10 @@ float get_PV2_VOLT_IN(void)
float V; float V;
uint16_t V_ADC; uint16_t V_ADC;
GPIO_WriteBit(G_FFMOS_CON2_GPIO, G_FFMOS_CON2_PIN, SET); // GPIO_WriteBit(G_FFMOS_CON2_GPIO, G_FFMOS_CON2_PIN, SET);
V_ADC = Get_ConversionVal(get_adc(PV2_VOLT_IN)); V_ADC = Get_ConversionVal(get_adc(PV2_VOLT_IN));
// V_ADC = get_adc(PV2_VOLT_IN); // V_ADC = get_adc(PV2_VOLT_IN);
GPIO_WriteBit(G_FFMOS_CON2_GPIO, G_FFMOS_CON2_PIN, RESET); // GPIO_WriteBit(G_FFMOS_CON2_GPIO, G_FFMOS_CON2_PIN, RESET);
V = (float)(V_ADC) / 4095 * 3.3 * P_PV2_VOLT_IN; V = (float)(V_ADC) / 4095 * 3.3 * P_PV2_VOLT_IN;

View File

@ -4,6 +4,7 @@
* Created on: 2024629 * Created on: 2024629
* Author: psx * Author: psx
*/ */
#include <math.h>
#include "mppt_control.h" #include "mppt_control.h"
#include "collect_Conversion.h" #include "collect_Conversion.h"
@ -11,6 +12,8 @@
#include "inflash.h" #include "inflash.h"
#include "gpio.h" #include "gpio.h"
#include "uart_dev.h"
SL_Mppt_para g_Mppt_Para = {0}; SL_Mppt_para g_Mppt_Para = {0};
static void TrickleCharge(void); static void TrickleCharge(void);
@ -19,7 +22,7 @@ static void ConstantVoltageCharge(void);
static void FloatingCharge(void); static void FloatingCharge(void);
/* 占空比 */ /* 占空比 */
float g_duty_ratio = 0.5; float g_duty_ratio = 0.7;
/* 用于确定工作模式 */ /* 用于确定工作模式 */
static uint8_t modeFlag = 0; static uint8_t modeFlag = 0;
@ -137,7 +140,7 @@ void printf_data(void)
get_CHG_CURR(); get_CHG_CURR();
get_PV_VOLT_OUT(); get_PV_VOLT_OUT();
get_DSG_CURR(); get_DSG_CURR();
get_PV1_VOLT_IN(); // get_PV1_VOLT_IN();
get_PV_VOLT_IN1(); get_PV_VOLT_IN1();
get_MOSFET_Temper(); get_MOSFET_Temper();
get_PV2_VOLT_IN(); get_PV2_VOLT_IN();
@ -152,36 +155,53 @@ void printf_data(void)
*/ */
void mppt_constantVoltage(float InVoltage) void mppt_constantVoltage(float InVoltage)
{ {
// 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;
// }
// }
static uint8_t ConstantVoltageFlag = 1; static float_t kp = 0.05;
float PV1_V = get_PV1_VOLT_IN(); static float_t ki = 0.0001;
// static float_t allError = 0;
if (ConstantVoltageFlag) { // float_t error = (get_PV1_VOLT_IN()) - InVoltage;
if (PV1_V > InVoltage) { // float_t error = InVoltage - (get_PV2_VOLT_IN());
g_duty_ratio += step1_pwm; // allError += error;
Set_duty_ratio(&g_duty_ratio);
} else {
g_duty_ratio -= step1_pwm;
Set_duty_ratio(&g_duty_ratio);
}
if (PV1_V - InVoltage < 0.1) { float_t pv1Volt = get_PV2_VOLT_IN();
ConstantVoltageFlag = 0; float_t error = pv1Volt - InVoltage;
} // float_t error = InVoltage - pv1Volt;
} else { float_t stepPwm = kp * error + ki * pv1Volt;
if (PV1_V > InVoltage) { g_duty_ratio += stepPwm;
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) { // printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
ConstantVoltageFlag = 1;
}
}
Set_duty_ratio(&g_duty_ratio);
} }
/** /**
@ -192,35 +212,48 @@ void mppt_constantVoltage(float InVoltage)
*/ */
void mppt_constantVoltageO(float OutVoltage) 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 uint8_t ConstantVoltageFlag = 1; static float_t kp = 0.02;
float PV1_V = get_PV_VOLT_OUT(); static float_t ki = 0.00001;
if (ConstantVoltageFlag) { float_t outVolt = get_PV_VOLT_OUT();
if (PV1_V > OutVoltage) { // float_t error = outVolt - OutVoltage;
g_duty_ratio -= step1_pwm; float_t error = OutVoltage - outVolt;
Set_duty_ratio(&g_duty_ratio); float_t stepPwm = kp * error + ki * outVolt;
} else { g_duty_ratio += stepPwm;
g_duty_ratio += step1_pwm;
Set_duty_ratio(&g_duty_ratio);
}
if (PV1_V - OutVoltage < 0.1) { printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
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; Set_duty_ratio(&g_duty_ratio);
}
}
} }
@ -232,38 +265,64 @@ void mppt_constantVoltageO(float OutVoltage)
*/ */
void mppt_constantCurrentO(float outCurrent) void mppt_constantCurrentO(float outCurrent)
{ {
// 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;
// }
// }
static uint8_t ConstantCurrent = 1; static float_t kp = 0.01;
float out_I = get_CHG_CURR(); static float_t ki = 0.0001;
if (ConstantCurrent) { // static float_t last_CHG_CURR = 0;
if (out_I > outCurrent) { // static float_t flag = 0;
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) { float_t outCurr = get_CHG_CURR();
ConstantCurrent = 0; float_t error = outCurrent - outCurr;
} // float_t error = outCurr - outCurrent;
} float_t stepPwm = kp * error + ki * outCurr;
else { // if ((last_CHG_CURR > outCurr) && flag) {
if (out_I > outCurrent) { // g_duty_ratio -= stepPwm;
g_duty_ratio -= step2_pwm; // } else {
Set_duty_ratio(&g_duty_ratio); g_duty_ratio += stepPwm;
} else { // }
g_duty_ratio += step2_pwm;
Set_duty_ratio(&g_duty_ratio);
}
if (out_I - outCurrent > 0.1) { printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
ConstantCurrent = 1;
}
}
Set_duty_ratio(&g_duty_ratio);
// last_CHG_CURR = outCurr;
// if (stepPwm > 0 && (last_CHG_CURR > outCurr)) {
// flag = 1;
// } else {
// flag = 0;
// }
} }
/** /**
@ -420,17 +479,20 @@ void test(void)
{ {
// mppt_readjust(); // mppt_readjust();
// Get_OutputPower(); // Get_OutputPower();
// mppt_constantVoltage(18);
// mppt_constantVoltage(17);
// findMiNDutyRatio(); // findMiNDutyRatio();
// MpptContorl(); // MpptContorl();
// printf_data(); // printf_data();
// void MpptContorl(); // void MpptContorl();
// mppt_constantVoltageO(12); // mppt_constantVoltageO(13);
// FloatingCharge(); // FloatingCharge();
mppt_readJust(); // mppt_readJust();
// mppt_constantCurrentO(0.7);
// mppt_constantCurrentO(1.0);
// static uint32_t run_num = 0; // static uint32_t run_num = 0;
// if (1000 < run_num++) { // if (1000 < run_num++) {
@ -441,6 +503,17 @@ void test(void)
// } // }
// mppt_readJust(); // mppt_readJust();
// mppt_constantCurrentO(1.2); // mppt_constantCurrentO(1.2);
// 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"));
} }

View File

@ -802,6 +802,7 @@ void read_and_process_uart_data(device_handle device)
// if (ring_queue_length(device) > 10) {uart_dev_char_present(device_handle device) // if (ring_queue_length(device) > 10) {uart_dev_char_present(device_handle device)
if (uart_dev_char_present(device)) { if (uart_dev_char_present(device)) {
Delay_Ms(20); Delay_Ms(20);
// printf("ring_queue_length = %d \n", ring_queue_length(device));
memset(rs485_buff, 0, sizeof(rs485_buff)); memset(rs485_buff, 0, sizeof(rs485_buff));
int ret = uart_read_climate_pack(device, rs485_buff, sizeof(rs485_buff)); int ret = uart_read_climate_pack(device, rs485_buff, sizeof(rs485_buff));
if(ret > 0){ if(ret > 0){

View File

@ -30,7 +30,15 @@
STR_TimeSliceOffset m_runled; STR_TimeSliceOffset m_runled;
void Task_RunLED(void) void Task_RunLED(void)
{ {
printf("duty_ratio : %d \n", (int)(g_duty_ratio * 1000)); // for (int i = 0; i < 200; ++i) {
// uart_sendstr(g_gw485_uart4_handle, "is gw485\n");
// }
//
// uart_sendstr(g_gw485_uart4_handle, "\n\n\n\n\n");
// uart_sendstr(g_gw485_uart4_handle, "is gw485\n");
// uart_sendstr(g_bat485_uart3_handle, "is bat485\n");
// printf("duty_ratio : %d/1000 \n", (int)(g_duty_ratio * 1000));
static uint8_t flag = RESET; static uint8_t flag = RESET;
flag = !flag; flag = !flag;
GPIO_WriteBit(RUN_LED_GPIO, RUN_LED_PIN, flag); GPIO_WriteBit(RUN_LED_GPIO, RUN_LED_PIN, flag);
@ -46,7 +54,8 @@ void Task_RunLED(void)
STR_TimeSliceOffset m_mpptControl; STR_TimeSliceOffset m_mpptControl;
void Task_mpptControl(void) void Task_mpptControl(void)
{ {
test(); // test();
get_MOSFET_Temper();
// static uint8_t test_flag = 0; // static uint8_t test_flag = 0;
// if (5 == ++test_flag) { // if (5 == ++test_flag) {
@ -70,6 +79,7 @@ uint8_t RegistrationRequestFlag = 0;
void Task_usart(void) void Task_usart(void)
{ {
read_and_process_uart_data(g_gw485_uart4_handle); read_and_process_uart_data(g_gw485_uart4_handle);
// read_and_process_uart_data(g_bat485_uart3_handle);
return; return;
} }
@ -252,33 +262,23 @@ void Task_recvbroadcast(void)
} }
/** /**
* @brief * @brief ʹÄܹ¦Âʲ¿·ÖdcdcµçÔ´
* @param * @param
* @retval * @retval
*/ */
void CapCharg(void) STR_TimeSliceOffset m_EnPowerSupply;
void Task_EnPowerSupply(void)
{ {
TIM_SetCompare4(TIM4, 0); if (get_PV_VOLT_IN1() > 17 - 0.4) {
TIM_SetCompare2(TIM4, 50); GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, SET);
Delay_Us(7); return;
TIM_SetCompare2(TIM4, 0); } else if (get_PV_VOLT_IN1() < 14 - 0.4) {
TIM_SetCompare4(TIM4, 135); GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, RESET);
}
STR_TimeSliceOffset m_CapCharg;
void Task_CapCharg(void)
{
if (get_CHG_CURR() > 0.05) {
return; return;
} }
else {
g_duty_ratio = 0.675;
printf("in capcharg \n");
CapCharg();
}
return; return;
} }
/** /**
* @brief * @brief
* @param * @param
@ -320,15 +320,15 @@ void task_Init(void)
// TimeSliceOffset_Register(&m_refreshRegister, Task_refreshRegister // TimeSliceOffset_Register(&m_refreshRegister, Task_refreshRegister
// , refreshRegister_reloadVal, refreshRegister_offset); // , refreshRegister_reloadVal, refreshRegister_offset);
TimeSliceOffset_Register(&m_mpptControl, Task_mpptControl // TimeSliceOffset_Register(&m_mpptControl, Task_mpptControl
, mpptControl_reloadVal, mpptControl_offset); // , mpptControl_reloadVal, mpptControl_offset);
// TimeSliceOffset_Register(&m_usart, Task_usart, usart_reloadVal, usart_offset); TimeSliceOffset_Register(&m_usart, Task_usart, usart_reloadVal, usart_offset);
// //
// TimeSliceOffset_Register(&m_wdi, Task_wdi, wdi_reloadVal, wdi_offset); // TimeSliceOffset_Register(&m_wdi, Task_wdi, wdi_reloadVal, wdi_offset);
m_CapCharg.runFlag = 1; /* 该启动后立即执行一次 */ // TimeSliceOffset_Register(&m_EnPowerSupply, Task_EnPowerSupply
TimeSliceOffset_Register(&m_CapCharg, Task_CapCharg, CapCharg_reloadVal, CapCharg_offset); // , EnPowerSupply_reloadVal, EnPowerSupply_offset);
TimeSliceOffset_Start(); /* 启动时间片轮询 */ TimeSliceOffset_Start(); /* 启动时间片轮询 */
} }
@ -354,12 +354,13 @@ void hardware_Init(void)
DSG_PROT_Init(); DSG_PROT_Init();
SPI_Flash_Init(); SPI_Flash_Init();
// Set_duty_ratio(0.5); EnPowerSupply_Init();
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
// TIM_SetCompare4(TIM4, 5000); // TIM_SetCompare4(TIM4, 5000);
Set_duty_ratio(&g_duty_ratio); Set_duty_ratio(&g_duty_ratio);
// Set_duty_ratio(0);
// Delay_Ms(100); // Delay_Ms(100);
// CapCharg();
// TIM_SetCompare2(TIM4, 50); // TIM_SetCompare2(TIM4, 50);
} }

View File

@ -52,10 +52,18 @@ void POW_OUT_CON_Init(void);
#define DSG_PROT_PIN GPIO_Pin_2 #define DSG_PROT_PIN GPIO_Pin_2
void DSG_PROT_Init(void); void DSG_PROT_Init(void);
///* */
///* PV_VOLTOUT_INT --> PA12 */
///* 电压过低时, */
//#define DSG_PROT_GPIO GPIOB
//#define DSG_PROT_PIN GPIO_Pin_2
//void DSG_PROT_Init(void);
/* ¸ø±Ãµç·µçÈݳäµç */ /* ¸ø±Ãµç·µçÈݳäµç */
/* CapCharg --> PB7 */ /* EnPowerSupply --> PB7 */
#define CAPCHARG_GPIO GPIOB #define EnPowerSupply_GPIO GPIOB
#define CAPCHARG_PIN GPIO_Pin_7 #define EnPowerSupply_PIN GPIO_Pin_7
void CAPCHARG_Init(void); void EnPowerSupply_Init(void);
#endif /* HARDWARE_INC_GPIO_H_ */ #endif /* HARDWARE_INC_GPIO_H_ */

View File

@ -13,9 +13,9 @@
#define Prescaler 0 #define Prescaler 0
/* 输出频率为240M */ /* 输出频率为240k */
#define Period 200 - 1 //#define Period 200 - 1
//#define Period 20000 - 1 #define Period 480 - 1
void PWM_TIM_Configuration(void); void PWM_TIM_Configuration(void);
void Set_duty_ratio(float *duty_ratio); void Set_duty_ratio(float *duty_ratio);

View File

@ -16,13 +16,13 @@ void G_FFMOS_CON_Init(void)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_WriteBit(GPIOA, GPIO_Pin_15, RESET); //关闭mos管打开光伏输入 GPIO_WriteBit(GPIOA, GPIO_Pin_15, SET); //关闭mos管打开光伏输入
/* G_FFMOS_CON2 --> PB3 */ /* G_FFMOS_CON2 --> PB3 */
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE); RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_WriteBit(GPIOB, GPIO_Pin_3, RESET); GPIO_WriteBit(GPIOB, GPIO_Pin_3, SET);
} }
void RUN_LED_Init(void) void RUN_LED_Init(void)
@ -101,16 +101,16 @@ void EXTI2_IRQHandler(void)
} }
} }
void CAPCHARG_Init(void) void EnPowerSupply_Init(void)
{ {
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE); RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = CAPCHARG_PIN; GPIO_InitStructure.GPIO_Pin = EnPowerSupply_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(CAPCHARG_GPIO, &GPIO_InitStructure); GPIO_Init(EnPowerSupply_GPIO, &GPIO_InitStructure);
// GPIO_WriteBit(CAPCHARG_GPIO, CAPCHARG_PIN, RESET); GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, RESET);
} }

View File

@ -57,11 +57,11 @@ void PWM_TIM_Configuration(void)
void Set_duty_ratio(float *duty_ratio) void Set_duty_ratio(float *duty_ratio)
{ {
if (*duty_ratio < 0) { if (*duty_ratio < 0.4) {
*duty_ratio = 0; *duty_ratio = 0.4;
return; return;
} else if (*duty_ratio > 1) { } else if (*duty_ratio > 0.9) {
*duty_ratio = 1; *duty_ratio = 0.9;
return; return;
} }

View File

@ -20,8 +20,7 @@
#define SYSCLK_FREQ_48MHz_HSE 48000000 #define SYSCLK_FREQ_48MHz_HSE 48000000
//#define SYSCLK_FREQ_56MHz_HSE 56000000 //#define SYSCLK_FREQ_56MHz_HSE 56000000
//#define SYSCLK_FREQ_72MHz_HSE 72000000 //#define SYSCLK_FREQ_72MHz_HSE 72000000
//#define SYSCLK_FREQ_96MHz_HSE 96000000 //#define SYSCLK_FREQ_96MHz_HSE 960000+
//#define SYSCLK_FREQ_HSI HSI_VALUE
//#define SYSCLK_FREQ_48MHz_HSI 48000000 //#define SYSCLK_FREQ_48MHz_HSI 48000000
//#define SYSCLK_FREQ_56MHz_HSI 56000000 //#define SYSCLK_FREQ_56MHz_HSI 56000000
//#define SYSCLK_FREQ_72MHz_HSI 72000000 //#define SYSCLK_FREQ_72MHz_HSI 72000000

Binary file not shown.

View File

@ -28,7 +28,10 @@ App/src/mppt_control.o: ../App/src/mppt_control.c \
D:\psx\MPPT\git\Peripheral\inc/ch32l103_opa.h \ D:\psx\MPPT\git\Peripheral\inc/ch32l103_opa.h \
D:\psx\MPPT\git\App\inc/collect_Conversion.h \ D:\psx\MPPT\git\App\inc/collect_Conversion.h \
D:\psx\MPPT\git\Hardware\inc/adc.h D:\psx\MPPT\git\Hardware\inc/pwm.h \ D:\psx\MPPT\git\Hardware\inc/adc.h D:\psx\MPPT\git\Hardware\inc/pwm.h \
D:\psx\MPPT\git\App\inc/inflash.h D:\psx\MPPT\git\Hardware\inc/gpio.h D:\psx\MPPT\git\App\inc/inflash.h D:\psx\MPPT\git\Hardware\inc/gpio.h \
D:\psx\MPPT\git\App\inc/uart_dev.h \
D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h \
D:\psx\MPPT\git\Hardware\inc/rs485.h
D:\psx\MPPT\git\App\inc/mppt_control.h: D:\psx\MPPT\git\App\inc/mppt_control.h:
@ -97,3 +100,9 @@ D:\psx\MPPT\git\Hardware\inc/pwm.h:
D:\psx\MPPT\git\App\inc/inflash.h: D:\psx\MPPT\git\App\inc/inflash.h:
D:\psx\MPPT\git\Hardware\inc/gpio.h: D:\psx\MPPT\git\Hardware\inc/gpio.h:
D:\psx\MPPT\git\App\inc/uart_dev.h:
D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h:
D:\psx\MPPT\git\Hardware\inc/rs485.h:

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