To find K40 conversion information use the "INDEX", "SEARCH" or "LABELS" sections in the sidebar.

Tuesday, December 20, 2016

Engraving and PWM Control

Pulse Width Modulation (PWM) Control Considerations for Engraving


I have been thinking about the power scaling in my K40-S, especially as it relates to engraving applications.
After tromping for months through the Laser Power Supply (LPS) & PWM forest I came to some realizations that drove me to probe deeper into the PWM control of my K40-S.

I have not done a lot of engraving yet but expect that in order to get to rational and repeatable engraving quality exacting the smoothie PWM settings is important.


Please consider donating (button to the right of this post).
Your donations help fund additional research, tools and parts that I will return to the community as information.For other information on the K40-S build use the  K40-S BUILD INDEX with schematicsnity as information 


Grey Shade Test Images


Section 1: Laser Power Control Function

Lets first describe a simple digital laser power control function:
  • LaserPowerOut (watts) = SoftwarePwmDF(%) * LaserPowerMax(watts) 
  • SoftwareDF = the PWM signal value [the software's PWM control output] as a percent that the pulse is ON relative to the period of the PWM cycle.
  • LaserPowerMax = the maximum power the laser can output
This means that the laser's power output will be proportional to the DF of the PWM signal if the LaserPowerMax is held constant.

How PWM power control works:

PWM is a schema for digitally controlling the power of a device by switching that device's power ON and OFF proportional to how much average power you want the device to output. Unlike analog control, the PWM signal has only two states, it is either ON or OFF.

Example: To make a 40 watt laser output 20 watts using PWM control, the software would turn the laser on 1/2 of the time and off for 1/2 of the time.

There are two important design factors in PWM control:
  • Duty Factor: the length of time the control is on during a given cycle or period
  • PwmPeriod: the time or period for one cycle of power control.  This the the time increment over which the PWM control is applied.
  • PWM frequency: The inverse of PwmPeriod is the PWM frequency.
Basic PWM definitions

Example: if the PwmPeriod is .016667 seconds that means that every .016667 seconds the power controller decides how long to turn on the laser based upon the desired DF. In the case where we want to output 20 watts the system would keep the PWM signal true for .008333 and off for .008333 seconds i.e. 50% DF.
Note: In this example the PWM frequency is 60hz.
  • PWMfreq = 1/PwmPeriod

Section 2: Predictable PWM Control Is Important in Engraving and Grey-Scale Imaging:

It is important that the PWM control of the LPS be stable and predictable otherwise the power output at the laser will not reproduce what the software is expecting. Although this may not impact output quality when cutting with a laser it will have a large effect on the fidelity of engravings or other jobs where software control algorithms expect a linear PWM vs power output function.

When digital laser engraving, the darkness of the image is controlled by scaling power (the PWM signal) across the range of the lasers power output curve. Whereas 100% DF turns a 40 watt laser on at 40 watts, a 10% DF will turn the laser on at 4 watts. When engraving a grey-scale image the controller decides during each pixel time what power to set the laser at to get a darkness that is proportional to other pixels in the image.

Note: A pixel time is the time that the laser is on to produce a digital bit of information. The pixel time is proportional to the resolution of the engraver and its speed across the surface.

In photography and computing, a gray scale or grey scale digital image is an image in which the value of each pixel is a single sample, that is, it carries only intensity information. Images of this sort, also known as black-and-white, are composed exclusively of shades of gray, varying from white at the weakest intensity to black at the strongest.[1]

The grey shade (from light to dark) control in a laser engraver is created by using increments of PWM DF values to create an increasing scale of intensity.

Therefore it follows that a given PWM value must create a predictable laser output power across it min to max range, if high quality digital laser engraving is to be expected.
As an example,if the controller sends the laser power supply a PWM value of 10% and the LPS subsystem does not output 4 watts then what the controller expects the image to look like and what is actually imaged, will be different.


Just as an FYI, Dithering is a technique employed to create one bit black and white digital images from grey shade. Dithering does not employ stepped control of the PWM it rebuilds an image by using patterns of black and white dots.

Sources of PWM control errors:

Power control errors can occur in the K40 system if it is not electronically (PWM) controlled in a predictable manner. Traditionally the K40 LPS has employed digital control using one of two input controls; "IN" or "L".

"IN" control

The IN input is an analog input that adjusts the lasers power output proportional to a DC voltage on its input. The IN input is an analog control.
When connecting a digital signal (PWM) to the analog IN input two errors may be created.

For this explanation a traditional and worse case form of interconnection is considered where:
  • The PWM signal is a digital signal traversing 0-5VDC connected to IN.
  • The "Current Regulation" pot is connected from 5VDC to ground with the IN signal connected to the center of the pot.

The driver (D) most often used in K40 conversions is a level shifter 

The Error

The PWM, in its high and low state, biases the IN pin at either 5VDC or ground. The proportion of the pots resistance to 5VDC vs the resistance to ground changes with the pots position. This configuration makes the value at IN for any given PWM and pot position a convoluted function of the PWM DC bias + the analog position of the pot. In this configuration IN is not a value that is known to the controller and the LPS is not accurately being digitally controlled.

When connecting the PWM to the "IN" pin the laser power function becomes:

  •  LaserPowerOut (watts) = SoftwareDF(%) * (RelativePotPosition(%) + (ErrorFunction)) * LaserPowerMax
  • ErrorFunction = DCOffset + PotsLiniarityError
I have not modeled the ErrorFunction and decided it is not worth doing since there is a more reliable and predictable way of digitally controlling the K40's LPS. Even if we knew the ErrorFunction I doubt it could be implemented in the software control since the postion of the "Current Regulation" pot is unknown to the controller.

Note: this is not to say using IN will not work. I does however predict that the use of IN, especially when the "Current Regulation" pot is installed, will result in irrational engraving results because of grey scaling errors created by power errors that are external to the controllers knowledge . The errors cited above may be adjusted out by "tinkering" with a combination of the laser power limits in the configuration files and the position of the "Current Regulation" pot. Ideally we want a control system that does not require tweaking and creates predicable control.

Getting to a predicable power control schema does not remove the many other errors that effect engraving such as those created by the LPS, optical subsystem and materials variations. It does however eliminate unnecessary control systems errors.

Predictable Digital Laser Power Control:

A better approach is to use the "L" input control signal. On some supplies this input can be found on the LPS DC connector and on others it is on both the DC connector and the center digital control connector. On other supplies the equivalent of "L" is TH or TL.

The "L" or TL control is a digital input that responds ONLY to ground to turn on the laser.

With a proper PWM signal connected to "L" and the "IN" line pulled to 5VDC (analog full on) the LaserPowerOut function becomes:
  • LaserPowerOut (watts) = SoftwareDF(%) * LaserPowerMax
You can see that this configuration elliminates all the control errors outlined above.

Note: Proper PWM control using "L" is to ground the "L" pin during the PWM's on period. An open drain or open collector is the best electronics circuit to use.


Section 3: The Laser is a Consumable: 

The laser in the K40 is a consumable meaning that the lasers power will decrease with use and time. This introduces another error in the digital control system in that LaserPowerMax will change over time. If the lasers max power decreases then the absolute intensity across a programmed grey scale will change. We need a way to adjust the overall intensity without changing the grey scales dynamic range nor relative values. This can be accomplished by leaving the "Current Regulation" pot installed in its stock configuration. This pot controls an internal power output vs current setting internal to the LPS unrelated to "L" PWM value.

Doing this changes our LaserPowerOut function to:

* LaserPowerOut (watts) = SoftwareDF(%) * (RelativePotPosition(%) * LaserPowerMax)

Now think of the "Current Regulation" pot as an overall Intensity Control. This configuration allows the max power of the laser to be a fixed adjustment while allowing the PWM to control the dynamic power within the range of (ReleativePotPostion * LaserPowerMax) values.

Configuring Max Power @ the Smoothie:

Another consideration in managing the K40's laser power is to limit the current to 18ma max. Even thought some lasers can output more than 18ma it is not recommended to run them above this level because this can reduce the lasers life. However the light power output @ 18ma will change as the laser ages and therefore the power supplies "Intensity" setting will need to change to keep the same light output at 18ma.

Configuring laser power in the smoothies configuration file three things can be controlled:

An example set of  a typical smoothie configuration:
laser_module_maximum_power                   .8         
laser_module_minimum_power                   0.0         
laser_module_default_power                        0.3                        
laser_module_minimum_power                   0.0            
laser_module_default_power                        0.3        

Without an manual "Intensity" control to insure the laser does not exceed its 18ma limit under PWM control, the smoothie configuration would need to change as the laser wears.

1. Putting the "Current Regulation" pot at max and pressing test resulted in a current = 24ma
2. Since we do not want the laser to run above 18ma we need to set

  • laser_module_maximum_power = 18/24 = .75 

After 6 months of use the current at max pot position now reads 19ma. Therefore we need to reset

  •  laser_module_maximum_power = 18/19 = .95 

With the "In" + "Intensity Control" installed as explained above the Smoothie's configuration file would not need to change. Adjust the "Intensity" knob so that when the "Test Switch" is pushed the laser does not exceed 18ma. As the laser wears the actual position of the "Intensity" knob will migrate clockwise yet the configuration file will not need to change. At the point that the current cannot attain 18ma at the max intensity position the laser may need replacement if you want the same level of darkness in an engraving.

This is how I would configure the Smoothie's control:

laser_module_maximum_power                   1.0         
laser_module_minimum_power                    0.0         
laser_module_default_power                         0.3                          
laser_module_minimum_power                    0.0         
laser_module_default_power                        0.3            


Section 4: Finding the PWM Period for Optimum Engraving

What should the PWM period be set to for the best engraving?

Design requirements:

  • The time that the laser controller has the opportunity to turn the laser on/off during writing a pixel must be <= the time it takes the gantry to traverse that pixel. Otherwise there will be a loss of resolution.
  • To apply full power to a pixel the power would be held on for a full pixel time, for 50% power it would be held on for 1/2 a pixel time and so on.
  • Ideally the period of the PWM should be much shorter than a pixel time so that multiple PWM cycles can have the opportunity to control the power within a single pixel time. We will call this PWM Control Resolution and it is defined as the # of PWM control cycles in a pixel period. I don't know what the minimum practical value for PWM Control Resolution would be because it depends on the ability of the PWM to be syncronized with a pixel time. The theoretical value is 1 if there are no synchronizing errors between the PWM assertion and the pixel generation.  A more safe value is at least 2.  A 10x factor would likely eliminate any errors cause by this factor.
The relationship between Pixel time and PWM period.

The K40 PWM Model

The optimum setting for PWM is dependent on multiple interacting factors making choosing the PWM period a complex exercise. Therefore a model has been constructed that calculates a range of key values based on these inputs:
  • Image resolution (DPI):
  • Laser response time (us);
  • PWM Control Resolution # of PWM cycles (per pixel period);
  • Gantry speed (mm/sec):

What-if Scenario #1 Laser Response = 20us

Table 1: PWM periods @ 20 us laser response

Understanding the Models Output:

The red areas indicate unacceptable operating points
The white areas indicate acceptable operating points
Axis definitions; 
  • Top and bottom X = various PWM periods
  • Top table Y = gantry speeds (mm/sec)
  • Bottom table Y= 5% increments of grey shade in 

Table 1 Inputs:

  • Image resolution (DPI): 360
  • Laser response time (us); 20
  • Threshold # of PWM cycles (per pixel period); >=1
  • Gantry speed (mm/sec): 300

Reading Table 1:

Pick a column in the top table and read downward until you encounter a red cell. This is the point at which the # of PWM cycles falls below the threshold.
Keep scanning down the same column into the bottom table until you encounter another red/white cell intersection. This is the point at which the PWM pulse width is slower than the response time of the laser. 
Acceptable operating points are at the intersection between white and red cells. The operating parameters for that point can be found as the x row and y column labels for that intersection.

Finding an acceptable operating point is a combination of the top table and bottom table. The ideal operating point(s) is a column(s) in the bottom table that are fully white across the 100-5% range, meaning that the laser can respond to each of those grey shade steps.

Interpretation of Table 1:

In the top table @ the column labeled 200us move down to the row corresponding to 300mm/sec which contains a white cell of 1.18. This means that there are 1.18 PWM periods in a pixel time of 200use for a speed of 300 mm/sec. That is larger than our input threshold of 1 that is why it is white.

Continue down that column and look for a red to white transition in the bottom table. We find that at the row labeled 10% and the value in that cell is 20us which is equal to the laser response time we input to the model. The next cell below is white with a value of 30us which is larger than the lasers response time. This means that the laser may not respond fully and expose the surface if the PWM DF is set <=10%.

What is the optimum PWM value(s) suggested by Table 1

The default PWM period value of 20us (column 2) in the smoothie configuration table will not enable quality engraving if the laser response was actually 20us.

A better range of configuration values would be a PWM period of 200us to 400us.

What-if Scenario #2: Laser Response = 2us

Table 2: PWM with 2us laser response time
The laser response was set to an order of magnitude faster and the results of scenario 2 show that the system would engrave across the grey scale for PWM period values >= 40us.
At a PWM period of 20us the engraving would be  marginal for PWM DF values of less than 15%.  


Section 5: Smoothie Configuration Settings:

Default Smoothie Values

So what should the Smoothies PWM period be set to? The default in my configuration was:
  • laser_module_pwm_period                      20  (in micro-seconds)
The modelling exercise above suggests that 20us is not a good choice for a PWM period. At the slower laser response value it would produce poor engraving across the entire range and at the faster laser response it would be marginal at the lowest 2 shades of grey.

Marginal PWM Control Resolution with Excellent Grey Scale Reproduction

If we assume the fastest laser response measured so far (table 2) and stay within the K40 specifications of 300 mm/sec, a PWM period setting of 200us period would allow marginal PWM Control Resolution but perfect grey shade reproduction. 
Consideration: I am not certain if PWM Control Resolutions >1 are important to K40 engraving quality.

Good PWM Control Resolution with Excellent Grey Scale Reproduction

Slowing the speed to 100mm/sec @ a PWM period of 200us would improve the PWM Control Resolution almost 3x and still produce perfect grey shade reproduction. 

Recommendations for Engraving Settings

Start your engraving evaluation with these setting using a grey shade test pattern.  
  • PWM period = 200us
  • Speed= 300 mm/sec
If the quality is not acceptable independently try the following, while retaining the above PWM settings;
  1. Adjust the max power until you find an acceptable level at the lowest grey shade
  2. Lower the speed below 300 mm/sec until you find an acceptable level
  • Try combinations of the 1&2 above


Section 6: ToDo's 

  • Continue to test the lasers response under various pulse widths to determine practical values.
  • Test using grey shade scales, a series of model input values to validate the model.

Appendix A: Sources of Model Input

Laser Response

There is no point in setting a PWM pulse duration less than the lasers ability to respond! If at the lowest PWM DF the resulting pulse is shorter than the lasers response the laser will not turn on or at best will not reach full power during a pixel time. As an example, with a 20us PWM period the pulse time of the PWM at 5% DF is only 1us. If the lasers response time was 20us this pulse would not even be realized.

The effect of the lasers response

Key Question: 
How long does it take the laser to ionize and get to full power after it is digitally told to turn on? 

Research information:

Tests done in the PPI community use pulse duration's of:
  • Minimum PPI Pulse Time: 3-4ms or .003-.004 seconds
  • For reference this frequency = 250-333hz
From its use in successful PPI implementation I would assume that a laser can respond at this rate. However this is 3 orders of magnitude to slow for our engraving example (see calculations in Appendix B).

Laser Response Testing :

The following summarizes tests I conducted in an attempt to characterize the 40 watt K40 lasers response.

Test Approach

Measure the rise time of current in the lasers cathode circuit as an indirect method of determining the lasers response time. The test makes the assumption that the lasers light output rise times are similar or faster than electrical rise times. This approach is being used after attempts to measure the actual lasers light output failed. Reasons for failure include:
  • Standard digital sensors have no response in the far infared (10600nm)
  • The power at the output destroys most sensors
  • Pyroelectric devices have long response times.

Test Setup:

  • Oscilloscope channel 1: in the lasers cathode circuit, @ the current meter on the control panel
  • Oscilloscope Trigger: Test button closure

Channel 1: Cathode current rise time = 1.84us

Channel 1: Cathode current rise time = 1.9us

Channel 1: Cathode current rise time = 20us

  Channel 1: LPS internal PWM.   Period = 408us

Test results

  • Rise times in the range of 1.84 to 20us were measured. 
  • There is evidence that rise times of < 2us are possible.
  • The LPS internal PWM is 408us. This may be an indicator of what the manufacture felt was a good PWM period for the K40. 
    • Referring to the model above 400us allows only .59 PWM cycles @ the rated 300 mm/sec. 
    • A related consideration is that stock K40 does not engrave with grey scales instead the image is dithered. Therefore small variations in PWM synchronization may not be visible. 
    • It is also possible that this is an error in the stock K40 that was not addressed
More testing is needed to rationalize and verify the relationship between cathode current and laser output responses. In the mean time these values will be used in an effort to "what-if" model K40 engraving operating ranges (see the model above).

Appendix B: Specifications and Calculations 

Stock K40 specs:

  • MAX: 600mm/S 
  • Carving: 7mm/S 
  • Cutting: 0.5mm/S 
  • X-Axis Motor: 0.33A/Phase 
  • Y-Axis Motor: 0.44A/Phase

Technical Parameters:
Interface to Computer: USB Port
Tube Trigger Volt: 20KV;Tube Operating Volt: 15KV
Engraving Area: 260x180mm
Maximum Item Size to Engrave: 10.25W x 8.75L x 2.85H in (260mm x 220mm x 70mm)
Laser Tube (life hours): 1000-1300 Hours
Laser Power: 40W
Engraving Speed: 0-13.8 in./s (0-350mm/s)
Cutting Speed: 0-1.38 in./s (0-35mm/s)
Minimum Shaping Character: 0.04 X0.04in (1mm X 1mm)
Resolution Ratio: 0.001 in (0.026mm) / (1000dpi)
Resetting Positioning: 0.0004 in (0.01mm)
Software Supported: MoshiDRAW software (both NewlyDraw and NewSeal function)
Power Consumption: 250W
Operating Temperature: 32-113F (0-45C)
Recommended Spare Parts/Consumables: Laser Tube, Focal lens, Reflection lens
Voltage: 110V~240V
Frequecy: 50Hz~60Hz

Example Calculations for Typical Engraving Configurations:
  • Image Resolution (DPI): 360
  • Grey-scale increments (%): 5
  • Gantry speed(mm/min): 1500-1800
  • Gantry speed(mm/sec): 250-300 
  • Gantry speed (inch/sec): 9.84 - 11.81 inch/sec [K40 machine specification says: 13.8 in/sec]
  • Time to move one inch: .1016-.085 sec/inch [101.6 - 85 ms]
Calculated values using assumptions:
  • MinPixelPeriod: (.085 sec/inch) / (360 pixels/inch) = .000235 sec/pixel = .235ms/pixel [235us]
  • PWM frequency(hz): 4251 [4.251 khz]
  • PixelPeriod: 235 us

Simple formula for calculating MinPixelPeriod: 

  • MinPixelPeriod (us) = 1524000000/(speed (mm/min)) * DPI)
