0
\$\begingroup\$

I know how to control where the servo will rotate: if I send 1 ms duty signal in a PWM interval it will rotate clockwise and if I send 2ms duty signal it will rotate counter-clockwise but how can I control the speed? I have searched and find that it is done with “delay()” method for ardunio but I use FPGA, so what is the logic behind it?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ With delay(), what you are doing is changing the time it takes for you to send a new "position" to the servo. It is still moving at the same speed, but it will stop, wait a bit, and move again - so the average speed is lower. \$\endgroup\$
    – Wesley Lee
    Dec 8, 2017 at 19:24
  • \$\begingroup\$ So, can I say that if I make my PWM interval 2t instead of t, then it moves 2x slower? I was thinking this way but in the datasheet of servo there is a numeric description for PWM, why would they write the value of PWM duration if it is up to me? \$\endgroup\$ Dec 8, 2017 at 19:28

2 Answers 2

3
\$\begingroup\$

In a normal position servo, 1mS will make it move from wherever it was to one end of its travel, at the fastest the servo can manage. 2mS will make it move to the other end.

If you step between 1 and 2mS length pulses, then it will do this as fast as it can. If instead you provide a ramp of intermediate length pulses, say 1.0, 1.1, 1.2 ... 1.9, 2.0mS, then it will move to each intermediate position along the way, effectively moving more slowly.

There are servos that behave as you say, 1mS makes it rotate one way and 2mS the other, but they are few and far between, and are often used for boat windlass duty, where rotation for many turns is required.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for the answer, which aroused a new question in my mind:If it is so then does the “send 1.5 ms duty to make it rotate towards centre” property tend to be a bit problematic? It can confuse it with the “move one side, but as slow as possible” property? Should I worry about this? \$\endgroup\$ Dec 8, 2017 at 19:53
  • 3
    \$\begingroup\$ if you apply 1.5mS pulses, the servo will rotate as fast as it can from wherever it was to the centre position, and stay there. There's nothing problematic about this, if that is what you want. If you want fast rotation, change the pulse from one value straight to another in a single step. If you want slow rotation, change the pulse lengths slowly. If you make it take 10 seconds to ramp the lengths of the pulses from (say) 1mS to 1.5mS, then the servo will take 10s to rotate slowly from one extreme to the centre. \$\endgroup\$
    – Neil_UK
    Dec 8, 2017 at 20:03
0
\$\begingroup\$

The first thing to remember is that servos are not inherently speed controlled. You're sending the servo a position signal, and the servo is trying to get to that position as fast as possible.

However you can reduce the speed of the servo by sending it a series of positions that lead to the end position.

Here's some psudocode illustrating the method:

int servo_position = 1500; //arbitrary starting values
int target = 1000;
const int speed = 5;

while(True){
    if(servo_position < target){
        servo_position += speed;
    }
    if(servo_position > target){
        servo_position -= speed;
    }
    if(abs(servo_position - target)<speed){
        break;
    }
    pwm_out(servo_position);
    delay_ms(20);
}

Every 20ms, this code moves the servo [speed] steps forward. How big a step is will depend on your pwm hardware and libraries.

The last IF basically just stops the loop once you've gotten as close as you can get.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.