测试电流采集
This commit is contained in:
parent
ff0ffbae91
commit
a418010b91
|
@ -5,7 +5,7 @@
|
||||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-156117377827207421" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="998107432084761222" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
|
|
|
@ -221,7 +221,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 = 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;
|
||||||
|
@ -247,7 +248,8 @@ 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_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) / 4095 * 2.5 * P_PV_VOLT_OUT;
|
V = (float)(V_ADC) / 4095 * 2.5 * P_PV_VOLT_OUT;
|
||||||
|
@ -276,9 +278,11 @@ 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 = get_adc(DSG_CURR);
|
// I_ADC = get_adc(DSG_CURR);
|
||||||
|
|
||||||
|
|
||||||
// I = (float)(I_ADC) / 4095 * 3.3 * P_DSG_CURR * 2;
|
// I = (float)(I_ADC) / 4095 * 3.3 * P_DSG_CURR * 2;
|
||||||
I = (float)(I_ADC) / 4095 * 2.5 * P_DSG_CURR;
|
I = (float)(I_ADC) / 4095 * 2.5 * P_DSG_CURR;
|
||||||
|
|
||||||
|
@ -302,7 +306,8 @@ float get_PV1_VOLT_IN(void)
|
||||||
|
|
||||||
// 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_aftercalculationAdc(PV1_VOLT_IN);
|
||||||
|
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);
|
||||||
|
@ -328,7 +333,8 @@ float get_PV_VOLT_IN1(void)
|
||||||
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_aftercalculationAdc(PV_VOLT_IN1);
|
||||||
|
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) / 4095 * 2.5 * P_PV_VOLT_IN1;
|
V = (float)(V_ADC) / 4095 * 2.5 * P_PV_VOLT_IN1;
|
||||||
|
@ -358,7 +364,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_aftercalculationAdc(MOSFET_Temper);
|
||||||
|
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));
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "sl_protocol.h"
|
#include "sl_protocol.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
#include "adc.h"
|
||||||
|
|
||||||
#include "uart_dev.h"
|
#include "uart_dev.h"
|
||||||
|
|
||||||
|
@ -807,119 +808,148 @@ void findMiNDutyRatio(void)
|
||||||
|
|
||||||
void test(void)
|
void test(void)
|
||||||
{
|
{
|
||||||
// mppt_readjust();
|
// g_Mppt_Para.Charg_Current = get_CHG_CURR();
|
||||||
// Get_OutputPower();
|
|
||||||
|
|
||||||
// mppt_constantVoltage(18);
|
|
||||||
|
|
||||||
// findMiNDutyRatio();
|
|
||||||
// MpptContorl();
|
|
||||||
|
|
||||||
// printf_data();
|
|
||||||
// void MpptContorl();
|
|
||||||
|
|
||||||
// mppt_constantVoltageO(12);
|
|
||||||
|
|
||||||
// FloatingCharge();
|
|
||||||
// mppt_readJust();
|
|
||||||
|
|
||||||
// mppt_constantCurrentO(1);
|
|
||||||
|
|
||||||
|
|
||||||
// if (g_interruptNum < 5) {
|
|
||||||
// g_interruptNum++;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// g_Mppt_Para.Charg_Current = get_capturedata(get_CHG_CURR);
|
|
||||||
// g_Mppt_Para.Discharg_Current = get_capturedata(get_DSG_CURR);
|
|
||||||
// g_Mppt_Para.Output_Voltage = get_capturedata(get_PV_VOLT_OUT);
|
|
||||||
// g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
|
|
||||||
g_Mppt_Para.Charg_Current = get_CHG_CURR();
|
|
||||||
g_Mppt_Para.Discharg_Current = get_DSG_CURR();
|
g_Mppt_Para.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_PV1_VOLT_IN();
|
// g_Mppt_Para.Input_Voltage = get_PV1_VOLT_IN();
|
||||||
|
// g_Mppt_Para.HighSideMos_Temperature = get_MOSFET_Temper();
|
||||||
|
|
||||||
// mppt_constantVoltage(18);
|
// printf("\n");
|
||||||
// return;
|
// printf("\n");
|
||||||
|
// printf("\n");
|
||||||
|
// printf("num = %d \n", g_adcData.num);
|
||||||
|
//// 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("Discharg_Current = %d/1000 \n", (int)(g_Mppt_Para.Discharg_Current * 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("HighSideMos_Temperature = %d/1000 \n", (int)(g_Mppt_Para.HighSideMos_Temperature * 1000));
|
||||||
|
// printf("\n");
|
||||||
|
// printf("\n");
|
||||||
|
// printf("\n");
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
if (g_Mppt_Para.Discharg_Current == 0 && g_Mppt_Para.Charg_Current == 0) {
|
//// mppt_readjust();
|
||||||
return;
|
//// Get_OutputPower();
|
||||||
}
|
|
||||||
// g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
|
|
||||||
|
|
||||||
// static float_t Volt = 0.7;
|
|
||||||
// static float_t Curr = 5.5;
|
|
||||||
// static float_t loopImpedance;
|
|
||||||
// static uint8_t onlyone = 1;
|
|
||||||
// if (onlyone) {
|
|
||||||
// loopImpedance = (float_t)g_slConfigInfo.loopImpedance / 100;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
static float_t inBatteryCurr;
|
|
||||||
static float_t outBatteryCurr;
|
|
||||||
inBatteryCurr = g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current;
|
|
||||||
outBatteryCurr = g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current;
|
|
||||||
if (inBatteryCurr > 0.1) {
|
|
||||||
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage - inBatteryCurr * g_impedance;
|
|
||||||
} else {
|
|
||||||
g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_batteryState == 0 && (inBatteryCurr > 0.1 || outBatteryCurr > 0.1) && g_Mppt_Para.Output_Voltage < 14.2) {
|
|
||||||
// printf("int g_batteryState : %d\n", g_batteryState);
|
|
||||||
g_batteryState = 1;
|
|
||||||
// TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
|
||||||
// , impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
// mppt_constantVoltage(18);
|
|
||||||
|
|
||||||
// if (g_Mppt_Para.MPPT_Mode == CONSTANTCURRENT
|
|
||||||
// || g_Mppt_Para.MPPT_Mode == CONSTANTVOLTAGE) {
|
|
||||||
//
|
//
|
||||||
// g_Mppt_Para.Battery_Voltage = get_capturedata(get_PV_VOLT_OUT)
|
//// mppt_constantVoltage(18);
|
||||||
// - g_impedance * (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current);
|
//
|
||||||
// } else {
|
//// findMiNDutyRatio();
|
||||||
// g_Mppt_Para.Battery_Voltage = get_capturedata(get_PV_VOLT_OUT);
|
//// MpptContorl();
|
||||||
// }
|
//
|
||||||
|
//// printf_data();
|
||||||
// voltOut = get_capturedata(get_PV_VOLT_OUT);
|
//// void MpptContorl();
|
||||||
// g_Mppt_Para.Battery_Voltage = voltOut - g_impedance * (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current);
|
//
|
||||||
|
//// mppt_constantVoltageO(12);
|
||||||
|
//
|
||||||
// ConstantVoltageCharge();
|
//// FloatingCharge();
|
||||||
// return;
|
//// mppt_readJust();
|
||||||
|
//
|
||||||
if (!overTemperature) {
|
//// mppt_constantCurrentO(1);
|
||||||
MpptMode();
|
//
|
||||||
MpptContorl();
|
//
|
||||||
}
|
//// if (g_interruptNum < 5) {
|
||||||
|
//// g_interruptNum++;
|
||||||
|
//// return;
|
||||||
// mppt_constantVoltageO(12);
|
//// }
|
||||||
|
//// g_Mppt_Para.Charg_Current = get_capturedata(get_CHG_CURR);
|
||||||
// static uint32_t run_num = 0;
|
//// g_Mppt_Para.Discharg_Current = get_capturedata(get_DSG_CURR);
|
||||||
// if (1000 < run_num++) {
|
//// g_Mppt_Para.Output_Voltage = get_capturedata(get_PV_VOLT_OUT);
|
||||||
// FloatingCharge();
|
//// g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
|
||||||
// run_num = 1200;
|
// g_Mppt_Para.Charg_Current = get_CHG_CURR();
|
||||||
// printf("in floatcharge \n");
|
// g_Mppt_Para.Discharg_Current = get_DSG_CURR();
|
||||||
|
// g_Mppt_Para.Output_Voltage = get_PV_VOLT_OUT();
|
||||||
|
// g_Mppt_Para.Input_Voltage = get_PV1_VOLT_IN();
|
||||||
|
//
|
||||||
|
//// mppt_constantVoltage(18);
|
||||||
|
//// return;
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// if (g_Mppt_Para.Discharg_Current == 0 && g_Mppt_Para.Charg_Current == 0) {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
// mppt_readJust();
|
//// g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
|
||||||
// mppt_constantCurrentO(1.2);
|
//
|
||||||
|
//// static float_t Volt = 0.7;
|
||||||
|
//// static float_t Curr = 5.5;
|
||||||
// int16_t var = 0;
|
//// static float_t loopImpedance;
|
||||||
// char buff[4];
|
//// static uint8_t onlyone = 1;
|
||||||
// for (var = 0; var < 100; ++var) {
|
//// if (onlyone) {
|
||||||
// sprintf(buff, "%3d:", var);
|
//// loopImpedance = (float_t)g_slConfigInfo.loopImpedance / 100;
|
||||||
// uart_dev_write(g_gw485_uart4_handle, buff, sizeof(buff));
|
//// }
|
||||||
// uart_dev_write(g_gw485_uart4_handle, "1234567890\n", sizeof("1234567890\n"));
|
//
|
||||||
// Delay_Ms(1);
|
//
|
||||||
|
// static float_t inBatteryCurr;
|
||||||
|
// static float_t outBatteryCurr;
|
||||||
|
// inBatteryCurr = g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current;
|
||||||
|
// outBatteryCurr = g_Mppt_Para.Discharg_Current - g_Mppt_Para.Charg_Current;
|
||||||
|
// if (inBatteryCurr > 0.1) {
|
||||||
|
// g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage - inBatteryCurr * g_impedance;
|
||||||
|
// } else {
|
||||||
|
// g_Mppt_Para.Battery_Voltage = g_Mppt_Para.Output_Voltage;
|
||||||
// }
|
// }
|
||||||
// uart_dev_write(g_gw485_uart4_handle, "\n\n\n\n\n\n", sizeof("\n\n\n\n\n\n"));
|
//
|
||||||
|
// if (g_batteryState == 0 && (inBatteryCurr > 0.1 || outBatteryCurr > 0.1) && g_Mppt_Para.Output_Voltage < 14.2) {
|
||||||
|
//// printf("int g_batteryState : %d\n", g_batteryState);
|
||||||
|
// g_batteryState = 1;
|
||||||
|
//// TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
||||||
|
//// , impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//// mppt_constantVoltage(18);
|
||||||
|
//
|
||||||
|
//// if (g_Mppt_Para.MPPT_Mode == CONSTANTCURRENT
|
||||||
|
//// || g_Mppt_Para.MPPT_Mode == CONSTANTVOLTAGE) {
|
||||||
|
////
|
||||||
|
//// g_Mppt_Para.Battery_Voltage = get_capturedata(get_PV_VOLT_OUT)
|
||||||
|
//// - g_impedance * (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current);
|
||||||
|
//// } else {
|
||||||
|
//// g_Mppt_Para.Battery_Voltage = get_capturedata(get_PV_VOLT_OUT);
|
||||||
|
//// }
|
||||||
|
//
|
||||||
|
//// voltOut = get_capturedata(get_PV_VOLT_OUT);
|
||||||
|
//// g_Mppt_Para.Battery_Voltage = voltOut - g_impedance * (g_Mppt_Para.Charg_Current - g_Mppt_Para.Discharg_Current);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// ConstantVoltageCharge();
|
||||||
|
//// return;
|
||||||
|
//
|
||||||
|
// if (!overTemperature) {
|
||||||
|
// MpptMode();
|
||||||
|
// MpptContorl();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// mppt_constantVoltageO(12);
|
||||||
|
//
|
||||||
|
//// static uint32_t run_num = 0;
|
||||||
|
//// if (1000 < run_num++) {
|
||||||
|
//// FloatingCharge();
|
||||||
|
//// run_num = 1200;
|
||||||
|
//// printf("in floatcharge \n");
|
||||||
|
//// return;
|
||||||
|
//// }
|
||||||
|
//// mppt_readJust();
|
||||||
|
//// mppt_constantCurrentO(1.2);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// int16_t var = 0;
|
||||||
|
//// char buff[4];
|
||||||
|
//// for (var = 0; var < 100; ++var) {
|
||||||
|
//// sprintf(buff, "%3d:", var);
|
||||||
|
//// uart_dev_write(g_gw485_uart4_handle, buff, sizeof(buff));
|
||||||
|
//// uart_dev_write(g_gw485_uart4_handle, "1234567890\n", sizeof("1234567890\n"));
|
||||||
|
//// Delay_Ms(1);
|
||||||
|
//// }
|
||||||
|
//// uart_dev_write(g_gw485_uart4_handle, "\n\n\n\n\n\n", sizeof("\n\n\n\n\n\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
162
App/src/task.c
162
App/src/task.c
|
@ -78,66 +78,66 @@ void Task_RunLED(void)
|
||||||
// printf(" \n");
|
// printf(" \n");
|
||||||
// uart_sendstr(g_bat485_uart3_handle, " \n");
|
// uart_sendstr(g_bat485_uart3_handle, " \n");
|
||||||
|
|
||||||
uart_dev_write(g_bat485_uart3_handle, " \n", sizeof(" \n"));
|
// uart_dev_write(g_bat485_uart3_handle, " \n", sizeof(" \n"));
|
||||||
|
//
|
||||||
char buffer[80];
|
// char buffer[80];
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " duty_ratio : %d/1000 \n", (int)(g_duty_ratio * 1000));
|
// sprintf(buffer, " duty_ratio : %d/1000 \n", (int)(g_duty_ratio * 1000));
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " Input_Voltage : %d/100 \n", (int)(g_Mppt_Para.Input_Voltage * 100));
|
// sprintf(buffer, " Input_Voltage : %d/100 \n", (int)(g_Mppt_Para.Input_Voltage * 100));
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " vout : %d/100 \n", (int)(g_Mppt_Para.Output_Voltage * 100));
|
// sprintf(buffer, " vout : %d/100 \n", (int)(g_Mppt_Para.Output_Voltage * 100));
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " vBattery : %d/100 \n", (int)(g_Mppt_Para.Battery_Voltage * 100));
|
// sprintf(buffer, " vBattery : %d/100 \n", (int)(g_Mppt_Para.Battery_Voltage * 100));
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " Iout : %d/100 \n", (int)(g_Mppt_Para.Charg_Current * 100));
|
// sprintf(buffer, " Iout : %d/100 \n", (int)(g_Mppt_Para.Charg_Current * 100));
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " Idisout : %d/100 \n", (int)(g_Mppt_Para.Discharg_Current * 100));
|
// sprintf(buffer, " Idisout : %d/100 \n", (int)(g_Mppt_Para.Discharg_Current * 100));
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " mosT : %d/10 \n", (int)(g_Mppt_Para.HighSideMos_Temperature * 10));
|
// sprintf(buffer, " mosT : %d/10 \n", (int)(g_Mppt_Para.HighSideMos_Temperature * 10));
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " impedance : %d/1000 \n", (int)(g_impedance * 1000));
|
// sprintf(buffer, " impedance : %d/1000 \n", (int)(g_impedance * 1000));
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " g_impedanceStart : %d \n", g_impedanceStart);
|
// sprintf(buffer, " g_impedanceStart : %d \n", g_impedanceStart);
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " mosState : %d \n", (int)(g_Mppt_Para.DischargMos_State));
|
// sprintf(buffer, " mosState : %d \n", (int)(g_Mppt_Para.DischargMos_State));
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " batteryState : %d \n", g_batteryState);
|
// sprintf(buffer, " batteryState : %d \n", g_batteryState);
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " outputAgainFlag : %d \n", outputAgainFlag);
|
// sprintf(buffer, " outputAgainFlag : %d \n", outputAgainFlag);
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " excessiveLoadFlag : %d \n", excessiveLoadFlag);
|
// sprintf(buffer, " excessiveLoadFlag : %d \n", excessiveLoadFlag);
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
memset(buffer, 0, sizeof(buffer));
|
// memset(buffer, 0, sizeof(buffer));
|
||||||
sprintf(buffer, " 0.没有工作; 1.涓流模式; 2.恒流模式; 3.恒压模式; 4.浮充模式; 5.没有电池 : %d \n", g_Mppt_Para.MPPT_Mode);
|
// sprintf(buffer, " 0.没有工作; 1.涓流模式; 2.恒流模式; 3.恒压模式; 4.浮充模式; 5.没有电池 : %d \n", g_Mppt_Para.MPPT_Mode);
|
||||||
uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
// uart_dev_write(g_bat485_uart3_handle, buffer, sizeof(buffer));
|
||||||
|
//
|
||||||
uart_dev_write(g_bat485_uart3_handle, " \n", sizeof(" \n"));
|
// uart_dev_write(g_bat485_uart3_handle, " \n", sizeof(" \n"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -145,6 +145,20 @@ void Task_RunLED(void)
|
||||||
|
|
||||||
// get_CHG_CURR();
|
// get_CHG_CURR();
|
||||||
|
|
||||||
|
// printf("\n");
|
||||||
|
// printf("\n");
|
||||||
|
// printf("\n");
|
||||||
|
//// printf("num = %d \n", g_adcData.num);
|
||||||
|
//// 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("Discharg_Current = %d/1000 \n", (int)(g_Mppt_Para.Discharg_Current * 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("HighSideMos_Temperature = %d/1000 \n", (int)(g_Mppt_Para.HighSideMos_Temperature * 1000));
|
||||||
|
// printf("\n");
|
||||||
|
// printf("\n");
|
||||||
|
// printf("\n");
|
||||||
|
|
||||||
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);
|
||||||
|
@ -318,10 +332,10 @@ void Task_refreshRegister(void)
|
||||||
// g_Mppt_Para.Discharg_Current = get_capturedata(get_DSG_CURR);
|
// g_Mppt_Para.Discharg_Current = get_capturedata(get_DSG_CURR);
|
||||||
// g_Mppt_Para.HighSideMos_Temperature = get_capturedata(get_MOSFET_Temper);
|
// g_Mppt_Para.HighSideMos_Temperature = get_capturedata(get_MOSFET_Temper);
|
||||||
// g_Mppt_Para.Battery_Voltage = get_PV_VOLT_OUT();
|
// g_Mppt_Para.Battery_Voltage = get_PV_VOLT_OUT();
|
||||||
g_Mppt_Para.Output_Voltage = get_PV_VOLT_OUT();
|
// g_Mppt_Para.Output_Voltage = get_PV_VOLT_OUT();
|
||||||
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.HighSideMos_Temperature = get_MOSFET_Temper();
|
// g_Mppt_Para.HighSideMos_Temperature = get_MOSFET_Temper();
|
||||||
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)
|
||||||
&& GPIO_ReadInputDataBit(DSG_PROT_GPIO, DSG_PROT_PIN);
|
&& GPIO_ReadInputDataBit(DSG_PROT_GPIO, DSG_PROT_PIN);
|
||||||
|
|
||||||
|
@ -785,18 +799,20 @@ 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_usart, Task_usart, usart_reloadVal, usart_offset);
|
// TimeSliceOffset_Register(&m_usart, Task_usart, usart_reloadVal, usart_offset);
|
||||||
|
|
||||||
TimeSliceOffset_Register(&m_wdi, Task_wdi, wdi_reloadVal, wdi_offset);
|
TimeSliceOffset_Register(&m_wdi, Task_wdi, wdi_reloadVal, wdi_offset);
|
||||||
|
|
||||||
// TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
// TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
||||||
// , impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
|
// , impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
|
||||||
|
//
|
||||||
|
// TimeSliceOffset_Register(&m_refreshRegister, Task_refreshRegister
|
||||||
|
// , refreshRegister_reloadVal, refreshRegister_reloadVal);
|
||||||
|
//
|
||||||
|
// TimeSliceOffset_Register(&m_startMpptControl, Task_startMpptControl
|
||||||
|
// , startMpptControl_reloadVal, startMpptControl_offset);
|
||||||
|
|
||||||
TimeSliceOffset_Register(&m_refreshRegister, Task_refreshRegister
|
ADC_TIM_DMA_Init();
|
||||||
, refreshRegister_reloadVal, refreshRegister_reloadVal);
|
|
||||||
|
|
||||||
TimeSliceOffset_Register(&m_startMpptControl, Task_startMpptControl
|
|
||||||
, startMpptControl_reloadVal, startMpptControl_offset);
|
|
||||||
|
|
||||||
TimeSliceOffset_Start(); /* Æô¶¯Ê±¼äƬÂÖѯ */
|
TimeSliceOffset_Start(); /* Æô¶¯Ê±¼äƬÂÖѯ */
|
||||||
}
|
}
|
||||||
|
@ -820,13 +836,17 @@ 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(10);
|
||||||
// TIM_Cmd(TIM3, ENABLE); //TIM3ʹÄÜ
|
// TIM_Cmd(TIM3, ENABLE); //TIM3ʹÄÜ
|
||||||
|
|
||||||
|
g_duty_ratio = 0.8;
|
||||||
|
Set_duty_ratio(&g_duty_ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,34 @@
|
||||||
|
|
||||||
#include "ch32l103.h"
|
#include "ch32l103.h"
|
||||||
|
|
||||||
|
//typedef struct _ADC_DATA {
|
||||||
|
// uint16_t total_CHG_CURR; /* 一个控制周期中,adc采集的值之和 充电电流 */
|
||||||
|
// uint16_t num_CHG_CURR; /* 一个控制周期中,adc采集次数之和 */
|
||||||
|
// uint16_t total_PV_VOLT_OUT; /* 输出电压 */
|
||||||
|
// uint16_t num_PV_VOLT_OUT;
|
||||||
|
// uint16_t total_DSG_CURR; /* 放电电流 */
|
||||||
|
// uint16_t num_DSG_CURR;
|
||||||
|
// uint16_t total_PV1_VOLT_IN; /* 系统输入电压 */
|
||||||
|
// uint16_t num_PV1_VOLT_IN;
|
||||||
|
// uint16_t total_PV_VOLT_IN1; /* 太阳能板输出电压 */
|
||||||
|
// uint16_t num_PV_VOLT_IN1;
|
||||||
|
// uint16_t total_MOSFET_Temper; /* mos管温度 */
|
||||||
|
// uint16_t num_MOSFET_Temper;
|
||||||
|
//}ADC_DATA;
|
||||||
|
typedef struct _ADC_DATA {
|
||||||
|
uint16_t num; /* 一个控制周期中,adc采集次数之和 */
|
||||||
|
uint16_t total_CHG_CURR; /* 一个控制周期中,adc采集的值之和 充电电流 */
|
||||||
|
uint16_t total_PV_VOLT_OUT; /* 输出电压 */
|
||||||
|
uint16_t total_DSG_CURR; /* 放电电流 */
|
||||||
|
uint16_t total_PV1_VOLT_IN; /* 太阳能板输出电压 */
|
||||||
|
uint16_t total_PV_VOLT_IN1; /* 系统输入电压 */
|
||||||
|
uint16_t total_MOSFET_Temper; /* mos管温度 */
|
||||||
|
}ADC_DATA;
|
||||||
|
|
||||||
|
extern ADC_DATA g_adcData;
|
||||||
extern int16_t Calibrattion_Val;
|
extern int16_t Calibrattion_Val;
|
||||||
|
|
||||||
void ADC_all_Init(void);
|
void ADC_all_Init(void);
|
||||||
|
void ADC_TIM_DMA_Init(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
void G_FFMOS_CON_Init(void);
|
void G_FFMOS_CON_Init(void);
|
||||||
|
|
||||||
/* 运行指示灯 */
|
/* 运行指示灯 */
|
||||||
/* RUN_LED --> PA8 */
|
///* RUN_LED --> PA8 */
|
||||||
|
/* RUN_LED --> PB7 */
|
||||||
#define RUN_LED_GPIO GPIOA
|
#define RUN_LED_GPIO GPIOA
|
||||||
#define RUN_LED_PIN GPIO_Pin_8
|
#define RUN_LED_PIN GPIO_Pin_8
|
||||||
void RUN_LED_Init(void);
|
void RUN_LED_Init(void);
|
||||||
|
|
|
@ -15,7 +15,10 @@
|
||||||
#define Prescaler 0
|
#define Prescaler 0
|
||||||
/* 输出频率为240k */
|
/* 输出频率为240k */
|
||||||
//#define Period 200 - 1
|
//#define Period 200 - 1
|
||||||
|
/* 输出频率为100k */
|
||||||
#define Period 480 - 1
|
#define Period 480 - 1
|
||||||
|
/* 输出频率为10k */
|
||||||
|
//#define Period 4800 - 1
|
||||||
|
|
||||||
void PWM_TIM_Configuration(void);
|
void PWM_TIM_Configuration(void);
|
||||||
void Set_duty_ratio(float *duty_ratio);
|
void Set_duty_ratio(float *duty_ratio);
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include <adc.h>
|
#include <adc.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
int16_t Calibrattion_Val = 0;
|
int16_t Calibrattion_Val = 0;
|
||||||
|
ADC_DATA g_adcData;
|
||||||
|
|
||||||
//ADC对应GPIO初始化配置以及ADC初始化配置
|
//ADC对应GPIO初始化配置以及ADC初始化配置
|
||||||
void ADC_all_Init(void)
|
void ADC_all_Init(void)
|
||||||
|
@ -43,3 +44,237 @@ void ADC_all_Init(void)
|
||||||
ADC_Sample_ModeConfig(ADC1,ADC_Sample_Over_1M_Mode);
|
ADC_Sample_ModeConfig(ADC1,ADC_Sample_Over_1M_Mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void DMA1_Channel1_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 初始化ADC的DMA
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void DMA_Tx_Init(u32 memadr, u16 bufsize)
|
||||||
|
{
|
||||||
|
DMA_InitTypeDef DMA_InitStructure = {0};
|
||||||
|
NVIC_InitTypeDef NVIC_InitStructure = {0};
|
||||||
|
|
||||||
|
RCC_HBPeriphClockCmd(RCC_HBPeriph_DMA1, ENABLE);
|
||||||
|
|
||||||
|
DMA_DeInit(DMA1_Channel1);
|
||||||
|
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&ADC1->RDATAR; //ADC1地址
|
||||||
|
DMA_InitStructure.DMA_MemoryBaseAddr = memadr; //内存地址
|
||||||
|
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //方向(从外设到内存)
|
||||||
|
DMA_InitStructure.DMA_BufferSize = bufsize; //传输内容的大小
|
||||||
|
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //外设地址固定
|
||||||
|
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //内存地址递增
|
||||||
|
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; //外设数据单位
|
||||||
|
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //内存数据单位
|
||||||
|
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //DMA模式:循环传输
|
||||||
|
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; //优先级:高
|
||||||
|
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //禁止内存到内存的传输
|
||||||
|
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
|
||||||
|
|
||||||
|
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE); //使能传输完成中断
|
||||||
|
|
||||||
|
//初始化TIM NVIC,设置中断优先级分组
|
||||||
|
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn; //
|
||||||
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //设置抢占优先级0
|
||||||
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //设置响应优先级3
|
||||||
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能通道中断
|
||||||
|
NVIC_Init(&NVIC_InitStructure); //初始化NVIC
|
||||||
|
|
||||||
|
DMA_Cmd(DMA1_Channel1,ENABLE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TIM1_Init1(u16 arr,u16 psc)
|
||||||
|
{
|
||||||
|
// /* 初始化PA8为模拟通道输入引脚 */
|
||||||
|
// GPIO_InitTypeDef GPIO_InitStructure={0};
|
||||||
|
// RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOA, ENABLE);
|
||||||
|
//// RCC_APB2PeriphClockCmd(RCC_PB2Periph_AFIO, ENABLE); //打开管脚复用AFIO时钟
|
||||||
|
//// GPIO_PinRemapConfig(GPIO_FullRemap_TIM1, ENABLE);
|
||||||
|
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
||||||
|
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
|
||||||
|
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||||
|
// GPIO_Init( GPIOA, &GPIO_InitStructure );
|
||||||
|
|
||||||
|
TIM_OCInitTypeDef TIM_OCInitStructure={0};
|
||||||
|
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure={0};
|
||||||
|
|
||||||
|
RCC_PB2PeriphClockCmd(RCC_PB2Periph_TIM1, ENABLE);
|
||||||
|
|
||||||
|
// TIM_TimeBaseInitStructure.TIM_Period = 30000 - 1;
|
||||||
|
// TIM_TimeBaseInitStructure.TIM_Prescaler = 48000 - 1;
|
||||||
|
TIM_TimeBaseInitStructure.TIM_Period = arr - 1;
|
||||||
|
TIM_TimeBaseInitStructure.TIM_Prescaler = psc - 1;
|
||||||
|
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||||
|
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||||
|
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseInitStructure);
|
||||||
|
|
||||||
|
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
|
||||||
|
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
|
||||||
|
TIM_OCInitStructure.TIM_Pulse = 10;
|
||||||
|
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
|
||||||
|
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
|
||||||
|
|
||||||
|
TIM_CtrlPWMOutputs(TIM1, ENABLE);
|
||||||
|
TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Disable);
|
||||||
|
TIM_ARRPreloadConfig(TIM1, ENABLE);
|
||||||
|
TIM_Cmd(TIM1, ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 通过定时器和DMA完成adc的采集
|
||||||
|
* 定时器采用定时器1的cc1完成ADC的外部触发 PA8 --> TIM1_CH1
|
||||||
|
* ADC通过DMA的通道1完成数据的传输
|
||||||
|
*
|
||||||
|
* */
|
||||||
|
volatile uint16_t ADC_ConvertedValue[6]; //ADC采样的数据
|
||||||
|
void ADC_TIM_DMA_Init(void)
|
||||||
|
{
|
||||||
|
ADC_InitTypeDef ADC_InitStructure = {0};
|
||||||
|
GPIO_InitTypeDef GPIO_InitStructure = {0};
|
||||||
|
|
||||||
|
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOA, ENABLE);
|
||||||
|
RCC_PB2PeriphClockCmd(RCC_PB2Periph_ADC1, ENABLE);
|
||||||
|
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_Mode = GPIO_Mode_AIN;
|
||||||
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
ADC_DeInit(ADC1);
|
||||||
|
Calibrattion_Val=Get_CalibrationValue(ADC1);
|
||||||
|
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
|
||||||
|
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
|
||||||
|
// ADC_InitStructure.ADC_ScanConvMode = DISABLE;
|
||||||
|
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
|
||||||
|
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
|
||||||
|
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
||||||
|
// ADC_InitStructure.ADC_NbrOfChannel = 1;
|
||||||
|
ADC_InitStructure.ADC_NbrOfChannel = 6;
|
||||||
|
ADC_Init(ADC1, &ADC_InitStructure);
|
||||||
|
|
||||||
|
//使能ADC、DMA
|
||||||
|
ADC_DMACmd(ADC1,ENABLE);
|
||||||
|
ADC_Cmd(ADC1, ENABLE);
|
||||||
|
|
||||||
|
// ADC_InjectedSequencerLengthConfig(ADC1, 1);
|
||||||
|
// ADC_InjectedChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_CyclesMode5);
|
||||||
|
// ADC_ExternalTrigInjectedConvCmd(ADC1, ENABLE);
|
||||||
|
|
||||||
|
ADC_FIFO_Cmd(ADC1, ENABLE);
|
||||||
|
ADC_BufferCmd(ADC1, DISABLE); //disable buffer
|
||||||
|
ADC_ResetCalibration(ADC1);
|
||||||
|
while(ADC_GetResetCalibrationStatus(ADC1));
|
||||||
|
ADC_StartCalibration(ADC1);
|
||||||
|
while(ADC_GetCalibrationStatus(ADC1));
|
||||||
|
|
||||||
|
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_CyclesMode5);
|
||||||
|
ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_CyclesMode5);
|
||||||
|
ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 3, ADC_SampleTime_CyclesMode5);
|
||||||
|
ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 4, ADC_SampleTime_CyclesMode5);
|
||||||
|
ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 5, ADC_SampleTime_CyclesMode5);
|
||||||
|
ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 6, ADC_SampleTime_CyclesMode5);
|
||||||
|
|
||||||
|
// /* 设置定时器输出的周期为1S */
|
||||||
|
// TIM1_Init1(1000, 48000);
|
||||||
|
/* 设置定时器输出的周期为30mS */
|
||||||
|
TIM1_Init1(30, 48000);
|
||||||
|
/* 设置定时器输出的周期为30uS */
|
||||||
|
// TIM1_Init1(30, 48);
|
||||||
|
DMA_Tx_Init((u32)&ADC_ConvertedValue, 6);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ADC_DeInit(ADC1);
|
||||||
|
// Calibrattion_Val = Get_CalibrationValue(ADC1);
|
||||||
|
// printf("Calibrattion_Val : %d\n", Calibrattion_Val);
|
||||||
|
// ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
|
||||||
|
// ADC_InitStructure.ADC_ScanConvMode = DISABLE;
|
||||||
|
// ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
|
||||||
|
// ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
|
||||||
|
// ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
|
||||||
|
// ADC_InitStructure.ADC_NbrOfChannel = 1;
|
||||||
|
// ADC_Init(ADC1, &ADC_InitStructure);
|
||||||
|
//
|
||||||
|
// ADC_Cmd(ADC1, ENABLE);
|
||||||
|
//
|
||||||
|
// ADC_FIFO_Cmd(ADC1, ENABLE);
|
||||||
|
// ADC_BufferCmd(ADC1, DISABLE); //disable buffer
|
||||||
|
//
|
||||||
|
// ADC_ResetCalibration(ADC1);
|
||||||
|
// while(ADC_GetResetCalibrationStatus(ADC1));
|
||||||
|
// ADC_StartCalibration(ADC1);
|
||||||
|
// while(ADC_GetCalibrationStatus(ADC1));
|
||||||
|
//
|
||||||
|
// RCC_ADCCLKConfig(RCC_HCLK_ADC);
|
||||||
|
// ADC_DutyDelayCmd(ADC1,ENABLE);
|
||||||
|
// ADC_Sample_ModeConfig(ADC1,ADC_Sample_Over_1M_Mode);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 将采集的adc进行校准
|
||||||
|
* @param val 采集的adc数据
|
||||||
|
* @retval 校准后的adc数据
|
||||||
|
*/
|
||||||
|
uint16_t Get_ConversionVal1(int16_t val)
|
||||||
|
{
|
||||||
|
if((val + Calibrattion_Val) < 0 || val == 0)
|
||||||
|
return 0;
|
||||||
|
if((Calibrattion_Val + val) > 4095 || val == 4095)
|
||||||
|
return 4095;
|
||||||
|
return (val + Calibrattion_Val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DMA1_Channel1_IRQHandler(void)
|
||||||
|
{
|
||||||
|
// printf("\r\nEnter DMA interrupt\r\n");
|
||||||
|
if(DMA_GetITStatus(DMA1_IT_TC1)!=RESET)
|
||||||
|
{
|
||||||
|
DMA_ClearITPendingBit(DMA1_IT_TC1);
|
||||||
|
//中断处理代码
|
||||||
|
// 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.total_CHG_CURR += Get_ConversionVal1(ADC_ConvertedValue[0]);
|
||||||
|
printf("%d\n", ADC_ConvertedValue[2]);
|
||||||
|
|
||||||
|
// 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]);
|
||||||
|
|
||||||
|
// printf("\r\n The current ADCH1 value = %d \r\n", ADC_ConvertedValue[0]);
|
||||||
|
// printf("\r\n The current ADCH2 value = %d \r\n", ADC_ConvertedValue[1]);
|
||||||
|
// printf("\r\n The current ADCH3 value = %d \r\n", ADC_ConvertedValue[2]);
|
||||||
|
// printf("\r\n The current ADCH4 value = %d \r\n", ADC_ConvertedValue[3]);
|
||||||
|
// printf("\r\n The current ADCH5 value = %d \r\n", ADC_ConvertedValue[4]);
|
||||||
|
// printf("\r\n The current ADCH5 value = %d \r\n", ADC_ConvertedValue[5]);
|
||||||
|
// ADC_ConvertedValue[0] = 0;
|
||||||
|
// ADC_ConvertedValue[1] = 0;
|
||||||
|
// ADC_ConvertedValue[2] = 0;
|
||||||
|
// ADC_ConvertedValue[3] = 0;
|
||||||
|
// ADC_ConvertedValue[4] = 0;
|
||||||
|
// ADC_ConvertedValue[5] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ void G_FFMOS_CON_Init(void)
|
||||||
void RUN_LED_Init(void)
|
void RUN_LED_Init(void)
|
||||||
{
|
{
|
||||||
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOA, ENABLE);
|
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOA, ENABLE);
|
||||||
|
RCC_PB2PeriphClockCmd(RCC_PB2Periph_GPIOB, ENABLE);
|
||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||||||
GPIO_InitStructure.GPIO_Pin = RUN_LED_PIN;
|
GPIO_InitStructure.GPIO_Pin = RUN_LED_PIN;
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
|
||||||
|
|
|
@ -23,7 +23,7 @@ void TIM3_Init(uint16_t delay_ms)
|
||||||
/* 分频系数 */
|
/* 分频系数 */
|
||||||
uint16_t psc = (SystemCoreClock / 10000) - 1;
|
uint16_t psc = (SystemCoreClock / 10000) - 1;
|
||||||
/* 周期数 */
|
/* 周期数 */
|
||||||
uint16_t arr = delay_ms * 1 - 1;
|
uint16_t arr = delay_ms * 10 - 1;
|
||||||
|
|
||||||
TIM3_Int_Init(arr, psc);
|
TIM3_Int_Init(arr, psc);
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ void SysTick_Handler(void)
|
||||||
void TIM1_Init(uint16_t delay_ms)
|
void TIM1_Init(uint16_t delay_ms)
|
||||||
{
|
{
|
||||||
/* 分频系数 */
|
/* 分频系数 */
|
||||||
uint16_t psc = (SystemCoreClock / 10000) - 1;
|
uint16_t psc = (SystemCoreClock / 10) - 1;
|
||||||
/* */
|
/* */
|
||||||
uint16_t arr = delay_ms * 10 - 1;
|
uint16_t arr = delay_ms * 10 - 1;
|
||||||
// uint16_t arr = 10 - 1;
|
// uint16_t arr = 10 - 1;
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
19964
obj/mppt_Nos_V0.4.lst
19964
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