Example: 1524000000/(1800 * 360) = 1524000000/6480000 = 235.18

Links to Related Posts

References to More Information and Previous Work
Understanding CO2 lasers
Principles of plasma discharge
Dynamic PSpice Model of C02 Laser Tube
Gas Laser Electronics
Basic Laser Principles

Enjoy and leave comments and discussion;

Maker Don

K40-S Cabinet Modifications

Cabinet Modifications

I strive to make the minimal modifications to my K40 in hopes that I will keep what minimal mechanical integrity that it has.


Please consider donating (button to the right of this post).
Your donations help fund additional research, tools and parts that I will return to the community as information. 
For other information on the K40-S build use the  K40-S BUILD INDEX with schematics. 

Rear air duct

While I was making modification to the cabinet for the drag chain I cut back the rear air vent.
Some remove the entire vent but in my machine that requires that I remove the entire gantry and I just did not want to upset the machine that much and at this time.
I used a Dremel tool with a flexible shaft to cut this and the drag chain opening. I managed to bind the blade a few times and then burned up the dremel motor. I should have been more patient. I completed the cut with a angle grinder which in hindsight may have been a better choice.
Make sure that you tape you mirrors and use a vacuum while you are cutting. Laying a big magnet in the cabinet near your cutting is also a good idea.

