Thursday, 3 January 2019

Writing Software for CNC Applications

Need to synchronise the spindle to the C axis? Or implement an electronic gearbox reduction for a lathe? Stepper on a rotary table? Or just plot a circle on XY planes? all of these implementations have a few common problems to solve, one of which is to coordinate the movement of two or more axis. Since each axis might have different resolution and or require fractional advance of that resolution to accomplish the desired motion. Most open and closed source implementations seem to make use of some sort of  Bresenham's line algorithm here, to deal with the resulting error.

void main () {
   double y0 = 0.00;
   double dy = 0.0125; // 5mm / 100x4
   double dx = 23; // gear ratio
   double k = (double)dy / (double)dx;

    double y = (double)y0;
    double yi = 0.0000;

    for (int x=0; x<23; x++)
    {
        y += k;

        if ((y+0.0005) > yi) // error larger than 0.0005? increment yi
        //if ((int)(y+0.5) > yi)
        {
            yi=yi+0.0005;
        }
      printf("%02d %02f %02f\n", x, y, yi );
    }

}

Let us look at Gear ratios, the concept of accurate synchronized electronic reduction gears for the lathe made me think. Why not use closed loop phased locked control?

1) decode position pulses to direction and 4x steps,
2) Multiply step pules by M an then divide by N. 
3) feed the resulting pules directly to a stepper which can act as the divider

To implement this one would require a PLL for multiplication. Using this method should make it possible to implement any gear ratio without error.  I have implemented this on Arduino making use of the internal clocks and one external PLL 4046. The lock and capture range now determine the spindle speeds. The solution runs entirely on hardware no software is required once the counters have been set. It is abit more complex than this, since direction needs to be accounted for. But here is the gist of it. I then found commercial industrial solution doing exactly this at http://www.motrona.net/encoder_divider.html




No comments:

Post a Comment

Chipmaster Gear Cutting

  Calculate all the possible gear combinations for the gear selector to cut a 15TPI thread: Imperial TPI C 5 24 20 Imperial TPI ...