控制方面大体框架完成

This commit is contained in:
起床就犯困 2024-12-11 17:51:48 +08:00
parent 0a1ae49530
commit 26c786e3f6
21 changed files with 1655 additions and 1451 deletions

View File

@ -8,7 +8,7 @@
void start(void) void start(void)
{ {
Init(); Init();
task_Init();
TimeSliceOffset_Start(); TimeSliceOffset_Start();
} }

View File

@ -8,6 +8,9 @@
void setChargControlFlag(BOOL state); void setChargControlFlag(BOOL state);
void bl_chargControl(void); void bl_chargControl(void);
void endChargWork(void);
void stopChargWork(void);
void startChargWork(void);
extern void chargControl(void); extern void chargControl(void);

View File

@ -79,6 +79,10 @@ void setBatteryState(BOOL state);
float getDutyRatio(void); float getDutyRatio(void);
void setDutyRatio(float DutyRatio); void setDutyRatio(float DutyRatio);
void setDutyRatioToZero(void); void setDutyRatioToZero(void);
uint8_t getMosTemperState(void);
void setMosTemperState(uint8_t state);
BOOL getCheckImpedanceState(void);
void setCheckImpedanceState(void);
float getBatteryVoltage(void); float getBatteryVoltage(void);
void setBatteryVoltage(void); void setBatteryVoltage(void);

View File

@ -9,7 +9,7 @@ void task_Init(void);
void beginStartControlTask(void); void beginStartControlTask(void);
void beginSoftStartTask(void);

View File

@ -30,4 +30,8 @@ void Init(void)
Init_GW485_uart(); Init_GW485_uart();
start_gw485Rx_It(); start_gw485Rx_It();
start_bat485Rx_It(); start_bat485Rx_It();
POW_FF_PCON_Open();
POW_OUT_PCON_Open();
} }

View File

@ -3,7 +3,7 @@
#include "parameter.h" #include "parameter.h"
#include "capture.h" #include "capture.h"
#include "checkTime.h" #include "checkTime.h"
#include "FM_GPIO.h"
void checkAbnormal(void) void checkAbnormal(void)
@ -18,9 +18,18 @@ void checkAbnormal(void)
setOutputVoltage(); setOutputVoltage();
setSolarInCircuitVoltage(); setSolarInCircuitVoltage();
/* 判断异常状态 */ /* 判断 */
/* 是否打开充电理想二极管 */
if (get_CHG_CURR() > 2.0f) {
FFMOS_CON_Open();
}
else if (get_CHG_CURR() < 1.0f) {
FFMOS_CON_Close();
}
// checkAbnormalTime = getCheckTime(); // checkAbnormalTime = getCheckTime();
} }

View File