Before cutting out the annoying vent. Note the cut lines.

After the vent is cut back

Controller Cabinet Cable Holes

There are two 1.5" holes drilled into the front of the K40 cabinet to allow cables to enter the controller cabinet. There is also 4x holes drilled for the controller cabinet mounting
Drawings coming soon.

One of the two large cable holes
Final controller cabinet assembly showing holes on left and right.

Enjoy and comment please
Maker Don

Sunday, December 18, 2016

K40-S Tool Chain

Design and Fabrication Tool-chain for the K40-S


I am sure that everyone has their view of what CAM can do for their tool chain.
For me the main thing CAM does is take a part drawing developed in CAD and modify it to be fabricated with a CNC machine. In this process the drawing is modified to account for the tools and process that are used to machine the part. Tool paths and changes are created within the capabilities of a particular CNC machine abilities and envelopes.
CAM software creates tool motions/paths such as: outside and inside cuts, plunges, tabs, folds, countersinks, center-lines and pocket faces, etc. It also manages the changing of tools and monitors the operation of the CNC machine within an manufacturing process. Note: many of these are not possible with a K40.
I found this nice guide while doing research:


Please consider donating (button to the right of this post).
Your donations help fund additional research, tools and parts that I will return to the community as information.
For other information on the K40-S build use the  K40-S BUILD INDEX with schematics

