LinuxCNC can control up to 8 spindles. The number is set in the INI file. The examples below all refer to a single-spindle config with spindle control pins with names like spindle.0... In the case of a multiple spindle machine all that changes is that additional pins exist with names such as spindle.6...

1. 0-10 Volt Spindle Speed

If your spindle speed is controlled by an analog signal, (for example, by a VFD with a 0 V to 10 V signal) and you’re using a DAC card like the m5i20 to output the control signal:

First you need to figure the scale of spindle speed to control signal, i.e. the voltage. For this example the spindle top speed of 5000 RPM is equal to 10 Volts.

images/spindle-math.png

We have to add a scale component to the HAL file to scale the spindle.N.speed-out to the 0 to 10 needed by the VFD if your DAC card does not do scaling.

2. PWM Spindle Speed

If your spindle can be controlled by a PWM signal, use the pwmgen component to create the signal:

This assumes that the spindle controller’s response to PWM is simple: 0% PWM gives 0 RPM, 10% PWM gives 180 RPM, etc. If there is a minimum PWM required to get the spindle to turn, follow the example in the nist-lathe sample configuration to use a scale component.

3. Spindle Enable

If you need a spindle enable signal, link your output pin to spindle.0.on. To link these pins to a parallel port pin put something like the following in your .hal file, making sure you pick the pin that is connected to your control device.

4. Spindle Direction

If you have direction control of your spindle, then the HAL pins spindle.N.forward and spindle.N.reverse are controlled by the G-codes M3 and M4. Spindle speed Sn must be set to a positive non-zero value for M3/M4 to turn on spindle motion.

To link these pins to a parallel port pin, put something like the following in your .hal file making sure you pick the pin that is connected to your control device.

5. Spindle Soft Start

If you need to ramp your spindle speed command and your control does not have that feature it can be done in HAL. Basically you need to hijack the output of spindle.N.speed-out and run it through a limit2 component with the scale set so it will ramp the rpm from spindle.N.speed-out to your device that receives the rpm. The second part is to let LinuxCNC know when the spindle is at speed so motion can begin.

In the 0-10 Volt example the line

is changed as shown in the following example:

Intro to HAL components limit2 and near

In case you have not run across them before, here’s a quick introduction to the two HAL components used in the following example.

  • A limit2 is a HAL component (floating point) that accepts an input value and provides an output that has been limited to a max/min range, and also limited to not exceed a specified rate of change.

  • A near is a HAL component (floating point) with a binary output that says whether two inputs are approximately equal.

More info is available in the documentation for HAL components, or from the man pages, just say man limit2 or man near in a terminal.

6. Spindle Feedback

6.1. Spindle Synchronized Motion

Spindle feedback is needed by LinuxCNC to perform any spindle coordinated motions like threading and constant surface speed. LinuxCNC can perform synchronized motion and CSS with any of up to 8 spindles. Which spindles are used is controlled from G-code. CSS is possible with several spindles simultaneously.

The StepConf Wizard can perform the connections for a single-spindle configuration for you if you select Encoder Phase A and Encoder Index as inputs.

Hardware assumptions for this example:

  • An encoder is connected to the spindle and puts out 100 pulses per revolution on phase A.

  • The encoder A phase is connected to the parallel port pin 10.

  • The encoder index pulse is connected to the parallel port pin 11.

Basic Steps to add the components and configure them:
[In this example, we will assume that some encoders have already been issued to axes/joints 0, 1, and 2. So the next encoder available for us to attach to the spindle would be number 3. Your situation may differ.]

[The HAL encoder index-enable is an exception to the rule in that it behaves as both an input and an output, see the Encoder Section for details]

[It is because we selected non-quadrature simple counting… above that we can get away with quadrature counting without having any B quadrature input.]

6.2. Spindle At Speed

To enable LinuxCNC to wait for the spindle to be at speed before executing a series of moves, the spindle.N.at-speed needs to turn true at the moment the spindle is at the commanded speed. To achieve this you need spindle feedback from an encoder. Since the feedback and the commanded speed are not usually exactly the same you should to use the near component to determine that the two numbers are close enough.

The connections needed are from the spindle velocity command signal to near.n.in1 and from the spindle velocity from the encoder to near.n.in2. Then the near.n.out is connected to spindle.N.at-speed. The near.n.scale needs to be set to say how close the two numbers must be before turning on the output. Depending on your setup you may need to adjust the scale to work with your hardware.

The following is typical of the additions needed to your HAL file to enable Spindle At Speed. If you already have near in your HAL file then increase the count and adjust code to suit. Check to make sure the signal names are the same in your HAL file.