@ -6,7 +6,6 @@
#include "task.h" #include "task.h"
static void stopChargWork(void);
static BOOL stopChargConditions(void); static BOOL stopChargConditions(void);
static BOOL floatChargConditions(void); static BOOL floatChargConditions(void);
static BOOL mpptChargConditions(void); static BOOL mpptChargConditions(void);
@ -37,18 +36,17 @@ void mppt_constantVoltage(float InVoltage)
{ {
static float kp = 0.005; static float kp = 0.005;
static float ki = 0.00001; static float ki = 0.00001;
static float solarInCircuitVoltage; // static float solarInCircuitVoltage;
static float error; static float error;
static float stepPwm; static float stepPwm;
solarInCircuitVoltage = getSolarInCircuitVoltage(); // solarInCircuitVoltage = getSolarInCircuitVoltage();
error = solarInCircuitVoltage - InVoltage; // error = InVoltage - getSolarInCircuitVoltage();
// float error = InVoltage - g_otherParameter.Solar_In_Circuit_Voltage; error = getSolarInCircuitVoltage() - InVoltage;
stepPwm = kp * error + ki * solarInCircuitVoltage; stepPwm = kp * error + ki * getSolarInCircuitVoltage();
setDutyRatio((getDutyRatio() + stepPwm)); setDutyRatio((getDutyRatio() + stepPwm));
set_pwmDutyRatio(getDutyRatio());
} }
/** /**
@ -70,7 +68,6 @@ void mppt_constantVoltageNoBatteryO(float OutVoltage)
stepPwm = kp * error + ki * outVolt; stepPwm = kp * error + ki * outVolt;
setDutyRatio((getDutyRatio() + stepPwm)); setDutyRatio((getDutyRatio() + stepPwm));
set_pwmDutyRatio(getDutyRatio());
} }
/** /**
@ -113,7 +110,6 @@ void mppt_constantVoltageO(float OutVoltage)
// lastVolt = outVolt; // lastVolt = outVolt;
// lastStepPwm = StepPwm; // lastStepPwm = StepPwm;
lastDutyRatio = getDutyRatio(); lastDutyRatio = getDutyRatio();
set_pwmDutyRatio(getDutyRatio());
} }
/** /**
@ -397,7 +393,21 @@ void mppt_readJust(void)
} }
/** /**
* @brief * @brief
* @param
* @retval
*
*/
void endChargWork(void)
{
EN_PWMOUT_Diseable();
pwm_Stop();
setMPPT_Mode(noWork);
beginStartControlTask();
}
/**
* @brief
* @param * @param
* @retval * @retval
* *
@ -407,9 +417,23 @@ void stopChargWork(void)
EN_PWMOUT_Diseable(); EN_PWMOUT_Diseable();
pwm_Stop(); pwm_Stop();
setMPPT_Mode(noWork); setMPPT_Mode(noWork);
beginStartControlTask();
} }
/**
* @brief
* @param
* @retval
*
*/
void startChargWork(void)
{
beginSoftStartTask();
}
/** /**
* @brief * @brief
* @param * @param
@ -470,7 +494,7 @@ BOOL mpptChargConditions(void)
BOOL constantVChargConditions(void) BOOL constantVChargConditions(void)
{ {
if ((g_cfgParameter.constantVoltageChargeV < getBatteryVoltage()) if ((g_cfgParameter.constantVoltageChargeV < getBatteryVoltage())
&& ((g_cfgParameter.floatI + 0.1) <= getChargBatteryCurrent())) { && ((g_cfgParameter.floatI + 0.1f) <= getChargBatteryCurrent())) {
return TRUE; return TRUE;
} }
@ -486,7 +510,7 @@ BOOL constantVChargConditions(void)
void chargControlMode(void) void chargControlMode(void)
{ {
if (stopChargConditions()) { if (stopChargConditions()) {
stopChargWork(); endChargWork();
} }
if (floatChargConditions()) { if (floatChargConditions()) {
@ -510,7 +534,11 @@ void chargControlMode(void)
*/ */
void judgeYNBattery(void) void judgeYNBattery(void)
{ {
if (getBatteryVoltage() > 16 || getBatteryVoltage() < 10) { // if (getBatteryVoltage() > 16 || getBatteryVoltage() < 10) {
// setBatteryState(FALSE);
// return;
// }
if (getOutputVoltage() > 16 || getOutputVoltage() < 10) {
setBatteryState(FALSE); setBatteryState(FALSE);
return; return;
} }
@ -572,6 +600,7 @@ void BatteryChargControl(void)
case MPPT: case MPPT:
mpptCharge(); mpptCharge();
// mppt_constantVoltage(17.0f);
break; break;
case constantVoltage: case constantVoltage:

View File

@ -78,19 +78,19 @@ static void read_backups_config_info(config_info *output_config_info)
*/ */
static void readFlashContent(config_info *config_info) static void readFlashContent(config_info *config_info)
{ {
read_config_info(config_info); // read_config_info(config_info);
/* 配置文件正确就返回 */ // /* 配置文件正确就返回 */
if (config_info->crc == configCheckFunc((uint8_t *)config_info, CONFIG_INFO_SIZE - 2)) { // if (config_info->crc == configCheckFunc((uint8_t *)config_info, CONFIG_INFO_SIZE - 2)) {
return; // return;
} // }
/* 更深处的配置文件正确就返回 */ // /* 更深处的配置文件正确就返回 */
read_backups_config_info(config_info); // read_backups_config_info(config_info);
if (config_info->crc == configCheckFunc((uint8_t *)config_info, CONFIG_INFO_SIZE - 2)) { // if (config_info->crc == configCheckFunc((uint8_t *)config_info, CONFIG_INFO_SIZE - 2)) {
save_config_info(config_info); // save_config_info(config_info);
return; // return;
} // }
/* 配置文件错误使用默认配置 */ /* 配置文件错误使用默认配置 */
config_info->address[0] = 0x11; config_info->address[0] = 0x11;

View File

@ -3,14 +3,15 @@
#include "FM_TIM.h" #include "FM_TIM.h"
#include "FM_GPIO.h" #include "FM_GPIO.h"
#include "capture.h" #include "capture.h"
#include "chargControlEnum.h"
config_parameter g_cfgParameter = {0}; config_parameter g_cfgParameter = {0};
static otherParameter g_otherParameter = {0}; static otherParameter g_otherParameter = {0};
static BOOL batteryState = FALSE; /* 有无电池(估计) */ static BOOL batteryState = FALSE; /* 有无电池(估计) */
static float dutyRatio; /* 占空比 */ static float dutyRatio; /* 占空比 */
static uint8_t mosTemperState = mosTemperStop; /* mos管温度状态 */
static BOOL checkImpedanceState = FALSE; /* 启动后是否进行了回路阻抗检测 */
/** /**
* @brief * @brief
@ -78,6 +79,50 @@ void setDutyRatioToZero(void)
set_pwmDutyRatio(dutyRatio); set_pwmDutyRatio(dutyRatio);
} }
/**
* @brief mos管温度状态
* @param
* @retval mosTemperState mos管温度状态
*/
uint8_t getMosTemperState(void)
{
return mosTemperState;
}
/**
* @brief mos管温度状态
* @param state mos管状态
* @retval
*/
void setMosTemperState(uint8_t state)
{
if (state == mosTemperStart || state == mosTemperEnd || state == mosTemperStop) {
mosTemperState = state;
}
}
/**
* @brief
* @param
* @retval checkImpedanceState FALSE
* TRUE
*/
BOOL getCheckImpedanceState(void)
{
return checkImpedanceState;
}
/**
* @brief
* @param
* @retval
*
*/
void setCheckImpedanceState(void)
{
checkImpedanceState = TRUE;
}
/** /**
* @brief * @brief
* @param * @param
@ -176,7 +221,7 @@ float getInputVoltage(void)
*/ */
void setInputVoltage(void) void setInputVoltage(void)
{ {
g_otherParameter.Discharg_Current = get_PV_VOLT_IN1(); g_otherParameter.Input_Voltage = get_PV_VOLT_IN1();
} }
/** /**
@ -390,7 +435,7 @@ BOOL getDischargMosState(void)
return readOnlyPowerOutputState(); return readOnlyPowerOutputState();
} else { } else {
return readOutputState(); return readOutputState();
} }
} }
/** /**

View File

@ -15,7 +15,7 @@ static void Task_Runled(void);
/* 喂狗 */ /* 喂狗 */
#define wdi_reloadVal 1000 /* 任务执行间隔 */ #define wdi_reloadVal 1000 /* 任务执行间隔 */
#define wdi_offset 100 /* 任务执行偏移量 */ #define wdi_offset 0 /* 任务执行偏移量 */
static STR_TimeSliceOffset m_wdi; static STR_TimeSliceOffset m_wdi;
static void Task_wdi(void); static void Task_wdi(void);
@ -38,7 +38,7 @@ static STR_TimeSliceOffset m_softStart;
static void Task_softStart(void); static void Task_softStart(void);
/* 回路阻抗检测 */ /* 回路阻抗检测 */
#define impedanceCalculation_reloadVal 100 /* 任务执行间隔 */ #define impedanceCalculation_reloadVal 20 /* 任务执行间隔 */
#define impedanceCalculation_offset 0 /* 任务执行偏移量 */ #define impedanceCalculation_offset 0 /* 任务执行偏移量 */
static STR_TimeSliceOffset m_impedanceCalculation; static STR_TimeSliceOffset m_impedanceCalculation;
static void Task_impedanceCalculation(void); static void Task_impedanceCalculation(void);
@ -56,7 +56,8 @@ void task_Init(void)
{ {
TimeSliceOffset_Register(&m_runled, Task_Runled, runled_reloadVal, runled_offset); TimeSliceOffset_Register(&m_runled, Task_Runled, runled_reloadVal, runled_offset);
TimeSliceOffset_Register(&m_wdi, Task_wdi, wdi_reloadVal, wdi_offset); TimeSliceOffset_Register(&m_wdi, Task_wdi, wdi_reloadVal, wdi_offset);
beginStartControlTask();
TimeSliceOffset_Register(&m_refreshJudgeData, Task_refreshJudgeData, refreshJudgeData_reloadVal, refreshJudgeData_offset);
} }
/** /**
@ -76,7 +77,19 @@ void Task_Runled(void)
* @retval None * @retval None
*/ */
void Task_wdi(void) void Task_wdi(void)
{ {
feedDog();
debug_printf("chargCurrent:%f \n", getChargCurrent());
debug_printf("outputVoltage:%f \n", getOutputVoltage());
debug_printf("dischargCurrent:%f \n", getDischargCurrent());
debug_printf("solarInCircuitVoltage:%f \n", getSolarInCircuitVoltage());
debug_printf("HighSideMosTemperature:%f \n", getHighSideMosTemperature());
debug_printf("InputVoltage:%f \n", getInputVoltage());
debug_printf("DischargMosState:%d \n", getDischargMosState());
debug_printf("MPPT_Mode:%d \n", getMPPT_Mode());
debug_printf("DutyRatio:%f \n", getDutyRatio());
/* 每天复位一次复位前将电量信息写入flash中 */ /* 每天复位一次复位前将电量信息写入flash中 */
static uint32_t temp = 60 * 60 * 24; static uint32_t temp = 60 * 60 * 24;
if (!(--temp)) { if (!(--temp)) {
@ -89,7 +102,6 @@ void Task_wdi(void)
NVIC_SystemReset(); NVIC_SystemReset();
} }
feedDog();
} }
/** /**
@ -102,7 +114,7 @@ void Task_refreshJudgeData(void)
{ {
/* 获取数据 */ /* 获取数据 */
setInputVoltage(); setInputVoltage();
setHighSideMosTemperature(); setHighSideMosTemperature();
/* 判断有无电池 */ /* 判断有无电池 */
if (getBatteryState() == FALSE && (getChargBatteryCurrent() > 1 || getChargBatteryCurrent() < -1) if (getBatteryState() == FALSE && (getChargBatteryCurrent() > 1 || getChargBatteryCurrent() < -1)
@ -110,9 +122,34 @@ void Task_refreshJudgeData(void)
setBatteryState(TRUE); setBatteryState(TRUE);
} }
/* 有电池,太阳能输出功率大,同时回路阻抗未测试或需要重新测试 */
if ((getCheckImpedanceState() == FALSE || g_cfgParameter.loopImpedance == 0.0f)
&& (getBatteryState() == TRUE) && (getChargCurrent() > 3.0f)
&& (getOutputVoltage() > 9) && (getSolarInCircuitVoltage() > 14)) {
TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
, impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
}
/* 温度检测 */ /* 温度检测 */
if (1) { if ((getMosTemperState() != mosTemperStart)
&& (getHighSideMosTemperature() < g_cfgParameter.HighSideMosTemperature_start)) {
/* 状态处于停止运行则打开充电开关 */
if (getMosTemperState() == mosTemperStop) {
}
setMosTemperState(mosTemperStart);
}
else if ((getMosTemperState() == mosTemperStart)
&& getHighSideMosTemperature() > g_cfgParameter.HighSideMosTemperature_end) {
setMosTemperState(mosTemperEnd);
}
else if ((getMosTemperState() == mosTemperEnd)
&& getHighSideMosTemperature() > g_cfgParameter.HighSideMosTemperature_stop) {
setMosTemperState(mosTemperStop);
/* 停止充电 */
EN_PWMOUT_Diseable();
pwm_Stop();
setMPPT_Mode(noWork);
} }
@ -154,7 +191,7 @@ void Task_startControl(void)
*/ */
void beginStartControlTask(void) void beginStartControlTask(void)
{ {
TimeSliceOffset_Register(&m_wdi, Task_startControl, startControl_reloadVal, startControl_offset); TimeSliceOffset_Register(&m_startControl, Task_startControl, startControl_reloadVal, startControl_offset);
} }
/** /**
@ -170,7 +207,8 @@ void Task_softStart(void)
num++; num++;
if (num < 5) { if (num < 5) {
set_pwmPulse(100); set_pwmDutyRatio(0.1f);
EN_PWMOUT_Eable();
} }
else if (num > 70 || dutyRatio > 0.75f) { else if (num > 70 || dutyRatio > 0.75f) {
@ -179,7 +217,7 @@ void Task_softStart(void)
dutyRatio = 0; dutyRatio = 0;
num = 0; num = 0;
setDutyRatio(0.75); setDutyRatio(0.75f);
set_pwmDutyRatio(getDutyRatio()); set_pwmDutyRatio(getDutyRatio());
if (getBatteryState() == TRUE) { if (getBatteryState() == TRUE) {
@ -188,13 +226,22 @@ void Task_softStart(void)
setMPPT_Mode(floatCharg); setMPPT_Mode(floatCharg);
} }
setChargControlFlag(TRUE); setChargControlFlag(TRUE);
} }
else { else {
setDutyRatio(getDutyRatio() + 0.01f); setDutyRatio(getDutyRatio() + 0.01f);
set_pwmDutyRatio(getDutyRatio()); set_pwmDutyRatio(getDutyRatio());
} }
} }
/**
* @brief
* @param
* @retval
*/
void beginSoftStartTask(void)
{
TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset);
}
/** /**
* @brief * @brief
@ -239,6 +286,7 @@ void Task_impedanceCalculation(void)
if (tempLoopImpedance < 1.0f && tempLoopImpedance > 0.05f) { if (tempLoopImpedance < 1.0f && tempLoopImpedance > 0.05f) {
g_cfgParameter.loopImpedance = tempLoopImpedance; g_cfgParameter.loopImpedance = tempLoopImpedance;
saveLoopImpedance(&g_cfgParameter.loopImpedance); saveLoopImpedance(&g_cfgParameter.loopImpedance);
setCheckImpedanceState();
} }
num = 0; num = 0;

View File

@ -15,11 +15,11 @@ void test(void)
while (1) { while (1) {
HAL_Delay(1000); HAL_Delay(1000);
debug_printf("time:%f\r\n", checkAbnormalTime); // debug_printf("time:%f\r\n", checkAbnormalTime);
debug_printf("chargCurrent:%f\r\n", getChargCurrent()); // debug_printf("chargCurrent:%f\r\n", getChargCurrent());
debug_printf("outputVoltage:%f\r\n", getOutputVoltage()); // debug_printf("outputVoltage:%f\r\n", getOutputVoltage());
debug_printf("dischargCurrent:%f\r\n", getDischargCurrent()); // debug_printf("dischargCurrent:%f\r\n", getDischargCurrent());
debug_printf("solarInCircuitVoltage:%f\r\n", getSolarInCircuitVoltage()); // debug_printf("solarInCircuitVoltage:%f\r\n", getSolarInCircuitVoltage());
} }
} }

View File

@ -7,7 +7,7 @@
void tim_Init(void); void tim_Init(void);
void pwm_Stop(void); void pwm_Stop(void);
void set_pwmDutyRatio(float DutyRatio); void set_pwmDutyRatio(float DutyRatio);
void set_pwmPulse(uint32_t Pulse); // void set_pwmPulse(uint32_t Pulse);
extern void chargControl(void); extern void chargControl(void);
extern void checkAbnormal(void); extern void checkAbnormal(void);

View File

@ -16,10 +16,10 @@ typedef struct _adcCapture
}adcCapture; }adcCapture;
#pragma pack(pop) #pragma pack(pop)
extern adcCapture WORK_VOLT_capture; // extern adcCapture WORK_VOLT_capture;
extern adcCapture DSG_CURR_capture; // extern adcCapture DSG_CURR_capture;
extern adcCapture PV_VOLT_IN_capture; // extern adcCapture PV_VOLT_IN_capture;
extern adcCapture CHG_CURR_capture; // extern adcCapture CHG_CURR_capture;
void ADC_Capture_Init(void); void ADC_Capture_Init(void);
void proportionalInt(int mode); void proportionalInt(int mode);

View File

@ -150,7 +150,8 @@ BOOL readOnlyPowerOutputState(void)
*/ */
BOOL readOutputState(void) BOOL readOutputState(void)
{ {
if (1) { if (HAL_GPIO_ReadPin(POW_OUT_CON_GPIO_Port, POW_OUT_CON_Pin)
&& HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin)) {
return TRUE; return TRUE;
} }

View File

@ -16,7 +16,8 @@ void tim_Init(void)
HD_PWM_Init(); HD_PWM_Init();
/* 得到pwm的分辨率 */ /* 得到pwm的分辨率 */
PWM_RESOLUTION = HAL_RCC_GetHCLKFreq() / 100000; PWM_RESOLUTION = HAL_RCC_GetHCLKFreq() / 100000;
HAL_TIM_Base_Start(&htim3); // HAL_TIM_Base_Start(&htim3);
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);
HD_controlTim_Init(); HD_controlTim_Init();
HAL_TIM_Base_Start_IT(&htim7); HAL_TIM_Base_Start_IT(&htim7);
@ -28,17 +29,6 @@ void tim_Init(void)
HAL_TIM_Base_Start_IT(&htim15); HAL_TIM_Base_Start_IT(&htim15);
} }
/**
* @brief PWM信号输出
*/
void pwm_Stop(void)
{
// 设置PWM脉冲宽度为0 effectively停止PWM信号输出
set_pwmPulse(0);
HAL_TIM_Base_Stop(&htim3);
}
/** /**
* @brief * @brief
* @param Pulse * @param Pulse
@ -52,6 +42,17 @@ void set_pwmPulse(uint32_t Pulse)
__HAL_TIM_SetCompare(&htim3, TIM_CHANNEL_4, Pulse); __HAL_TIM_SetCompare(&htim3, TIM_CHANNEL_4, Pulse);
} }
/**
* @brief PWM信号输出
*/
void pwm_Stop(void)
{
// 设置PWM脉冲宽度为0 effectively停止PWM信号输出
set_pwmPulse(0);
// HAL_TIM_Base_Stop(&htim3);
}
/** /**
* @brief * @brief
* @param DutyRatio * @param DutyRatio

View File

@ -95,8 +95,8 @@ const uint16_t mosTemperADC[mosTemperADCLen] = {
enum { enum {
WORK_VOLT_NUM = 0, WORK_VOLT_NUM = 0,
DSG_CURR_NUM = 1, DSG_CURR_NUM = 1,
PV_VOLT_IN_NUM = 2, CHG_CURR_NUM = 2,
CHG_CURR_NUM = 3, PV_VOLT_IN_NUM = 3,
}; };
int16_t adcBuff[4]; int16_t adcBuff[4];
/* 指向adcCapture中的inData16数组中的第一位也是最后一位 */ /* 指向adcCapture中的inData16数组中的第一位也是最后一位 */
@ -125,13 +125,20 @@ const float32_t Proportion = 3.0 / 4095.0;
// 0.01861755922 // 0.01861755922
// }; // };
/* matlab生成的3阶滤波器系数 */ // /* matlab生成的3阶滤波器系数 */
// const int firLen = 4;
// const float32_t firLP[4] = {
// 0.178709805, 0.3671073616, 0.3671073616, 0.178709805
// };
/* matlab生成的3阶滤波器系数,乘比例使和接近为1 */
const int firLen = 4; const int firLen = 4;
const float firLP[4] = { const float32_t firLP[4] = {
0.178709805, 0.3671073616, 0.3671073616, 0.178709805 0.163708486, 0.336291513, 0.336291513, 0.163708486
}; };
void captureFirInit(void);
// void captureFirInit(void);
/** /**
* @brief adc * @brief adc
@ -149,8 +156,8 @@ void ADC_Capture_Init(void)
HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED); HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
HAL_ADCEx_Calibration_Start(&hadc2, ADC_SINGLE_ENDED); HAL_ADCEx_Calibration_Start(&hadc2, ADC_SINGLE_ENDED);
/* 初始化滤波器 */ // /* 初始化滤波器 */
captureFirInit(); // captureFirInit();
HAL_TIM_Base_Start(&htim6); HAL_TIM_Base_Start(&htim6);
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adcBuff, 4); HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adcBuff, 4);
@ -201,6 +208,17 @@ void proportionalInt(int mode)
/* 系统电源电压比例 */ /* 系统电源电压比例 */
P_PV_VOLT_IN1 = ((47 + 4.7) / 4.7) * Proportion; P_PV_VOLT_IN1 = ((47 + 4.7) / 4.7) * Proportion;
} }
/* 光伏充电输出电流比例,放大倍数*电阻 */
P_CHG_CURR = (1.0 / (50 * (1 / (1 / 0.01 + 1 / 0.002)))) * Proportion;
/* 充电控制盒输出电压比例,分压系数 */
P_PV_VOLT_OUT = ((47.0 + 10.0) / 10.0) * Proportion;
/* 放电电流采集电流倍数 */
P_DSG_CURR = (1.0 / (50 * (1 / (1 / 0.002 * 2)))) * Proportion;
/* 光伏板输出电压比例 */
P_PV1_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
/* 系统电源电压比例 */
P_PV_VOLT_IN1 = ((47 + 4.7) / 4.7) * Proportion;
} }
#define N 4 #define N 4
@ -416,7 +434,7 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hdma)
CHG_CURR_capture.totalInData += CHG_CURR_capture.inData16[pointer]; CHG_CURR_capture.totalInData += CHG_CURR_capture.inData16[pointer];
pointer++; pointer++;
if (pointer >= indata16_size) { if (pointer >= 10) {
pointer = 0; pointer = 0;
} }
@ -432,20 +450,20 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hdma)
} }
} }
static arm_fir_instance_f32 armFirInstanceF32; // static arm_fir_instance_f32 armFirInstanceF32;
static float32_t *inputF32, *outputF32; // static float32_t *inputF32, *outputF32;
static uint32_t blockSize = 1; // static uint32_t blockSize = 4;
static float32_t firStateF32[4]; /* 状态缓存 */ // static float32_t firStateF32[4]; /* 状态缓存 */
static float32_t outputf; // static float32_t outputf;
void captureFirInit(void) // void captureFirInit(void)
{ // {
/* 初始化结构体 */ // /* 初始化结构体 */
arm_fir_init_f32(&armFirInstanceF32, // arm_fir_init_f32(&armFirInstanceF32,
firLen, // firLen,
(float_t *)&firLP[0], // (float_t *)&firLP[0],
&firStateF32[0], // &firStateF32[0],
blockSize); // blockSize);
} // }
/** /**
@ -455,28 +473,62 @@ void captureFirInit(void)
*/ */
void adcCaptureFir(void) void adcCaptureFir(void)
{ {
/* 初始化输入输出缓存指针 */ // static arm_fir_instance_f32 armFirInstanceF32;
inputF32 = &WORK_VOLT_capture.IODataF[0]; // static volatile float32_t *inputF32;
outputF32 = &outputf; // static volatile float32_t *outputF32;
arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize); // static uint32_t blockSize = 4;
// static float32_t firStateF32[4]; /* 状态缓存 */
// static volatile float32_t outputf;
// /* 初始化结构体 */
// arm_fir_init_f32(&armFirInstanceF32,
// firLen,
// &firLP[0],
// &firStateF32[0],
// blockSize);
// /* 初始化输入输出缓存指针 */
// inputF32 = &WORK_VOLT_capture.IODataF[0];
// outputF32 = &outputf;
// // arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize);
// arm_fir_f32(&armFirInstanceF32, (const float32_t *)inputF32, (float32_t *)outputF32, 1);
// WORK_VOLT_capture.outData = (int16_t)outputf;
// /* 初始化输入输出缓存指针 */
// inputF32 = &DSG_CURR_capture.IODataF[0];
// outputF32 = &outputf;
// // arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize);
// arm_fir_f32(&armFirInstanceF32, (const float32_t *)inputF32, (float32_t *)outputF32, 1);
// DSG_CURR_capture.outData = (int16_t)outputf;
// /* 初始化输入输出缓存指针 */
// inputF32 = &PV_VOLT_IN_capture.IODataF[0];
// outputF32 = &outputf;
// // arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize);
// arm_fir_f32(&armFirInstanceF32, (const float32_t *)inputF32, (float32_t *)outputF32, 1);
// PV_VOLT_IN_capture.outData = (int16_t)outputf;
// /* 初始化输入输出缓存指针 */
// inputF32 = &CHG_CURR_capture.IODataF[0];
// outputF32 = &outputf;
// // arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize);
// arm_fir_f32(&armFirInstanceF32, (const float32_t *)inputF32, (float32_t *)outputF32, 1);
// CHG_CURR_capture.outData = (int16_t)outputf;
// WORK_VOLT_capture.outData = 1;
// DSG_CURR_capture.outData = 1;
// PV_VOLT_IN_capture.outData = 1;
// CHG_CURR_capture.outData = 1;
static float32_t outputf;
arm_dot_prod_f32(WORK_VOLT_capture.IODataF, firLP, firLen, &outputf);
WORK_VOLT_capture.outData = (int16_t)outputf; WORK_VOLT_capture.outData = (int16_t)outputf;
arm_dot_prod_f32(DSG_CURR_capture.IODataF, firLP, firLen, &outputf);
/* 初始化输入输出缓存指针 */
inputF32 = &DSG_CURR_capture.IODataF[0];
outputF32 = &outputf;
arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize);
DSG_CURR_capture.outData = (int16_t)outputf; DSG_CURR_capture.outData = (int16_t)outputf;
arm_dot_prod_f32(PV_VOLT_IN_capture.IODataF, firLP, firLen, &outputf);
/* 初始化输入输出缓存指针 */
inputF32 = &PV_VOLT_IN_capture.IODataF[0];
outputF32 = &outputf;
arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize);
PV_VOLT_IN_capture.outData = (int16_t)outputf; PV_VOLT_IN_capture.outData = (int16_t)outputf;
arm_dot_prod_f32(CHG_CURR_capture.IODataF, firLP, firLen, &outputf);
/* 初始化输入输出缓存指针 */
inputF32 = &CHG_CURR_capture.IODataF[0];
outputF32 = &outputf;
arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize);
CHG_CURR_capture.outData = (int16_t)outputf; CHG_CURR_capture.outData = (int16_t)outputf;
} }