Tool chain

My overall goal is to be able to design & fab parts that can be made on any type CNC machine, including a Laser cutter, using the same master CAD design.

My 2017 plan is to add a CNC router to the shop using Sketchup/LaserWeb/Smoothie/ as the tool chain and controller.

I have learned that the variable in this tool chain is the CAM which customizes the CAD parts design to be fabricated on a specific machine. To that end I added SketchUcam to my SketchUp based tool chain with the use of Gcode as the base language. SketchUcam can store machine setup files that can be applied to the same CAD design enabling one to setup the same design for different type of machines.
This is the reason that I have stayed away from CAD output formats like DXF and am trying to get to Gcode based machine interfaces.

I see that LaserWeb is on an impressive journey to get CAM functionality as a front end to a CNC machines interface including engraving.

Now engraving ..... well that's another thing!

My Tool Chain Choices

There are many free and for purchase CAD/CAM programs available that will probably work with the K40-S configuration. I chose to stick with a tool chain with these main components:
  1. CAD: SketchUp and associated plugins for design and drawing
  2. CAM: SketchUCam for fabrication
  3. LaserWeb (LW) to drive the laser unit itself (not LW has many cam-like functions)
  4. Smoothieware as the devices firmware

Getting to know Gcode

Since Gcode is the underlying language for CAM cut files (for mills, lathes and lasers) it is a good foundation to get. It is also useful to set up Gcode tools and reference information so that we can understand, check and troubleshoot the Gcodes that are created during a parts journey through the CAD to CAM process.

