PWM frequency change Via gcode, assigned by layer

This is more of an ask for afeature than anything.
Adjustble pwm frequency changes via gcode, so that it could be done by layers.
So my Co2 laser (stock k40 tube and type2 white psu) has been set to 5khz by default in the MKS DLC32 firmware.
copied form github:
"Default frequency is set to 5’000Hz (=200us PWM period), which is a good mix for grayscale engraving and cutting.

Higher frequencies (like 20,000Hz) tend to cut deeper with less burning and lower frequencies (like 2’500Hz) could deliver slightly better grayscale representation. The effect depends on many factors like the laser power supply, material, focus, feed…"

I know that firmwares would have to be adjusted. I like FluidNC and anything GRBL, and making a program change like that isnt terribly difficult.
Not sure if rewriting that setting during a job is wise though.

If this matters much, it depends on how the DCS is connected to the lps…

Does the pwm go to IN on the lps or to L (maybe H, inverted input of L).
Might be easier to see if the console pot ends up generating a dc voltage to the IN terminal of the LPS.

Don’t remember seeing anything in my grbl machine to change this per layer. So, I know of no way in gcode to change it during a run on a different layer…

A few people, including me, has fussed with this, but it seems as not to be worth the trouble… Along with how you are wired to the lps, it may be moot.

I know the Ruida has this option in the cut/layer editor, which is where I changed it…

There has been a couple posts of something similar in the feature suggestions area. One of these, the user has an RF laser… they may act differently.


We are working on something that ‘should’ handle the emerging technology. I’ll get this to the team working on it.

IMHO, obviously conflicting with @JohnJohn, I don’t know how you could possibly accomplish this with a K40, not the frequency, but the concept…

These control the lps in a totally different manner than a dsp and that makes doing this moot or maybe even worse, unpredictable.

The pwm does not control tube current on these configurations. It only controls laser enable

A 1kHz pwm is the highest frequency they could possibly use with a dc excited laser…

Check out this post about wiring… I drifted into pwm control of a K40… :face_with_spiral_eyes:

Good luck


I have my unit wired as follows:
Mks pins S and TTL, to K40 white type 2 psu pins G and In.

My spindle minus is hooked to L

My unit for a very long time was working with only the in and g hooked up, but I was getting a wierd interference on my display… That went away when I conned to L to spindle -. Turns out that was ~200VDC peak leaking ftom inside the PSU somewhere.

I reproduced that issue with two type 2 Psu’s.

I will be adjusting frequencies tonight and seeing what happens.

This all started when I maxed my laser out at 1000mm/s and 100%- or so I thought…
Manual override of power to 200% allows me to run at 2000mm/s.
2000 accel on x
.1% overscan…

It makes very nice 0.15" tall letters at that speed.

So I have taken a dive into a hell of a rabbit hole, of why S1000 does not equal true full pwm output.

I will be measuring voltages tonight as well., unfortunately someone at work stole the o-scope…

Quick background of my machine… It’s a universal engraver frame wiith the mks DLC32 v 2.1 running 2.3 latest firmware. I built the tube onto Tha gantry so as to minimize beam travel…

Now I need speed, because time is money. And if my machine can do double, but I have to manually set that with each job, then I need to do something different.

So yeah laser enable did nothing to prevent firing via pwm, but it made stray voltage leak through pwm line.

I have no inline potentiometer, have never used one, my machine came with the digital panel to set the power.

The pot inside the psu has been turned down to limit max laser power. I have kept it at 25mA. I do not care if I burn out this tube… I will upgrade. I have the cw 5000 chiller too.

The chiller input and the k+ k are just jumpered for now. I will be changing that with a relay, once I get firmware and controls sorted out

Did you read the link… same wiring, yes?

I know of few lasers that will run 1000mm/s… I’d like to see a photo of what your machine looks like to be able to pull that off. I find 2000mm/s unfathomable. Both of these will more than likely outrun your lps.

Convince us that it’s running this fast… I’m always open and they get faster… However I know what it took to get mine up to 1650mm/s and those speeds are useless except for academia.

I don’t know what manual override of power is… and how does it speed up the axes?

Is your controller configured to allow for these kinds of speeds?


I’ll happily give a full break down later.
Look at a universal engraver diode laser, then imagine a tube on an extra gantry beam…

And I will gladly post pictures and video as proof of my machine doing this stuff.

I have a large sheet of cardboard with alot of test cuts on it right now.

And yes, my max x is 6000, I will not go that fast. X is my scanning axis for engraving. I have dual y motors so that is set much slower because the gantry is relatively heavy.