View File

@ -27,7 +27,8 @@
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
#include "test.h" // #include "test.h"
#include "start.h"
@ -93,22 +94,22 @@ int main(void)
/* USER CODE END SysInit */ /* USER CODE END SysInit */
/* Initialize all configured peripherals */ /* Initialize all configured peripherals */
MX_GPIO_Init(); // MX_GPIO_Init();
MX_DMA_Init(); // MX_DMA_Init();
MX_ADC1_Init(); // MX_ADC1_Init();
MX_ADC2_Init(); // MX_ADC2_Init();
MX_SPI1_Init(); // MX_SPI1_Init();
MX_TIM3_Init(); // MX_TIM3_Init();
MX_TIM6_Init(); // MX_TIM6_Init();
MX_UART4_Init(); // MX_UART4_Init();
MX_USART2_UART_Init(); // MX_USART2_UART_Init();
MX_USART3_UART_Init(); // MX_USART3_UART_Init();
MX_TIM7_Init(); // MX_TIM7_Init();
MX_TIM16_Init(); // MX_TIM16_Init();
MX_TIM15_Init(); // MX_TIM15_Init();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
test(); start();

View File

@ -90,7 +90,7 @@ void MX_TIM6_Init(void)
htim6.Instance = TIM6; htim6.Instance = TIM6;
htim6.Init.Prescaler = 71; htim6.Init.Prescaler = 71;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP; htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.Period = 29; htim6.Init.Period = 9;
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim6) != HAL_OK) if (HAL_TIM_Base_Init(&htim6) != HAL_OK)
{ {
@ -123,7 +123,7 @@ void MX_TIM7_Init(void)
htim7.Instance = TIM7; htim7.Instance = TIM7;
htim7.Init.Prescaler = 71; htim7.Init.Prescaler = 71;
htim7.Init.CounterMode = TIM_COUNTERMODE_UP; htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
htim7.Init.Period = 999; htim7.Init.Period = 99;
htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim7) != HAL_OK) if (HAL_TIM_Base_Init(&htim7) != HAL_OK)
{ {
@ -155,9 +155,9 @@ void MX_TIM15_Init(void)
/* USER CODE END TIM15_Init 1 */ /* USER CODE END TIM15_Init 1 */
htim15.Instance = TIM15; htim15.Instance = TIM15;
htim15.Init.Prescaler = 10; htim15.Init.Prescaler = 1;
htim15.Init.CounterMode = TIM_COUNTERMODE_UP; htim15.Init.CounterMode = TIM_COUNTERMODE_UP;
htim15.Init.Period = 7199; htim15.Init.Period = 35999;
htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim15.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim15.Init.RepetitionCounter = 0; htim15.Init.RepetitionCounter = 0;
htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; htim15.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

File diff suppressed because it is too large Load Diff

View File

@ -304,7 +304,7 @@ ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath= ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath= ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=false ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_ADC2_Init-ADC2-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_TIM3_Init-TIM3-false-HAL-true,8-MX_TIM6_Init-TIM6-false-HAL-true,9-MX_UART4_Init-UART4-false-HAL-true,10-MX_USART2_UART_Init-USART2-false-HAL-true,11-MX_USART3_UART_Init-USART3-false-HAL-true,12-MX_TIM7_Init-TIM7-false-HAL-true,13-MX_TIM16_Init-TIM16-false-HAL-true,14-MX_TIM17_Init-TIM17-false-HAL-true,15-MX_TIM15_Init-TIM15-false-HAL-true ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_ADC2_Init-ADC2-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_TIM3_Init-TIM3-false-HAL-true,8-MX_TIM6_Init-TIM6-false-HAL-true,9-MX_UART4_Init-UART4-false-HAL-true,10-MX_USART2_UART_Init-USART2-false-HAL-true,11-MX_USART3_UART_Init-USART3-false-HAL-true,12-MX_TIM7_Init-TIM7-false-HAL-true,13-MX_TIM16_Init-TIM16-false-HAL-true,14-MX_TIM15_Init-TIM15-false-HAL-true
RCC.ADC12Freq_Value=72000000 RCC.ADC12Freq_Value=72000000
RCC.AHBFreq_Value=72000000 RCC.AHBFreq_Value=72000000
RCC.APB1Freq_Value=72000000 RCC.APB1Freq_Value=72000000
@ -369,8 +369,8 @@ STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.IPParameters=LibraryCcDSPOoLibraryJjDS
STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.LibraryCcDSPOoLibraryJjDSPOoLibrary=true STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.LibraryCcDSPOoLibraryJjDSPOoLibrary=true
STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0_SwParameter=LibraryCcDSPOoLibraryJjDSPOoLibrary\:true; STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0_SwParameter=LibraryCcDSPOoLibraryJjDSPOoLibrary\:true;
TIM15.IPParameters=PeriodNoDither,Prescaler TIM15.IPParameters=PeriodNoDither,Prescaler
TIM15.PeriodNoDither=7199 TIM15.PeriodNoDither=35999
TIM15.Prescaler=10 TIM15.Prescaler=1
TIM16.IPParameters=Prescaler,PeriodNoDither TIM16.IPParameters=Prescaler,PeriodNoDither
TIM16.PeriodNoDither=999 TIM16.PeriodNoDither=999
TIM16.Prescaler=71 TIM16.Prescaler=71
@ -378,11 +378,11 @@ TIM3.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
TIM3.IPParameters=PeriodNoDither,Channel-PWM Generation4 CH4 TIM3.IPParameters=PeriodNoDither,Channel-PWM Generation4 CH4
TIM3.PeriodNoDither=720 TIM3.PeriodNoDither=720
TIM6.IPParameters=Prescaler,PeriodNoDither,TIM_MasterOutputTrigger TIM6.IPParameters=Prescaler,PeriodNoDither,TIM_MasterOutputTrigger
TIM6.PeriodNoDither=29 TIM6.PeriodNoDither=9
TIM6.Prescaler=71 TIM6.Prescaler=71
TIM6.TIM_MasterOutputTrigger=TIM_TRGO_UPDATE TIM6.TIM_MasterOutputTrigger=TIM_TRGO_UPDATE
TIM7.IPParameters=Prescaler,PeriodNoDither,TIM_MasterOutputTrigger TIM7.IPParameters=Prescaler,PeriodNoDither,TIM_MasterOutputTrigger
TIM7.PeriodNoDither=999 TIM7.PeriodNoDither=99
TIM7.Prescaler=71 TIM7.Prescaler=71
TIM7.TIM_MasterOutputTrigger=TIM_TRGO_RESET TIM7.TIM_MasterOutputTrigger=TIM_TRGO_RESET
USART2.IPParameters=VirtualMode-Asynchronous,VirtualMode-Hardware Flow Control (RS485) USART2.IPParameters=VirtualMode-Asynchronous,VirtualMode-Hardware Flow Control (RS485)

View File

@ -2,12 +2,18 @@
#ifndef CHARG_CONTROL_ENUM_ #ifndef CHARG_CONTROL_ENUM_
#define CHARG_CONTROL_ENUM_ #define CHARG_CONTROL_ENUM_
typedef enum { typedef enum _chargMode{
noWork = 0, /* 未进行充电 */ noWork = 0, /* 未进行充电 */
MPPT = 1, /* 最大功率充电 */ MPPT = 1, /* 最大功率充电 */
constantVoltage = 2, /* 恒压充电 */ constantVoltage = 2, /* 恒压充电 */
floatCharg = 3 /* 浮充充电 */ floatCharg = 3 /* 浮充充电 */
}_chargControlMode; }chargMode;
typedef enum _mosTState{
mosTemperStart = 0, /* 满功率充电mos状态 */
mosTemperEnd = 1, /* 降功率充电mos状态 */
mosTemperStop = 2, /* 停止充电mos状态 */
}mosTState;
#endif #endif