简陋检验,几种充电状态的切换

This commit is contained in:
起床就犯困 2024-08-23 16:50:34 +08:00
parent b7e1572375
commit de2f325604
26 changed files with 12497 additions and 8790 deletions

View File

@ -19,8 +19,7 @@ typedef struct _SL_Mppt_para{
uint16_t Battery_Voltage; /* µç³Øµçѹ */
uint16_t Battery_temperature; /* µç³ØÎÂ¶È */
uint16_t Remaining_Battery_Bower; /* µç³ØÊ£ÓàµçÁ¿ */
uint16_t Solar_Open_Circuit_Voltage1; /* 太阳能开路电压1 */
uint16_t Solar_Open_Circuit_Voltage2; /* 太阳能开路电压2 */
uint16_t Solar_Open_Circuit_Voltage; /* 太阳能开路电压 */
}SL_Mppt_para;
extern SL_Mppt_para g_Mppt_Para;
#pragma pack(pop)
@ -48,5 +47,6 @@ void mppt_readJust(void);
void MpptMode(void);
void mppt_constantVoltage(float InVoltage);
void test(void);
void printf_data(void);
#endif /* APP_INC_MPPT_CONTROL_H_ */

View File

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

View File

@ -21,7 +21,7 @@
#define MOSFET_Temper ADC_Channel_6
#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));
@ -30,9 +30,9 @@ const float P_PV_VOLT_OUT = (47.0 + 10.0) / 10.0;
/* 放电电流采集电流倍数 */
const float P_DSG_CURR = (1.0 / (50 * 0.005));
///* 光伏1开路输出电压比例 */
//const float P_PV1_VOLT_IN = (100 + 4.7) / 4.7;
const float P_PV1_VOLT_IN = (100 + 4.7) / 4.7;
/* 光伏1开路输出电压比例 */
const float P_PV1_VOLT_IN = (47 + 4.7) / 4.7;
//const float P_PV1_VOLT_IN = (47 + 4.7) / 4.7;
/* 系统电源电压比例 */
const float P_PV_VOLT_IN1 = (47 + 4.7) / 4.7;
/* 温度采集比例 */
@ -166,7 +166,7 @@ float get_DSG_CURR(void)
I_ADC = Get_ConversionVal(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 * 2;
#ifdef enable_Printf_VI
printf("\n DSG_CURR ADC : %d \n", I_ADC);

View File

@ -16,10 +16,10 @@ config_info g_slConfigInfo = {
.Communication_Methods = RS485,
.bat485_Baud = 9600,
.gw485_Baud = 9600,
.ConstantCurrentV = 1030,
.ConstantCurrentV = 1300,
.FloatI = 10,
.startSolarOpenCircuitV = 1800,
.ConstantCurrentV = 1100,
.ConstantVoltageV = 1400,
.FloatI = 50,
.startSolarOpenCircuitV = 1600,
};

View File

@ -24,7 +24,7 @@ static void FloatingCharge(void);
/* 占空比 */
float g_duty_ratio = 0.7;
/* 用于确定工作模式 */
static uint8_t modeFlag = 0;
static uint8_t modeFlag = 2;
/**
* @brief
@ -137,13 +137,16 @@ void mppt_readJust(void)
void printf_data(void)
{
printf("\n");
get_CHG_CURR();
get_PV_VOLT_OUT();
get_DSG_CURR();
// 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();
// get_PV_VOLT_IN1();
// get_MOSFET_Temper();
// get_PV2_VOLT_IN();
printf("1. 涓流模式; 2. 恒流模式; 3, 恒压模式; 4, 浮充模式modeFlag : %d \n", modeFlag);
printf("\n");
}
@ -184,22 +187,23 @@ void mppt_constantVoltage(float InVoltage)
// }
// }
static float_t kp = 0.05;
static float_t ki = 0.0001;
static float_t kp = 0.005;
static float_t ki = 0.00001;
// static float_t allError = 0;
// float_t error = (get_PV1_VOLT_IN()) - InVoltage;
// float_t error = InVoltage - (get_PV2_VOLT_IN());
// allError += error;
float_t pv1Volt = get_PV2_VOLT_IN();
float_t pv1Volt = get_PV1_VOLT_IN();
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));
// printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
// printf("g_duty_ratio : %d/10000 \n", (int)(g_duty_ratio * 10000));
Set_duty_ratio(&g_duty_ratio);
}
@ -243,6 +247,8 @@ void mppt_constantVoltageO(float OutVoltage)
static float_t kp = 0.02;
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 error = outVolt - OutVoltage;
@ -250,8 +256,7 @@ void mppt_constantVoltageO(float OutVoltage)
float_t stepPwm = kp * error + ki * outVolt;
g_duty_ratio += stepPwm;
printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
// printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
Set_duty_ratio(&g_duty_ratio);
@ -296,24 +301,43 @@ void mppt_constantCurrentO(float outCurrent)
// }
// }
static float_t kp = 0.01;
static float_t ki = 0.0001;
static float_t kp = 0.005;
static float_t ki = 0.00005;
// static float_t last_CHG_CURR = 0;
// static float_t flag = 0;
// static float_t flag = 1;
// static float_t last_OutputPower = 0;
float_t outCurr = get_CHG_CURR();
// float_t OutputPower = outCurr * get_PV_VOLT_OUT();
float_t error = outCurrent - outCurr;
// float_t error = outCurr - outCurrent;
float_t stepPwm = kp * error + ki * outCurr;
// if ((last_CHG_CURR > outCurr) && flag) {
// g_duty_ratio -= stepPwm;
// if (flag) {
// if (OutputPower > last_OutputPower) {
// g_duty_ratio += stepPwm;
// flag = 1;
// } else {
g_duty_ratio += stepPwm;
// g_duty_ratio -= stepPwm;
// flag = 0;
// }
// } else {
// if (OutputPower > last_OutputPower) {
// g_duty_ratio -= stepPwm;
// flag = 0;
// } else {
// g_duty_ratio += stepPwm;
// flag = 1;
// }
// }
//
// last_OutputPower = OutputPower;
printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
g_duty_ratio += stepPwm;
// printf("setPwm : %d/10000 \n", (int)(stepPwm * 10000));
// printf("g_duty_ratio : %d/10000 \n", (int)(g_duty_ratio * 10000));
Set_duty_ratio(&g_duty_ratio);
@ -333,7 +357,7 @@ void mppt_constantCurrentO(float outCurrent)
*/
void TrickleCharge(void)
{
mppt_constantCurrentO(0.7);
mppt_constantCurrentO(1);
}
/**
@ -344,7 +368,9 @@ void TrickleCharge(void)
*/
void ConstantCurrentCharge(void)
{
mppt_readJust();
// mppt_readJust();
mppt_constantVoltage(18);
}
/**
@ -355,7 +381,12 @@ void ConstantCurrentCharge(void)
*/
void ConstantVoltageCharge(void)
{
mppt_constantVoltage(17.5);
// mppt_constantVoltage(17.5);
// mppt_constantVoltageO((float_t)g_Mppt_Para.Battery_Voltage);
mppt_constantVoltageO(14.5);
// g_duty_ratio = 0.9;
// Set_duty_ratio(&g_duty_ratio);
}
/**
@ -366,39 +397,57 @@ void ConstantVoltageCharge(void)
*/
void FloatingCharge(void)
{
static uint8_t run_num;
// static uint32_t run_num;
if (get_CHG_CURR() > 0.1) {
mppt_constantVoltageO(12);
if (run_num++ > 100) {
if ((get_PV_VOLT_OUT()) < 14) {
run_num = 0;
modeFlag = CONSTANTVOLTAGE;
return;
}
}
}
// if (get_CHG_CURR() > 0.01) {
// mppt_constantVoltageO(12);
// if (run_num++ > 100) {
// if ((get_PV_VOLT_OUT()) < 14) {
// run_num = 0;
// modeFlag = CONSTANTVOLTAGE;
// return;
// }
// }
// }
//
// else {
// TIM_SetCompare4(TIM4, 0);
// if (run_num++) {
// if ((get_PV_VOLT_OUT()) < 14) {
// run_num = 0;
// modeFlag = CONSTANTVOLTAGE;
// return;
// }
// }
//
// if (run_num > 100) {
// run_num = 0;
// modeFlag = CONSTANTVOLTAGE;
// return;
// }
// }
//
// if (run_num > 200) {
// run_num = 100;
// }
else {
static uint32_t num = 0;
TIM_SetCompare4(TIM4, 0);
if (run_num++) {
if ((get_PV_VOLT_OUT()) < 14) {
run_num = 0;
// mppt_constantVoltageO(12);
if (500 == num++) {
// if ((get_PV_VOLT_OUT()) > 13.5) {
num = 0;
modeFlag = CONSTANTVOLTAGE;
return;
}
// return;
// }
}
if (run_num > 100) {
run_num = 0;
modeFlag = CONSTANTVOLTAGE;
return;
}
}
// if ((get_PV_VOLT_OUT()) > 13.5) {
// modeFlag = CONSTANTVOLTAGE;
// return;
// }
if (run_num > 200) {
run_num = 100;
}
}
@ -428,38 +477,68 @@ void MpptContorl(void)
void MpptMode(void)
{
static uint8_t temp_flag = 1;
static float ConstantCurrentV;
static float ConstantVoltageV;
static float FloatI;
/* ¸³Öµ½öÖ´ÐÐÒ»´Î */
if (temp_flag) {
ConstantCurrentV = (float)g_slConfigInfo.ConstantCurrentV / 100;
ConstantVoltageV = (float)g_slConfigInfo.ConstantVoltageV / 100;
FloatI = (float)g_slConfigInfo.FloatI / 100;
temp_flag = 0;
}
// static uint8_t temp_flag = 1;
// static float ConstantCurrentV;
// static float ConstantVoltageV;
// static float FloatI;
// /* 赋值仅执行一次 */
// if (temp_flag) {
// ConstantCurrentV = (float)g_slConfigInfo.ConstantCurrentV / 100;
// ConstantVoltageV = (float)g_slConfigInfo.ConstantVoltageV / 100;
// FloatI = (float)g_slConfigInfo.FloatI / 100;
// temp_flag = 0;
//// printf("g_slConfigInfo.ConstantCurrentV : %d g_slConfigInfo.ConstantVoltageV : %d /100 \n", g_slConfigInfo.ConstantCurrentV, g_slConfigInfo.ConstantVoltageV);
//// printf("ConstantCurrentV : %d /100 ConstantVoltageV : %d /100 \n", (int)ConstantCurrentV, (int)ConstantVoltageV);
// }
if ((ConstantCurrentV < g_Mppt_Para.Battery_Voltage) &&
(ConstantVoltageV > g_Mppt_Para.Battery_Voltage)) {
modeFlag = CONSTANTCURRENT;
return;
}
printf("vout : %d /100 \n", g_Mppt_Para.Battery_Voltage);
printf("iout : %d /1000 \n", (int)(get_CHG_CURR() * 1000));
printf("in checkSolarOpenCircuitVoltage v: %d/100 \n", g_Mppt_Para.Solar_Open_Circuit_Voltage);
// printf("ConstantCurrentV : %d ConstantVoltageV : %d \n", (int)ConstantCurrentV, (int)ConstantVoltageV);
if (!(ConstantVoltageV > g_Mppt_Para.Battery_Voltage) &&
(FloatI < get_CHG_CURR())) {
modeFlag = CONSTANTVOLTAGE;
return;
}
// if (((ConstantVoltageV < (float)g_Mppt_Para.Battery_Voltage / 100) &&
// (FloatI > get_CHG_CURR())) || modeFlag == FLOAT) {
// modeFlag = FLOAT;
// return;
// }
//
// if ((ConstantCurrentV < (float)g_Mppt_Para.Battery_Voltage / 100) &&
// (ConstantVoltageV >= (float)g_Mppt_Para.Battery_Voltage / 100)) {
// modeFlag = CONSTANTCURRENT;
// return;
// }
//
// if ((ConstantVoltageV < (float)g_Mppt_Para.Battery_Voltage / 100) &&
// (FloatI <= get_CHG_CURR())) {
// modeFlag = CONSTANTVOLTAGE;
// return;
// }
if ((!(ConstantVoltageV > g_Mppt_Para.Battery_Voltage) &&
(FloatI > get_CHG_CURR())) || modeFlag == FLOAT) {
if (((14.3 < (float)g_Mppt_Para.Battery_Voltage / 100) &&
(0.08 > get_CHG_CURR())) || modeFlag == FLOAT) {
modeFlag = FLOAT;
return;
}
if ((13 < (float)g_Mppt_Para.Battery_Voltage / 100) &&
(13.8 >= (float)g_Mppt_Para.Battery_Voltage / 100)) {
modeFlag = CONSTANTCURRENT;
return;
}
if ((14.3 < (float)g_Mppt_Para.Battery_Voltage / 100) &&
(0.2 <= get_CHG_CURR())) {
modeFlag = CONSTANTVOLTAGE;
return;
}
if (12.5 > (float)g_Mppt_Para.Battery_Voltage / 100) {
modeFlag = TRICKLE;
return;
}
// modeFlag = CONSTANTCURRENT;
// return;
}
void findMiNDutyRatio(void)
@ -488,11 +567,13 @@ void test(void)
// printf_data();
// void MpptContorl();
// mppt_constantVoltageO(13);
// mppt_constantVoltageO(12);
// FloatingCharge();
// mppt_readJust();
// mppt_constantCurrentO(1.0);
// mppt_constantCurrentO(1);
MpptContorl();
// static uint32_t run_num = 0;
// if (1000 < run_num++) {

View File

@ -30,8 +30,8 @@ static uint16_t SL_ReadRegisterCommunicationMethods(void *pMsg);
static uint16_t SL_ReadRegisterBatteryVoltage(void *pMsg);
static uint16_t SL_ReadRegisterBatterytemperature(void *pMsg);
static uint16_t SL_ReadRegisterRemainingBatteryBower(void *pMsg);
static uint16_t SL_ReadRegisterSolarOpenCircuitVoltage1(void *pMsg);
static uint16_t SL_ReadRegisterSolarOpenCircuitVoltage2(void *pMsg);
static uint16_t SL_ReadRegisterSolarOpenCircuitVoltage(void *pMsg);
//static uint16_t SL_ReadRegisterSolarOpenCircuitVoltage2(void *pMsg);
//static uint16_t SL_WriteRegisterRegistrationStatus(void *pMsg);
//static uint16_t SL_WriteRegisteraddress(void *pMsg);
@ -82,8 +82,8 @@ SL_RegProcTable g_RegTblR[] =
{SL_Register_Battery_Voltage, SL_ReadRegisterBatteryVoltage},
{SL_Register_Battery_temperature, SL_ReadRegisterBatterytemperature},
{SL_Register_Remaining_Battery_Bower, SL_ReadRegisterRemainingBatteryBower},
{SL_Register_Solar_Open_Circuit_Voltage1, SL_ReadRegisterSolarOpenCircuitVoltage1},
{SL_Register_Solar_Open_Circuit_Voltage2, SL_ReadRegisterSolarOpenCircuitVoltage2},
{SL_Register_Solar_Open_Circuit_Voltage1, SL_ReadRegisterSolarOpenCircuitVoltage},
// {SL_Register_Solar_Open_Circuit_Voltage2, SL_ReadRegisterSolarOpenCircuitVoltage2},
};
/* 寄存器处理表 */
@ -508,24 +508,24 @@ uint16_t SL_ReadRegisterRemainingBatteryBower(void *pMsg)
* @param
* @retval
*/
uint16_t SL_ReadRegisterSolarOpenCircuitVoltage1(void *pMsg)
uint16_t SL_ReadRegisterSolarOpenCircuitVoltage(void *pMsg)
{
log_info(" SL_ReadRegisterSolarOpenCircuitVoltage1 ");
uint16_t value = (uint16_t)g_Mppt_Para.Solar_Open_Circuit_Voltage1 * 10;
return value;
}
/**
* @brief 2
* @param
* @retval
*/
uint16_t SL_ReadRegisterSolarOpenCircuitVoltage2(void *pMsg)
{
log_info(" SL_ReadRegisterSolarOpenCircuitVoltage2 ");
uint16_t value = (uint16_t)g_Mppt_Para.Solar_Open_Circuit_Voltage2 * 10;
uint16_t value = (uint16_t)g_Mppt_Para.Solar_Open_Circuit_Voltage * 10;
return value;
}
//
///**
// * @brief 读取太阳能开路电压2寄存器
// * @param
// * @retval
// */
//uint16_t SL_ReadRegisterSolarOpenCircuitVoltage2(void *pMsg)
//{
// log_info(" SL_ReadRegisterSolarOpenCircuitVoltage2 ");
// uint16_t value = (uint16_t)g_Mppt_Para.Solar_Open_Circuit_Voltage2 * 10;
// return value;
//}
///**
// * @brief 写入注册状态寄存器
@ -770,7 +770,7 @@ static int uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, uint3
}
if ((offset == 14) && (pack->function_Code == SL_Function_Code_Write_Register)) {
if ((pack->function_Code == SL_Function_Code_Write_Register) && (offset >= 14)) {
SL_Mppt_Worecv_pack *wpack = (SL_Mppt_Worecv_pack *)buff;
uint8_t Register_Number = (wpack->write_Register_Number_H << 8) | wpack->write_Register_Number_L;
len = Register_Number * 2 + SL_MPPT_WORECV_PACK_SIZE - 4;

View File

@ -33,7 +33,10 @@ void Task_RunLED(void)
// 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));
printf("duty_ratio : %d/1000 \n", (int)(g_duty_ratio * 1000));
printf_data();
// get_CHG_CURR();
static uint8_t flag = RESET;
flag = !flag;
@ -50,7 +53,7 @@ void Task_RunLED(void)
STR_TimeSliceOffset m_mpptControl;
void Task_mpptControl(void)
{
// test();
test();
// static uint8_t test_flag = 0;
// if (5 == ++test_flag) {
@ -102,8 +105,9 @@ void Task_wdi(void)
* @retval
*/
#define checkRemainingBatteryBower 30 //电池剩余电量30s刷新一次
#define checkSolarOpenCircuitVoltage 1800 //太阳能板开路电压30min刷新一次
#define mpptmodedelay 60 //mppt工作模式60s刷新一次小于1000S
//#define checkSolarOpenCircuitVoltage 1800 //太阳能板开路电压30min刷新一次
#define checkSolarOpenCircuitVoltage 100 //太阳能板开路电压刷新一次
#define mpptmodedelay 1 //mppt工作模式60s刷新一次小于1000S
//#define checkSolarOpenCircuitDelay 500 //检测太阳能板开路电压时,关闭太阳能板的延时时间
STR_TimeSliceOffset m_refreshRegister;
void Task_refreshRegister(void)
@ -114,9 +118,9 @@ void Task_refreshRegister(void)
static uint32_t opencheckFlag = 0;
static uint32_t mpptModeFlag = mpptmodedelay -1;
/* 后续可以添加考虑减少放电电流的影响 */
g_Mppt_Para.Battery_Voltage = 0;
// g_Mppt_Para.Battery_Voltage = 0;
g_Mppt_Para.Battery_temperature = 0;
g_Mppt_Para.Battery_Voltage = (uint16_t)(get_PV_VOLT_OUT() * 100);
if (checkRemainingBatteryBower == ++checkFlagTemp1) {
g_Mppt_Para.Remaining_Battery_Bower = 0;
@ -124,43 +128,72 @@ void Task_refreshRegister(void)
}
if (checkSolarOpenCircuitVoltage == ++checkFlagTemp2 || (opencheckFlag && ++checkFlagTemp2)) {
if (!opencheckFlag) {
Set_duty_ratio(0);
// printf("in checkSolarOpenCircuitVoltage \n");
if (!opencheckFlag) {
TIM_SetCompare4(TIM4, 0);
opencheckFlag = 1;
checkFlagTemp2 = 0;
}
else {
GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, SET);
GPIO_WriteBit(G_FFMOS_CON2_GPIO, G_FFMOS_CON2_PIN, SET);
g_Mppt_Para.Solar_Open_Circuit_Voltage1 = get_PV1_VOLT_IN();
g_Mppt_Para.Solar_Open_Circuit_Voltage2 = get_PV2_VOLT_IN();
GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, RESET);
GPIO_WriteBit(G_FFMOS_CON2_GPIO, G_FFMOS_CON2_PIN, RESET);
// GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, SET);
// GPIO_WriteBit(G_FFMOS_CON2_GPIO, G_FFMOS_CON2_PIN, SET);
// g_Mppt_Para.Solar_Open_Circuit_Voltage1 = get_PV1_VOLT_IN();
// g_Mppt_Para.Solar_Open_Circuit_Voltage2 = get_PV2_VOLT_IN();
// GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, RESET);
// GPIO_WriteBit(G_FFMOS_CON2_GPIO, G_FFMOS_CON2_PIN, RESET);
// opencheckFlag = 0;
//
// if ((g_Mppt_Para.Solar_Open_Circuit_Voltage1
// > g_slConfigInfo.startSolarOpenCircuitV)
// || (g_Mppt_Para.Solar_Open_Circuit_Voltage2
// > g_slConfigInfo.startSolarOpenCircuitV)) {
// TimeSliceOffset_Register(&m_mpptControl, Task_mpptControl
// , mpptControl_reloadVal, mpptControl_offset);
// mpptModeFlag = 0;
// Set_duty_ratio(&g_duty_ratio);
// } else {
// TimeSliceOffset_Unregister(&m_mpptControl);
// mpptModeFlag = 100;
// }
g_Mppt_Para.Solar_Open_Circuit_Voltage = (uint16_t)(get_PV1_VOLT_IN() * 100);
opencheckFlag = 0;
if ((g_Mppt_Para.Solar_Open_Circuit_Voltage1
> g_slConfigInfo.startSolarOpenCircuitV)
|| (g_Mppt_Para.Solar_Open_Circuit_Voltage2
> g_slConfigInfo.startSolarOpenCircuitV)) {
TimeSliceOffset_Register(&m_mpptControl, Task_mpptControl
, mpptControl_reloadVal, mpptControl_offset);
// printf("in checkSolarOpenCircuitVoltage v: %d/100 \n", g_Mppt_Para.Solar_Open_Circuit_Voltage1);
if (g_Mppt_Para.Solar_Open_Circuit_Voltage
> g_slConfigInfo.startSolarOpenCircuitV) {
// TimeSliceOffset_Register(&m_mpptControl, Task_mpptControl
// , mpptControl_reloadVal, mpptControl_offset);
mpptModeFlag = 0;
TIM_Cmd(TIM3, ENABLE);
Set_duty_ratio(&g_duty_ratio);
} else {
TimeSliceOffset_Unregister(&m_mpptControl);
// TimeSliceOffset_Unregister(&m_mpptControl);
TIM_Cmd(TIM3, DISABLE);
TIM_SetCompare4(TIM4, 0);
mpptModeFlag = 100;
}
}
}
// if (mpptModeFlag != 100) {
// if (mpptmodedelay == ++mpptModeFlag) {
//// printf("vout : %d /100", g_Mppt_Para.Battery_Voltage);
// MpptMode();
// mpptModeFlag = 0;
// }
// }
if (mpptModeFlag != 100) {
if (mpptmodedelay == ++mpptModeFlag) {
// printf("vout : %d /100", g_Mppt_Para.Battery_Voltage);
MpptMode();
mpptModeFlag = 0;
}
}
// MpptMode();
return;
}
@ -264,12 +297,12 @@ void Task_recvbroadcast(void)
STR_TimeSliceOffset m_EnPowerSupply;
void Task_EnPowerSupply(void)
{
if (get_PV_VOLT_IN1() > 17 - 0.4) {
GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, SET);
return;
} else if (get_PV_VOLT_IN1() < 14 - 0.4) {
if (get_PV_VOLT_IN1() > 16.0) {
GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, RESET);
return;
} else if (get_PV_VOLT_IN1() < 14.5) {
GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, SET);
return;
}
return;
}
@ -294,8 +327,8 @@ void g_Mppt_Para_Init(void)
g_Mppt_Para.Battery_Voltage = 0;
g_Mppt_Para.Battery_temperature = 0;
g_Mppt_Para.Remaining_Battery_Bower = 0;
g_Mppt_Para.Solar_Open_Circuit_Voltage1 = 0;
g_Mppt_Para.Solar_Open_Circuit_Voltage2 = 0;
g_Mppt_Para.Solar_Open_Circuit_Voltage = 0;
// g_Mppt_Para.Solar_Open_Circuit_Voltage2 = 0;
}
/**
@ -305,25 +338,26 @@ void g_Mppt_Para_Init(void)
*/
void task_Init(void)
{
read_config_info();
// read_config_info();
g_Mppt_Para_Init();
TimeSliceOffset_Register(&m_runled, Task_RunLED, runled_reloadVal, runled_offset);
// m_refreshRegister.runFlag = 1; /* 该启动后立即执行一次 */
// TimeSliceOffset_Register(&m_refreshRegister, Task_refreshRegister
// , refreshRegister_reloadVal, refreshRegister_offset);
TimeSliceOffset_Register(&m_refreshRegister, Task_refreshRegister
, refreshRegister_reloadVal, refreshRegister_offset);
// TimeSliceOffset_Register(&m_mpptControl, Task_mpptControl
// , mpptControl_reloadVal, mpptControl_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);
TimeSliceOffset_Register(&m_EnPowerSupply, Task_EnPowerSupply
, EnPowerSupply_reloadVal, EnPowerSupply_offset);
// TimeSliceOffset_Register(&m_EnPowerSupply, Task_EnPowerSupply
// , EnPowerSupply_reloadVal, EnPowerSupply_offset);
TimeSliceOffset_Start(); /* 启动时间片轮询 */
}
@ -336,7 +370,7 @@ void task_Init(void)
*/
void hardware_Init(void)
{
TIM3_Init();
Systick_Init();
TIM2_Init();
uart_dev_init();
PWM_TIM_Configuration();
@ -353,10 +387,13 @@ void hardware_Init(void)
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
// TIM_SetCompare4(TIM4, 5000);
GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, RESET);
Set_duty_ratio(&g_duty_ratio);
// Set_duty_ratio(0);
// Delay_Ms(100);
// TIM_SetCompare2(TIM4, 50);
// TIM1_Init(20);
TIM3_Init(5);
}

