Pulse Width Modulation (PWM) Control Considerations for Engraving
In RESEARCH PHASEI 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.
Donate:
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.
------------------------------------------------------------------------------
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
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 is the time increment over which the PWM control is applied.
- PWM frequency: The inverse of PwmPeriod is the PWM frequency.
Basic PWM definitions |
For 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 laser's 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 darkness that is proportional to other pixels in the image.
Note: A pixel time is a 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 grayscale or greyscale 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.
Dithering
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 laser's 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 the 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 resistance of the pot to 5VDC vs the resistance to ground changes with the position of the pot. 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
Note: this is not to say using IN will not work. I do 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 controller's 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 predictable control.
Getting to a predicable power control schema does not remove the many other errors that effect engravings 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 the 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
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 consumable meaning that the power of the laser will decrease with use and time. This introduces another error in the digital control system in that LaserPowerMax will change over time. If the laser's max power decreases then the absolute intensity across a programmed greyscale will change. We need a way to adjust the overall intensity without changing the greyscales 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 though some lasers can output more than 18ma it is not recommended to run them above this level because this can reduce the laser's 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 a 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.
Example:
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 synchronized 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 caused by this factor.
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 is fully white across the 100-5% range, meaning that the laser can respond to each of those grey shade steps.
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 laser's response time. This means that the laser may not respond fully and expose the surface if the PWM DF is set <=10%.
A better range of configuration values would be a PWM period of 200us to 400us.
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 greyscale for PWM period values >= 40us.
At a PWM period of 20us, the engraving would be marginal for PWM DF values of less than 15%.
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 is 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 which 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 laser's 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 |
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 modeling 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 settings 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;
- Adjust the max power until you find an acceptable level at the lowest grey shade
- Lower the speed below 300 mm/sec until you find an acceptable level
- Try combinations of the 1&2 above
Default Smoothie Values
So what should the Smoothies PWM period be set to? The default in my configuration was:
The modeling 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 settings 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;
- Adjust the max power until you find an acceptable level at the lowest grey shade
- 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 response of the laser under various pulse widths to determine practical values.
- Test using grey shade scales, a series of model input values to validate the model.
- Continue to test the response of the laser 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 laser's ability to respond! If at the lowest PWM DF the resulting pulse is shorter than the response of the laser it 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 laser's response time was 20us this pulse would not even be realized.
The effect of the response of the laser |
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 were 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 too 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 laser response.
Test Approach
Measure the rise time of current in the laser cathode circuit as an indirect method of determining the laser's response time. The test makes the assumption that the laser's light output rise times are similar or faster than electrical rise times. This approach is being used after attempts to measure the actual laser's light output failed. Reasons for failure include:
- Standard digital sensors have no response in the far infrared (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 meantime these values will be used in an effort to "what-if" model K40 engraving operating ranges (see the model above).
Test Approach
Measure the rise time of current in the laser cathode circuit as an indirect method of determining the laser's response time. The test makes the assumption that the laser's light output rise times are similar or faster than electrical rise times. This approach is being used after attempts to measure the actual laser's light output failed. Reasons for failure include:
- Standard digital sensors have no response in the far infrared (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 meantime 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
Current:0~22mA
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
Frequency: 50Hz~60Hz
Interface to Computer: USB Port
Tube Trigger Volt: 20KV;Tube Operating Volt: 15KV
Current:0~22mA
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
Frequency: 50Hz~60Hz
Assumptions:
- 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]
- 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)
Links to Related Posts
References to More Information and Previous Work
https://en.wikipedia.org/wiki/GrayscaleUnderstanding 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