From 790becb7015cb6a044ff16dc6a149c30c585e0dc Mon Sep 17 00:00:00 2001 From: Aiden Date: Wed, 1 Jul 2026 17:18:04 +0800 Subject: [PATCH] refactor: comment out unused variables and functions for code clarity --- .../Examples/template/LLC_48V/src/main.c | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/pec930_sdk-v1.0.1/Examples/template/LLC_48V/src/main.c b/pec930_sdk-v1.0.1/Examples/template/LLC_48V/src/main.c index 4d7b75c..2fe6ae3 100644 --- a/pec930_sdk-v1.0.1/Examples/template/LLC_48V/src/main.c +++ b/pec930_sdk-v1.0.1/Examples/template/LLC_48V/src/main.c @@ -58,12 +58,12 @@ typedef struct // int32_t a2 = 0; // -A2(PID 特例時 a2 常為 0) SystemState_t sys_state = STATE_STOP; -uint8_t is_zero_crossing = 0; +// uint8_t is_zero_crossing = 0; uint8_t llc_running = 0; -uint8_t pfc_running = 0; -uint8_t is_brown_in = 0; // 0: 關機/保護中, 1: 正常工作 -static uint8_t cur_loop_fun_en = 0; +// uint8_t pfc_running = 0; +// uint8_t is_brown_in = 0; // 0: 關機/保護中, 1: 正常工作 +// static uint8_t cur_loop_fun_en = 0; static uint16_t vbus = 0; static uint16_t ipcs = 0; @@ -74,20 +74,21 @@ uint32_t count1; uint32_t vbus_ovp = (VBUS_OVP * 4096 / VBUS_2ADC / 3.3); uint32_t vbus_uvp = (VBUS_UVP * 4096 / VBUS_2ADC / 3.3); -uint32_t digi_vcomp_max = (LLC_PERIOD_MAX - LLC_PERIOD_MIN) << LLC_COMP_GAIN_BIT; -int32_t vbus_comp2 = 0; // 過零點用 +// uint32_t digi_vcomp_max = (LLC_PERIOD_MAX - LLC_PERIOD_MIN) << LLC_COMP_GAIN_BIT; +// int32_t vbus_comp2 = 0; // 過零點用 uint16_t llc_ss_cnt = 0; //----------------------------------------------- -uint8_t power_on_cmd = 0; +// uint8_t power_on_cmd = 0; uint32_t vac_avg1; uint32_t vbus_avg; uint32_t vcomp_avg; -uint32_t ipcs_avg; - +uint32_t ipcs_avg1, ipcs_avg2; uint8_t power_on = 0; +static uint32_t new_arr = LLC_PERIOD_MIN; +static int32_t fast_arr = 0; -uint32_t static digital_vcomp = (LLC_PERIOD_MAX - LLC_PERIOD_MIN) << LLC_COMP_GAIN_BIT; +// uint32_t static digital_vcomp = (LLC_PERIOD_MAX - LLC_PERIOD_MIN) << LLC_COMP_GAIN_BIT; uint16_t llc_period_ss = LLC_SS_MIN; uint16_t llc_run_arr = LLC_PERIOD_MIN; uint8_t v_loop_cnt = 0; @@ -124,8 +125,8 @@ uint16_t capture_packet_gap_ms = 1000; //============================================================================= void A_Para_Reset(void) { - digital_vcomp = (LLC_PERIOD_MAX - LLC_PERIOD_MIN) << LLC_COMP_GAIN_BIT; - // vbus_set = (VBUS_SET * 4096 / VBUS_2ADC / 3.3); + // digital_vcomp = (LLC_PERIOD_MAX - LLC_PERIOD_MIN) << LLC_COMP_GAIN_BIT; + // vbus_set = (VBUS_SET * 4096 / VBUS_2ADC / 3.3); v_loop_cnt = 0; iac_err_1 = 0; @@ -141,7 +142,7 @@ void A_Para_Reset(void) TIM0->MR0 = TIM0_PERIOD; - pfc_running = 0; + // pfc_running = 0; llc_running = 0; } //------------------------------------------------------------------------- @@ -371,7 +372,7 @@ static void Vol_Loop_PFC_1P1Z_UI(void) // ZERO: 120HZ, POLE:0.1HZ, G:10 vbus_comp2 = (vbus_comp_1 >> 9); } #endif - +/* //======================================================================== __attribute__((always_inline)) static inline void Cur_Loop_PFC_2P2Z(void) // 優化後 3.65us { @@ -440,11 +441,9 @@ __attribute__((always_inline)) static inline void Cur_Loop_PFC_2P2Z(void) // 優 TIM2->CCR1 = local_duty; } //============================================================================ - +*/ void Vol_Loop_LLC(void) // 調整 period 控制 vcomp 穩定 { - uint32_t new_arr = EPWM->ARR; - if (vcomp_avg > 2000) new_arr++; // vcomp 上升, arr ++ else @@ -493,7 +492,7 @@ void reset_pid_parameters(void) iac_comp_1 = 0; iac_comp_2 = 0; - digital_vcomp = (LLC_PERIOD_MAX - LLC_PERIOD_MIN) << LLC_COMP_GAIN_BIT; + // digital_vcomp = (LLC_PERIOD_MAX - LLC_PERIOD_MIN) << LLC_COMP_GAIN_BIT; } //================================================================================ @@ -545,7 +544,7 @@ void Handle_UART_Monitor(void) static uint32_t msg_timer2 = 0; if (sys_get_tick() - msg_timer2 >= 1000) { - printf("%d %d %d\r\n", vbus, ipcs, vcomp); + printf("%d %d %d\r\n", ipcs_avg1, ipcs_avg2, fast_arr); msg_timer2 = sys_get_tick(); } } @@ -580,8 +579,10 @@ int main(void) // 高速信號濾波 (簡易位移算法減少算力消耗) --- vbus_avg = (vbus_avg - (vbus_avg >> 3)) + (vbus >> 3); - ipcs_avg = (ipcs_avg - (ipcs_avg >> 3)) + (ipcs >> 3); vcomp_avg = (vcomp_avg - (vcomp_avg >> 3)) + (vcomp >> 3); + ipcs_avg1 = (ipcs_avg1 - (ipcs_avg1 >> 3)) + (ipcs >> 3); // 高頻 ip + ipcs_avg2 = (ipcs_avg2 - (ipcs_avg2 >> 5)) + (ipcs >> 5); // 低頻 ip + #if 0 // vbus ovp, uvp, 超出工作電壓範圍就不工作 if (vbus_avg > vbus_ovp || vbus_avg < vbus_uvp) @@ -627,13 +628,16 @@ int main(void) break; case STATE_RUN: // 2 - // 根據電壓環、電流環調整頻率 + // 根據電壓環只做穩壓 + if (++v_loop_cnt >= 10) // 10 比較好 + { + Vol_Loop_LLC(); + v_loop_cnt = 0; + } + // 電流環做高速負載變化 + fast_arr = (((int32_t)ipcs_avg1 - ipcs_avg2)); // period 加上這個值 + if (fast_arr > 10 || fast_arr < -10) llc_set_period((fast_arr >> 1) + new_arr); - // if (++v_loop_cnt >= 10) // 10KHZ - // { - Vol_Loop_LLC(); - // v_loop_cnt = 0; - // } break; } // switch case #endif