<p>This is too long for a good comment but may fall short of being a true answer.  If the mods prefer, I can recast it as a set of comments.</p>

<p>There are several differences between using a GPIO pin as a binary data pin and using one as a PWM pin, and the behavior depends on several factors:</p>

<ol>
<li>Is the PWM pin a native PWN pin with hardware support, or is the PWM function being implemented with software?</li>
<li>Has the PWM pin been initialized as a PWM pin?</li>
<li>What processor type is used?</li>
<li>What is the PWM frequency?</li>
<li>Is the pin a TTL compatible output [0.4 V low, 2.7 V high]?  CMOS?  What Vcc?</li>
<li>For that matter, what is the CPU?</li>
</ol>

<p>As @0scar points out, the fan control pin is typically not connected directly to the fan, but instead uses a FET to provide isolation and switch more current than the output pin can provide.  Depending on the circuit, it may be inverting or non-inverting.  M42 Pxx S255 may be full on or full off.  When the fan is controlled through the fan G-code, the firmware can take possible inversion into account.</p>

<p>You haven't said what the input circuit to the laser involves.  </p>

<ol>
<li>It is active high or active low?  </li>
<li>Does it require a pulse train to keep the output on, or is it
static?  I don't know how yours works, but I could imagine designing
a laser module to require a continuous stream of pulses to keep the
beam active so that a failure in the drive circuit could not create
a safety hazard.</li>
<li>Is it a TTL compatible input [0.7 low, 2.4 high]?  CMOS?  What Vcc?</li>
<li>Is it something else?</li>
</ol>

<p>Laser etching is generally on-topic for this group given the close association with 3D printing tech, but people are less familiar with the "standard systems".  For some of us to be helpful (especially for me to be helpful) we need more of the circuitry and firmware context.</p>

CC BY-SA 4.0
2019-06-18T03:25:18.760Z
I will try to answer as much as I understand (totally new to electronics diy).  (A) The board of my 3D printer is an Arduino Mega 2560 board with a Ramps 1.4 board. (B) my laser module has a PWM pin on it, which I connected to D4 on my Ramps 1.4 board..... I really am not sure about the other questions as I don't really know what they mean.
codeNinja
CC BY-SA 4.0
2019-06-18T03:49:06.853Z
Do you have specs on the laser?  Do you know what firmware you are using?
cmm
CC BY-SA 4.0
2019-06-23T03:30:38.677Z
It's a 5w laser straight from China. Came with no documents. The firmware is Marlin.
codeNinja
CC BY-SA 4.0
2019-06-17T13:12:27.190Z
2019-06-17T13:18:22.447Z
2019-06-17T13:18:22.447Z
cmm
<p><code>M42</code> command is an immediate command. This means that it will run before the move GCode commands finish. This is exactly what I was facing. </p>

<p>This video has the walk-through of solving the issue: <div class="youtube-embed"><div>
                <iframe width="640px" height="395px" src="https://www.youtube.com/embed/LEjgp77TIy4?start=625"></iframe>
            </div></div></p>

<p>Here is the relevant PDF it talks about: <a href="https://www.v1engineering.com/wp-content/uploads/2016/01/MPCNC-laser-add-on-walk-through-Rev2.0.pdf" rel="nofollow noreferrer">The 2.8 watt, $100 Laser
Upgrade for MPCNC</a>.</p>

<p>Here is the relevant section on page 7 of the PDF:</p>

<blockquote>
  <ol>
  <li><p>The laser driver requires a 5 volt TTL input control signal. The
  Marlin fan control Mcodes (M106 and M107) will be used to
  control the laser .Unfortunately, the Ramps fan output (D9) is a
  12 volt signal so we can’t use it. We'll need a quick firmware edit
  to remap the fan output from pin D9 (12v) to pin 44(5v).</p></li>
  <li><p>Make a backup copy of your Marlin firmware folder first. Open
  the pins_RAMPS_13.h file in your Marlin firmware folder with a
  text editor (Wordpad). Search for the line where the fan pin is
  assigned and change it from pin 9 to pin 44.</p></li>
  <li><p>Save the changes and flash the revised firmware back onto your
  Mega board. </p></li>
  </ol>
</blockquote>

CC BY-SA 4.0
2019-08-01T17:31:51.890Z
2020-01-28T21:53:24.943Z
2020-01-28T21:53:24.943Z
codeNinja
<p>I am using LightBurn to laser engrave on wood. I am just trying to print some letters. </p>

<p>In the softwares preview the output looks correct. The black part is where the laser should burn and the red part are traversal/scan lines
<a href="https://i.sstatic.net/nLs8P.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nLs8P.png" alt="enter image description here"></a></p>

<p>When i actually print it the negative space is burnt by the laser (basically where the traversal/scan lines are shown in the preview above)</p>

<p><a href="https://i.sstatic.net/DjRPw.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/DjRPw.png" alt=""></a></p>

