| @@ -637,7 +637,7 @@ void PLSR_PWM_Start(void) | |||||
| */ | */ | ||||
| void PLSR_Section_PWM_Stop(void) | void PLSR_Section_PWM_Stop(void) | ||||
| { | { | ||||
| StopFlag = 1; | |||||
| StopFlag = 1; /*为确保PLSR_PWM_SetFrequency函数不意外启动脉冲输出*/ | |||||
| // 根据output_port选择目标定时器并停止PWM输出 | // 根据output_port选择目标定时器并停止PWM输出 | ||||
| switch(PlsrRoute.output_port) | switch(PlsrRoute.output_port) | ||||
| { | { | ||||
| @@ -875,21 +875,28 @@ void PLSR_HandleSectionEnd(void) | |||||
| PlsrRoute.decel_pulse_count = 0; | PlsrRoute.decel_pulse_count = 0; | ||||
| if(PlsrRoute.mode == PLSR_MODE_RELATIVE) | if(PlsrRoute.mode == PLSR_MODE_RELATIVE) | ||||
| { | { | ||||
| if(current_section->target_pulse > 0) | |||||
| if(PLSR_Section_CheckPulseComplete(&PlsrRoute) == 1) | |||||
| { | { | ||||
| SectionUpdatePluse += current_section->target_pulse; | |||||
| if(current_section->target_pulse > 0) | |||||
| { | |||||
| SectionUpdatePluse += current_section->target_pulse; | |||||
| } | |||||
| else | |||||
| { | |||||
| SectionUpdatePluse -= current_section->target_pulse; | |||||
| } | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| SectionUpdatePluse -= current_section->target_pulse; | |||||
| SectionUpdatePluse = PlsrTotalPulseCount; | |||||
| } | } | ||||
| } | } | ||||
| // 重置部分状态 | // 重置部分状态 | ||||
| PlsrRoute.current_part = PLSR_PART_COMPLETE; | PlsrRoute.current_part = PLSR_PART_COMPLETE; | ||||
| // 检查是否为最后一段且下一段为0(路径结束) | // 检查是否为最后一段且下一段为0(路径结束) | ||||
| if(PlsrRoute.current_section_num >= PlsrRoute.section_num | |||||
| if((PlsrRoute.current_section_num >= PlsrRoute.section_num | |||||
| && PlsrRoute.section[PlsrRoute.current_section_num - 1].next_section == 0) | && PlsrRoute.section[PlsrRoute.current_section_num - 1].next_section == 0) | ||||
| || PlsrRoute.current_section_num >= PlsrRoute.section_num && PlsrRoute.section_num == 1) | |||||
| { | { | ||||
| // 最后一段完成,路径结束 | // 最后一段完成,路径结束 | ||||
| PLSR_Route_Stop(&PlsrRoute); | PLSR_Route_Stop(&PlsrRoute); | ||||
| @@ -1906,6 +1913,11 @@ void PLSR_Accel_Process(PLSR_RouteConfig_t* route) | |||||
| PLSR_PWM_SetFrequency(route->current_freq); | PLSR_PWM_SetFrequency(route->current_freq); | ||||
| return; | return; | ||||
| } | } | ||||
| else if(route->run_state == PLSR_STATE_DECEL && route->current_freq <= route->target_freq && route->target_freq == 0) | |||||
| { | |||||
| PLSR_HandleSectionEnd(); | |||||
| return; | |||||
| } | |||||
| // ==================== 加速处理 ==================== | // ==================== 加速处理 ==================== | ||||
| if (route->run_state == PLSR_STATE_ACCEL) | if (route->run_state == PLSR_STATE_ACCEL) | ||||
| @@ -2087,7 +2099,7 @@ void PLSR_TaskSectionSwitch(PLSR_RouteConfig_t* route) | |||||
| __HAL_TIM_SET_COUNTER(&htim2, 0); | __HAL_TIM_SET_COUNTER(&htim2, 0); | ||||
| /* 如果当前频率已经为0,直接停止 */ | /* 如果当前频率已经为0,直接停止 */ | ||||
| if (route->current_freq == 0) | |||||
| if (route->current_freq <= 0) | |||||
| { | { | ||||
| route->route_state = PLSR_ROUTE_COMPLETED; | route->route_state = PLSR_ROUTE_COMPLETED; | ||||
| PLSR_Route_Stop(route); | PLSR_Route_Stop(route); | ||||
| @@ -2109,6 +2121,7 @@ void PLSR_TaskSectionSwitch(PLSR_RouteConfig_t* route) | |||||
| PLSR_PWM_Start(); | PLSR_PWM_Start(); | ||||
| } | } | ||||
| PLSR_ClearGpioTriggerFlag(); // 清除GPIO触发标志 | PLSR_ClearGpioTriggerFlag(); // 清除GPIO触发标志 | ||||
| return ; | |||||
| } | } | ||||
| return; // 等待外部事件时不需要继续处理 | return; // 等待外部事件时不需要继续处理 | ||||
| } | } | ||||