If you are not using a VFD, and your spindle motor is a DC motor of low enough power (voltage and current, including any current extremes when stalled), you can control it directly using the MOSFETs on the Smoothieboard.
MOSFETs are present on-board, but have limited current capacity (up to 12A) and need to be protected by a ‘flyback’ diode when controlling a motor, electromechanical relay or other inductive load. See Wikipedia Flyback_diode and Driving inductive load, Electronics StackExchange.
Motors have the property of inductance, which is the electrical equivalent of inertia. The motor current will continue to flow after the MOSFET is switched off, because the energy stored in the inductor by the current does not instantly disappear. The current will decrease as the stored energy is dissipated. This current flow results in the voltage across the motor reversing and increasing (or “spiking”) until the current finds a path to flow.
An appropriately connected ‘flyback’ diode with sufficient voltage and current ratings will provide a safe, intended path for the motor current.
Without a diode, when the MOSFET turns off the motor voltage will spike up until the current finds an unintended path. Typically this degrades or immediately destroys the MOSFET and perhaps other circuitry such as that driving the MOSFET gate.
Connect the diode in reverse across the motor (when the MOSFET is on, it must NOT cause power to flow through the diode). Connect the anode (‘arrow’) to the MOSFET Drain terminal and the cathode (‘bar’, often marked by a line on the package) to the motor power supply. The diode rating should be rated with Voltage exceeding the maximum expected supply voltage by at least 20% (usually low cost to get a higher voltage rating), and (conservatively) Current at least equal to half the motor current (the current through the diode will not be continuous). An example part number is 6A4-T, rated 6A and 400V, under $1 USD.
The same considerations apply to other inductive loads such as solenoid valves and relay coils.
Solid state relays are controlled via a GPIO pin, and can control higher loads, but are on/off only (no control of the exact amount of power sent via PWM). For more information about SSRs, see this appendix.
[!WARNING] It is critical that you add a diode across your motor if you are going to control it with a Smoothieboard. If you do not do this, you are absolutely guaranteed to destroy the MOSFET, and possibly the Smoothieboard.
Here is a brief on the MOSFETs on the Smoothieboard:
Note: a mosfet cannot provide power if it is not provided power via an input.
[!WARNING]
If it will burn your skin, don’t touch it. Simple.
Smoothie has up to 6 MOSFET controls (6 on 5X, 4 on 4X, and 2 on 3X). The MOSFETs act as switches to ground: loads must be connected between the power source and the MOSFET switched terminal. When the MOSFET is switched on, power will be applied to the load. When the MOSFET is switched off, power will be removed, because one load terminal will be essentially disconnected and current cannot flow. The exception being inductive load ‘flyback’ switching transients, discussed above.
Connect your PSU to the power input connector for those FETs (providing power to the load), and connect your power-consuming element (be it heating element, spindle, etc.) between the power output terminal and the MOSFET terminal. Smoothie connects/disconnects the element’s ground as needed to maintain temperature or as requested by G-codes.
There are three main pairs of MOSFETs on the board:
[!TIP] Contrary to other boards, Smoothieboard does not have a single power input, but multiple power inputs.
This allows you to use different voltages for different things if you want, and makes it easier to use more current as the current is shared between more connectors. It does mean wiring one or two more connectors though.
If you are trying to control MOSFETs and they are not turning on, make sure you provided power to their power input.
MOSFETs list:
MOSFET group | MOSFET name | Controlling pin | Output connector | Input method | Voltage | Current |
---|---|---|---|---|---|---|
Big MOSFETs | First big MOSFET | 2.7 |
X15 | Big MOSFETs power input X13 | 12-24V | 12.5A max |
Big MOSFETs | Second big MOSFET | 2.5 |
X10 | Big MOSFETs power input X13 | 12-24V | 12.5A max |
Small MOSFETs | First small MOSFET | 2.4 |
X7 | Small MOSFETs power input X6 | 12-24V | 3A max |
Small MOSFETs | Second small MOSFET | 2.6 |
X8 | Small MOSFETs power input X6 | 12-24V | 3A max |
Mixed MOSFETs | Third big MOSFET | 1.23 |
X16 | VBB (motor) input | 12-24V | 12.5A max |
Mixed MOSFETs | Third small MOSFET | 1.22 |
X9 | VBB (motor) input | 12-24V | 3A max |
MOSFETs diagram:
[!WARNING] MOSFET power inputs have a polarity, make sure you connect
+
on that connector to+
on your PSU, and-
to-
on the PSU. Heater elements, however, do not have a polarity, so you do not have to worry about polarity on the outputs. If you are using another output element like a Peltier or a Spindle, you need to be careful to respect the polarity for the outputs too.
Never use the big MOSFETS for more than 12.5A (and monitor connector and MOSFET temperatures at that current use, too much heating can be a sign of a bad wire connection), and the small MOSFETS should never be used for more than 3A.
Trying to power a 40W (or more) hotend cartridge heater at 12V with the small FETs will destroy them, usually locking (melting) them to the “ON” state (shorted) and possibly destroying the circuitry driving the MOSFET gate.
If you need to control more than 12 Amps, you cannot do it with one of the MOSFETS on board, however, you can use a Solid State Relay. For information see the Solid State Relay Appendix on this page.
[!NOTE] In the case of both the Big MOSFETS pair and the Small MOSFETS pair, you take power from the PSU (Power Supply Unit) to them via their respective power input connectors.
There is an alternative, however (for currents up to 2 Amps or 4 Amps). For each pair, you can use jumpers (one jumper for the small MOSFETS pair (JP28), two parallel jumpers for the two big MOSFETS pair (JP11 and JP27)). If you solder the pins for those OR connect a jumper to those pins, closing the circuit to VBB (the stepper motors power input), allowing you to take the power from those MOSFETS from the same place as the stepper motors do.
In the case of the big MOSFETS, you have to solder and put in place two jumpers, in parallel, in order to handle more current.
[!WARNING] However, WARNING, each jumper is rated for only 2A of current. This means you cannot use this way of powering your MOSFETS if you are going to use more than 2A (for the small MOSFETS) or 4A (for the big MOSFETS, with both jumpers used, for 2 x 2A).
Do not use the jumpers to power a heated bed, for example, as it uses much more than 4A.
In order to configure your Smoothieboard to use a specific MOSFET, you need to know which pin corresponds to which MOSFET. Here is a recapitulating table to help you find that out:
MOSFET Pair | Big MOSFETS | Small MOSFETS | Mixed MOSFETS | |||
---|---|---|---|---|---|---|
Label on diagram | P2_7 | P2_5 | P2_4 | P2_6 | P1_23 | P1_22 |
Digital output pin | 2.7 |
2.5 |
2.4 |
2.6 |
1.23 |
1.22 |
Power Input | Between P2_7 and P2_5 |
Between P2_6 and P1_23 |
Taken from VBB | |||
Size | Big | Big | Small | Small | Big | Small |
Maximum current | 12A | 12A | 3A | 3A | 12A | 3A |
Used by default for | Heated bed | Hotend 0 | Fan | Hotend 1 |
TODO: diagram
Now that you have located which MOSFET you are going to use for Spindle control, and what GPIO pin it corresponds to, you need to add a spindle control section to your configuration file.
We will be doing this using the Switch module.
Add this to your configuration file:
# Spindle control Switch module
switch.spindle.enable true #
switch.spindle.input_on_command M3 #
switch.spindle.input_off_command M5 #
switch.spindle.output_pin 2.7 # Here we are using the first big MOSFET
switch.spindle.output_type pwm # pwm output settable with S parameter in the input_on_command
switch.spindle.max_pwm 255 # set max pwm for the pin default is 255
Now that everything is configured, you can use G-codes to control the Spindle.
You can do this either manually by sending G-codes directly to the board via serial or your host software, or add those G-codes to the beginning/end.
You can choose the exact G-codes in the configuration, here we used the standard M3
to turn the Spindle ON, and M5
to turn the Spindle OFF.
If you need to choose the power (speed) of your Spindle, you can do so because the output is configured as PWM.
Simply do:
M3 S128
To set the spindle to half power/speed. PWM values go from 0 to 255.
0 means no power to the spindle, and 255 means full power to the spindle.
Because the spindle can feed power back into the MOSFET and damage the MOSFET, you also need to wire a diode of sufficient size across the output. See notes in the first section above.
To get more accurate RPM control, you can use a feedback sensor. This can be optical or a hall effect sensor, which senses the rotation of the spindle. Smoothie then measures the real RPM of the spindle and adjusts the PWM value accordingly.
To use this module, you need to connect your spindle to pins with proper hardware support:
| Option | Example value | Explanation | | —— | ————- | ———– |
[!NOTE] This part of the documentation is deprecated. Please refer to the spindle module page instead.
Parameter | Value | Description |
---|---|---|
spindle_enable |
true | If set to true, enables the Spindle module, which uses an encoder to PID-control a PWM-modulated spindle motor |
spindle_pwm_pin |
2.4 |
Output PWM pin (uses hardware PWM). Note: hardware PWM is available only on pins 2.0 to 2.5 , 1.18 , 1.20 , 1.21 , 1.23 , 1.24 , 1.26 , 3.25 and 3.26 |
spindle_pwm_period |
100 | PWM period to use in microseconds |
spindle_feedback_pin |
2.6 |
Feedback input pin (must be Port 0 or 2, meaning the pin number must be 2.x or 0.x ) |
spindle_pulses_per_rev |
3 | Number of feedback pulses per revolution on the feedback input pin |
spindle_default_rpm |
5000 | RPM to use if none given in M3 command, in rotations/minute |
spindle_control_P |
0.0002 | PID P factor (unit is 1 / RPM) |
spindle_control_I |
0.0001 | PID I factor (unit is 1 / ( RPM x seconds )) |
spindle_control_D |
0.000001 | PID D factor (unit is 1 / (R PM / seconds )) |
Available G-code commands:
M3
will start the spindle. M3 S5000
will start the spindle and set speed to 5000 RPM.M5
will stop the spindle. Last set RPM is remembered and used for next M3
command if S argument is not given.M957
will report the current spindle speed and PWM value.M958
will report the current PID parameters. M958 Px.xxx Ix.xxx Dx.xxx
will set them (to save the new values, you need to edit config file manually).There is no PID autotuning for spindle parameters currently. You can use the following process to manually tune the PID:
M958 P0.0001 I0 D0
M5
and make sure spindle is ready to run on next M3
command (i.e. power supply is on).M3 S100000
, which should start the spindle at maximum speed.M957
Now set the parameters to:
Some manual tuning may be needed after this. Test speed changes using the M3
command and try loading the spindle to see if it reacts fast enough to load changes.