As you’ve already figured out, M950 allows one of the PWM capable pins on the Duet2 to be designated as the input to a PWM to analogue converter board for spindle RPM control. However, not all Duet2 pins are PWM capable so it’s best to refer to the Duet2 wiring diagram to check. IIRC various of the fan pins as well as the heated bed and extruder heater outputs are PWM capable.
With RRF3.3 and newer firmware, once the spindle control pin has been defined using M950, you then assign it to a tool using M563 and enable CNC mode, like this, for example:
M950 R0 C"exp.13" Q2000 L0:20000 ; Create spindle index 0, PWM frequency 2KHz,
; Lmin:max rpm ranges from 0rpm at PWM=0% to 20000rpm at 100% PWM
; spindle speed PWM pin : exp.13
M563 P0 R0 S"Spindle" ; Create Tool 0 with Spindle 0 and call it Spindle
T0 ; Select Tool 0 (or make sure generated by CAM)
; CNC Mode
M453
After this a M3 S8000 command will set the spindle RPM to 8000 rpm (for example) and M3 S0 stops the spindle. It’s possible that M5 may also stop the spindle with this setup but I haven’t checked this, so someone else would need to comment.
However, if your spindle VFD has a RUN input, then M950 can be used to define a Duet pin to control the RUN state and in this case the M5 command can definitely be used to stop the spindle:
M950 R0 C"exp.13+exp.8" Q2000 L0:20000 ; Create spindle index 0, PWM frequency 2KHz,
; Lmin:max rpm ranges from 0rpm at PWM=0% to 20000rpm at 100% PWM
; spindle speed PWM pin : exp.13
; spindle run pin : exp.8
If your VFD has a DIR input then M950 can also be used to configure a pin for this too:
M950 R0 C"exp.13+exp.8+exp.14" Q2000 L0:20000 ; Create spindle index 0, PWM frequency 2KHz,
; Lmin:max rpm ranges from 0rpm at PWM=0% to 20000rpm at 100% PWM
; spindle speed PWM pin : exp.13
; spindle run pin : exp.8
; spindle direction pin : exp.14
With the DIR pin connected, M3 S8000 runs the spindle in a clockwise direction at 8000rpm and M4 S8000 runs the spindle at 8000rpm in a counterclockwise direction.
A couple of other points to note:
A) VFDs generally require higher control voltages than the Duet outputs provide, so some extra circuitry (e.g relays or opto-isolators) is needed to match the Duet control outputs to the VFD inputs
B) Some VFDs have FWD and REV inputs instead of RUN and DIR inputs. In my case (an “AskPower” unit from eBay) I found that wiring RUN -> FWD and DIR -> REV worked fine. However, this may not be a universal solution.
Edit 7/8/2021 - Closing quotation marks corrected - thanks to @Wurke for spotting this.