How-To: Modify Marlin to control a laser with an SKR Pro

I see a lot of people online are using those. I spent $12 at my local pet store for a much smaller pump. It was several years ago, but I think it was sized for 15-20 gallon tanks. Not the smallest they had, but it didn’t make sense to me to spend big bucks on an air pump.

thanks for the information it will guide me to whitch one i will buy !

I’m going to be using a Sculpfun S9 which has a 12V +, - and PWM but Fan0 (on the SKR Pro 1.2) simply has +/- out.

Since the paperwork says the PWM on the S9 can support 12V - I presume the laser’s +/- can pull straight from the Power In (screw terminals) and that for the PWM I can use Fan0’s + with a 2.2kOhm resistor across Fan0’s +/- (to pull down).

EDIT: For clarity

1 Like

First take a close look at specs for your laser. Most lasers that can handle 12V PWM will handle a range of PWM inputs…like 3V - 12V. If your laser handles a range, then the path of least resistance is to use the laser pin on the SKR Pro. Assuming you are using the V1 maintained firmware, laser support is already enabled, and the laser pin is PC9. This is a 5V pin. If your board requires 12V PWM, then you will need to reassign the the laser pin. It is assigned in the top of configuration.h. Note that on may boards, the PWM is ground-side switching which can be a problem for controlling lasers.

As for powering the laser from the control board, you need to make sure the power supply is big enough to run both the control board and the laser. Assuming you have a standard/common setup, the steppers and control board will need around 6A max. Your laser required 3A.

1 Like

Thanks for your answer, my laser does give a range, 5-12v on PWM and I have a 12V 6A supply, the diode needs 3A max so I may need a beefier supply.

So if I use PC9 as the PWM or “laser pin” there’s no firmware changes needed?
What’s the gcode in that case for laser power?
Do I still need to pull PC9 down?

Edit: 6A won’t be enough

First you need a 9A power supply…6A for the steppers and the control board and another 3A for your laser [and you see caught that by your edit]. I just use a separate power supply for my laser, but in this configuration, you need to make sure you connect both a PWM pin and the ground pin to the control board. The laser control board needs to share a ground with the control board.

So if I use PC9 as the PWM or “laser pin” there’s no firmware changes needed?

No changes needed assuming you are running a newer version of the V1 maintained firmware. I think laser support was enabled around version 509.

What’s the gcode in that case for laser power?

In this configuration, the S parameter of the G0 - G3 g-codes is used to specify laser power with a range of values of 0 to 255. The first post in this topic contains a g-code file you can use to test your laser. In addition I’m 99% sure that M3, M4, and M5 g-codes are also enabled. I don’t have an SKR Pro board, but I believe that the laser items on the TFT display work, and I know the laser menu in Marlin mode works (though the wording is strange).

Do I still need to pull PC9 down?

I doubt it, but you will need to check. Try your setup (with your glasses on and the laser pointed in a safe direction). If your laser gives a brief shot at startup, then you will need to pull the pin down. I did not have to install a resistor for my laser on the Rambo, but every control board and laser board combination is different.

Edit: The SKR Pro is a 3.3V board, so PC9 will be 3.3V, not 5V. Most PWM devices that are designed for 5V PWM can be driven by a 3.3V signal, but not all. I suspect you will be just fine, but if you have issues, this might be the cause.

4 Likes

Excellent, thank you for the detailed response!

I recently got a 5.5W blue diode laser (VoidMicro LD3070LA). It has 3 leads: +, GND, PWM. The specs say that the PWM input is for DC3.3V-12V, 100Hz~50KHz, Preferred: 5KHz. The SKR Pro V1.2 is fixed at 2.5KHz, but to my understanding that shouldn’t be a problem. If I connect the laser to 12V and short the PWM to + it fires at full blast.

However when connected PWM to PC9 (and for now + and gnd to a separate 12V supply), even if I increase laser power to 255 it only fires at a low intensity.

I attached my little scope and found that actually between gnd and PC9 on the EXT1 header, the duty cycle is only 60% at 3.3V when laser power is set to 255. If I decrease the power the duty cycle decreases as well. Am I missing something obvious? I’m running the latest Marlin release with these settings:

#define LASER_FEATURE
#define SPINDLE_LASER_ENA_PIN PB0 // Heater2
#define SPINDLE_LASER_PWM_PIN PC9
#define SPINDLE_LASER_USE_PWM

#if ENABLED(SPINDLE_LASER_USE_PWM)
  #define SPINDLE_LASER_PWM_INVERT    false
  #define SPINDLE_LASER_FREQUENCY     2500
#endif

#define CUTTER_POWER_UNIT PWM255
//#define CUTTER_POWER_RELATIVE

#if ENABLED(SPINDLE_LASER_USE_PWM)
  #define SPEED_POWER_INTERCEPT       0    // (%) 0-100 i.e., Minimum power percentage
  #define SPEED_POWER_MIN             0    // (%) 0-100
  #define SPEED_POWER_MAX           100    // (%) 0-100
  #define SPEED_POWER_STARTUP        80    // (%) M3/M4 speed/power default (with no arguments)
#endif


If I’m reading your scope right you aren’t getting 2.5KHz either, 1KHz. I presume if you lower the power you get a shorter duty cycle.

Right, seems the PWM frequency of the SKR is actually 1000Hz. But that’s still in the supported range for my laser. And yes, if I lower the power, the duty cycle is reduced analogously.

