4 Trapezoidal Ramping

Trapezoidal Ramping


When I ramped the motors up to a high speed earlier, the program just assumed the motors kept going and never happened to stop. If we were to combine this ramping with the positional program then the motors would ramp up to speed and then just stop when the specified number of steps have passed.

Unfortunately, its not that simple.

If I sent the motors going at high speed and just stopped them, the momentum we carry them forwards and back emf would make it difficult for a coil to energise correctly. To put it simply, if you just try and stop the motor dead from high speed it will keep going for a while and you lose steps and accuracy.


To combat this, we can ramp the stepping speed back down just like we ramped it up. This is known as a trapezoid ramping profile as in the picture below.


Time is along the bottom and pulse frequency is on the left.


To implement this we have to do the following:


set a variable for the minimum speed of the motor
set a variable for the maximum speed of the motor
set a variable for the value of the required number of steps divided by 2
set a variable for the current speed of the motor (we can use the delay time)

while the current speed is lower than the maximum speed and the number of steps left is greater than the total number of step divided by 2 we are going to ramp up the speed.

when the speed reaches the maximumspeed or the number of steps left equals the total number of steps divided by 2 we are going to continue at the current speed until the number of total steps divided by 2 minus the number of steps left equal 0

we now decrement the current speed until either we reach the minimum speed or there are no steps left to perform.


Here is the C file to add trapezoidal ramping



There is really very little added, just a couple more variables in the struct, some initialising in the setupMotor(), some initialising in moveSteps(), and also some if's in moveSteps()

I have alse changed the moveSteps() call to 12000 steps so we can see it ramping up to speed - travelling at speed - then ramping back down again.




You can adjust the ramping speeds etc.. if your motors are capable of it. Also I made the ramping down become equal to the ramping up, you may find that you can ramp 1 way faster than the other, this was just an overview of a basic technique that can be built on.


See the next page for improving ramping technique

trapezoid1.jpg7.66 KB