Compare commits

..

No commits in common. "0929ac0d965d23503fe1044546bf467a32b33419" and "0a1ae495306d973b92ff99dbe00c5001d6c434b5" have entirely different histories.

21 changed files with 1464 additions and 1719 deletions

View File

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

View File

@ -5,13 +5,9 @@
#include "FM_TIM.h" #include "FM_TIM.h"
#include "comm_types.h" #include "comm_types.h"
BOOL getChargControlFlag(void);
void setChargControlFlag(BOOL state); void setChargControlFlag(BOOL state);
void bl_chargControl(void); void bl_chargControl(void);
void endChargWork(void);
void stopChargWork(void);
void beginChargWork(void);
void startChargWork(void);
extern void chargControl(void); extern void chargControl(void);

View File

@ -79,10 +79,6 @@ 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,8 +30,4 @@ 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,18 +18,9 @@ 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,6 +6,7 @@
#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);
@ -23,7 +24,7 @@ static void BatteryChargControl(void);
static void noBatteryChargControl(void); static void noBatteryChargControl(void);
static BOOL chargControlFlag = FALSE; static BOOL chargControlFlag = FALSE;
// static BOOL getChargControlFlag(void); static BOOL getChargControlFlag(void);
void setChargControlFlag(BOOL state); void setChargControlFlag(BOOL state);
/** /**
@ -36,17 +37,18 @@ 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 = InVoltage - getSolarInCircuitVoltage(); error = solarInCircuitVoltage - InVoltage;
error = getSolarInCircuitVoltage() - InVoltage; // float error = InVoltage - g_otherParameter.Solar_In_Circuit_Voltage;
stepPwm = kp * error + ki * getSolarInCircuitVoltage(); stepPwm = kp * error + ki * solarInCircuitVoltage;
setDutyRatio((getDutyRatio() + stepPwm)); setDutyRatio((getDutyRatio() + stepPwm));
set_pwmDutyRatio(getDutyRatio());
} }
/** /**
@ -68,6 +70,7 @@ void mppt_constantVoltageNoBatteryO(float OutVoltage)
stepPwm = kp * error + ki * outVolt; stepPwm = kp * error + ki * outVolt;
setDutyRatio((getDutyRatio() + stepPwm)); setDutyRatio((getDutyRatio() + stepPwm));
set_pwmDutyRatio(getDutyRatio());
} }
/** /**
@ -110,6 +113,7 @@ void mppt_constantVoltageO(float OutVoltage)
// lastVolt = outVolt; // lastVolt = outVolt;
// lastStepPwm = StepPwm; // lastStepPwm = StepPwm;
lastDutyRatio = getDutyRatio(); lastDutyRatio = getDutyRatio();
set_pwmDutyRatio(getDutyRatio());
} }
/** /**
@ -393,56 +397,19 @@ void mppt_readJust(void)
} }
/** /**
* @brief * @brief
* @param
* @retval
*
*/
void endChargWork(void)
{
setChargControlFlag(FALSE);
setDutyRatioToZero();
setMPPT_Mode(noWork);
beginStartControlTask();
}
/**
* @brief
* @param * @param
* @retval * @retval
* *
*/ */
void stopChargWork(void) void stopChargWork(void)
{ {
setChargControlFlag(FALSE); EN_PWMOUT_Diseable();
setDutyRatioToZero(); pwm_Stop();
setMPPT_Mode(noWork); setMPPT_Mode(noWork);
}
/**
* @brief
* @param
* @retval
*
*/
void beginChargWork(void)
{
beginStartControlTask(); beginStartControlTask();
} }
/**
* @brief
* @param
* @retval
*
*/
void startChargWork(void)
{
beginSoftStartTask();
}
/** /**
* @brief * @brief
* @param * @param
@ -503,7 +470,7 @@ BOOL mpptChargConditions(void)
BOOL constantVChargConditions(void) BOOL constantVChargConditions(void)
{ {
if ((g_cfgParameter.constantVoltageChargeV < getBatteryVoltage()) if ((g_cfgParameter.constantVoltageChargeV < getBatteryVoltage())
&& ((g_cfgParameter.floatI + 0.1f) <= getChargBatteryCurrent())) { && ((g_cfgParameter.floatI + 0.1) <= getChargBatteryCurrent())) {
return TRUE; return TRUE;
} }
@ -519,7 +486,7 @@ BOOL constantVChargConditions(void)
void chargControlMode(void) void chargControlMode(void)
{ {
if (stopChargConditions()) { if (stopChargConditions()) {
endChargWork(); stopChargWork();
} }
if (floatChargConditions()) { if (floatChargConditions()) {
@ -547,10 +514,6 @@ void judgeYNBattery(void)
setBatteryState(FALSE); setBatteryState(FALSE);
return; return;
} }
// if (getOutputVoltage() > 16 || getOutputVoltage() < 10) {
// setBatteryState(FALSE);
// return;
// }
} }
/** /**
@ -609,7 +572,6 @@ void BatteryChargControl(void)
case MPPT: case MPPT:
mpptCharge(); mpptCharge();
// mppt_constantVoltage(17.0f);
break; break;
case constantVoltage: case constantVoltage:
@ -632,13 +594,7 @@ BOOL getChargControlFlag(void)
return chargControlFlag; return chargControlFlag;
} }
/**
* @brief
* @param TRUE
* FALSE
* @retval
*
*/
void setChargControlFlag(BOOL state) void setChargControlFlag(BOOL state)
{ {
if (state == TRUE || state == FALSE) { if (state == TRUE || state == FALSE) {
@ -659,7 +615,6 @@ void bl_chargControl(void)
} }
// getCVData(); // getCVData();
setBatteryVoltage();
judgeYNBattery(); judgeYNBattery();
chargControlMode(); chargControlMode();

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,15 +3,14 @@
#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
@ -79,50 +78,6 @@ 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
@ -221,7 +176,7 @@ float getInputVoltage(void)
*/ */
void setInputVoltage(void) void setInputVoltage(void)
{ {
g_otherParameter.Input_Voltage = get_PV_VOLT_IN1(); g_otherParameter.Discharg_Current = get_PV_VOLT_IN1();
} }
/** /**
@ -435,7 +390,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 0 /* 任务执行偏移量 */ #define wdi_offset 100 /* 任务执行偏移量 */
static STR_TimeSliceOffset m_wdi; static STR_TimeSliceOffset m_wdi;
static void Task_wdi(void); static void Task_wdi(void);
@ -38,16 +38,13 @@ static STR_TimeSliceOffset m_softStart;
static void Task_softStart(void); static void Task_softStart(void);
/* 回路阻抗检测 */ /* 回路阻抗检测 */
#define impedanceCalculation_reloadVal 20 /* 任务执行间隔 */ #define impedanceCalculation_reloadVal 100 /* 任务执行间隔 */
#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);
/* 开路电压采集 */
#define collectOpenCircuitVoltage_reloadVal 1000 /* 任务执行间隔 */
#define collectOpenCircuitVoltage_offset 0 /* 任务执行偏移量 */
STR_TimeSliceOffset g_collectOpenCircuitVoltage;
void Task_collectOpenCircuitVoltage(void);
/** /**
* @brief * @brief
@ -59,8 +56,7 @@ 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);
TimeSliceOffset_Register(&m_startControl, Task_startControl, startControl_reloadVal, startControl_offset);
TimeSliceOffset_Register(&m_refreshJudgeData, Task_refreshJudgeData, refreshJudgeData_reloadVal, refreshJudgeData_offset);
} }
/** /**
@ -80,19 +76,7 @@ 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)) {
@ -105,6 +89,7 @@ void Task_wdi(void)
NVIC_SystemReset(); NVIC_SystemReset();
} }
feedDog();
} }
/** /**
@ -117,7 +102,7 @@ void Task_refreshJudgeData(void)
{ {
/* 获取数据 */ /* 获取数据 */
setInputVoltage(); setInputVoltage();
setHighSideMosTemperature(); setHighSideMosTemperature();
/* 判断有无电池 */ /* 判断有无电池 */
if (getBatteryState() == FALSE && (getChargBatteryCurrent() > 1 || getChargBatteryCurrent() < -1) if (getBatteryState() == FALSE && (getChargBatteryCurrent() > 1 || getChargBatteryCurrent() < -1)
@ -125,33 +110,13 @@ 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 ((getMosTemperState() != mosTemperStart) if (1) {
&& (getHighSideMosTemperature() < g_cfgParameter.HighSideMosTemperature_start)) {
/* 状态处于停止运行则打开充电开关 */
if (getMosTemperState() == mosTemperStop) {
beginChargWork();
}
setMosTemperState(mosTemperStart);
} }
else if ((getMosTemperState() == mosTemperStart)
&& getHighSideMosTemperature() > g_cfgParameter.HighSideMosTemperature_end) {
setMosTemperState(mosTemperEnd);
}
else if ((getMosTemperState() == mosTemperEnd)
&& getHighSideMosTemperature() > g_cfgParameter.HighSideMosTemperature_stop) {
setMosTemperState(mosTemperStop);
/* 停止充电 */
stopChargWork();
}
} }
/** /**
@ -189,8 +154,7 @@ void Task_startControl(void)
*/ */
void beginStartControlTask(void) void beginStartControlTask(void)
{ {
TimeSliceOffset_Register(&m_startControl, Task_startControl, startControl_reloadVal, startControl_offset); TimeSliceOffset_Register(&m_wdi, Task_startControl, startControl_reloadVal, startControl_offset);
m_startControl.runFlag = 1;
} }
/** /**
@ -206,8 +170,7 @@ void Task_softStart(void)
num++; num++;
if (num < 5) { if (num < 5) {
set_pwmDutyRatio(0.1f); set_pwmPulse(100);
EN_PWMOUT_Eable();
} }
else if (num > 70 || dutyRatio > 0.75f) { else if (num > 70 || dutyRatio > 0.75f) {
@ -216,7 +179,8 @@ void Task_softStart(void)
dutyRatio = 0; dutyRatio = 0;
num = 0; num = 0;
setDutyRatio(0.75f); setDutyRatio(0.75);
set_pwmDutyRatio(getDutyRatio());
if (getBatteryState() == TRUE) { if (getBatteryState() == TRUE) {
setMPPT_Mode(MPPT); setMPPT_Mode(MPPT);
@ -224,21 +188,13 @@ 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());
} }
} }
/**
* @brief
* @param
* @retval
*/
void beginSoftStartTask(void)
{
TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset);
}
/** /**
* @brief * @brief
@ -283,7 +239,6 @@ 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;
@ -293,44 +248,7 @@ void Task_impedanceCalculation(void)
} }
} }
/**
* @brief
* @retval
*/
void Task_collectOpenCircuitVoltage(void)
{
/* 用于无充电控制时获取开路电压 */
static uint32_t collectOpenCircuitVoltageNoNUM = 0;
/* 用于有充电控制时获取开路电压 */
static uint8_t collectOpenCircuitVoltageYesNUM = 0;
if (FALSE == getChargControlFlag()) {
if (1 <= collectOpenCircuitVoltageNoNUM++) {
setSolarOpenCircuitVoltage();
collectOpenCircuitVoltageNoNUM = 0;
}
collectOpenCircuitVoltageYesNUM = 0;
}
collectOpenCircuitVoltageYesNUM++;
/* 到达开路电压检测时间 */
if (collectOpenCircuitVoltageYesNUM == g_cfgParameter.collectOpenCircuitVoltageTime) {
/* 有电池才进行开路电压检测 */
if (getBatteryState()) {
stopChargWork();
/* 设置延时为1000-500ms */
g_collectOpenCircuitVoltage.count = 500;
}
collectOpenCircuitVoltageYesNUM = 0;
}
/* 检测开路电压 */
if (collectOpenCircuitVoltageYesNUM == g_cfgParameter.collectOpenCircuitVoltageTime + 1) {
setSolarOpenCircuitVoltage();
beginChargWork();
}
}

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

View File

@ -16,8 +16,7 @@ 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);
@ -29,6 +28,17 @@ 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
@ -42,17 +52,6 @@ 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,
CHG_CURR_NUM = 2, PV_VOLT_IN_NUM = 2,
PV_VOLT_IN_NUM = 3, CHG_CURR_NUM = 3,
}; };
int16_t adcBuff[4]; int16_t adcBuff[4];
/* 指向adcCapture中的inData16数组中的第一位也是最后一位 */ /* 指向adcCapture中的inData16数组中的第一位也是最后一位 */
@ -125,20 +125,13 @@ 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 float32_t firLP[4] = { const float firLP[4] = {
0.163708486, 0.336291513, 0.336291513, 0.163708486 0.178709805, 0.3671073616, 0.3671073616, 0.178709805
}; };
void captureFirInit(void);
// void captureFirInit(void);
/** /**
* @brief adc * @brief adc
@ -156,8 +149,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);
@ -208,17 +201,6 @@ 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
@ -434,7 +416,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 >= 10) { if (pointer >= indata16_size) {
pointer = 0; pointer = 0;
} }
@ -450,20 +432,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 = 4; static uint32_t blockSize = 1;
// 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);
// } }
/** /**
@ -473,62 +455,28 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hdma)
*/ */
void adcCaptureFir(void) void adcCaptureFir(void)
{ {
// static arm_fir_instance_f32 armFirInstanceF32; /* 初始化输入输出缓存指针 */
// static volatile float32_t *inputF32; inputF32 = &WORK_VOLT_capture.IODataF[0];
// static volatile float32_t *outputF32; outputF32 = &outputf;
// static uint32_t blockSize = 4; arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize);
// 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);
DSG_CURR_capture.outData = (int16_t)outputf;
arm_dot_prod_f32(PV_VOLT_IN_capture.IODataF, firLP, firLen, &outputf);
PV_VOLT_IN_capture.outData = (int16_t)outputf;
arm_dot_prod_f32(CHG_CURR_capture.IODataF, firLP, firLen, &outputf);
CHG_CURR_capture.outData = (int16_t)outputf;
/* 初始化输入输出缓存指针 */
inputF32 = &DSG_CURR_capture.IODataF[0];
outputF32 = &outputf;
arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize);
DSG_CURR_capture.outData = (int16_t)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;
/* 初始化输入输出缓存指针 */
inputF32 = &CHG_CURR_capture.IODataF[0];
outputF32 = &outputf;
arm_fir_f32(&armFirInstanceF32, inputF32, outputF32, blockSize);
CHG_CURR_capture.outData = (int16_t)outputf;
} }

View File

@ -27,8 +27,7 @@
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
// #include "test.h" #include "test.h"
#include "start.h"
@ -94,22 +93,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 */
start(); test();

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 = 9; htim6.Init.Period = 29;
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 = 99; htim7.Init.Period = 999;
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 = 1; htim15.Init.Prescaler = 10;
htim15.Init.CounterMode = TIM_COUNTERMODE_UP; htim15.Init.CounterMode = TIM_COUNTERMODE_UP;
htim15.Init.Period = 35999; htim15.Init.Period = 7199;
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_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_TIM17_Init-TIM17-false-HAL-true,15-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=35999 TIM15.PeriodNoDither=7199
TIM15.Prescaler=1 TIM15.Prescaler=10
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=9 TIM6.PeriodNoDither=29
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=99 TIM7.PeriodNoDither=999
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,18 +2,12 @@
#ifndef CHARG_CONTROL_ENUM_ #ifndef CHARG_CONTROL_ENUM_
#define CHARG_CONTROL_ENUM_ #define CHARG_CONTROL_ENUM_
typedef enum _chargMode{ typedef enum {
noWork = 0, /* 未进行充电 */ noWork = 0, /* 未进行充电 */
MPPT = 1, /* 最大功率充电 */ MPPT = 1, /* 最大功率充电 */
constantVoltage = 2, /* 恒压充电 */ constantVoltage = 2, /* 恒压充电 */
floatCharg = 3 /* 浮充充电 */ floatCharg = 3 /* 浮充充电 */
}chargMode; }_chargControlMode;
typedef enum _mosTState{
mosTemperStart = 0, /* 满功率充电mos状态 */
mosTemperEnd = 1, /* 降功率充电mos状态 */
mosTemperStop = 2, /* 停止充电mos状态 */
}mosTState;
#endif #endif