基本功能都已经实现,但是mppt开始工作后电流采集不准
This commit is contained in:
parent
ca4948aa4e
commit
ff0ffbae91
|
@ -62,6 +62,9 @@ typedef struct _config_info{
|
|||
uint16_t HighSideMosTemperature_stop; /* 当上桥温度达到该值时,停止输出 */
|
||||
uint16_t HighSideMosTemperature_end; /* 当上桥温度上升到该值时,降低功率运行 */
|
||||
uint16_t HighSideMosTemperature_start; /* 当上桥温度降低到该值时,按照正常情况输出 */
|
||||
uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 */
|
||||
uint16_t excessiveLoadFlagTime; /* 出现过载后,在该段时间中再次出现过载,则关闭输出 */
|
||||
uint16_t eLAgainTime; /* 出现过载过载保护后,该段时间后,再次尝试输出 */
|
||||
uint8_t end_Flag; /* 结束标志 */
|
||||
}config_info;
|
||||
#define CONFIG_INFO_SIZE (sizeof(config_info))
|
||||
|
@ -72,8 +75,8 @@ extern config_info g_slConfigInfo;
|
|||
#define FLASH_SAVE_ADDR_BEGIN (0x00)
|
||||
#define FLASH_SAVE_ADDR_END (0x00 + CONFIG_INFO_SIZE)
|
||||
|
||||
void save_config_info(config_info save_config_info);
|
||||
void save_config_info(config_info *save_config_info);
|
||||
uint8_t read_config_info(void);
|
||||
|
||||
uint8_t read_config_info1(config_info *in_config_info);
|
||||
|
||||
#endif /* APP_INC_INFLASH_H_ */
|
||||
|
|
|
@ -62,6 +62,7 @@ extern void Task_recvbroadcast(void);
|
|||
#define impedanceCalculation_offset 0 /* 任务执行偏移量 */
|
||||
extern float_t g_impedance;
|
||||
extern uint8_t g_batteryState;
|
||||
extern uint8_t g_impedanceStart;
|
||||
extern STR_TimeSliceOffset m_impedanceCalculation;
|
||||
extern void Task_impedanceCalculation(void);
|
||||
|
||||
|
@ -71,6 +72,12 @@ extern uint8_t outputAgainFlag;
|
|||
extern STR_TimeSliceOffset m_outputAgain;
|
||||
extern void Task_outputAgain(void);
|
||||
|
||||
#define excessiveLoad_reloadVal 1000 /* 任务执行间隔 */
|
||||
#define excessiveLoad_offset 0 /* 任务执行偏移量 */
|
||||
extern uint8_t excessiveLoadFlag;
|
||||
extern STR_TimeSliceOffset m_excessiveLoad;
|
||||
extern void Task_excessiveLoad(void);
|
||||
|
||||
#define sensorEnableBroadcast_reloadVal 1000 /* 任务执行间隔 */
|
||||
#define sensorEnableBroadcast_offset 0 /* 任务执行偏移量 */
|
||||
extern STR_TimeSliceOffset m_sensorEnableBroadcast;
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
const float P_CHG_CURR = (1.0 / (50 * 0.005 / 2));
|
||||
/* 光伏充电输出电压比例,分压系数(放电时采集不准) */
|
||||
//const float P_PV_VOLT_OUT = (47.0 + 10.0) / 10.0;
|
||||
const float P_PV_VOLT_OUT = (47.0 + 4.7) / 4.7;
|
||||
//const float P_PV_VOLT_OUT = (47.0 + 4.7) / 4.7;
|
||||
const float P_PV_VOLT_OUT = (56.0 + 10.0) / 10.0;
|
||||
/* 放电电流采集电流倍数 */
|
||||
const float P_DSG_CURR = (1.0 / (50 * 0.005 / 2));
|
||||
///* 光伏1开路输出电压比例 */
|
||||
|
|
|
@ -27,6 +27,9 @@ config_info g_slConfigInfo = {
|
|||
.HighSideMosTemperature_stop = 70,
|
||||
.HighSideMosTemperature_end = 50,
|
||||
.HighSideMosTemperature_start = 40,
|
||||
.outputAgainFlagTime = 10,
|
||||
.excessiveLoadFlagTime = 60,
|
||||
.eLAgainTime = 3600,
|
||||
};
|
||||
|
||||
|
||||
|
@ -35,9 +38,9 @@ config_info g_slConfigInfo = {
|
|||
* @param save_config_info 需要保存的配置信息
|
||||
* @retval
|
||||
*/
|
||||
void save_config_info(config_info save_config_info)
|
||||
void save_config_info(config_info *save_config_info)
|
||||
{
|
||||
SPI_Flash_Write((uint8_t *)&save_config_info, FLASH_SAVE_ADDR_BEGIN, CONFIG_INFO_SIZE);
|
||||
SPI_Flash_Write((uint8_t *)save_config_info, FLASH_SAVE_ADDR_BEGIN, CONFIG_INFO_SIZE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,7 +76,36 @@ uint8_t read_config_info(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 读取配置信息
|
||||
* @param read_config_info1 读取的配置信息并保存在in_config_info中
|
||||
* @retval 0 flash中读取配置失败,使用默认配置
|
||||
* 1 flash中读取配置成功
|
||||
*/
|
||||
uint8_t read_config_info1(config_info *in_config_info)
|
||||
{
|
||||
config_info temp_config_info;
|
||||
SPI_Flash_Read((uint8_t *)&temp_config_info, FLASH_SAVE_ADDR_BEGIN, CONFIG_INFO_SIZE);
|
||||
if (temp_config_info.start_Flag[0] == 'S'
|
||||
&& temp_config_info.start_Flag[1] == 'L'
|
||||
&& temp_config_info.end_Flag == 0x16) {
|
||||
*in_config_info = temp_config_info;
|
||||
return 1;
|
||||
} else {
|
||||
in_config_info->start_Flag[0] = defaultValue.start_Flag[0];
|
||||
in_config_info->start_Flag[1] = defaultValue.start_Flag[1];
|
||||
in_config_info->address[0] = defaultValue.address[0];
|
||||
in_config_info->address[1] = defaultValue.address[1];
|
||||
in_config_info->address[2] = defaultValue.address[2];
|
||||
in_config_info->address[3] = defaultValue.address[3];
|
||||
in_config_info->address[4] = defaultValue.address[4];
|
||||
in_config_info->address[5] = defaultValue.address[5];
|
||||
in_config_info->address[6] = defaultValue.address[6];
|
||||
in_config_info->end_Flag = defaultValue.end_Flag;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ static void FloatingCharge(void);
|
|||
|
||||
|
||||
/* 占空比 */
|
||||
float g_duty_ratio = 0.8;
|
||||
float g_duty_ratio = 0.75;
|
||||
/* 用于确定工作模式 */
|
||||
//static uint8_t modeFlag = 2;
|
||||
|
||||
|
@ -779,8 +779,8 @@ void MpptMode(void)
|
|||
|
||||
if ((((ConstantVoltageV < g_Mppt_Para.Battery_Voltage)
|
||||
&& (FloatI > g_Mppt_Para.Charg_Current))
|
||||
&& (FloatI > g_Mppt_Para.Discharg_Current))
|
||||
|| g_Mppt_Para.MPPT_Mode == FLOAT) {
|
||||
&& (FloatI > g_Mppt_Para.Discharg_Current))) {
|
||||
// || g_Mppt_Para.MPPT_Mode == FLOAT) {
|
||||
g_Mppt_Para.MPPT_Mode = FLOAT;
|
||||
return;
|
||||
}
|
||||
|
@ -858,18 +858,20 @@ void test(void)
|
|||
|
||||
|
||||
static float_t inBatteryCurr;
|
||||
static float_t outBatteryCurr;
|
||||
inBatteryCurr = g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current;
|
||||
outBatteryCurr = g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current;
|
||||
if (inBatteryCurr > 0.1) {
|
||||
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage - inBatteryCurr * g_impedance;
|
||||
} else {
|
||||
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
|
||||
}
|
||||
|
||||
if (g_batteryState == 0 && inBatteryCurr > 0.1 && g_Mppt_Para.Output_Voltage < 14.2) {
|
||||
printf("int g_batteryState : %d\n", g_batteryState);
|
||||
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);
|
||||
g_batteryState = 1;
|
||||
TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
||||
, impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
|
||||
// TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
||||
// , impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
|
||||
}
|
||||
|
||||
// mppt_constantVoltage(18);
|
||||
|
|
199
App/src/task.c
199
App/src/task.c
|
@ -113,6 +113,10 @@ void Task_RunLED(void)
|
|||
sprintf(buffer, " impedance : %d/1000 \n", (int)(g_impedance * 1000));
|
||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
sprintf(buffer, " g_impedanceStart : %d \n", g_impedanceStart);
|
||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
sprintf(buffer, " mosState : %d \n", (int)(g_Mppt_Para.DischargMos_State));
|
||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||
|
@ -121,6 +125,14 @@ void Task_RunLED(void)
|
|||
sprintf(buffer, " batteryState : %d \n", g_batteryState);
|
||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
sprintf(buffer, " outputAgainFlag : %d \n", outputAgainFlag);
|
||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
sprintf(buffer, " excessiveLoadFlag : %d \n", excessiveLoadFlag);
|
||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
sprintf(buffer, " 0.没有工作; 1.涓流模式; 2.恒流模式; 3.恒压模式; 4.浮充模式; 5.没有电池 : %d \n", g_Mppt_Para.MPPT_Mode);
|
||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||
|
@ -137,16 +149,12 @@ void Task_RunLED(void)
|
|||
flag = !flag;
|
||||
GPIO_WriteBit(RUN_LED_GPIO, RUN_LED_PIN, flag);
|
||||
|
||||
|
||||
static uint8_t num = 0;
|
||||
if (num++ == 20) {
|
||||
if (10 == ++num) {
|
||||
GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
|
||||
}
|
||||
|
||||
// static uint8_t num = 0;
|
||||
// if (10 == ++num) {
|
||||
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
|
||||
// }
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -170,10 +178,10 @@ void Task_startMpptControl(void)
|
|||
checkSolarOpenCircuitVTimeFlag = 0;
|
||||
g_Mppt_Para.Solar_Open_Circuit_Voltage = get_PV1_VOLT_IN();
|
||||
// printf("volt in : %d/100 \n", (int)(g_Mppt_Para.Solar_Open_Circuit_Voltage * 100));
|
||||
char buff[50];
|
||||
memset(buff, 0, sizeof(buff));
|
||||
sprintf(buff, "volt in : %d/100 \n", (int)(g_Mppt_Para.Solar_Open_Circuit_Voltage * 100));
|
||||
uart_dev_write(g_bat485_uart3_handle, buff, sizeof(buff));
|
||||
// char buff[50];
|
||||
// memset(buff, 0, sizeof(buff));
|
||||
// sprintf(buff, "volt in : %d/100 \n", (int)(g_Mppt_Para.Solar_Open_Circuit_Voltage * 100));
|
||||
// uart_dev_write(g_bat485_uart3_handle, buff, sizeof(buff));
|
||||
|
||||
if (g_Mppt_Para.Solar_Open_Circuit_Voltage
|
||||
> ((float_t)g_slConfigInfo.startSolarOpenCircuitV / 100)) {
|
||||
|
@ -181,7 +189,7 @@ void Task_startMpptControl(void)
|
|||
m_startMpptControl.runFlag = 0;
|
||||
// printf("1\n");
|
||||
// start_mpptWork();
|
||||
if (g_Mppt_Para.Output_Voltage > 10) {
|
||||
if (g_Mppt_Para.Output_Voltage > 11) {
|
||||
g_batteryState = 1;
|
||||
} else {
|
||||
g_batteryState = 0;
|
||||
|
@ -222,9 +230,10 @@ void Task_softStart(void)
|
|||
Set_duty_ratio(&g_duty_ratio);
|
||||
|
||||
if (g_batteryState == 1) {
|
||||
// start_mpptWork();
|
||||
TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
||||
, impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
|
||||
start_mpptWork();
|
||||
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
|
||||
// TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
||||
// , impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
|
||||
return;
|
||||
} else {
|
||||
dutyRatio = 0;
|
||||
|
@ -234,15 +243,18 @@ void Task_softStart(void)
|
|||
// m_softStart.runFlag = 0;
|
||||
|
||||
//软起动后bms保护板开启电池充电
|
||||
if (get_CHG_CURR() - get_DSG_CURR() > 0.2) {
|
||||
if (get_CHG_CURR() - get_DSG_CURR() > 0.1
|
||||
|| get_DSG_CURR() - get_CHG_CURR() > 0.1) {
|
||||
// printf("111\n");
|
||||
TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
||||
, impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
|
||||
// TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
||||
// , impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
|
||||
start_mpptWork();
|
||||
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
|
||||
return;
|
||||
}
|
||||
|
||||
g_Mppt_Para.MPPT_Mode = FLOAT;
|
||||
TIM_Cmd(TIM3, ENABLE);
|
||||
g_Mppt_Para.MPPT_Mode = NoWork;
|
||||
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
|
||||
|
||||
return;
|
||||
|
@ -315,14 +327,26 @@ void Task_refreshRegister(void)
|
|||
|
||||
if (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current < -0.1) {
|
||||
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage
|
||||
- (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current)
|
||||
* g_impedance / 100;
|
||||
- (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current) * g_impedance;
|
||||
}
|
||||
|
||||
float_t inBatteryCurr = g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current;
|
||||
float_t outBatteryCurr = g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current;
|
||||
if (g_batteryState == 0 && (inBatteryCurr > 0.1 || outBatteryCurr > 0.1) && g_Mppt_Para.Output_Voltage < 14.2) {
|
||||
g_batteryState = 1;
|
||||
}
|
||||
|
||||
/* 有电池,太阳能输出功率大,同时回路阻抗未测试或需要重新测试 */
|
||||
if (g_batteryState == 1 && (g_Mppt_Para.Charg_Current > 3.0) && (g_impedanceStart == 1 || g_impedance == 0.0)) {
|
||||
TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
||||
, impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
|
||||
}
|
||||
|
||||
// g_Mppt_Para.DischargMos_State = GPIO_ReadOutputDataBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN);
|
||||
// g_Mppt_Para.Solar_Open_Circuit_Voltage = get_capturedata(get_PV1_VOLT_IN);
|
||||
g_Mppt_Para.Input_Voltage = get_PV1_VOLT_IN();
|
||||
|
||||
if (g_Mppt_Para.HighSideMos_Temperature < g_slConfigInfo.HighSideMosTemperature_start) {
|
||||
if (g_Mppt_Para.HighSideMos_Temperature < g_slConfigInfo.HighSideMosTemperature_start + 3) {
|
||||
if (overTemperature == 2) {
|
||||
// start_mpptWork();
|
||||
TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset);
|
||||
|
@ -331,14 +355,16 @@ void Task_refreshRegister(void)
|
|||
return;
|
||||
}
|
||||
|
||||
if (g_Mppt_Para.HighSideMos_Temperature > g_slConfigInfo.HighSideMosTemperature_end) {
|
||||
if (g_Mppt_Para.HighSideMos_Temperature > g_slConfigInfo.HighSideMosTemperature_end + 3
|
||||
&& g_Mppt_Para.HighSideMos_Temperature < g_slConfigInfo.HighSideMosTemperature_stop) {
|
||||
// g_Mppt_Para.MPPT_Mode = NoBattery;
|
||||
g_duty_ratio = 0.5;
|
||||
// g_duty_ratio -= 0.1;
|
||||
g_duty_ratio = 0.6;
|
||||
Set_duty_ratio(&g_duty_ratio);
|
||||
overTemperature = 1;
|
||||
}
|
||||
|
||||
if (g_Mppt_Para.HighSideMos_Temperature > g_slConfigInfo.HighSideMosTemperature_stop) {
|
||||
if (g_Mppt_Para.HighSideMos_Temperature > g_slConfigInfo.HighSideMosTemperature_stop + 3) {
|
||||
overTemperature = 2;
|
||||
stop_mpptWork();
|
||||
}
|
||||
|
@ -446,6 +472,8 @@ void Task_recvbroadcast(void)
|
|||
STR_TimeSliceOffset m_impedanceCalculation;
|
||||
float_t g_impedance = 0; /* 回路阻抗的值 */
|
||||
uint8_t g_batteryState = 0; /* 有无电池 */
|
||||
uint8_t g_impedanceStart = 0; /* 是否开始测量回路阻抗 */
|
||||
//config_info tempConfigInfo;
|
||||
void Task_impedanceCalculation(void)
|
||||
{
|
||||
static uint8_t num = 0;
|
||||
|
@ -453,6 +481,10 @@ void Task_impedanceCalculation(void)
|
|||
static float_t voltOne = 0;
|
||||
static float_t currTwo = 0;
|
||||
static float_t voltTwo = 0;
|
||||
// static uint8_t only_one = 1;
|
||||
// if (only_one) {
|
||||
// g_impedance = g_slConfigInfo.loopImpedance;
|
||||
// }
|
||||
|
||||
// if (g_Mppt_Para.MPPT_Mode == CONSTANTCURRENT
|
||||
// || g_Mppt_Para.MPPT_Mode == CONSTANTVOLTAGE) {
|
||||
|
@ -517,10 +549,42 @@ void Task_impedanceCalculation(void)
|
|||
|
||||
// printf("g_batteryState : %d\n", g_batteryState);
|
||||
|
||||
printf("currOne = %d/1000, voltOne = %d/100 \n", (int)(currOne * 1000), (int)(voltOne * 100));
|
||||
printf("currTwo = %d/1000, voltTwo = %d/100 \n", (int)(currTwo * 1000), (int)(voltTwo * 100));
|
||||
printf("Res = %d/1000, E = %d/100 \n", (int)(g_impedance * 1000), (int)((voltTwo - currTwo * g_impedance) * 100));
|
||||
// printf("currOne = %d/1000, voltOne = %d/100 \n", (int)(currOne * 1000), (int)(voltOne * 100));
|
||||
// printf("currTwo = %d/1000, voltTwo = %d/100 \n", (int)(currTwo * 1000), (int)(voltTwo * 100));
|
||||
// printf("Res = %d/1000, E = %d/100 \n", (int)(g_impedance * 1000), (int)((voltTwo - currTwo * g_impedance) * 100));
|
||||
|
||||
/* 判断回路阻抗是否合理 */
|
||||
if (g_impedance > 1.0 || g_impedance < 0.05) {
|
||||
g_impedance = 0;
|
||||
num = 0;
|
||||
start_mpptWork();
|
||||
return;
|
||||
}
|
||||
|
||||
/* 将回路阻抗的值放入flash中 */
|
||||
config_info tempConfigInfo;
|
||||
if (read_config_info1(&tempConfigInfo)) {
|
||||
tempConfigInfo.loopImpedance = (uint16_t)(g_impedance * 1000);
|
||||
save_config_info(&tempConfigInfo);
|
||||
} else {
|
||||
tempConfigInfo = g_slConfigInfo;
|
||||
tempConfigInfo.loopImpedance = (uint16_t)(g_impedance * 1000);
|
||||
save_config_info(&tempConfigInfo);
|
||||
}
|
||||
|
||||
// uart_dev_write(g_bat485_uart3_handle, "\n\n\n\n\n", sizeof("\n\n\n\n\n"));
|
||||
// char buffer[80];
|
||||
// memset(buffer, 0, sizeof(buffer));
|
||||
// sprintf(buffer, " tempConfigInfo.loopImpedance : %d/1000 \n", tempConfigInfo.loopImpedance);
|
||||
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||
// memset(buffer, 0, sizeof(buffer));
|
||||
// config_info tempConfigInfo2 = {0};
|
||||
// read_config_info1(&tempConfigInfo2);
|
||||
// sprintf(buffer, " tempConfigInfo2.loopImpedance : %d/1000 \n", tempConfigInfo2.loopImpedance);
|
||||
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||
// uart_dev_write(g_bat485_uart3_handle, "\n\n\n\n\n", sizeof("\n\n\n\n\n"));
|
||||
|
||||
g_impedanceStart = 0;
|
||||
num = 0;
|
||||
start_mpptWork();
|
||||
// TIM_Cmd(TIM3, ENABLE);
|
||||
|
@ -531,13 +595,12 @@ void Task_impedanceCalculation(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 延时一段时间后检测是否短路
|
||||
* @brief 延时一段时间后检测是否仍然短路
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
STR_TimeSliceOffset m_outputAgain;
|
||||
uint8_t outputAgainFlag = 0;
|
||||
static const uint8_t outputAgainFlagTime = 6;
|
||||
void Task_outputAgain(void)
|
||||
{
|
||||
static uint8_t num = 0;
|
||||
|
@ -552,7 +615,7 @@ void Task_outputAgain(void)
|
|||
// }
|
||||
|
||||
// printf(" in POW_OUT_CON\n");
|
||||
if (num == outputAgainFlagTime) {
|
||||
if (num == g_slConfigInfo.outputAgainFlagTime) {
|
||||
num = 0;
|
||||
outputAgainFlag = 0;
|
||||
TimeSliceOffset_Unregister(&m_outputAgain);
|
||||
|
@ -570,6 +633,69 @@ void Task_outputAgain(void)
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 过载后开始延时,这段时间内再次过载则关闭输出
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
STR_TimeSliceOffset m_excessiveLoad;
|
||||
uint8_t excessiveLoadFlag = 0;
|
||||
void Task_excessiveLoad(void)
|
||||
{
|
||||
static uint8_t num = 0;
|
||||
static uint16_t numLong = 0;
|
||||
|
||||
// if (outputAgainFlag == 1) {
|
||||
//// outputAgainFlag = 0;
|
||||
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, RESET);
|
||||
// TimeSliceOffset_Unregister(&m_outputAgain);
|
||||
// m_outputAgain.runFlag = 0;
|
||||
// num = 0;
|
||||
// }
|
||||
|
||||
// printf(" in POW_OUT_CON\n");
|
||||
if (outputAgainFlag == 1) {
|
||||
num = 0;
|
||||
numLong = 0;
|
||||
excessiveLoadFlag = 0;
|
||||
TimeSliceOffset_Unregister(&m_excessiveLoad);
|
||||
m_excessiveLoad.runFlag = 0;
|
||||
}
|
||||
|
||||
if (excessiveLoadFlag == 1) {
|
||||
num++;
|
||||
}
|
||||
|
||||
if (num == g_slConfigInfo.excessiveLoadFlagTime) {
|
||||
num = 0;
|
||||
excessiveLoadFlag = 0;
|
||||
TimeSliceOffset_Unregister(&m_excessiveLoad);
|
||||
m_excessiveLoad.runFlag = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (excessiveLoadFlag >= 2) {
|
||||
GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, RESET);
|
||||
num = 0;
|
||||
}
|
||||
|
||||
if (!(GPIO_ReadOutputDataBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN))) {
|
||||
numLong++;
|
||||
}
|
||||
|
||||
if (numLong == g_slConfigInfo.eLAgainTime) {
|
||||
numLong = 0;
|
||||
GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
|
||||
excessiveLoadFlag = 0;
|
||||
TimeSliceOffset_Unregister(&m_excessiveLoad);
|
||||
m_excessiveLoad.runFlag = 0;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设定传感器能再次注册的间隔时间
|
||||
* @param
|
||||
|
@ -600,6 +726,8 @@ void Task_sensorEnableBroadcast(void)
|
|||
*/
|
||||
void g_Mppt_Para_Init(void)
|
||||
{
|
||||
g_impedance = (float_t)g_slConfigInfo.loopImpedance / 1000;
|
||||
|
||||
g_Mppt_Para.Registration_Status = UNREGISTER;
|
||||
g_Mppt_Para.address[0] = g_slConfigInfo.address[0];
|
||||
g_Mppt_Para.address[1] = g_slConfigInfo.address[1];
|
||||
|
@ -619,15 +747,18 @@ void g_Mppt_Para_Init(void)
|
|||
// g_Mppt_Para.HighSideMos_Temperature = get_capturedata(get_MOSFET_Temper); g_Mppt_Para.Output_Voltage = get_capturedata(get_PV_VOLT_OUT);
|
||||
|
||||
g_Mppt_Para.Output_Voltage = get_PV_VOLT_OUT();
|
||||
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
|
||||
// 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.Battery_Voltage = g_Mppt_Para.Output_Voltage
|
||||
- (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current) * g_impedance;
|
||||
g_Mppt_Para.Solar_Open_Circuit_Voltage = get_PV1_VOLT_IN();
|
||||
g_Mppt_Para.HighSideMos_Temperature = get_MOSFET_Temper();
|
||||
|
||||
// if (g_Mppt_Para.Battery_Voltage < 15 || g_Mppt_Para.Battery_Voltage > 12) {
|
||||
if (g_Mppt_Para.Battery_Voltage < 15 || g_Mppt_Para.Battery_Voltage > 11) {
|
||||
// GPIO_WriteBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN, SET);
|
||||
// }
|
||||
g_impedanceStart = 1;
|
||||
}
|
||||
g_Mppt_Para.DischargMos_State = GPIO_ReadOutputDataBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN)
|
||||
&& GPIO_ReadInputDataBit(DSG_PROT_GPIO, DSG_PROT_PIN);
|
||||
g_Mppt_Para.MPPT_Mode = NoWork;
|
||||
|
@ -681,12 +812,14 @@ void hardware_Init(void)
|
|||
TIM2_Init(1);
|
||||
uart_dev_init();
|
||||
PWM_TIM_Configuration();
|
||||
// TIM_SetCompare4(TIM4, 0);
|
||||
ADC_all_Init();
|
||||
RUN_LED_Init();
|
||||
WDI_INPUT_Init();
|
||||
SPI_Flash_Init();
|
||||
POW_OUT_CON_Init();
|
||||
DSG_PROT_Init();
|
||||
WORK_VOLT_INT_Init();
|
||||
// EnPowerSupply_Init();
|
||||
|
||||
// Set_duty_ratio(&g_duty_ratio);
|
||||
|
|
|
@ -105,7 +105,8 @@ void EXTI2_IRQHandler(void)
|
|||
// printf("Run at EXTI 111\r\n");
|
||||
if (outputAgainFlag == 0) {
|
||||
outputAgainFlag = 1;
|
||||
TimeSliceOffset_Register(&m_outputAgain, Task_outputAgain, outputAgain_reloadVal, outputAgain_offset);
|
||||
TimeSliceOffset_Register(&m_outputAgain, Task_outputAgain
|
||||
, outputAgain_reloadVal, outputAgain_offset);
|
||||
// m_outputAgain.runFlag = 1;
|
||||
return;
|
||||
}
|
||||
|
@ -132,37 +133,49 @@ void EnPowerSupply_Init(void)
|
|||
GPIO_WriteBit(EnPowerSupply_GPIO, EnPowerSupply_PIN, RESET);
|
||||
}
|
||||
|
||||
void EXTI1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
void EXTI15_10_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||
|
||||
void WORK_VOLT_INT_Init(void)
|
||||
{
|
||||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_AFIO | RCC_PB2Periph_GPIOA, ENABLE);
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Pin = WORK_VOLT_INT_PIN;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //下拉输入
|
||||
GPIO_Init(WORK_VOLT_INT_GPIO, &GPIO_InitStructure);
|
||||
|
||||
/* GPIOA ----> EXTI_Line1 */
|
||||
/* GPIOA ----> EXTI_Line12 */
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource12); //指定中断/事件线的输入源,实际上是设定外部中断配置寄存器AFIO_EXTICRx的值,此处为PA12
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line1; //EXTI中断/事件线选择,此处选择EXTI_Line1
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource12);//指定中断/事件线的输入源,实际上是设定外部中断配置寄存器AFIO_EXTICRx的值,此处为PA12
|
||||
EXTI_InitStructure.EXTI_Line = EXTI_Line12; //EXTI中断/事件线选择,此处选择EXTI_Line12
|
||||
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //EXTI模式选择,此处选择为产生中断模式
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //EXTI边沿触发事件,此处选择为下降沿触发
|
||||
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //EXTI边沿触发事件,此处选择为上升沿触发
|
||||
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //使能EXTI线
|
||||
EXTI_Init(&EXTI_InitStructure);
|
||||
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn; //使能EXTI2中断通道
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //设置抢占优先级为1
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //设置子优先级为2
|
||||
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //使能EXTI12中断通道
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //设置抢占优先级为1
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //设置子优先级为2
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
|
||||
NVIC_Init(&NVIC_InitStructure); //中断优先级分组初始化
|
||||
}
|
||||
|
||||
void EXTI1_IRQHandler(void)
|
||||
void EXTI15_10_IRQHandler(void)
|
||||
{
|
||||
if(EXTI_GetITStatus(EXTI_Line1)==SET) { //EXTI_GetITStatus用来获取中断标志位状态,如果EXTI线产生中断则返回SET,否则返回RESET
|
||||
printf(" vout low 11V \n");
|
||||
if(EXTI_GetITStatus(EXTI_Line12)==SET) { //EXTI_GetITStatus用来获取中断标志位状态,如果EXTI线产生中断则返回SET,否则返回RESET
|
||||
// printf(" vout low 11V \n");
|
||||
EXTI_ClearITPendingBit(EXTI_Line12); //清除中断标志位
|
||||
excessiveLoadFlag++;
|
||||
TimeSliceOffset_Register(&m_excessiveLoad, Task_excessiveLoad
|
||||
, excessiveLoad_reloadVal, excessiveLoad_offset);
|
||||
|
||||
|
||||
// uart_dev_write(g_bat485_uart3_handle, "\n\n\n\n\n in vout low 8V (Set)\n\n\n\n\n", sizeof("\n\n\n\n\n in vout low 8V (Set)\n\n\n\n\n"));
|
||||
}
|
||||
// uart_dev_write(g_bat485_uart3_handle, "\n\n\n\n\n in vout low 8V\n\n\n\n\n", sizeof("\n\n\n\n\n in vout low 8V\n\n\n\n\n"));
|
||||
// if(EXTI_GetITStatus(EXTI_Line12)==SET) { //EXTI_GetITStatus用来获取中断标志位状态,如果EXTI线产生中断则返回SET,否则返回RESET
|
||||
//// printf(" vout low 11V \n");
|
||||
// uart_dev_write(g_bat485_uart3_handle, "\n\n\n\n\n in vout low 8V\n\n\n\n\n", sizeof("\n\n\n\n\n in vout low 8V\n\n\n\n\n"));
|
||||
// }
|
||||
}
|
||||
|
||||
|
|
|
@ -55,8 +55,8 @@ void Set_duty_ratio(float *duty_ratio)
|
|||
if (*duty_ratio < 0.05) {
|
||||
*duty_ratio = 0.05;
|
||||
// return;
|
||||
} else if (*duty_ratio > 0.95) {
|
||||
*duty_ratio = 0.95;
|
||||
} else if (*duty_ratio > 0.9) {
|
||||
*duty_ratio = 0.9;
|
||||
// return;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ void TIM3_Int_Init(uint16_t arr, uint16_t psc)
|
|||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIM计数模式,向上计数模式
|
||||
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //根据指定的参数初始化TIMx的时间基数单位
|
||||
|
||||
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); //清除TIM3的中断挂起位。
|
||||
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE ); //使能TIM3中断,允许更新中断
|
||||
|
||||
//初始化TIM NVIC,设置中断优先级分组
|
||||
|
@ -57,6 +58,7 @@ void TIM3_IRQHandler(void)
|
|||
{
|
||||
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) { //检查TIM3中断是否发生。
|
||||
TIM_ClearITPendingBit(TIM3, TIM_IT_Update); //清除TIM3的中断挂起位。
|
||||
// uart_dev_write(g_bat485_uart3_handle, "\n\n\n\n\nin tim3 irt\n\n\n\n\n", sizeof("\n\n\n\n\nin tim3 irt\n\n\n\n\n"));
|
||||
test();
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
obj/User/main.o
BIN
obj/User/main.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
23467
obj/mppt_Nos_V0.4.lst
23467
obj/mppt_Nos_V0.4.lst
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue