| @@ -1740,7 +1740,7 @@ void PLSR_Section_SwitchNext(PLSR_RouteConfig_t* route, uint8_t is_pulse_complet | |||||
| // 清除新段的外部事件标志,确保每段都是干净的状态 | // 清除新段的外部事件标志,确保每段都是干净的状态 | ||||
| PLSR_ClearExtEvent(route); | PLSR_ClearExtEvent(route); | ||||
| route->initial_freq = route->current_freq; | |||||
| route->initial_freq = route->current_freq; //???? | |||||
| } | } | ||||
| @@ -2045,14 +2045,24 @@ void PLSR_TaskSectionSwitch(PLSR_RouteConfig_t* route) | |||||
| PLSR_SectionConfig_t* current_section = &route->section[route->current_section_num - 1]; | PLSR_SectionConfig_t* current_section = &route->section[route->current_section_num - 1]; | ||||
| if(current_section->wait_condition.wait_type == PLSR_WAIT_EXT_EVENT) | if(current_section->wait_condition.wait_type == PLSR_WAIT_EXT_EVENT) | ||||
| { | { | ||||
| route->current_freq = 0; | |||||
| route->initial_freq = 0; | |||||
| PLSR_Route_PWM_Stop(); | |||||
| PLSR_Section_PWM_Stop(); | |||||
| /* 如果当前段等待外部事件,检查是否有事件触发 */ | /* 如果当前段等待外部事件,检查是否有事件触发 */ | ||||
| if (PLSR_Wait_CheckExtEvent(route)) | if (PLSR_Wait_CheckExtEvent(route)) | ||||
| { | { | ||||
| /*检查是否完成,在外部事件这种特殊情况下对脉冲数进行计数*/ | |||||
| AllPulse += __HAL_TIM_GET_COUNTER(&htim2); // 累加当前段已发送的脉冲数 | AllPulse += __HAL_TIM_GET_COUNTER(&htim2); // 累加当前段已发送的脉冲数 | ||||
| TotalSePulse = AllPulse; | |||||
| if(PLSR_Section_CheckPulseComplete(route)) | |||||
| { | |||||
| route->current_freq = 0; | |||||
| route->initial_freq = 0; | |||||
| } | |||||
| else | |||||
| { | |||||
| AllPulse -= 1; | |||||
| TotalSePulse -= 1; | |||||
| } | |||||
| //PLSR_Route_PWM_Stop(); | |||||
| /* 检查当前段是否为最后一段 */ | /* 检查当前段是否为最后一段 */ | ||||
| if (route->current_section_num >= route->section_num) | if (route->current_section_num >= route->section_num) | ||||
| { | { | ||||
| @@ -2061,7 +2071,7 @@ void PLSR_TaskSectionSwitch(PLSR_RouteConfig_t* route) | |||||
| route->run_state = PLSR_STATE_DECEL; // 设置为减速状态 | route->run_state = PLSR_STATE_DECEL; // 设置为减速状态 | ||||
| route->initial_freq = route->current_freq; | route->initial_freq = route->current_freq; | ||||
| __HAL_TIM_SetAutoreload(&htim2, 0xffffff); | __HAL_TIM_SetAutoreload(&htim2, 0xffffff); | ||||
| __HAL_TIM_SET_COUNTER(&htim2, 1); | |||||
| __HAL_TIM_SET_COUNTER(&htim2, 0); | |||||
| /* 如果当前频率已经为0,直接停止 */ | /* 如果当前频率已经为0,直接停止 */ | ||||
| if (route->current_freq == 0) | if (route->current_freq == 0) | ||||
| @@ -2077,6 +2087,7 @@ void PLSR_TaskSectionSwitch(PLSR_RouteConfig_t* route) | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| __HAL_TIM_SET_COUNTER(&htim2, 0); | |||||
| /* 非最后一段,正常进行段切换 */ | /* 非最后一段,正常进行段切换 */ | ||||
| PLSR_Section_SwitchNext(route, 0); // 外部事件触发,传入0 | PLSR_Section_SwitchNext(route, 0); // 外部事件触发,传入0 | ||||
| /* 启动新段,设置新的脉冲参数和频率 */ | /* 启动新段,设置新的脉冲参数和频率 */ | ||||
| @@ -2084,7 +2095,6 @@ void PLSR_TaskSectionSwitch(PLSR_RouteConfig_t* route) | |||||
| /* 启动PWM输出 */ | /* 启动PWM输出 */ | ||||
| PLSR_PWM_Start(); | PLSR_PWM_Start(); | ||||
| } | } | ||||
| PLSR_ClearGpioTriggerFlag(); // 清除GPIO触发标志 | PLSR_ClearGpioTriggerFlag(); // 清除GPIO触发标志 | ||||
| } | } | ||||
| return; // 等待外部事件时不需要继续处理 | return; // 等待外部事件时不需要继续处理 | ||||