Hawk - 2015-06-16

This topic gathers together all the discussions about the motor synchronization.

I report a mail exchange with Meir:

Francesco:

...About the motor synchronization with only one timer interrupt, you give a look at the Bresenham algorithm. It is a raster algorithm but the problem can be translated in the our case changing the pixels with the steps. For instance, you want go from (X1, Y1) to (X2, Y2), compute the number of steps for each axis STEPx(X2-X1) and STEPy(Y2-Y1), the greater one is the master axis. Set the timer to move forward the master axis and at each step use the Bresenham algorithm in order to know if the slave axis must be updated.

This is the way I use the timer. More in deep, I use two timer, the first one triggers the steps for all involved axes (the pins go up) and the second one switches off the steps pins (the pins go down). It is important because the a4988 works better if the time of step pin up is about 20us. At each tep update, I set up a timer that, when it triggers, it switches off the active steps pins and then it stops itself...

Meir:

...
The algorithm I used for the stepping is kind of the one you described. The timer runs at a hardcoded cycle (it could be 20us ) , we increment a cycle counter per axis, when calculating the move each motor will have its own bucket. In operations like laser engraving, having perfect control of time is a must, in it not just doing the right step order but keeping a constant speed.
...

Francesco:

... if I understood, you have an hardcoded cycle with a period of 20(us) (but I have not readthe code yet). I know the problems about the timing when you use a laser, and I think that the main goal is to keep a constant speed along each linear motion.
Let suppose that for each step we move forward of A(mm) and the update time is constant (each 20us), if we want go from (X1, 0) to (X2, 0), we are moving with a speed of A(mm/us). But if we want go from (X1, Y1) to (X2, Y2), we are moving along the path with a speed B(mm/us) that is B > A.

In my firmware, I start from the speed along the path and then I compute the update frequency of the timer interrupt, so the period can vary. ...

Meir:

If you read the code you will see my implementation.
for the example that you gave, being that the length is now sqrt(2) roughly 1.41mm I would adjust the rate of each axis to
T= sqrt(Xd*Xd +Yd+Yd) ; // pitagoras
rateX= T/Xd;
rateY= T/Yd;
//attention has to be given when Xd (X delta) or Yd is zero.
so lets say on G01 X1.0 Y0 F100
if it was suppose to finish the command in 200 steps at a speed of a step every 100us, then rateX will be 5 (cycles of 20us) in the case of G01 X3.0 Y4.0 F100
the total length of travel is 5.0, therefore if I need 200 steps to do 1mm
T= 5 * 200 / F ; // my firmware considers situation where each axis may have a diff steppermm
rateX= T / X;
rateY= T / Y;