Variable spindle speed

I need some help in seting variable spindle sped in GRBL so that I can trun the spindle on and off by M03 and M05 commands and control speed. My purpose is not to control the speed but use this pwm output to control the power of laser

I hope someone could help me

I connected as this one wire to pin 12 other to ground, but when checked the voltage across this using a multimeter it’s 4.3 V and M03 and M05 comand doesn’t seem to change anything.
Which is the pwm pin?

Depending on your board/GRBL version, it has probably moved to Pin 11, at least it is on my X-Carve.

Like Ian suggested, depending on whether you are running GRBL 0.8 vs 0.9:

I am using 0.9i and I want to use pwm pin(pin 11)
Can anyone tell me what should be the maximum value of PWM? is it 256?

I give a command M3 S 256 but I am only getting 0.11 V at Pin 11
If I give S12000 I’m getting 4.33V

FYI: PWM signal and a voltage signal are closely related but still too different things.
So in order to hook up your laser one needs to know:

Does the laser require a PWM signal or an voltage (analog) signal?

PWM is generally 0 to 100% duty cycle
Voltage is generally 0 to 5V.

However honestly this doesn’t matter, since you don’t have control over this anyway…
Like you measured already, you can only tell GRBL the speed you want, and it will adjust the PWM for you.
Realisticly, the higher the PWM the higher the voltage will be.

From the same GRLB wiki:

If you have a desire or need for spindle or coolant control, Grbl will toggle these output pins (D12, D13, A3) high or low, depending on the G-code commands you send to Grbl. With v0.9 and variable spindle PWM enabled, the D11 pin will output a range of voltages from 0V to 5V depending the spindle speed G-code command. 0V indicates spindle off in this case. Since these pins are all application dependent in how they are used, we’ll leave it to you to determine how to control and use these for your machine. You can also hack the spindle and coolant control source files to easily alter how they work and then compile and upload your modified Grbl through the Arduino IDE.

Try a M3 S99999 and see what the max voltage is. Hopefully it’s 5V. Scale your GCODE software from there when controlling the laser.

With the J-Tech 2.8w laser I’m using M3 S18000 for 100% PWM duty cycle and M3 S1200 for minimum power for focusing the laser.

I solved it.
I had to change the config.h file in GRBL

#define VARIABLE_SPINDLE // Default enabled. Comment to disable.

// Used by the variable spindle output only. These parameters set the maximum and minimum spindle speed
// “S” g-code values to correspond to the maximum and minimum pin voltages. There are 256 discrete and
// equally divided voltage bins between the maximum and minimum spindle speeds. So for a 5V pin, 1000
// max rpm, and 250 min rpm, the spindle output voltage would be set for the following “S” commands:
// “S1000” @ 5V, “S250” @ 0.02V, and “S625” @ 2.5V (mid-range). The pin outputs 0V when disabled.
#define SPINDLE_MAX_RPM 1000.0 // Max spindle RPM. This value is equal to 100% duty cycle on the PWM.
#define SPINDLE_MIN_RPM 0.0 // Min spindle RPM. This value is equal to (1/256) duty cycle on the PWM.

I changed the maximum spindle speed to 255 . Compiling the edited file with Arduino didn’t work so I had to compile it using WinAVR

So now if I give M3 S255 I will gwt 5.01V at the output of pin 11

Try a M3 S99999 and see what the max voltage is. Hopefully it’s 5V. Scale your GCODE software from there when controlling the laser.

I use Inkscape and jphotonics laser plug in to generate gcode, in which if I give 100% laser power, generated gcode only have S255

I don’t know how to change that.
Is there any way to do that, I mean to change the PWM value in Jphotonics plug in?

Tube is producing laser as per the gcode, that was my primary concern.

@JeremyJohnstone @IanWatkins Thanks for the help

My laser can work with either 0-5 V analog signal in pin IN or 5 V PWM signal