I created another post that focuses more on the Gcode language vs the tool-chain, if you are new to Gcode I suggest you start here and then return to this post.

CAD with SketchUp

As indicated above I use SketchUp for mechanical design. The following plugins provide the export functions I need to import to LaserWeb.

STL/DXF plugin: 

This plugin exports STL and DXF files. This is the only plugin that I have found to provide DXF files for the free version of SketchUp that work. It also exports STL files so it is a good single choice for export in this tool chain.
When exporting DXF files directly to LaserWeb for cutting fabrication adjustments (for tools and tool paths) must be already included in those files.

Export Hints:

I spent a ridiculous amount of time to discover that to export DXF files from the plugin above the faces that are being exported must be flat on the X plane. Vertical faces are exported as a line.

Turns out that the object you want to export must be flat on the x axis to export anything but a line (for the x axis).

In this picture the vertical object (even if you select it face on) will not export correctly but both of those on the right will.

CAM: SketchUCam

It took me some prodding to realize what the practical difference between CAD and CAM was as it applies to fabrication on my K40-S, or any of my CNC machines for that matter. Note: There is a CNC mill in my future!
In my case the simple reason for CAM in my tool-chain is that the actual dimensions needed to fabricate a part are different than those designed at the CAD step. The main difference is the change in dimensions needed to account for the tool width and certain operations like drilling or milling. The CAD step creates a design that represents the finished part and the CAM step modifies that design to account for the tools used in its fabrication.
For example: the perimeter of a a 1" x 1" part must be increased by 1/16" (1/2 of the diameter) if a 1/8" diameter cutting tool is used.
This adjustment accounts for the kerf of the tool. Although in the case of laser cutting the kerf is very small (.15mm) it still exists and must be accounted for is parts are to be exactly the right size.
The good news is that CAM tools like SketchUcam will allow you to take a SketchUp design and while in SketchUp, create the Gcode cut file with the CAM related adjustments. That Gcode is then sent to the K40-S via LaserWeb.

