Spindle control with a Mosfet
If you are not using a VFD, and your spindle has low enough power, 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 diode when controlling a motor.
[http://smoothieware.org/general-appendixes#solidstaterelay 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.
DiodesIt 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 :
Mosfet power input and outputs
Note a mosfet can not provide power, if it is not provided power via an input
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 ). You have to connect your PSU to the power input connector for those FETs, and connect your power consuming element ( be it heating element, spindle, etc… ) to the power outputs of those same FETs. Essentially Smoothie connects/disconnects the element ( connected to the mosfet connector ) from the PSU ( connected to the power input connector ) as needed to maintain temperature or as requested by G-codes.
There are three main pairs of Mosfets on the board :
- Big MOSFETS pair : Their outputs are labelled P2_7 and P2_5 on the schematic, the input connector for them is found between them. They are found on the 4X and 5X boards. To power those mosfets, you need to provide them with power by wiring their power input to the power supply.
- Small MOSFETS pair : Their outputs are labelled P2_6 and P2_4 on the schematic, the input connector for them is found by their side, between P2_6 and P1_23. They are found on all of the boards. To power those mosfets, you need to provide them with power by wiring their power input to the power supply.
- Mixed MOSFETS pair : Their outputs are labelled P1_22 and P1_23 on the schematic. The pair is called “mixed” because it consists of one big MOSFET and one small MOSFET. They do not have a specific input, they take power directly from VBB ( the Stepper motors power input described in the Stepper Motors chapter ). To power those mosfets, you need to provide them with power by wiring their power input ( which is the same as the one for the stepper motors ) to the power supply.
Power inputContrary 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 :
PolarityMOSFET 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, locking them to the “ON” state. Less powerful
If you need to control more than 12Amps, you can not 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.
JumpersIn the case of both the Big MOSFETS pair, and the Small MOSFETS pair, you take power from the PSU to them via their respective power input connectors.
There is an alternative however. For each pair, you can use jumpers ( one jumper for the small MOSFETS pair ( JP28 ), two parralel jumpers for the two big MOSFETS pair ( JP11 and JP27 ) ). If you solder the pins for those, and 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.
Current ratingHowever, WARNING, each jumper is rated for only 2A of current. This means you can not 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|
|Used by default for||Heated bed||First hotend heater||Fan||Second hotend heater|
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_comand switch.spindle.max_pwm 255 # set max pwm for the pin default is 255
Controlling the Spindle
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 :
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.
PID loopback spindle control
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:
- PWM output pin: any of P1.18, P1.20, P1.21, P1.23, P1.24, P1.26, P2.0 - P2.5, P2.26, P3.25
- Feedback sensor pin: must be in port 0 or port 2; P2.6 and P2.7 are available on smoothieboard
|~ Option||~ Example value||~ Explanation|
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).
Tuning the PID parameters
There is no PID autotuning for spindle parameters currently. You can use the following process to manually tune the PID:
- Set dummy values with M958 P0.0001 I0 D0
- Stop the spindle with M5 and make sure spindle is ready to run on next M3 command (i.e. power supply is on).
- Run M3 S100000, which should start the spindle at maximum speed.
- Measure the time T it takes for the spindle to reach full speed (using your ears and a stopwatch).
- Check the maximum RPM R the spindle reaches by running M957
Now set the parameters to:
- P = 1/R (e.g. for 10 000 RPM, set P = 0.0001)
- I = 2/(R*T) (e.g. if it took 1 second to speed up to 10 000 RPM, set I = 0.0002)
- D = T / R / 10 (e.g. D = 0.00001)
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.