I forget which stepper drivers I have rn. But this is far from a stock K40.

I guess so…

Pardon my doubt, but I see more enhanced claims of performance, so I’ve become a bit cynical.

Can’t get a picture of the tube on a separate gantry…

What can you possibly use a co2 laser for with speeds over 1000mm/s? You can’t cut that fast and you can’t engrave at that speed, what’s left?

Yes I’d love to see it run, especially at 6M/S :exploding_head:

It’s hard to imagine a gantry laser moving faster than my galvo machine…


To answer your question, manual speed and power overrides are done via the ts35 touch screen. There is a menu to change it on the fly during jobs.

And the psu you have in your post is type 1. See
Its a good resource for the basics.

I mean, my controller is doing what I’m asking of it. Whter or not it truly is 2000mm/s… I’ll do a long run and time it.
And yeah I know 6 is rediculous. I just set it to some BS number higher than I intend to go.

Here is my wiring. Dual y and singe x motor, no z

Very nice… Love seeing these…

I get the beam path now…

Is the table adjustable, Z wise?

You have lots of real estate to accelerate.

This is mine from new, sans honeycomb… original and lately…

Many have used a camera to video a line with mm marked on it. It along with the frame rate will tell you have fast it’s running…

Thanks for the photos…


Don’t laugh, I just move the whole table up. I use pieces of wood the same thickness as what I’m working on to acheive desired Z height
Kept the gantry simple and light that way. Most of my jobs are varying thin birch plys.

Here is a sample engraving I did last night.

And here is my override:

Now to comfirm some suspicion, I’m gonna run some solid fill long shapes to get voltage readings that aren’t too fast for my meter. Inital readings confirm 100% at 0.15v and 200% maxed at 0.3v
I know it’s not 5v but my multimeter may not be sensitive enough or taking fast enough readings.

What are you reading and from where?


Pictures and data incoming.
Then on to part two 3 and 4.
As set on parameter $33

Well crap, $33 not recognized in this setup…
OK, we’ll there goes my idea.

I’ll post results then:

So setting overscan to off, doesn’t work, but the minimum value of. 1% is too large

See how it cut off the words?

Anyways. The voltage dropped as speed increased.
1900 vs 2000 both at 200%. 51v to. 49.

One last quick test.
1000mm/s at 200 just gave me… Wait for it…
19.9 volts!!! WTF…

And yet it only peak at 10ma on my ammeter.
My ammeter is right, because I know what true 100% full power looks like at slow slow speed when cutting, and it’s enough to go through this cardboard and into my table a ways.

I think it’s time for fluid NC, unless mks releases source code the 2.3 firmware…

I’m getting invested in this enough, I’m considering buying another mks board just to see if my lack of L to spindle - caused perma damage…

This is very clean text for being 0.1875" tall at what it claims to be 2000mm/s.

I’m afraid I’ve lost it here…

I have no idea what the $33 variable is… it’s not on any of my grbl machines or documentation.

You increase the speed by 200% and measure the pwm voltage… is this correct?

Or are you increasing the power by 200% and measure the pwm?

The pwm should go from 0 to 5V… you are measuring <1V, something is wrong here.

The lps should not fire with the L terminal floating.

I guess we have very different ideas to what is clean text… It’s almost 5mm tall…?


OK, the L is not floating. There is a wire there, it’s not quite showing up, it is wrapped around the post to test. It lights up the red led on the mks.

It is power increase.

I measured the same spot for all tests…
Something is terribly wrong somewhere.
Its either my board, or I’m delving into speeds not messed with by K40 people because 1000 has been max of most.

19.9 volts is very bad for something expecting 5v Max.
But it is making a nice clean text. … Somehow.

There is no trickery going on, those rectangles only showed 0.51 volts max…
I want to see someone else with a type 2 psu measure their voltage and see what it actually reads…

Im at a loss right now, it works like it is…
But not like I want.

I will do more tests at various speed levels,. Use proper connector, and attach spare leads to just leave the multimeter in place without holding it…

I’ll start off at 300mm/s and 37% which was making really nice business cards for me…

Looking like a tomorrow project…

It’s clean as in there is not shape distortion caused by erro in machine moves, the onky issue is the extreme power level…
Ill bust out the plywood for further testing

In the schematic you posted the L input is not connected. Are you connecting this to the spindle somehow?

Your board is probably ok, something else is going on.

From what? A 200% power increase from what original setting?

It will be the same as I’ve stated, they all work that way… Are you sure you have a common ground for all of these signals?