SketcUcam plugin download (by Phlatboyz) @:
Instructions for SketchUcam:

SketchUcam Getting Started

I found these to be useful videos to initially learn SketchUcam

SketchUcam Updates:


LaserWeb is the last step in the tool chain before the K40-S controller. I chose LaserWeb because of these functions it supports:
  • Imports: .svg, .dxf, image files, .gcode files
  • Operating system independence: runs in browser
  • Networking: USB, Ethernet and wireless in the future
  • Firmware: Smothieware and GRBL compatible
The community:

Laserweb-Sketchup workflow references:

Operating CAD-CAM using LaserWeb

What I learned in my first serious encounter with LaserWeb v3

I assumed that STL slicing in LW

  • creates a list of slices defined by the slice size through the part and the parts height. 
  • then you can select what slice you want to add to the tool path and then view a single tool path with the "eye" button.

What I found using LW: 

  • I got the STL import to work but only with a 1x1x1 cube. It will not work with a 1x1 cube no matter what plugin I used. Seems other programs have trouble importing 2 dimensional STL files as well but they will error without loading. 
  • Some slices render with open segments
  • The "Preview tool path" button after defining a parameter for a single vector did not seem to do anything. IE: did now show a tool path view.
I found the following things were compounding my understanding of how to import issues for both