View File

@ -63,7 +63,7 @@ void DSG_PROT_Init(void);
/* ¸ø±Ãµç·µçÈݳäµç */
/* EnPowerSupply --> PB7 */
#define EnPowerSupply_GPIO GPIOB
#define EnPowerSupply_PIN GPIO_Pin_7
#define EnPowerSupply_PIN GPIO_Pin_3
void EnPowerSupply_Init(void);
#endif /* HARDWARE_INC_GPIO_H_ */

View File

@ -14,11 +14,16 @@
extern uint8_t run_Broadcast;
void TIM3_Init(void);
void TIM3_Init(uint16_t delay_ms);
void TIM3_Int_Init(uint16_t arr,uint16_t psc);
void TIM2_Init(void);
void TIM2_Int_Init(uint16_t arr,uint16_t psc);
void Systick_Init(void);
void TIM1_Init(uint16_t delay_ms);
void TIM1_Int_Init(uint16_t arr,uint16_t psc);
#endif /* HARDWARE_INC_TIM_H_ */

View File

@ -63,6 +63,8 @@ void POW_OUT_CON_Init(void)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(POW_OUT_CON_GPIO, &GPIO_InitStructure);
GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
}
void EXTI2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
@ -110,7 +112,7 @@ void EnPowerSupply_Init(void)
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(EnPowerSupply_GPIO, &GPIO_InitStructure);
GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, RESET);
GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, SET);
}

