Maslow Home Maslow Community Garden

Colaboration request to add spindle speed via g-code in FW/GC



This (on the left) arrived today. I had no other chance then to play wit it.

Although I was sceptic that it only put out 9.2V at 255 PWM, the testing results are for me impressive.
I used an arduino-uno to create the PWM sigal for the module and tested and measured steps.


Further testing:
–> 40 <-- is a cool ‘S-command to PWM-value to spindle-RPM translation number’ for my setup.
This would be the setting/variable to adjust for different hardware.

Increments of 5 in the PWM result in increments of ~200 in the RPM.
But what happens with a S-command not resulting in a integer number for the PWM?
Testing with the aduino uno, putting a value of 102 for the PWM gives me the same RPM as 102.999 does (S4100 would translate to PWM 102.5), so at least on the uno, decimals for PWM seem to be completely ignored.
I could live with that, as 1 PWM difference is 40 RPM difference and I doubt that I would need that precision, but thinking that this might be a more universal pin, other hardware like a servo might require that we round that to the closest integer. Thoughts?

  1. Pin 44 is labeled aux7 on @Bee 's v1.4 TLE shield.
    In the Sysyem.cpp pin 44 is not used and for TLE listed as v1.3 aux7 is pin 45.
else if(pcbVersion == 3){ // TLE5206
    //TLE5206 PCB v1.3 Detected
    //MP1 - Right Motor
    encoder1A = 20; // INPUT
    encoder1B = 21; // INPUT
    in1 = 6;        // OUTPUT
    in2 = 4;        // OUTPUT
    enA = 5;        // errorFlag

    //MP2 - Z-axis
    encoder2A = 19; // INPUT
    encoder2B = 18; // INPUT
    in3 = 7;        // OUTPUT
    in4 = 9;        // OUTPUT
    enB = 8;        // errorFlag

    //MP3 - Left Motor
    encoder3A = 2;   // INPUT
    encoder3B = 3;   // INPUT
    in5 = 10;        // OUTPUT
    in6 = 11;        // OUTPUT
    enC = 12;        // errorFlag

    //AUX pins
    aux1 = 40;
    aux2 = 41;
    aux3 = 42;
    aux4 = 43;
    aux5 = 68;
    aux6 = 69;
    aux7 = 45;
    aux8 = 46;
    aux9 = 47;

Greping for aux7 I feel like it’s not used?

Firmware-1.25/cnc_ctrl_v1/System.cpp:93: int aux7;
Firmware-1.25/cnc_ctrl_v1/System.cpp:224: aux7 = 45;
Firmware-1.25/cnc_ctrl_v1/System.cpp:249: configAuxHigh(aux7, aux8, aux9);
Firmware-1.25/cnc_ctrl_v1/System.cpp:262:void configAuxHigh(int aux7, int aux8, int aux9) {

Am I correct that I would have to take aux7 out of the last 2, as will use ‘analogWrite’ to set the PWM% ?


Just posting this here so that others can see what you bought and what it does. I have no affiliation with Banggood other than as a satisfied customer.


Regarding your constant of “40”, this needs to be recorded somewhere, but it is different for different machines. I’m not sure if it should be in Ground Control or the Arduino. Probably the Arduino.

What you could do is store the max rpm of your spindle. Then the maths becomes:

Speed = argument of S command
pwm = speed*255/max
If pwm > 255 then pwm = 255
Analog Write(pwm)

So, if your max speed is 4000rpm and you get S4000:

pwm = 1020000/4000 = 255

If you get S2000

pwm = 510000/4000 = 127.5 -> 127

If you get S6000

pwm = 1530000/4000 = 382.5 -> 255

Having written that I realise your max rpm is 10000, but the calculation is the same.

You could also do the maths by ‘rpm per unit of pwm’, in your case it’s 40. So, get the argument of the S command and divide by 40, capping the result at 255.

But… where to store the max speed for the spindle, or the ‘rpm per unit of pwm’? And how to view it or change it?


I’m not sure I understand your post completely, but will try to answer as far as I can.
Creating a defined PWM pin in the firmware will always have integers from 0-255, no matter what you connect to it. In my case that results to a voltage output for my spindle and is 40 because of the RPM’s I’ve measured.
S-comands in the g-code do stand for spindle speed, but I thought if a variable laser exists, it could also be controlled by the same pin, simply changing that divider/multiplier so the S10000 gives you whatever value you need on the PWM pin. What hardware you connect to it to deal with the PWM is a separate thing.

I have no deal with them but 2 more links for the PWM to voltage module:

So from $4.5 to $11.50 depending on how long you want to wait.


This is a new parameter to save to the eeprom (where the other calibration
values are stored), they should probably be set/viewed by $ commands

David Lang


Update: The potentiometer needs to be removed for full spindle speed control. It ‘kind-of works’ if the knob is not on min or max, but did not bother to measure RPM as I found that removing it gave me full control.