Imported DFX and STL files:

  • The tabbed views (All layers, tool paths, gcode view, slicedxxx)  aren't always in sync with changes to objects and sometimes you need to click in and out of them to get them to refresh after making a change in,  for example the TREE tab.
  • The Tab "eyes" don't always enable and disable the tool path views 
  • and you can't tell when an "eye" is selected cause it does not change color...
  • Sometimes one or more of the tab views disappear including the source tab and only reloading everything will get it back.
  • The last Gcode will remain in the Gcode tab even if you remove the object that created it from the pallet. . I.E. if you x out everything from the TREE and open a new file the previous Gcode will remain until you generate a new set of code for the newly loaded object.


The community: 

The firmware in the K40-S, that is the software running on the controller, is Smoothieware. Although this software is buried in the tool chain it is important to understand what G&M codes the Smoothieware understands:

The main page:

Supported Gcodes:

Getting and updating the firmware:

Enjoy and comment,
Maker Don

Gcode: Getting Started

G-coding K40-S & LaserWeb

Getting started with numerical coding languages ......

G-code (or G programming language) is the street name for the most widely used numerical code programming language.  Utilized mainly in automation, G-code is sometimes called G programming language.  Very simply, G-code tells computerized machine tools - like laser systems - what to do and how to do it. For example, how fast to move, what path to take, etc.

M-code (for 'miscellaneous function') is an auxiliary command; descriptions vary.  Many M-codes call for machine functions like 'open workstation door,' which is why some say "M" stands for "machine", though it was not intended to.

A good starting point: 


Please consider donating (button to the right of this post).
Your donations help fund additional research, tools and parts that I will return to the community as information.
For other information on the K40-S build use the  K40-S BUILD INDEX with schematics


A good starting guide for CAD-CAM:

Gcode references:

Gcode's are somewhat universal in definition but various legitimate flavors exist depending on what software is injesting them and what machine they are controlling.
This post focuses on Gcoding that is compatible with the K40-S + LW configuration

What follows does not attempt to recreate the definitions in the links above, rather to document the differences. Refer to the references for complete treatments other than the changes outlined below.

Gcode Simulators/Editors;

For learning and developing Gcode these tools are useful:


Although Gcode is a standard for talking to CNC devices the implementation and interpretation of these codes can vary. This is clearly a case of "your results may vary". The best approach is to create a series of tests that emulate the Gcodes you plan to employ and see how they react. 
For example and in the case of a laser cutter, the way the laser cuts is different than a mill therefore to control power a parameter for setting the lasers PWM is needed. In the K40-S that parameter is the "S" value.
You must understand the adaptations your machines interface software (LaserWeb) and firmware (Smoothieware) have made to properly control the target machine.

Gcode hand coding:

I have found these conventions to be useful in G-coding in a way that is universally interpreted correctly. This is especially true in LaserWeb.
  • Put each Gcode and its parameters on a separate line
  • Use capital letters for parameters i.e. X,Y,Z,F
  • Use at least one decimal place on numbers I.E. G1 X1.0
  • Absolute positioning (G90) is less confusing than incremental positioning (G91) and less likely to run gantries into the stops.

Special K40-S Gcode formats

Adapted Gcodes for K40-S follow.

The G01 command

G01 <X Y F S>
  • X- x position
  • Y- Y position
  • S- Laser power in decimal from 1(max) - 0(min)

Currently Unsupported LaserWeb Gcodes

G20 will be ignored and all values will be interpreted as metric. Example: 1" will render as 1mm

Mcodes (Machine options)

Coordinate systems:

Coordinate systems in CNC can be very confusing but in 2D laser systems they are the simplest. In fact when using software like LaserWeb the complexity of the coordinate systems is transparent to the user.

However there are advanced times when you want to understand the machines movements within the context of the coordinate systems so here is some information.

WCO: Work coordinate offset.

When using your K40 the WCO and MCO aren't important as LW hides this complexity and describes positions within one system.

There are six user-definable work coordinate systems (WCS) available that are selected with the G54-G59 commands (Note that if using Carbide Motion it seems to store position information in G54 and will over-write any user setting). These are modal, meaning that once you select a WCS all following commands will reference that coordinate system until you select a different one. They are also persistent, meaning that they will be stored between resets and power cycles.

