简体   繁体   English

步进电机加速和中断

[英]Stepper motor acceleration and break

I have to make a project where I have to control a stepper motor from buttons.我必须制作一个项目,我必须通过按钮控制步进电机。 I use an ATXMEGA256a3u microcontroller.我使用 ATXMEGA256a3u 微控制器。 When I start the motor it has to accelerate in a few seconds to a constant speed then at the end of the sequence it has to slow down and stop.当我启动电机时,它必须在几秒钟内加速到恒定速度,然后在序列结束时它必须减速并停止。 I made a code to initialize and start the motor but I'm not so familiar working with stepper motors.我编写了一个代码来初始化和启动电机,但我不太熟悉使用步进电机。 My code to start the motor is: void startMotor(void) { PORT_STEP.OUT |= (EN1 + STEP1 + DIR1);我启动电机的代码是: void startMotor(void) { PORT_STEP.OUT |= (EN1 + STEP1 + DIR1); PORT_STEP.OUT &= ~(EN1); PORT_STEP.OUT &= ~(EN1); PORT_STEP.DIR |= (EN1 + STEP1 + DIR1); PORT_STEP.DIR |= (EN1 + STEP1 + DIR1);

    while (1)
    {
        PORT_STEP.OUT |= STEP1;
        delay_us(100);
        PORT_STEP.OUT &= ~STEP1;
        delay_us(100);
    }
}

This way it runs constantly.这样它就不断地运行。 Thanks for any help.谢谢你的帮助。

Well, it seems you are driving a "step/direction" stepper driver.好吧,看来您正在驾驶“步进/方向”步进驱动器。 These kind of driver make a step for every pulse.这种驱动器为每个脉冲迈出一步。

To achieve different speeds you have to produce more or less pulses in the same time or, in other words, to change the delay (your delay_us(100)) in the cycle.为了达到不同的速度,您必须在同一时间内产生或多或少的脉冲,或者换句话说,改变周期中的延迟(您的 delay_us(100))。 With two "delay_us(200)" the speed will be halved, and with two "delay_us(50)" the speed will be doubled.使用两个“delay_us(200)”,速度将减半,使用两个“delay_us(50)”,速度将加倍。

To make a ramp up, you start with long delays and reduce them up to the final value;为了提高速度,你从长时间的延迟开始,然后将它们减少到最终值; to make a ramp down you make bigger and bigger delays until they are long enough to stop completely to generate pulses.要进行斜坡下降,您会产生越来越大的延迟,直到它们足够长以完全停止以产生脉冲。 The speed of change in delays will regulate the ramp slope (acceleration).延迟变化的速度将调节斜坡斜率(加速度)。

Last note: you use two delays - there is no need for them to be equal, probably you can take one fixed and operate on the other.最后一点:你使用了两个延迟——它们不需要相等,可能你可以固定一个并在另一个上操作。 But even changing both is not a problem (it depends on the application).但即使改变两者也不是问题(这取决于应用程序)。 If you driver can select different microstepping values (1/8192, 1/4096 or whatever) play also with those values, that could simplify your program.如果您的驱动程序可以 select 不同的微步值(1/8192、1/4096 或其他)也可以使用这些值,那么可以简化您的程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM