确定电流波动原因为理想二极管和防反mos
This commit is contained in:
parent
c14165f58d
commit
c5ed140daf
|
@ -14,8 +14,8 @@
|
||||||
float get_CHG_CURR(void);
|
float get_CHG_CURR(void);
|
||||||
float get_PV_VOLT_OUT(void);
|
float get_PV_VOLT_OUT(void);
|
||||||
float get_DSG_CURR(void);
|
float get_DSG_CURR(void);
|
||||||
float get_PV1_VOLT_IN(void);
|
float get_PV_VOLT_IN(void);
|
||||||
float get_PV_VOLT_IN1(void);
|
float get_SYS_VOLT_IN(void);
|
||||||
float get_MOSFET_Temper(void);
|
float get_MOSFET_Temper(void);
|
||||||
float get_PV2_VOLT_IN(void);
|
float get_PV2_VOLT_IN(void);
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,20 @@
|
||||||
#include "uart_dev.h"
|
#include "uart_dev.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define ONLYPOWER 1
|
//#define ONLYPOWER 1
|
||||||
|
//#define CHG_CURR ADC_Channel_1
|
||||||
|
//#define PV_VOLT_OUT ADC_Channel_2
|
||||||
|
//#define DSG_CURR ADC_Channel_3
|
||||||
|
//#define PV1_VOLT_IN ADC_Channel_4
|
||||||
|
//#define PV_VOLT_IN1 ADC_Channel_5
|
||||||
|
//#define MOSFET_Temper ADC_Channel_6
|
||||||
|
//#define PV2_VOLT_IN ADC_Channel_7
|
||||||
|
|
||||||
#define CHG_CURR ADC_Channel_1
|
#define CHG_CURR ADC_Channel_1
|
||||||
#define PV_VOLT_OUT ADC_Channel_2
|
#define PV_VOLT_OUT ADC_Channel_2
|
||||||
#define DSG_CURR ADC_Channel_3
|
#define DSG_CURR ADC_Channel_3
|
||||||
#define PV1_VOLT_IN ADC_Channel_4
|
#define PV_VOLT_IN ADC_Channel_4
|
||||||
#define PV_VOLT_IN1 ADC_Channel_5
|
#define SYS_VOLT_IN ADC_Channel_5
|
||||||
#define MOSFET_Temper ADC_Channel_6
|
#define MOSFET_Temper ADC_Channel_6
|
||||||
#define PV2_VOLT_IN ADC_Channel_7
|
#define PV2_VOLT_IN ADC_Channel_7
|
||||||
|
|
||||||
|
@ -32,8 +39,8 @@
|
||||||
const float P_CHG_CURR = ((1.0 / (50 * 0.005 / 2)) / 4095 * 2.5);
|
const float P_CHG_CURR = ((1.0 / (50 * 0.005 / 2)) / 4095 * 2.5);
|
||||||
/* 光伏充电输出电压比例,分压系数(放电时采集不准) */
|
/* 光伏充电输出电压比例,分压系数(放电时采集不准) */
|
||||||
//const float P_PV_VOLT_OUT = (47.0 + 10.0) / 10.0;
|
//const float P_PV_VOLT_OUT = (47.0 + 10.0) / 10.0;
|
||||||
const float P_PV_VOLT_OUT = ((47.0 + 4.7) / 4.7 / 4095 * 2.5);
|
//const float P_PV_VOLT_OUT = ((47.0 + 4.7) / 4.7 / 4095 * 2.5);
|
||||||
//const float P_PV_VOLT_OUT = ((56.0 + 10.0) / 10.0 / 4095 * 2.5);
|
const float P_PV_VOLT_OUT = ((56.0 + 10.0) / 10.0 / 4095 * 2.5);
|
||||||
/* 放电电流采集电流倍数 */
|
/* 放电电流采集电流倍数 */
|
||||||
const float P_DSG_CURR = ((1.0 / (50 * 0.005 / 2)) / 4095 * 2.5);
|
const float P_DSG_CURR = ((1.0 / (50 * 0.005 / 2)) / 4095 * 2.5);
|
||||||
///* 光伏1开路输出电压比例 */
|
///* 光伏1开路输出电压比例 */
|
||||||
|
@ -133,6 +140,7 @@ const uint16_t mosTemperADC[mosTemperADCLen] = {
|
||||||
static uint16_t get_adc(uint8_t ADC_Channel);
|
static uint16_t get_adc(uint8_t ADC_Channel);
|
||||||
static uint16_t get_aftercalculationAdc(uint8_t ADC_Channel);
|
static uint16_t get_aftercalculationAdc(uint8_t ADC_Channel);
|
||||||
static uint16_t middleAverageFilter(uint8_t ADC_Channel);
|
static uint16_t middleAverageFilter(uint8_t ADC_Channel);
|
||||||
|
static uint16_t get_adcDmaTim_middleAverageFilter(uint8_t ADC_Channel);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 获取计算后的adc的值
|
* @brief 获取计算后的adc的值
|
||||||
|
@ -140,10 +148,82 @@ static uint16_t middleAverageFilter(uint8_t ADC_Channel);
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
uint16_t get_aftercalculationAdc(uint8_t ADC_Channel)
|
uint16_t get_aftercalculationAdc(uint8_t ADC_Channel)
|
||||||
|
{
|
||||||
|
return get_adcDmaTim_middleAverageFilter(ADC_Channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取计算后的adc的值
|
||||||
|
* @param ADC_Channel ADC通道
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
uint16_t get_aftercalculationAdc1(uint8_t ADC_Channel)
|
||||||
{
|
{
|
||||||
return middleAverageFilter(ADC_Channel);
|
return middleAverageFilter(ADC_Channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 中位值平均滤波
|
||||||
|
* @param ADC_Channel ADC通道
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
uint16_t get_adcDmaTim_middleAverageFilter(uint8_t ADC_Channel)
|
||||||
|
{
|
||||||
|
uint16_t i,j,k;
|
||||||
|
uint16_t temp,sum = 0;
|
||||||
|
uint16_t value_buf[g_adcData.num];
|
||||||
|
|
||||||
|
if (ADC_Channel == CHG_CURR) {
|
||||||
|
for(i = 0; i < g_adcData.num; ++i) {
|
||||||
|
value_buf[i] = g_adcData.CHG_CURR_array[i];
|
||||||
|
}
|
||||||
|
// } else if (ADC_Channel == PV_VOLT_OUT) {
|
||||||
|
// for(i = 0; i < g_adcData.num; ++i) {
|
||||||
|
// value_buf[i] = g_adcData.PV_VOLT_OUT_array[i];
|
||||||
|
// }
|
||||||
|
} else if (ADC_Channel == DSG_CURR) {
|
||||||
|
for(i = 0; i < g_adcData.num; ++i) {
|
||||||
|
value_buf[i] = g_adcData.DSG_CURR_array[i];
|
||||||
|
}
|
||||||
|
// } else if (ADC_Channel == PV_VOLT_IN) {
|
||||||
|
// for(i = 0; i < g_adcData.num; ++i) {
|
||||||
|
// value_buf[i] = g_adcData.PV_VOLT_IN_array[i];
|
||||||
|
// }
|
||||||
|
// } else if (ADC_Channel == SYS_VOLT_IN) {
|
||||||
|
// for(i = 0; i < g_adcData.num; ++i) {
|
||||||
|
// value_buf[i] = g_adcData.SYS_VOLT_IN_array[i];
|
||||||
|
// }
|
||||||
|
// } else if (ADC_Channel == MOSFET_Temper) {
|
||||||
|
// for(i = 0; i < g_adcData.num; ++i) {
|
||||||
|
// value_buf[i] = g_adcData.MOSFET_Temper_array[i];
|
||||||
|
// }
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*从小到大冒泡排序*/
|
||||||
|
for(j = 0; j < g_adcData.num-1; ++j)
|
||||||
|
{
|
||||||
|
for(k = 0; k < g_adcData.num-j-1; ++k)
|
||||||
|
{
|
||||||
|
if(value_buf[k] > value_buf[k+1])
|
||||||
|
{
|
||||||
|
temp = value_buf[k];
|
||||||
|
value_buf[k] = value_buf[k+1];
|
||||||
|
value_buf[k+1] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(i = 2; i < g_adcData.num - 2; ++i)
|
||||||
|
{
|
||||||
|
sum += value_buf[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return sum / (g_adcData.num - 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define N 6
|
#define N 6
|
||||||
/**
|
/**
|
||||||
* @brief 中位值平均滤波
|
* @brief 中位值平均滤波
|
||||||
|
@ -221,8 +301,8 @@ float get_CHG_CURR(void)
|
||||||
uint16_t I_ADC;
|
uint16_t I_ADC;
|
||||||
|
|
||||||
// I_ADC = Get_ConversionVal(get_adc(CHG_CURR));
|
// I_ADC = Get_ConversionVal(get_adc(CHG_CURR));
|
||||||
// I_ADC = get_aftercalculationAdc(CHG_CURR);
|
I_ADC = get_aftercalculationAdc(CHG_CURR);
|
||||||
I_ADC = g_adcData.total_CHG_CURR / g_adcData.num;
|
// I_ADC = g_adcData.total_CHG_CURR / g_adcData.num;
|
||||||
// I_ADC = get_adc(CHG_CURR);
|
// I_ADC = get_adc(CHG_CURR);
|
||||||
|
|
||||||
// I = (float)(I_ADC) / 4095 * 3.3 * P_CHG_CURR * 2;
|
// I = (float)(I_ADC) / 4095 * 3.3 * P_CHG_CURR * 2;
|
||||||
|
@ -248,8 +328,9 @@ float get_PV_VOLT_OUT(void)
|
||||||
uint16_t V_ADC;
|
uint16_t V_ADC;
|
||||||
|
|
||||||
// V_ADC = Get_ConversionVal(get_adc(PV_VOLT_OUT));
|
// V_ADC = Get_ConversionVal(get_adc(PV_VOLT_OUT));
|
||||||
// V_ADC = get_aftercalculationAdc(PV_VOLT_OUT);
|
// V_ADC = get_aftercalculationAdc1(PV_VOLT_OUT);
|
||||||
V_ADC = g_adcData.total_PV_VOLT_OUT / g_adcData.num;
|
V_ADC = get_aftercalculationAdc(PV_VOLT_OUT);
|
||||||
|
// V_ADC = g_adcData.total_PV_VOLT_OUT / g_adcData.num;
|
||||||
// V_ADC = get_adc(PV_VOLT_OUT);
|
// V_ADC = get_adc(PV_VOLT_OUT);
|
||||||
|
|
||||||
V = (float)(V_ADC) * P_PV_VOLT_OUT;
|
V = (float)(V_ADC) * P_PV_VOLT_OUT;
|
||||||
|
@ -278,8 +359,8 @@ float get_DSG_CURR(void)
|
||||||
uint16_t I_ADC;
|
uint16_t I_ADC;
|
||||||
|
|
||||||
// I_ADC = Get_ConversionVal(get_adc(DSG_CURR));
|
// I_ADC = Get_ConversionVal(get_adc(DSG_CURR));
|
||||||
// I_ADC = get_aftercalculationAdc(DSG_CURR);
|
I_ADC = get_aftercalculationAdc(DSG_CURR);
|
||||||
I_ADC = g_adcData.total_DSG_CURR / g_adcData.num;
|
// I_ADC = g_adcData.total_DSG_CURR / g_adcData.num;
|
||||||
// I_ADC = get_adc(DSG_CURR);
|
// I_ADC = get_adc(DSG_CURR);
|
||||||
|
|
||||||
|
|
||||||
|
@ -299,15 +380,15 @@ float get_DSG_CURR(void)
|
||||||
* @param
|
* @param
|
||||||
* @retval V 电压值
|
* @retval V 电压值
|
||||||
*/
|
*/
|
||||||
float get_PV1_VOLT_IN(void)
|
float get_PV_VOLT_IN(void)
|
||||||
{
|
{
|
||||||
float V;
|
float V;
|
||||||
uint16_t V_ADC;
|
uint16_t V_ADC;
|
||||||
|
|
||||||
// GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, SET);
|
// GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, SET);
|
||||||
// V_ADC = Get_ConversionVal(get_adc(PV1_VOLT_IN));
|
// V_ADC = Get_ConversionVal(get_adc(PV1_VOLT_IN));
|
||||||
// V_ADC = get_aftercalculationAdc(PV1_VOLT_IN);
|
V_ADC = get_aftercalculationAdc1(PV_VOLT_IN);
|
||||||
V_ADC = g_adcData.total_PV1_VOLT_IN / g_adcData.num;
|
// V_ADC = g_adcData.total_PV1_VOLT_IN / g_adcData.num;
|
||||||
|
|
||||||
// V_ADC = get_adc(PV1_VOLT_IN);
|
// V_ADC = get_adc(PV1_VOLT_IN);
|
||||||
// GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, RESET);
|
// GPIO_WriteBit(G_FFMOS_CON1_GPIO, G_FFMOS_CON1_PIN, RESET);
|
||||||
|
@ -327,14 +408,14 @@ float get_PV1_VOLT_IN(void)
|
||||||
* @param
|
* @param
|
||||||
* @retval V 电压值
|
* @retval V 电压值
|
||||||
*/
|
*/
|
||||||
float get_PV_VOLT_IN1(void)
|
float get_SYS_VOLT_IN(void)
|
||||||
{
|
{
|
||||||
float V;
|
float V;
|
||||||
uint16_t V_ADC;
|
uint16_t V_ADC;
|
||||||
|
|
||||||
// V_ADC = Get_ConversionVal(get_adc(PV_VOLT_IN1));
|
// V_ADC = Get_ConversionVal(get_adc(PV_VOLT_IN1));
|
||||||
// V_ADC = get_aftercalculationAdc(PV_VOLT_IN1);
|
V_ADC = get_aftercalculationAdc1(SYS_VOLT_IN);
|
||||||
V_ADC = g_adcData.total_PV_VOLT_IN1 / g_adcData.num;
|
// V_ADC = g_adcData.total_PV_VOLT_IN1 / g_adcData.num;
|
||||||
// V_ADC = get_adc(PV_VOLT_IN1);
|
// V_ADC = get_adc(PV_VOLT_IN1);
|
||||||
|
|
||||||
V = (float)(V_ADC) * P_PV_VOLT_IN1;
|
V = (float)(V_ADC) * P_PV_VOLT_IN1;
|
||||||
|
@ -364,8 +445,8 @@ float get_MOSFET_Temper(void)
|
||||||
uint16_t T_ADC;
|
uint16_t T_ADC;
|
||||||
|
|
||||||
// T_ADC = Get_ConversionVal(get_adc(MOSFET_Temper));
|
// T_ADC = Get_ConversionVal(get_adc(MOSFET_Temper));
|
||||||
// T_ADC = get_aftercalculationAdc(MOSFET_Temper);
|
T_ADC = get_aftercalculationAdc1(MOSFET_Temper);
|
||||||
T_ADC = g_adcData.total_MOSFET_Temper / g_adcData.num;
|
// T_ADC = g_adcData.total_MOSFET_Temper / g_adcData.num;
|
||||||
|
|
||||||
// char buffer[30];
|
// char buffer[30];
|
||||||
// memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
|
|
|
@ -811,28 +811,27 @@ void test(void)
|
||||||
g_Mppt_Para.Charg_Current = get_CHG_CURR();
|
g_Mppt_Para.Charg_Current = get_CHG_CURR();
|
||||||
g_Mppt_Para.Discharg_Current = get_DSG_CURR();
|
g_Mppt_Para.Discharg_Current = get_DSG_CURR();
|
||||||
g_Mppt_Para.Output_Voltage = get_PV_VOLT_OUT();
|
g_Mppt_Para.Output_Voltage = get_PV_VOLT_OUT();
|
||||||
g_Mppt_Para.Input_Voltage = get_PV_VOLT_IN1();
|
// g_Mppt_Para.Input_Voltage = get_SYS_VOLT_IN();
|
||||||
g_Mppt_Para.HighSideMos_Temperature = get_MOSFET_Temper();
|
// g_Mppt_Para.HighSideMos_Temperature = get_MOSFET_Temper();
|
||||||
g_Mppt_Para.Solar_Open_Circuit_Voltage = get_PV1_VOLT_IN();
|
// g_Mppt_Para.Solar_Open_Circuit_Voltage = get_PV_VOLT_IN();
|
||||||
|
|
||||||
// printf("\n\n\n");
|
// printf("\n\n\n");
|
||||||
// printf("num = %d \n", g_adcData.num);
|
// printf("num = %d \n", g_adcData.num);
|
||||||
// printf("Charg_Current = %d/1000 \n", (int)(g_Mppt_Para.Charg_Current * 1000));
|
// printf("Charg_Current = %d/1000 \n", (int)(g_Mppt_Para.Charg_Current * 1000));
|
||||||
// printf("Output_Voltage = %d/1000 \n", (int)(g_Mppt_Para.Output_Voltage * 1000));
|
// printf("Output_Voltage = %d/1000 \n", (int)(g_Mppt_Para.Output_Voltage * 1000));
|
||||||
// printf("Discharg_Current = %d/1000 \n", (int)(g_Mppt_Para.Discharg_Current * 1000));
|
// printf("Discharg_Current = %d/1000 \n", (int)(g_Mppt_Para.Discharg_Current * 1000));
|
||||||
|
// printf("\n\n\n");
|
||||||
|
|
||||||
|
printf("%d\n", g_adcData.num);
|
||||||
|
printf("%d\n", (int)(g_Mppt_Para.Charg_Current * 1000));
|
||||||
|
printf("%d\n", (int)(g_Mppt_Para.Output_Voltage * 1000));
|
||||||
|
printf("%d\r\n", (int)(g_Mppt_Para.Discharg_Current * 1000));
|
||||||
|
|
||||||
// printf("Input_Voltage = %d/1000 \n", (int)(g_Mppt_Para.Input_Voltage * 1000));
|
// printf("Input_Voltage = %d/1000 \n", (int)(g_Mppt_Para.Input_Voltage * 1000));
|
||||||
// printf("get_PV_VOLT_IN1 = %d/1000 \n", (int)(get_PV_VOLT_IN1() * 1000));
|
// printf("get_PV_VOLT_IN1 = %d/1000 \n", (int)(get_PV_VOLT_IN1() * 1000));
|
||||||
// printf("HighSideMos_Temperature = %d/1000 \n", (int)(g_Mppt_Para.HighSideMos_Temperature * 1000));
|
// printf("HighSideMos_Temperature = %d/1000 \n", (int)(g_Mppt_Para.HighSideMos_Temperature * 1000));
|
||||||
// printf("\n\n\n");
|
|
||||||
|
|
||||||
g_adcData.num = 0;
|
g_adcData.num = 0;
|
||||||
g_adcData.total_CHG_CURR = 0;
|
|
||||||
g_adcData.total_PV_VOLT_OUT = 0;
|
|
||||||
g_adcData.total_DSG_CURR = 0;
|
|
||||||
g_adcData.total_PV1_VOLT_IN = 0;
|
|
||||||
g_adcData.total_PV_VOLT_IN1 = 0;
|
|
||||||
g_adcData.total_MOSFET_Temper = 0;
|
|
||||||
|
|
||||||
|
|
||||||
//// mppt_readjust();
|
//// mppt_readjust();
|
||||||
//// Get_OutputPower();
|
//// Get_OutputPower();
|
||||||
|
|
|
@ -155,6 +155,14 @@ void Task_RunLED(void)
|
||||||
// printf("HighSideMos_Temperature = %d/1000 \n", (int)(g_Mppt_Para.HighSideMos_Temperature * 1000));
|
// printf("HighSideMos_Temperature = %d/1000 \n", (int)(g_Mppt_Para.HighSideMos_Temperature * 1000));
|
||||||
// printf("\n\n\n");
|
// printf("\n\n\n");
|
||||||
|
|
||||||
|
// printf("%d\n", g_adcData.num);
|
||||||
|
// printf("%d\n", (int)(g_Mppt_Para.Charg_Current * 1000));
|
||||||
|
// printf("%d\n", (int)(g_Mppt_Para.Output_Voltage * 1000));
|
||||||
|
// printf("%d\n", (int)(g_Mppt_Para.Discharg_Current * 1000));
|
||||||
|
// printf("%d\n", (int)(g_Mppt_Para.Input_Voltage * 1000));
|
||||||
|
// printf("%d\n", (int)(g_Mppt_Para.Solar_Open_Circuit_Voltage * 1000));
|
||||||
|
// printf("%d\r\n", (int)(g_Mppt_Para.HighSideMos_Temperature * 1000));
|
||||||
|
|
||||||
static uint8_t flag = RESET;
|
static uint8_t flag = RESET;
|
||||||
flag = !flag;
|
flag = !flag;
|
||||||
GPIO_WriteBit(RUN_LED_GPIO, RUN_LED_PIN, flag);
|
GPIO_WriteBit(RUN_LED_GPIO, RUN_LED_PIN, flag);
|
||||||
|
@ -186,7 +194,7 @@ void Task_startMpptControl(void)
|
||||||
|
|
||||||
if (g_slConfigInfo.checkSolarOpenCircuitVTime == ++checkSolarOpenCircuitVTimeFlag) {
|
if (g_slConfigInfo.checkSolarOpenCircuitVTime == ++checkSolarOpenCircuitVTimeFlag) {
|
||||||
checkSolarOpenCircuitVTimeFlag = 0;
|
checkSolarOpenCircuitVTimeFlag = 0;
|
||||||
g_Mppt_Para.Solar_Open_Circuit_Voltage = get_PV1_VOLT_IN();
|
g_Mppt_Para.Solar_Open_Circuit_Voltage = get_PV_VOLT_IN();
|
||||||
// printf("volt in : %d/100 \n", (int)(g_Mppt_Para.Solar_Open_Circuit_Voltage * 100));
|
// printf("volt in : %d/100 \n", (int)(g_Mppt_Para.Solar_Open_Circuit_Voltage * 100));
|
||||||
// char buff[50];
|
// char buff[50];
|
||||||
// memset(buff, 0, sizeof(buff));
|
// memset(buff, 0, sizeof(buff));
|
||||||
|
@ -354,7 +362,7 @@ void Task_refreshRegister(void)
|
||||||
|
|
||||||
// g_Mppt_Para.DischargMos_State = GPIO_ReadOutputDataBit(POW_OUT_CON_GPIO, POW_OUT_CON_PIN);
|
// 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.Solar_Open_Circuit_Voltage = get_capturedata(get_PV1_VOLT_IN);
|
||||||
g_Mppt_Para.Input_Voltage = get_PV1_VOLT_IN();
|
g_Mppt_Para.Input_Voltage = get_PV_VOLT_IN();
|
||||||
|
|
||||||
if (g_Mppt_Para.HighSideMos_Temperature < g_slConfigInfo.HighSideMosTemperature_start + 3) {
|
if (g_Mppt_Para.HighSideMos_Temperature < g_slConfigInfo.HighSideMosTemperature_start + 3) {
|
||||||
if (overTemperature == 2) {
|
if (overTemperature == 2) {
|
||||||
|
@ -762,7 +770,7 @@ void g_Mppt_Para_Init(void)
|
||||||
g_Mppt_Para.Discharg_Current = get_DSG_CURR();
|
g_Mppt_Para.Discharg_Current = get_DSG_CURR();
|
||||||
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 - g_Mppt_Para.Discharg_Current) * g_impedance;
|
- (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.Solar_Open_Circuit_Voltage = get_PV_VOLT_IN();
|
||||||
g_Mppt_Para.HighSideMos_Temperature = get_MOSFET_Temper();
|
g_Mppt_Para.HighSideMos_Temperature = get_MOSFET_Temper();
|
||||||
|
|
||||||
if (g_Mppt_Para.Battery_Voltage < 15 || g_Mppt_Para.Battery_Voltage > 11) {
|
if (g_Mppt_Para.Battery_Voltage < 15 || g_Mppt_Para.Battery_Voltage > 11) {
|
||||||
|
@ -809,6 +817,8 @@ void task_Init(void)
|
||||||
// , startMpptControl_reloadVal, startMpptControl_offset);
|
// , startMpptControl_reloadVal, startMpptControl_offset);
|
||||||
|
|
||||||
|
|
||||||
|
ADC_TIM_DMA_Init();
|
||||||
|
|
||||||
TimeSliceOffset_Start(); /* Æô¶¯Ê±¼äƬÂÖѯ */
|
TimeSliceOffset_Start(); /* Æô¶¯Ê±¼äƬÂÖѯ */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -831,14 +841,13 @@ void hardware_Init(void)
|
||||||
POW_OUT_CON_Init();
|
POW_OUT_CON_Init();
|
||||||
DSG_PROT_Init();
|
DSG_PROT_Init();
|
||||||
WORK_VOLT_INT_Init();
|
WORK_VOLT_INT_Init();
|
||||||
ADC_TIM_DMA_Init();
|
|
||||||
// EnPowerSupply_Init();
|
// EnPowerSupply_Init();
|
||||||
|
|
||||||
// Set_duty_ratio(&g_duty_ratio);
|
// Set_duty_ratio(&g_duty_ratio);
|
||||||
|
|
||||||
// uart_dev_write(g_bat485_uart3_handle, " hello world \n", sizeof(" hello world \n"));
|
// uart_dev_write(g_bat485_uart3_handle, " hello world \n", sizeof(" hello world \n"));
|
||||||
|
|
||||||
// TIM3_Init(10);
|
// TIM3_Init(10000);
|
||||||
// TIM_Cmd(TIM3, ENABLE); //TIM3ʹÄÜ
|
// TIM_Cmd(TIM3, ENABLE); //TIM3ʹÄÜ
|
||||||
|
|
||||||
g_duty_ratio = 0.8;
|
g_duty_ratio = 0.8;
|
||||||
|
|
|
@ -17,15 +17,23 @@
|
||||||
// uint16_t total_MOSFET_Temper; /* mos¹ÜÎÂ¶È */
|
// uint16_t total_MOSFET_Temper; /* mos¹ÜÎÂ¶È */
|
||||||
// uint16_t num_MOSFET_Temper;
|
// uint16_t num_MOSFET_Temper;
|
||||||
//}ADC_DATA;
|
//}ADC_DATA;
|
||||||
|
|
||||||
|
#define data_len 50
|
||||||
|
|
||||||
typedef struct _ADC_DATA {
|
typedef struct _ADC_DATA {
|
||||||
uint16_t num; /* 一个控制周期中,adc采集次数之和 */
|
uint16_t num; /* 一个控制周期中,adc采集次数 */
|
||||||
uint16_t total_CHG_CURR; /* 一个控制周期中,adc采集的值之和 充电电流 */
|
uint16_t CHG_CURR_array[data_len]; /* 充电电流 */
|
||||||
uint16_t total_PV_VOLT_OUT; /* 输出电压 */
|
uint16_t PV_VOLT_OUT_array[data_len]; /* 输出电压 */
|
||||||
uint16_t total_DSG_CURR; /* 放电电流 */
|
uint16_t DSG_CURR_array[data_len]; /* 放电电流 */
|
||||||
uint16_t total_PV1_VOLT_IN; /* 太阳能板输出电压 */
|
uint16_t PV_VOLT_IN_array[data_len]; /* 太阳能板输出电压 */
|
||||||
uint16_t total_PV_VOLT_IN1; /* 系统输入电压 */
|
uint16_t SYS_VOLT_IN_array[data_len]; /* 系统输入电压 */
|
||||||
uint16_t total_MOSFET_Temper; /* mos管温度 */
|
uint16_t MOSFET_Temper_array[data_len]; /* mos管温度 */
|
||||||
}ADC_DATA;
|
}ADC_DATA;
|
||||||
|
//typedef struct _ADC_DATA {
|
||||||
|
// uint16_t num; /* 一个控制周期中,adc采集次数 */
|
||||||
|
// uint16_t CHG_CURR_array[data_len]; /* 充电电流 */
|
||||||
|
// uint16_t DSG_CURR_array[data_len]; /* 放电电流 */
|
||||||
|
//}ADC_DATA;
|
||||||
|
|
||||||
extern ADC_DATA g_adcData;
|
extern ADC_DATA g_adcData;
|
||||||
extern int16_t Calibrattion_Val;
|
extern int16_t Calibrattion_Val;
|
||||||
|
|
|
@ -14,7 +14,8 @@ void ADC_all_Init(void)
|
||||||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_ADC1, ENABLE);
|
RCC_PB2PeriphClockCmd(RCC_PB2Periph_ADC1, ENABLE);
|
||||||
RCC_ADCCLKConfig(RCC_PCLK2_Div2);
|
RCC_ADCCLKConfig(RCC_PCLK2_Div2);
|
||||||
|
|
||||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7; //PA1~7对应ADC通道1~7
|
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7; //PA1~7对应ADC通道1~7
|
||||||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7; //PA1~7对应ADC通道1~7
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
||||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
@ -51,8 +52,6 @@ void ADC_all_Init(void)
|
||||||
|
|
||||||
void DMA1_Channel1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
void DMA1_Channel1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 初始化ADC的DMA
|
* 初始化ADC的DMA
|
||||||
*
|
*
|
||||||
|
@ -84,7 +83,7 @@ void DMA_Tx_Init(u32 memadr, u16 bufsize)
|
||||||
//初始化TIM NVIC,设置中断优先级分组
|
//初始化TIM NVIC,设置中断优先级分组
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn; //
|
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn; //
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //设置抢占优先级0
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //设置抢占优先级0
|
||||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //设置响应优先级3
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //设置响应优先级3
|
||||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能通道中断
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能通道中断
|
||||||
NVIC_Init(&NVIC_InitStructure); //初始化NVIC
|
NVIC_Init(&NVIC_InitStructure); //初始化NVIC
|
||||||
|
|
||||||
|
@ -129,7 +128,13 @@ void TIM1_Init1(u16 arr,u16 psc)
|
||||||
TIM_Cmd(TIM1, ENABLE);
|
TIM_Cmd(TIM1, ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define CHG_CURR ADC_Channel_1
|
||||||
|
#define PV_VOLT_OUT ADC_Channel_2
|
||||||
|
#define DSG_CURR ADC_Channel_3
|
||||||
|
#define PV_VOLT_IN ADC_Channel_4
|
||||||
|
#define SYS_VOLT_IN ADC_Channel_5
|
||||||
|
#define MOSFET_Temper ADC_Channel_6
|
||||||
|
#define PV2_VOLT_IN ADC_Channel_7
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 通过定时器和DMA完成adc的采集
|
* 通过定时器和DMA完成adc的采集
|
||||||
|
@ -137,7 +142,7 @@ void TIM1_Init1(u16 arr,u16 psc)
|
||||||
* ADC通过DMA的通道1完成数据的传输
|
* ADC通过DMA的通道1完成数据的传输
|
||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
volatile uint16_t ADC_ConvertedValue[6]; //ADC采样的数据
|
volatile uint16_t ADC_ConvertedValue[3]; //ADC采样的数据
|
||||||
void ADC_TIM_DMA_Init(void)
|
void ADC_TIM_DMA_Init(void)
|
||||||
{
|
{
|
||||||
ADC_InitTypeDef ADC_InitStructure = {0};
|
ADC_InitTypeDef ADC_InitStructure = {0};
|
||||||
|
@ -147,7 +152,10 @@ void ADC_TIM_DMA_Init(void)
|
||||||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_ADC1, ENABLE);
|
RCC_PB2PeriphClockCmd(RCC_PB2Periph_ADC1, ENABLE);
|
||||||
RCC_ADCCLKConfig(RCC_PCLK2_Div2);
|
RCC_ADCCLKConfig(RCC_PCLK2_Div2);
|
||||||
|
|
||||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6; //PA1~7对应ADC通道1~7
|
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6; //PA1~7对应ADC通道1~7
|
||||||
|
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
||||||
|
// GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||||
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3; //PA1~7对应ADC通道1~7
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
||||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
@ -160,7 +168,7 @@ void ADC_TIM_DMA_Init(void)
|
||||||
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
|
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
|
||||||
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
||||||
// ADC_InitStructure.ADC_NbrOfChannel = 1;
|
// ADC_InitStructure.ADC_NbrOfChannel = 1;
|
||||||
ADC_InitStructure.ADC_NbrOfChannel = 6;
|
ADC_InitStructure.ADC_NbrOfChannel = 3;
|
||||||
ADC_Init(ADC1, &ADC_InitStructure);
|
ADC_Init(ADC1, &ADC_InitStructure);
|
||||||
|
|
||||||
//使能ADC、DMA
|
//使能ADC、DMA
|
||||||
|
@ -178,20 +186,24 @@ void ADC_TIM_DMA_Init(void)
|
||||||
ADC_StartCalibration(ADC1);
|
ADC_StartCalibration(ADC1);
|
||||||
while(ADC_GetCalibrationStatus(ADC1));
|
while(ADC_GetCalibrationStatus(ADC1));
|
||||||
|
|
||||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_CyclesMode5);
|
// ADC_RegularChannelConfig(ADC1, CHG_CURR, 1, ADC_SampleTime_CyclesMode5);
|
||||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_CyclesMode5);
|
// ADC_RegularChannelConfig(ADC1, PV_VOLT_OUT, 2, ADC_SampleTime_CyclesMode5);
|
||||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 3, ADC_SampleTime_CyclesMode5);
|
// ADC_RegularChannelConfig(ADC1, DSG_CURR, 3, ADC_SampleTime_CyclesMode5);
|
||||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 4, ADC_SampleTime_CyclesMode5);
|
// ADC_RegularChannelConfig(ADC1, PV_VOLT_IN, 4, ADC_SampleTime_CyclesMode5);
|
||||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 5, ADC_SampleTime_CyclesMode5);
|
// ADC_RegularChannelConfig(ADC1, SYS_VOLT_IN, 5, ADC_SampleTime_CyclesMode5);
|
||||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 6, ADC_SampleTime_CyclesMode5);
|
// ADC_RegularChannelConfig(ADC1, MOSFET_Temper, 6, ADC_SampleTime_CyclesMode5);
|
||||||
|
|
||||||
|
ADC_RegularChannelConfig(ADC1, CHG_CURR, 1, ADC_SampleTime_CyclesMode5);
|
||||||
|
ADC_RegularChannelConfig(ADC1, PV_VOLT_OUT, 2, ADC_SampleTime_CyclesMode5);
|
||||||
|
ADC_RegularChannelConfig(ADC1, DSG_CURR, 3, ADC_SampleTime_CyclesMode5);
|
||||||
|
|
||||||
// /* 设置定时器输出的周期为1S */
|
// /* 设置定时器输出的周期为1S */
|
||||||
// TIM1_Init1(1000, 48000);
|
// TIM1_Init1(1000, 48000);
|
||||||
/* 设置定时器输出的周期为30mS */
|
/* 设置定时器输出的周期为30mS */
|
||||||
TIM1_Init1(30, 48000);
|
TIM1_Init1(30, 48000);
|
||||||
/* 设置定时器输出的周期为100uS */
|
/* 设置定时器输出的周期为100uS */
|
||||||
// TIM1_Init1(100, 48);
|
// TIM1_Init1(300, 48);
|
||||||
DMA_Tx_Init((u32)&ADC_ConvertedValue, 6);
|
DMA_Tx_Init((u32)&ADC_ConvertedValue, 3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -243,19 +255,30 @@ void DMA1_Channel1_IRQHandler(void)
|
||||||
{
|
{
|
||||||
DMA_ClearITPendingBit(DMA1_IT_TC1);
|
DMA_ClearITPendingBit(DMA1_IT_TC1);
|
||||||
//中断处理代码
|
//中断处理代码
|
||||||
|
// g_adcData.CHG_CURR_array[g_adcData.num] = Get_ConversionVal1(ADC_ConvertedValue[0]);
|
||||||
|
// g_adcData.PV_VOLT_OUT_array[g_adcData.num] = Get_ConversionVal1(ADC_ConvertedValue[1]);
|
||||||
|
// g_adcData.DSG_CURR_array[g_adcData.num] = Get_ConversionVal1(ADC_ConvertedValue[2]);
|
||||||
|
// g_adcData.PV_VOLT_IN_array[g_adcData.num] = Get_ConversionVal1(ADC_ConvertedValue[3]);
|
||||||
|
// g_adcData.SYS_VOLT_IN_array[g_adcData.num] = Get_ConversionVal1(ADC_ConvertedValue[4]);
|
||||||
|
// g_adcData.MOSFET_Temper_array[g_adcData.num] = Get_ConversionVal1(ADC_ConvertedValue[5]);
|
||||||
|
// g_adcData.num++;
|
||||||
|
|
||||||
|
|
||||||
|
// g_adcData.CHG_CURR_array[g_adcData.num] = ADC_ConvertedValue[0];
|
||||||
|
// g_adcData.DSG_CURR_array[g_adcData.num] = ADC_ConvertedValue[1];
|
||||||
|
// g_adcData.PV_VOLT_OUT_array[g_adcData.num] = ADC_ConvertedValue[2];
|
||||||
// g_adcData.num++;
|
// g_adcData.num++;
|
||||||
// g_adcData.total_CHG_CURR += Get_ConversionVal1(ADC_ConvertedValue[0]);
|
|
||||||
// g_adcData.total_PV_VOLT_OUT += Get_ConversionVal1(ADC_ConvertedValue[1]);
|
|
||||||
// g_adcData.total_DSG_CURR += Get_ConversionVal1(ADC_ConvertedValue[2]);
|
|
||||||
// g_adcData.total_PV1_VOLT_IN += Get_ConversionVal1(ADC_ConvertedValue[3]);
|
|
||||||
// g_adcData.total_PV_VOLT_IN1 += Get_ConversionVal1(ADC_ConvertedValue[4]);
|
|
||||||
// g_adcData.total_MOSFET_Temper += Get_ConversionVal1(ADC_ConvertedValue[5]);
|
|
||||||
|
|
||||||
// g_adcData.num++;
|
// g_adcData.num++;
|
||||||
|
|
||||||
// g_adcData.total_CHG_CURR += Get_ConversionVal1(ADC_ConvertedValue[0]);
|
// g_adcData.total_CHG_CURR += Get_ConversionVal1(ADC_ConvertedValue[0]);
|
||||||
|
|
||||||
|
printf("%d\n", ADC_ConvertedValue[0]);
|
||||||
printf("%d\n", ADC_ConvertedValue[1]);
|
printf("%d\n", ADC_ConvertedValue[1]);
|
||||||
printf("%d\r\n", ADC_ConvertedValue[2]);
|
printf("%d\r\n", ADC_ConvertedValue[2]);
|
||||||
|
// printf("%d\n", ADC_ConvertedValue[3]);
|
||||||
|
// printf("%d\n", ADC_ConvertedValue[4]);
|
||||||
|
// printf("%d\r\n", ADC_ConvertedValue[5]);
|
||||||
|
|
||||||
// g_adcData.total_PV_VOLT_OUT += Get_ConversionVal1(ADC_ConvertedValue[1]);
|
// g_adcData.total_PV_VOLT_OUT += Get_ConversionVal1(ADC_ConvertedValue[1]);
|
||||||
// g_adcData.total_DSG_CURR += Get_ConversionVal1(ADC_ConvertedValue[2]);
|
// g_adcData.total_DSG_CURR += Get_ConversionVal1(ADC_ConvertedValue[2]);
|
||||||
|
|
|
@ -47,7 +47,7 @@ void TIM3_Int_Init(uint16_t arr, uint16_t psc)
|
||||||
//初始化TIM NVIC,设置中断优先级分组
|
//初始化TIM NVIC,设置中断优先级分组
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3中断
|
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3中断
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //设置抢占优先级0
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //设置抢占优先级0
|
||||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //ÉèÖÃÏìÓ¦ÓÅÏȼ¶3
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //ÉèÖÃÏìÓ¦ÓÅÏȼ¶3
|
||||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能通道1中断
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能通道1中断
|
||||||
NVIC_Init(&NVIC_InitStructure); //初始化NVIC
|
NVIC_Init(&NVIC_InitStructure); //初始化NVIC
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ void TIM2_Int_Init(uint16_t arr, uint16_t psc)
|
||||||
//初始化TIM NVIC,设置中断优先级分组
|
//初始化TIM NVIC,设置中断优先级分组
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; //TIM2中断
|
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; //TIM2中断
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //设置抢占优先级0
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //设置抢占优先级0
|
||||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //ÉèÖÃÏìÓ¦ÓÅÏȼ¶3
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //ÉèÖÃÏìÓ¦ÓÅÏȼ¶3
|
||||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能通道1中断
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能通道1中断
|
||||||
NVIC_Init(&NVIC_InitStructure); //初始化NVIC
|
NVIC_Init(&NVIC_InitStructure); //初始化NVIC
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
15629
obj/mppt_Nos_V0.4.lst
15629
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