Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

步进电机梯形精度问题 #1

Open
zhaoyang6 opened this issue Apr 8, 2021 · 0 comments
Open

步进电机梯形精度问题 #1

zhaoyang6 opened this issue Apr 8, 2021 · 0 comments

Comments

@zhaoyang6
Copy link

问题:该算法每运行一次时会多走一个脉冲。
解决办法: 修改bsp_stepper_T_speed.c中的void speed_decision(),将STOP状态拿出if(i==2)的条件判断,修改为如下:
`
if(i==2) // 2次,说明已经输出一个完整脉冲
{
i=0; // 清零定时器中断次数计数值
switch(srd.run_state)
{
/步进电机停止状态/
//在这里判断是否在停止状态,会在每一次运行后多一个脉冲
// case STOP:
// step_count = 0;
// rest = 0;

			// 		// 关闭通道
			// 		HAL_TIM_OC_Stop_IT(&TIM_TimeBaseStructure,MOTOR_PUL_CHANNEL_x);

			// 		status.running = FALSE;
			// 		break;
			/*步进电机加速状态*/
			case ACCEL:
					TIM_CCxChannelCmd(MOTOR_PUL_TIM, MOTOR_PUL_CHANNEL_x, TIM_CCx_ENABLE);
					StepperCounter(srd.dir);
					step_count++;
					srd.accel_count++;
					new_step_delay = srd.step_delay - (((2 * (long)srd.step_delay) 
													 + rest)/(4 * srd.accel_count + 1));
					rest = ((2 * (long)srd.step_delay)+rest)%(4 * srd.accel_count + 1);
					//检查是够应该开始减速
					if(step_count >= srd.decel_start) {
						srd.accel_count = srd.decel_val;
						srd.run_state = DECEL;
					}
					//检查是否到达期望的最大速度
					else if(new_step_delay <= srd.min_delay) {
						last_accel_delay = new_step_delay;
						new_step_delay = srd.min_delay;
						rest = 0;
						srd.run_state = RUN;
					}
					break;
			/*步进电机最大速度运行状态*/
			case RUN:

		      StepperCounter(srd.dir);//根据脉冲计数位置
					step_count++;
					new_step_delay = srd.min_delay;
					//检查是否需要开始减速
					if(step_count >= srd.decel_start) 
					{
						srd.accel_count = srd.decel_val;
						//以最后一次加速的延时作为开始减速的延时
						new_step_delay = last_accel_delay;
						srd.run_state = DECEL;
					}
					break;
			/*步进电机减速状态*/
			case DECEL:

		      StepperCounter(srd.dir);
					step_count++;
					srd.accel_count++;
					new_step_delay = srd.step_delay - (((2 * (long)srd.step_delay) 
													 + rest)/(4 * srd.accel_count + 1));
					rest = ((2 * (long)srd.step_delay)+rest)%(4 * srd.accel_count + 1);
					//检查是否为最后一步
					if(srd.accel_count >= 0)
					{
						srd.run_state = STOP;
					}
					break;
		}
  if(srd.run_state == STOP){
      step_count = 0;
      rest = 0;
      // 关闭通道
      HAL_TIM_OC_Stop_IT(&TIM_TimeBaseStructure,MOTOR_PUL_CHANNEL_x);
      status.running = FALSE;
  }

`

@zhaoyang6 zhaoyang6 changed the title 步进电机梯形加速问题 步进电机梯形精度问题 Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant