I just finished building my mpcnc primo with a mks gen l 2.1 using the Ramps dual firmware as a base configuration. I bought a genmitsu 24v spindle that comes with a controller that accepts a 5v pwm signal. I connected the pwm cable to the D11 pin on my mainboard and the GND cable to the corresponding GND pin. After setting a pwm frequency with m42 p11, the spindle always runs at the same speed from 150-255 and stops at numbers below. Another question would be how to include this spindle pin in my gcode, so I can change its speed via code.
Thanks for your help in advance
the spindle always runs at the same speed from 150-255 and stops at numbers below
Just to be absolutely sure, carefully put a voltmeter on pin 11 and see how the voltage varies as the PWM value is changed. If the voltage is varying as expected from 0V to around 5V, then you might want to contact genmitsu about what is expected from the PWM.
include this spindle pin in my gcode, so I can change its speed via code.
There are two approaches. If you don’t mind setting the speed “by hand” for each file, then you can just have the M42 added in the start g-code. CAM solutions and also some g-code sender solutions include a way to add g-code to the start and end of your g-code file, but if you do it this way, you will have to modify the M42 setting by hand for each RPM.
If you want a more automatic solution, you will have to do a bit of research about what g-code method(s) of setting the RPM are used by your CAM software. Choices are M3/M4/M5 and inline commands.
Next you will need to figure out the spindle PWM pin. I took a looked at the pins file for the MKS Gen-L boards, and am a bit puzzled. It appears that this board uses Ramps.h, but, according to the pinout for the MKS board, the spindle pin defined in Ramps.h (D44) is in use by the UART block. If you need to redefine the spindle pin, D45 might work.
Finally, as Mike indicated, you will need to sort through the settings in configuration_adv.h. These settings take a g-code input specifying RPM and map them to PWM values. I’m not sure which version number of the Ramps firmware you are using for your basis. The V1 maintained version 515 of the firmware is different than the previous versions both because Marlin changed (rewritten laser support), and because V1 enabled laser support by default. Both may impact setting up the spindle commands.
I measured the voltage on pin 11 as you said and got around 4.9V starting at 150 and 0V below. Now I tested the D45 pin you mentioned and it works. Starting from around 26 the spindle speeds increases gradually up to 255. I also changed this pin to be used for M3-M5 commands in the ramps board file and that works to. Thanks for your help