MCO: Machine coordinate offset.

Machine coordinate system. The systems initial home at power on.

Enjoy and comment,
Maker DON

K40-S & LaserWeb3 startup

A K40-S/LaserWeb3 Quick Start

This post captures the process that I went (going) through to get LaserWeb up and working.
In my tool chain LaserWeb serves as the web based interface component of my K40-S tool-chain.

Check back here or at the links included below when the LaserWeb is updated as these instructions may change.


Please consider donating (button to the right of this post).
Your donations help fund additional research, tools and parts that I will return to the community as information.
For other information on the K40-S build use the  K40-S BUILD INDEX with schematics


Follow these instructions. Make sure you install GIT as the instructions suggest.

To Start LaserWeb3

cd \laserweb3
c:\ laserweb3\ node server.js

To Update

cd \
cd:\laserweb3>git pull

Clean the browser cache (CTRL-F5) after a git pull, because otherwise some code might be loaded from cache instead the new sources.

Initial setup values

Go to the settings menu and enter these initial values

Size Menu

X-length: 300 mm
Y-length: 200 mm
Laser Beam Diameter: .15 mm
Cutting Mat Thickness: 0 mm
Air Assist Noxzzle: Disable

Default Import DPI

Generic SVG: 72
Inkscape: 90
Illustrator: 72
Bitmap: 300


Optional entries (Opt) are ignored for now

Concatenate Raster x Moves: Disable
Start G-code: Opt
Laser ON Command:Opt
Laser OFF Command: Opt
PWM max: 1
Homing sequence: G28.2
NOTE: G28 will not home corrctly insure you use G28.2
End Gcode: Opt
Travel Moves: 100 mm/s
LaserTest Power: Opt
LaserTest Duration: Opt

Tool Menu

Safety Lock: disable
CNC Cam: Disable

  • NOTE: enable this when you are loading GCODE files
  • You cannot engrave when this is enabled
Origin location: bottom left
Use Touch Numpads: Disable
Use Webcam Video Overlay: Disable
Remote Webcam URL: Opt.
Quote Tab: Show

Jog menu

Home: homes the laser to whatever postion you have set in the Smoothie's configuration file
Run Gcode: runs the gcode in the Gcode tab. Make sure you have executed "Genrate G-code" from the CAM tab after you load a file.
Abort: stops the jog (after a delay) and a dialog will appear with instructions for continuing.
Set Zero: sets the 0,0 position to whatever the physical position of the gantry. Typically this is lower left for a K40.

Set Zero sets the work offset, not the machine zero point.
If you are on Grbl, you must set $10=0 to see work coordinates on the dro, otherwise you will not see any change in the dro, when doing a Set Zero.
Be careful, if you move the 0,0 away from lower left you could drive the gantry into the stops since the safe area is smaller than your configuration setting.

Jog somewhere, see the dro show X100, Y100 for example? Click Set Zero X under the dropdown next to X DRO. See how the DRO shows X:0,Y100? You just zeroed X.
Jog X back to say 100: Dro shows X100, Y100
Click the set zero button itself: see how X0 and Y0 is shown in DRO? That zeroed all axes

Check Outline: moves the gantry, tracing an outline of the object. Caution: if the part is positioned toward the top of the pallet the gantry could be driven into the stops.

Loading Native Gcode

Gcode files can be loaded directly onto the pallet and run from the Jog menu
Some anomolies:
  • These tabs will not always show the gcode toolpaths accurately as it will drive the machine
    • Gcode View, Tool Path View
  • Generally the tool paths will always show in the "All Layers View"

Backup Settings

I will update this later.

Setting up log files

You will notice that the Start command opens a dos window that is in the background on your desktop. This window will show the communications between your K40 and LaserWeb. It is useful to capture these conversations when something is going wrong. You can tell if LW is sending the correct codes (your G-code may not be doing what you think) or if the hardware is not responding as expected, or whatever. 

To set up a LW log file start this batch file:


{leave these brackets out
  cd c:\laserweb3 
  start "LW Started with log file [LW3log] on Desktop" cmd /c "node server.js ^1> c:\Users\Owner\Desktop\LW3log.txt"
  start chrome http://localhost:8000/

The above .bat will create and write the LW console output to LW3log.txt on your desktop.
When started this way the LW console will not be visible but you can open the .txt file to do any analysis you need.
Enjoy and comment,
Maker Don