Обновление

This commit is contained in:
cfif 2026-04-06 17:16:34 +03:00
parent 0bfa1f70b2
commit e556f8538d
2 changed files with 14 additions and 6 deletions

View File

@ -44,7 +44,7 @@ void Get_Set_Tpu_PwmCallback(tPwmFlagchip *env);
#define TPU_FREQ (BUS_CLK / SCG_CLK_DIV) #define TPU_FREQ (BUS_CLK / SCG_CLK_DIV)
#define PWM_FREQ 100 // 100 Hz #define PWM_FREQ 50 // 100 Hz
#define PERIOD_TICKS (TPU_FREQ / PWM_FREQ) #define PERIOD_TICKS (TPU_FREQ / PWM_FREQ)

View File

@ -80,17 +80,25 @@ static void vPwmRun(tPwmFlagchip *env) {
} }
static void setActivePercent(tPwmFlagchip *env, uint8_t percent) { static void setActivePercent(tPwmFlagchip *env, uint8_t percent) {
uint8_t final_percent;
// Ограничения
if (percent >= 100) if (percent >= 100)
percent = 85; percent = 95;
if (percent == 0) if (percent == 0)
percent = 5; percent = 5;
// Расчет времени активности в тактах // Для active LOW (bActiveHigh = false) нужна инверсия
uint32_t data = PERIOD_TICKS * percent / 100; // 10% → 90%, 20% → 80% и т.д.
osMessageQueuePut(env->q_u32ActiveTime, &data, 0, 0); if (env->etpu_pwmconfig_tbl.bActiveHigh == false) {
final_percent = 100 - percent;
} else {
final_percent = percent;
}
// Расчет времени активности в тактах
uint32_t data = env->etpu_pwmconfig_tbl.u32PeriodTime * final_percent / 100;
osMessageQueuePut(env->q_u32ActiveTime, &data, 0, 0);
} }