View File

@ -57,12 +57,12 @@ void PWM_TIM_Configuration(void)
void Set_duty_ratio(float *duty_ratio)
{
if (*duty_ratio < 0.4) {
*duty_ratio = 0.4;
return;
if (*duty_ratio < 0.5) {
*duty_ratio = 0.5;
// return;
} else if (*duty_ratio > 0.9) {
*duty_ratio = 0.9;
return;
// return;
}
uint16_t pulse = *duty_ratio * (Period + 1);

View File

@ -8,9 +8,7 @@
#include "tim.h"
#include "timeSliceOffset.h"
#include "pwm.h"
/* 时间基准为1ms1ms切换一次任务 */
#define delayms 1
#include "mppt_control.h"
/* 延时时间 */
#define delays 20
@ -20,13 +18,18 @@ uint8_t run_Broadcast = 1;
void TIM3_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void TIM2_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void SysTick_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void TIM3_Init(void)
void TIM1_UP_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void TIM3_Init(uint16_t delay_ms)
{
/* 分频系数 */
uint16_t psc = (SystemCoreClock / 10000) - 1;
/* 分频系数 */
uint16_t arr = delayms * 10 - 1;
uint16_t arr = delay_ms * 10 - 1;
TIM3_Int_Init(arr, psc);
}
@ -49,11 +52,11 @@ void TIM3_Int_Init(uint16_t arr, uint16_t psc)
//初始化TIM NVIC设置中断优先级分组
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //设置抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //设置响应优先级3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //设置响应优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能通道1中断
NVIC_Init(&NVIC_InitStructure); //初始化NVIC
TIM_Cmd(TIM3, ENABLE); //TIM3使能
// TIM_Cmd(TIM3, ENABLE); //TIM3使能
}
void TIM3_IRQHandler(void)
@ -63,7 +66,7 @@ void TIM3_IRQHandler(void)
// static int flag1 = 0;
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) { //检查TIM3中断是否发生。
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); //清除TIM3的中断挂起位。
TimeSliceOffset_Produce();
test();
// flag1++;
// if (flag1 == 20) {
// if (flag) {
@ -129,3 +132,70 @@ void TIM2_IRQHandler(void)
run_Broadcast = 1;
}
}
//SysTick初始化配置 1MS进入一次中断
static void SysTick_Config(uint32_t ticks)
{
SysTick->SR = 0;
SysTick->CNT = 0;
SysTick->CMP = ticks;
SysTick->CTLR =0xF;
NVIC_SetPriority(SysTicK_IRQn, 15);
NVIC_EnableIRQ(SysTicK_IRQn);
}
void Systick_Init(void)
{
SysTick_Config((SystemCoreClock / 1000) - 1);
}
void SysTick_Handler(void)
{
SysTick->SR = 0;
TimeSliceOffset_Produce();
}
void TIM1_Init(uint16_t delay_ms)
{
/* 分频系数 */
uint16_t psc = (SystemCoreClock / 10000) - 1;
/* */
uint16_t arr = delay_ms * 10 - 1;
// uint16_t arr = 10 - 1;
TIM1_Int_Init(arr, psc);
}
void TIM1_Int_Init(uint16_t arr, uint16_t psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_PB2PeriphClockCmd(RCC_PB2Periph_TIM1, ENABLE); //使能TIM1时钟
TIM_TimeBaseStructure.TIM_Period = arr; //指定下次更新事件时要加载到活动自动重新加载寄存器中的周期值。
TIM_TimeBaseStructure.TIM_Prescaler = psc; //指定用于划分TIM时钟的预分频器值。
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //时钟分频因子
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM计数模式向上计数模式
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); //根据指定的参数初始化TIMx的时间基数单位
TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE); //使能TIM1中断允许更新中断
//初始化TIM NVIC设置中断优先级分组
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn; //TIM1中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //设置抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //设置响应优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能通道中断
NVIC_Init(&NVIC_InitStructure); //初始化NVIC
TIM_Cmd(TIM1, ENABLE); //TIM1使能
}
void TIM1_UP_IRQHandler(void)
{
if (TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET) { //检查TIM1中断是否发生。
TIM_ClearITPendingBit(TIM1, TIM_IT_Update); //清除TIM1的中断挂起位。
printf("in tim1 irq \n");
}
}

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.

View File

@ -29,7 +29,8 @@ Hardware/src/tim.o: ../Hardware/src/tim.c \
D:\psx\MPPT\git\Drivers\TimeSliceOffset/timeSliceOffset.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\Hardware\inc/pwm.h
D:\psx\MPPT\git\Hardware\inc/rs485.h D:\psx\MPPT\git\Hardware\inc/pwm.h \
D:\psx\MPPT\git\App\inc/mppt_control.h
D:\psx\MPPT\git\Hardware\inc/tim.h:
@ -98,3 +99,5 @@ D:\psx\MPPT\git\Drivers\RingQueue/ring_queue.h:
D:\psx\MPPT\git\Hardware\inc/rs485.h:
D:\psx\MPPT\git\Hardware\inc/pwm.h:
D:\psx\MPPT\git\App\inc/mppt_control.h:

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