OK, I think I figured it out:
the duty cycle was due to SPINDLE_LASER_FREQUENCY 2500 - once I commented that out (like in @vicious1 's config), it worked as expected.

However the laser still didn’t fire at full power until I connected the GND pin from EXT-1 to the ground from the separate 12V power supply that’s powering the laser. I’m running my MPCNC at 24V, so until my buck converter has arrived I can’t power the laser directly from the board.

My question: Is it risky to directly connect the gnd pin to the gnd pin from the separate 12V supply? Will this problem disappear once I power the laser from the board (via the buck converter)? Or is there another way, e.g with a pullup or pulldown resistor on PC9?

If there is 0V potential between the 2 power supply grounds, then there is no problem with connecting them, and in fact it’s probably a good idea to get a common ground plane between the 2 different systems. Many multi-voltage power supplies do the same thing internally, (for example, a computer power supply often has a separate 5V and 12V SMPS which are tied together at the ground plane). Do keep in mind that this means that you will also get a potential voltage now across the positive rails of your power supplies (PC power supplies get a voltage of 7V across the 12V and 5V pins, which is sometimes used to run fans at lower than 12V, but more than 5V.)

3 Likes

Thanks Dan! Since my buck converter didn’t arrive yet I hooked up the 12V power supply to my board’s bed power input and the laser to the bed output. They seem to share a common ground with the logic pins, so I was good to go.

Not too bad for a first try:

Next up: hooking up the air pump.

2 Likes

i am trying to do photo burning with lightburn and it is giving me trouble!
I tried the 2 ways M03 / M05 and inline!
my problem is that I don’t have a good result!
I am using the latest firmware version 513 from V1CNC_SkrPro_DualLR_2209-2.0.9.2.zip
i have the impression that the Marlin firmware is not compatible for photo burning with lightburn it seems that this firmware is not fast enough to do a good job, it gives me different problem and i can’t get good results!
I have looked at several posts here and I can not find anything to solve my problem!

See Marlin documentation Configuring Marlin | Marlin Firmware

Do you have laser mode enabled in the firmware? The firmware supports a spindle mode where tool motion is paused for a moment after RPM changes to allow the bit to settle at its new speed. With a laser, this pause results in burned areas, and often areas where tool motion speed changes (e.g. slowing down for a corner) end up burned as well. Laser mode addresses these issues since laser intensity changes are, for all intents and purposes, immediate. The pauses on intensity changes are removed, and laser intensity is modified to match velocity/acceleration changes.

Setting a non-zero minimum power may also help, depending on your specific laser. Many will not fire at very low intensities, so you’d want the minimum to be where the laser actually does fire.

1 Like

this is a big content to read i will take time to read it and look in my firmware whit visual studio code to compare the setting
thanks i will give you news

THIS IS MY SETUP IN FIRMWARE ¸
#if ENABLED(SPINDLE_FEATURE)

//#define SPINDLE_CHANGE_DIR               // Enable if your spindle controller can change spindle direction

#define SPINDLE_CHANGE_DIR_STOP            // Enable if the spindle should stop before changing spin direction

#define SPINDLE_INVERT_DIR          false  // Set to "true" if the spin direction is reversed

#define SPINDLE_LASER_POWERUP_DELAY   5000 // (ms) Delay to allow the spindle/laser to come up to speed/power

#define SPINDLE_LASER_POWERDOWN_DELAY 5000 // (ms) Delay to allow the spindle to stop

/**

 * M3/M4 Power Equation

 *

 * Each tool uses different value ranges for speed / power control.

 * These parameters are used to convert between tool power units and PWM.

 *

 * Speed/Power = (PWMDC / 255 * 100 - SPEED_POWER_INTERCEPT) / SPEED_POWER_SLOPE

 * PWMDC = (spdpwr - SPEED_POWER_MIN) / (SPEED_POWER_MAX - SPEED_POWER_MIN) / SPEED_POWER_SLOPE

 */

#if ENABLED(SPINDLE_LASER_USE_PWM)

  #define SPEED_POWER_INTERCEPT       0    // (%) 0-100 i.e., Minimum power percentage

  #define SPEED_POWER_MIN          5000    // (RPM)

  #define SPEED_POWER_MAX         30000    // (RPM) SuperPID router controller 0 - 30,000 RPM

  #define SPEED_POWER_STARTUP     25000    // (RPM) M3/M4 speed/power default (with no arguments)

#endif

#else

#if ENABLED(SPINDLE_LASER_USE_PWM)

  #define SPEED_POWER_INTERCEPT       0    // (%) 0-100 i.e., Minimum power percentage

  #define SPEED_POWER_MIN             0    // (%) 0-100

  #define SPEED_POWER_MAX           100    // (%) 0-100

  #define SPEED_POWER_STARTUP        80    // (%) M3/M4 speed/power default (with no arguments)

#endif

// Define the minimum and maximum test pulse time values for a laser test fire function

#define LASER_TEST_PULSE_MIN           1   // Used with Laser Control Menu

#define LASER_TEST_PULSE_MAX         999   // Caution: Menu may not show more than 3 characters

Which (if either) of these do you have enabled?

//#define SPINDLE_FEATURE
//#define LASER_FEATURE

I would expect you’d want LASER_FEATURE enabled.

I should warn you, I’m not using Marlin myself, so I can’t guide you by looking at my owne working configuration. On grbl I can switch between laser and spindle without having to recompile the firmware.

yes exactly
//#define SPINDLE_FEATURE
#define LASER_FEATURE
i now marlin is not perfect for what i am trying to do but for now it is the only one i have !
i order a small machine from NEZE to do my photo engraving on tiled but it will take a while to come !
For other job my cnc is good whit laser only whit tiled is the problem !

NEJE Master 2S plus laser engraver & cutter with N40630 laser module- – NEJE.SHOP

Follow the steps in this thread, that should help you get things up and running:

1 Like