laser is engraving the negative space 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 &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


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.
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.

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


  
  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).
  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.
  Save the changes and flash the revised firmware back onto your
  Mega board.