Преглед изворни кода

修改了多段相同频率但是加速度不足时产生的问题

2
JIU JIALIN пре 1 месец
родитељ
комит
9506005974
4 измењених фајлова са 667 додато и 665 уклоњено
  1. +18
    -16
      PLSR/PLSR/Core/Src/tim.c
  2. +649
    -649
      PLSR/PLSR/EWARM/test.1.dep
  3. BIN
      PLSR/PLSR/EWARM/test.1/Exe/test.1.sim
  4. BIN
      参数表-初版.xlsx

+ 18
- 16
PLSR/PLSR/Core/Src/tim.c Прегледај датотеку

@@ -961,7 +961,7 @@ static void PLSR_UpdateGlobalPulseCount(int32_t current_pulse_count)
s_last_total_pulse = current_pulse_count;
}
// 将32位全局累加脉冲计数分解为两个16位寄存器(支持负数)
int32_t signed_count = g_plsr_location; // 使用有符号数进行计算
int32_t signed_count = g_plsr_total_pulse_count; // 使用有符号数进行计算
ModbusSlave.holding_regs[0x1000] = signed_count & 0xFFFF; // 低16位
ModbusSlave.holding_regs[0x1001] = (signed_count >> 16) & 0xFFFF; // 高16位
}
@@ -1371,12 +1371,12 @@ void Calculate_PluseNum(PLSR_RouteConfig_t *route)
else
{
// 无法找到有效的运动规划,保持当前频率
part1_state = PLSR_STATE_CONST;
part1_state = PLSR_STATE_DECEL;
part1_pulse_num = total_pulses;
part1_time = (total_pulses * 1000) / v0;
part3_pulse_num = 0;
part3_time = 0;
vt = v0; // 实际目标频率等于起始频率
vt = 0; // 实际目标频率等于起始频率
}
}
@@ -1560,7 +1560,14 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
// TIM2中断:负责段切换逻辑
if(htim->Instance == TIM2)
{
PLSR_Section_PWM_Stop();
if(g_plsr_route.current_section_num >= g_plsr_route.section_num &&
g_plsr_route.current_part != PLSR_PART_1 &&
g_plsr_route.run_state == PLSR_STATE_DECEL)
{
PLSR_Route_PWM_Stop();
}
else PLSR_Section_PWM_Stop();

// 精确累加当前段已发送的脉冲数
int32_t current_section_pulses = __HAL_TIM_GetAutoreload(&htim2);
AllPluse += current_section_pulses;
@@ -2026,11 +2033,11 @@ void PLSR_Section_StartNewSection(PLSR_RouteConfig_t* route)
// 目标频率被修改,重新计算实际脉冲数
if(current_section->target_pulse > 0)
{
current_section->actual_pulse = (current_section->target_pulse - route->accel_pulse_count - __HAL_TIM_GET_COUNTER(&htim2));
current_section->actual_pulse = (current_section->target_pulse - route->accel_pulse_count - __HAL_TIM_GET_COUNTER(&htim2) + 1);
}
else
{
current_section->actual_pulse = ((-current_section->target_pulse) - route->accel_pulse_count - __HAL_TIM_GET_COUNTER(&htim2));
current_section->actual_pulse = ((-current_section->target_pulse) - route->accel_pulse_count - __HAL_TIM_GET_COUNTER(&htim2) + 1);
}
}
else if(route->current_part == PLSR_PART_1)//加速过程被修改
@@ -2038,11 +2045,11 @@ void PLSR_Section_StartNewSection(PLSR_RouteConfig_t* route)
// 目标频率被修改,重新计算实际脉冲数
if(current_section->target_pulse > 0)
{
current_section->actual_pulse = (current_section->target_pulse - __HAL_TIM_GET_COUNTER(&htim2));
current_section->actual_pulse = (current_section->target_pulse - __HAL_TIM_GET_COUNTER(&htim2) + 1);
}
else
{
current_section->actual_pulse = ((-current_section->target_pulse) - __HAL_TIM_GET_COUNTER(&htim2));
current_section->actual_pulse = ((-current_section->target_pulse) - __HAL_TIM_GET_COUNTER(&htim2) + 1);
}
}
else if(route->current_part == PLSR_PART_3)//减速过程被修改
@@ -2051,12 +2058,12 @@ void PLSR_Section_StartNewSection(PLSR_RouteConfig_t* route)
if(current_section->target_pulse > 0)
{
current_section->actual_pulse = (current_section->target_pulse -
route->accel_pulse_count - route->const_pulse_count - __HAL_TIM_GET_COUNTER(&htim2));
route->accel_pulse_count - route->const_pulse_count - __HAL_TIM_GET_COUNTER(&htim2) + 1);
}
else
{
current_section->actual_pulse = ((-current_section->target_pulse) -
route->accel_pulse_count - route->const_pulse_count - __HAL_TIM_GET_COUNTER(&htim2));
route->accel_pulse_count - route->const_pulse_count - __HAL_TIM_GET_COUNTER(&htim2) + 1);
}
}
g_plsr_mod_flag = 0; // 清除修改标记
@@ -2400,13 +2407,8 @@ void PLSR_Section_SwitchNext(PLSR_RouteConfig_t* route, uint8_t is_pulse_complet
// 清除新段的外部事件标志,确保每段都是干净的状态
PLSR_ClearExtEvent(route);
route->initial_freq = route->current_freq;
// 根据切换原因更新当前频率
if (is_pulse_complete)
{
// 脉冲完成触发:更新为上一段的目标频率
route->current_freq = current_section->target_freq;
}
// 外部事件触发时保持当前频率不变,确保频率连续性
}



+ 649
- 649
PLSR/PLSR/EWARM/test.1.dep
Разлика између датотеке није приказан због своје велике величине
Прегледај датотеку


BIN
PLSR/PLSR/EWARM/test.1/Exe/test.1.sim Прегледај датотеку


BIN
参数表-初版.xlsx Прегледај датотеку


Loading…
Откажи
Сачувај