feat: remove isr.c & isr.h

This commit is contained in:
roy01
2026-06-12 09:02:40 +08:00
parent c846ad9793
commit 7d23d69a15
5 changed files with 47 additions and 174 deletions
@@ -10,7 +10,6 @@ extern "C"
{
#endif
#include "isr.h"
#include "main.h"
//=============================================================================
@@ -1,53 +0,0 @@
/**
* Copyright (c) 2024 Wei-Lun Hsu. All Rights Reserved.
*/
/** @file isr.h
*
* @author Wei-Lun Hsu
* @version 0.1
* @date 2024/09/16
* @license
* @description
*/
#ifndef __isr_H_wuraIpBA_lTJm_HvJw_sNDo_uEd5JnucTReY__
#define __isr_H_wuraIpBA_lTJm_HvJw_sNDo_uEd5JnucTReY__
#ifdef __cplusplus
extern "C"
{
#endif
#include "main.h"
//=============================================================================
// Constant Definition
//=============================================================================
//=============================================================================
// Macro Definition
//=============================================================================
//=============================================================================
// Structure Definition
//=============================================================================
//=============================================================================
// Global Data Definition
//=============================================================================
//=============================================================================
// Private Function Definition
//=============================================================================
//=============================================================================
// Public Function Definition
//=============================================================================
// void isr_tim2_handle(void);
// void isr_adc_handle(void);
// void isr_tim0_handle(void);
#ifdef __cplusplus
}
#endif
#endif
@@ -8,7 +8,6 @@
#include "init.h"
#include "app.h"
#include "hal_device.h"
#include "isr.h"
//=============================================================================
// Constant Definition
@@ -1,69 +0,0 @@
/**
* Copyright (c) 2024 Wei-Lun Hsu. All Rights Reserved.
*/
/** @file isr.c
*
* @author Wei-Lun Hsu
* @version 0.1
* @date 2024/09/16
* @license
* @description
*/
#include "isr.h"
#include "init.h"
//=============================================================================
// Constant Definition
//=============================================================================
//=============================================================================
// Macro Definition
//=============================================================================
//=============================================================================
// Global Data Definition
//=============================================================================
// uint8_t volatile tim0_trigger = 0;
// extern uint16_t iac;
// extern uint16_t vac;
// extern uint16_t vbus;
// extern uint16_t vac_avg1, vac_avg2;
// extern uint16_t vbus_avg;
// extern uint8_t hi_line;
//=============================================================================
// Private Function Definition
//=============================================================================
//=============================================================================
// Public Function Definition
//=============================================================================
/*
__INTERRUPT void isr_tim2_handle(void)
{
if((TIM2->SR & 0x20000) == 0x20000) // UDIF: Underflow interrupt flag
{
TIM_ClearITPendingBit(TIM2, 0x20000);
}
}
*/
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
#if 0
__INTERRUPT void isr_tim0_handle(void)
{
SAVE_IRQ_CSR_CONTEXT();
if( LPTIM_GetFlagStatus(TIM0, LPTIM_Flag_Match0) )
{
LPTIM_ClearFlag(TIM0, LPTIM_Flag_Match0);
tim0_trigger = 1;
GPIO_TogglePin(GPIOA, GPIO_Pin_05);
}
RESTORE_IRQ_CSR_CONTEXT();
return;
}
#endif
@@ -2,7 +2,6 @@
#include "main.h"
#include "app.h"
#include "init.h"
#include "isr.h"
//=============================================================================
// Constant Definition
//=============================================================================
@@ -16,7 +15,7 @@
#define CR_1P1Z_A1_Q14 -5803
// 前饋輸出限制(請根據您主環 Q14 格式的數值範圍調整)
// 假設最大前饋量限制為實數值 50.0 -> 50.0 * 16384 = 819200
#define CR_FF_MAX_Q14 1638400 //819200 // 50 duty << 14
#define CR_FF_MAX_Q14 1638400 // 819200 // 50 duty << 14
#define CR_FF_MIN_Q14 -1638400 //-819200
//=============================================================================
@@ -355,31 +354,31 @@ void Vol_Loop_PFC_1P1Z(void)
int32_t vbus_err_n = (int32_t)vbus_set - (int32_t)vbus_avg;
// --- 策略 A:動態增益調整 ---
int32_t b0 = 139;
int32_t b1 = -129;
int32_t b0 = 139;
int32_t b1 = -129;
// vloop_p->b0 = 139;
// vloop_p->b1 = -129;
// vloop_p->a1 = -16383;
/*
if (vbus_err_n > 40 || vbus_err_n < -40) // ~ 20V
{
// 大誤差時(通常是剛啟動或大跳載),強化參數加快反應
//b0 = 250;
//b1 = -249;
//b0 = 180; // 稍微調降強增益的力道
//b1 = -178;
b0 = 500;
b1 = -499;
}
// --- 策略 B:接近目標時微調零點 (抗過衝) ---
else if (vbus_err_n < 20 && vbus_err_n > -20) // ~ 5V
{
// 當誤差縮小時,稍微減小 b0 與 b1 的差值,降低積分衝力
b0 = 120;
b1 = -119; // 如果不能用浮點數,請維持 120 / -119,增加阻尼感
}
*/
/*
if (vbus_err_n > 40 || vbus_err_n < -40) // ~ 20V
{
// 大誤差時(通常是剛啟動或大跳載),強化參數加快反應
//b0 = 250;
//b1 = -249;
//b0 = 180; // 稍微調降強增益的力道
//b1 = -178;
b0 = 500;
b1 = -499;
}
// --- 策略 B:接近目標時微調零點 (抗過衝) ---
else if (vbus_err_n < 20 && vbus_err_n > -20) // ~ 5V
{
// 當誤差縮小時,稍微減小 b0 與 b1 的差值,降低積分衝力
b0 = 120;
b1 = -119; // 如果不能用浮點數,請維持 120 / -119,增加阻尼感
}
*/
// 2. 差分方程計算
int64_t acc = (int64_t)b0 * vbus_err_n;
acc += (int64_t)b1 * vbus_err_1;
@@ -420,12 +419,12 @@ void Vol_Loop_PFC_1P1Z(void)
// 5. 輸出 Duty >> 14
if (sys_state == STATE_PFC_SOFT_START || sys_state == STATE_RUN_SKIP) // 緩啟動期間直接控制 DUTY
TIM2->CCR1 = (vbus_comp_1 >> 14); // 0 ~ 540
TIM2->CCR1 = (vbus_comp_1 >> 14); // 0 ~ 540
// 6. 輸出 comp >> 9 (變大 32 倍) (MAX ~ 18000) (540*32=17280)差不多,>> 9 應該是對的
// if (sys_state == STATE_RUN_NORMAL) // 正常工作時間輸出 COMP 值
vbus_comp2 = (vbus_comp_1 >> 9) + (cr_feed_forward_output_q14 << 1); // 太大會直接 OVP
//vbus_comp2 = (vbus_comp_1 >> 9);
// vbus_comp2 = (vbus_comp_1 >> 9);
}
//=============================================================
static void Vol_Loop_PFC_1P1Z_UI(void) // ZERO: 120HZ, POLE:0.1HZ, G:10
@@ -456,7 +455,7 @@ static void Vol_Loop_PFC_1P1Z_UI(void) // ZERO: 120HZ, POLE:0.1HZ, G:10
// 5. 輸出 Duty >> 14
if (sys_state == STATE_PFC_SOFT_START || sys_state == STATE_RUN_SKIP) // 緩啟動期間直接控制 DUTY
TIM2->CCR1 = (vbus_comp_1 >> 14); // 0 ~ 540
TIM2->CCR1 = (vbus_comp_1 >> 14); // 0 ~ 540
// 6. 輸出 comp >> 9 (變大 32 倍) (MAX ~ 18000) (540*32=17280)差不多,>> 9 應該是對的
// if (sys_state == STATE_RUN_NORMAL) // 正常工作時間輸出 COMP 值
@@ -664,8 +663,8 @@ void Handle_UART_Monitor(void)
{
printf("%d\r\n", vac);
// printf("%d %d %d %d %d %d", power_on_cmd, sys_state, vbus_comp2, print1, print2, print3);
//msg("%d %d %d", power_on_cmd, sys_state, vac_pk2);
//msg("%d %d %d", iac, vac, vbus);
// msg("%d %d %d", power_on_cmd, sys_state, vac_pk2);
// msg("%d %d %d", iac, vac, vbus);
// 電壓環輸出最大 COMP,但是電流環輸出最小 DUTY
msg_timer = sys_get_tick();
}
@@ -755,18 +754,18 @@ int main(void)
// 基礎硬體底層設定 (HIRC 60MHz, GPIO, ADC 採樣率 1Msps) [cite: 55, 127, 184]
SYS_Config();
//pfc_set_duty(15);
//pfc_pwm_enable();
//while(1);
// pfc_set_duty(15);
// pfc_pwm_enable();
// while(1);
//llc_set_period(600);
//llc_pwm_enable();
//while(1);
// llc_set_period(600);
// llc_pwm_enable();
// while(1);
/*
while(1)
{
Handle_UART_Monitor();
Handle_UART_Monitor();
}
*/
@@ -784,11 +783,11 @@ int main(void)
// vloop_p->a1 = -16383;
/*********************************************************************/
/* PFC 電流環參數*/
//bplot_p->b0 = 3353681;
//bplot_p->b1 = -1577632;
//bplot_p->b2 = -1712512;
//bplot_p->a1 = -20921;
//bplot_p->a2 = 4545;
// bplot_p->b0 = 3353681;
// bplot_p->b1 = -1577632;
// bplot_p->b2 = -1712512;
// bplot_p->a1 = -20921;
// bplot_p->a2 = 4545;
/*********************************************************************/
#if 0 // 單測 PFC 電壓環 (OK)
@@ -993,11 +992,11 @@ int main(void)
/* PFC 電流環參數*/
// Z1=200, Z2=100000, P1=10, P2=20000, G=8000
bplot_p->b0 = 3353681;
bplot_p->b1 = -1577632;
bplot_p->b2 = -1712512;
bplot_p->a1 = -20114;
bplot_p->a2 = 3737;
bplot_p->b0 = 3353681;
bplot_p->b1 = -1577632;
bplot_p->b2 = -1712512;
bplot_p->a1 = -20114;
bplot_p->a2 = 3737;
cur_loop_fun_en = 1; // 開啟電流環,專測電流環
while (1)
@@ -1070,7 +1069,7 @@ int main(void)
if (++v_loop_cnt >= 10) // 10KHZ
{
Vol_Loop_PFC_1P1Z();
//Vol_Loop_PFC_1P1Z();
// Vol_Loop_PFC_1P1Z();
v_loop_cnt = 0;
}
@@ -1129,20 +1128,18 @@ int main(void)
if (++v_loop_cnt >= 10)
{
// 先算前饋,再算主環,最後疊加
Load_Loop_1P1Z(); // Cr 前饋
Load_Loop_1P1Z(); // Cr 前饋
Vol_Loop_PFC_1P1Z(); // PFC 電壓環
//Vol_Loop_LLC(); // LLC 電壓環
// Vol_Loop_LLC(); // LLC 電壓環
v_loop_cnt = 0;
}
if (++v_loop_cnt2 >= 5) // 好一點
{
Vol_Loop_LLC(); // LLC 電壓環
v_loop_cnt2 = 0;
}
break;
case STATE_RUN_SKIP: // 5