<hr>

<p>What I was able to figure out is that:</p>

<ul>
<li><code>M42 P4 S255</code> properly turns on the laser when I send this command on its own,</li>
<li><code>M42 P4 S0</code> properly turns off the laser.</li>
</ul>

<p>But the issue is when I send the following G-code, the following happens:</p>

<pre><code>M42 P4 S255 &lt;--- Laser turns on for a flash of a second
G1 X15 &lt;--- By the time the movement starts the laser is already off.
M42 P4 S0
</code></pre>

<p>When i stopped using PWM (via the D11) and instead connected directly to D9 (which is for the fan) this issue stops occurring. So this issue is only occurring when I use PWM. Any Guidance on what to check</p>

<p><strong>Update:</strong> I read the following on another forum. This might be the root cause here.</p>

<blockquote>
  <p>M42 is an immediate command and would turn on the laser before it reached its intended start point, M106 and M107 are buffered so the on/off can happen in its intended locations.</p>
</blockquote>

CC BY-SA 4.0
2019-05-24T19:08:13.903Z
Laser engraving and cutting is unrelated to 3D printing. You would have much greater success with the forum set up by Lightburn Software to find your answers.
fred_dot_u
CC BY-SA 4.0
2019-05-25T10:43:43.557Z
Also what laser engraving system do you have? I have no experience with laser engraving, but it seems obvious that this could be a software issue, a hardware issue, or an issue of the two communicating. Have you ever gotten engraving to work correctly or are you just starting?
T. M.
CC BY-SA 4.0
2019-05-28T23:09:38.063Z
See [Is laser etching, specifically a question linked below, considered to be on topic?](https://3dprinting.meta.stackexchange.com/questions/404/is-laser-etching-specifically-a-question-linked-below-considered-to-be-on-topi)
Greenonline
CC BY-SA 4.0
2019-05-29T02:23:48.527Z
I don't know of any situation like "negative space" in 3D printing.   It looks add if you may be just inserting the laser output, which is unlikely to work.   Why?  Because the software wouldn't know what was etching, and would command faster movement for the negative space than for the etched space, and may traverse regions when it thinks the least is off.  Also,  the bounding region of the "negative space" is not well defined.   I would suggest trying it with "positive space" engraving and seeing how it works.   It may also be that the leader control is inverted.   Was this a homebrew machin
cmm
CC BY-SA 4.0
2019-06-07T21:13:41.587Z
This looks like it may possibly be a firmware issue, where the laser has an inverse relationship with power vs what the software thinks it's sending. We really need more information about what the hardware in question is, as well as possibly a sample g-code file.
Nach0z
CC BY-SA 4.0
2019-06-17T01:13:15.917Z
G-code is executed sequentially, it does not skip a line, that is not possible.
0scar
CC BY-SA 4.0
2019-06-17T01:49:23.277Z
@oscar please see my Update#2
codeNinja
CC BY-SA 4.0
2019-06-17T01:58:10.767Z
Stating "Update" is not explicitly essential, your last addition (update 2) is not necessary, as you compare apples and oranges. The D9 of the fan is not connected to the microprocessor directly, there is a MOSFET in between.
0scar
CC BY-SA 4.0
2019-09-29T11:34:33.413Z
I have a 2500 mW laser and I am with the same problem. I want to engrave using LightBurn, and also engrave a negative red line. How can I do this?
bruno alexandre
<g-code><laser>
laser is engraving the negative space
codeNinja
# laser is engraving the negative space

(Asked by: username_0 on 2019-05-24)

I am using LightBurn to laser engrave on wood. I am just trying to print some letters. 
In the softwares preview the output looks correct. The black part is where the laser should burn and the red part are traversal/scan lines

When i actually print it the negative space is burnt by the laser (basically where the traversal/scan lines are shown in the preview above)


What I was able to figure out is that:

M42 P4 S255 properly turns on the laser when I send this command on its own,
M42 P4 S0 properly turns off the laser.

But the issue is when I send the following G-code, the following happens:
M42 P4 S255 <--- Laser turns on for a flash of a second
G1 X15 <--- By the time the movement starts the laser is already off.
M42 P4 S0

When i stopped using PWM (via the D11) and instead connected directly to D9 (which is for the fan) this issue stops occurring. So this issue is only occurring when I use PWM. Any Guidance on what to check
Update: I read the following on another forum. This might be the root cause here.

M42 is an immediate command and would turn on the laser before it reached its intended start point, M106 and M107 are buffered so the on/off can happen in its intended locations.

**Tags:** g-code, laser
> **Comments:**
> **username_1**: Laser engraving and cutting is unrelated to 3D printing. You would have much greater success with the forum set up by Lightburn Software to find your answers.  
> **username_2**: Also what laser engraving system do you have? I have no experience with laser engraving, but it seems obvious that this could be a software issue, a hardware issue, or an issue of the two communicating. Have you ever gotten engraving to work correctly or are you just starting?  
> **username_3**: See [Is laser etching, specifically a question linked below, considered to be on topic?](https://3dprinting.meta.stackexchange.com/questions/404/is-laser-etching-specifically-a-question-linked-below-considered-to-be-on-topi)  
> **username_4**: I don't know of any situation like "negative space" in 3D printing.   It looks add if you may be just inserting the laser output, which is unlikely to work.   Why?  Because the software wouldn't know what was etching, and would command faster movement for the negative space than for the etched space, and may traverse regions when it thinks the least is off.  Also,  the bounding region of the "negative space" is not well defined.   I would suggest trying it with "positive space" engraving and seeing how it works.   It may also be that the leader control is inverted.   Was this a homebrew machin  
> **username_5**: This looks like it may possibly be a firmware issue, where the laser has an inverse relationship with power vs what the software thinks it's sending. We really need more information about what the hardware in question is, as well as possibly a sample g-code file.  
> **username_6**: G-code is executed sequentially, it does not skip a line, that is not possible.  
> **username_0**: @oscar please see my Update#2  
> **username_6**: Stating "Update" is not explicitly essential, your last addition (update 2) is not necessary, as you compare apples and oranges. The D9 of the fan is not connected to the microprocessor directly, there is a MOSFET in between.  
> **username_7**: I have a 2500 mW laser and I am with the same problem. I want to engrave using LightBurn, and also engrave a negative red line. How can I do this?  

---

## 2 answers

### Answer by username_0 on 2019-08-01. Score: 5 | Accepted answer

`M42` command is an immediate command. This means that it will run before the move GCode commands finish. This is exactly what I was facing.

This video has the walk-through of solving the issue:

Here is the relevant PDF it talks about: [The 2.8 watt, $100 Laser
Upgrade for MPCNC](https://www.v1engineering.com/wp-content/uploads/2016/01/MPCNC-laser-add-on-walk-through-Rev2.0.pdf).

Here is the relevant section on page 7 of the PDF:

> 1. The laser driver requires a 5 volt TTL input control signal. The
>    Marlin fan control Mcodes (M106 and M107) will be used to
>    control the laser .Unfortunately, the Ramps fan output (D9) is a
>    12 volt signal so we can’t use it. We'll need a quick firmware edit
>    to remap the fan output from pin D9 (12v) to pin 44(5v).
> 2. Make a backup copy of your Marlin firmware folder first. Open
>    the pins\_RAMPS\_13.h file in your Marlin firmware folder with a
>    text editor (Wordpad). Search for the line where the fan pin is
>    assigned and change it from pin 9 to pin 44.
> 3. Save the changes and flash the revised firmware back onto your
>    Mega board.


---

### Answer by username_4 on 2019-06-17. Score: 4

This is too long for a good comment but may fall short of being a true answer. If the mods prefer, I can recast it as a set of comments.

There are several differences between using a GPIO pin as a binary data pin and using one as a PWM pin, and the behavior depends on several factors:

1. Is the PWM pin a native PWN pin with hardware support, or is the PWM function being implemented with software?
2. Has the PWM pin been initialized as a PWM pin?
3. What processor type is used?
4. What is the PWM frequency?
5. Is the pin a TTL compatible output [0.4 V low, 2.7 V high]? CMOS? What Vcc?
6. For that matter, what is the CPU?

As @0scar points out, the fan control pin is typically not connected directly to the fan, but instead uses a FET to provide isolation and switch more current than the output pin can provide. Depending on the circuit, it may be inverting or non-inverting. M42 Pxx S255 may be full on or full off. When the fan is controlled through the fan G-code, the firmware can take possible inversion into account.

You haven't said what the input circuit to the laser involves.

1. It is active high or active low?
2. Does it require a pulse train to keep the output on, or is it
   static? I don't know how yours works, but I could imagine designing
   a laser module to require a continuous stream of pulses to keep the
   beam active so that a failure in the drive circuit could not create
   a safety hazard.
3. Is it a TTL compatible input [0.7 low, 2.4 high]? CMOS? What Vcc?
4. Is it something else?

Laser etching is generally on-topic for this group given the close association with 3D printing tech, but people are less familiar with the "standard systems". For some of us to be helpful (especially for me to be helpful) we need more of the circuitry and firmware context.

> **Comments:**
> **username_0**: I will try to answer as much as I understand (totally new to electronics diy).  (A) The board of my 3D printer is an Arduino Mega 2560 board with a Ramps 1.4 board. (B) my laser module has a PWM pin on it, which I connected to D4 on my Ramps 1.4 board..... I really am not sure about the other questions as I don't really know what they mean.  
> **username_4**: Do you have specs on the laser?  Do you know what firmware you are using?  
> **username_0**: It's a 5w laser straight from China. Came with no documents. The firmware is Marlin.  

---

