Laser PWM control
How to configure RRF to use a PWM driven laser module
This document is relevant to: Duet 2 WiFi / Ethernet, Duet 2 Maestro, Duet 3 MB6HC and Duet 3 Mini 5+
Firmware versions: RepRapFirmware 3.1.1 and 2.05.1
This guide covers connecting and configuring a PWM-driven laser module to Duet 2 and Duet 3 boards.
- Your laser runs on 12v
- Your laser requires a 5v active-high PWM
- You want to control the laser with M3 and M5 commands
- You have a laser module
- You have a Duet 2 or Duet 3 board
The Duet 3 main board revisions 1.0 and later, and the Duet 3 Mini 5+, have a 5V-level output that may be suitable for controlling your PWM laser directly.
The Duet 2 board will not be able to drive the laser's 5V PWM directly, and will need some interfacing electronics. The circuit diagram for the needed circuit, including protection for shorting of 3v3 line to prevent unintended Laser Power on is shown below.
Assuming the above assumptions are correct for you, then you can continue with this guide.
Connecting laser to Duet 2 - additional hardware
The Duet 2 board will not be able to drive the laser's PWM directly, and will need some interfacing electronics. The circuit diagram for the needed circuit, including protection for shorting of 3v3 line to prevent unintended Laser Power on is shown below.
There is an EasyEDA project here with the circuit, released as Open Source to utilise if needed.
You will need to provide +12V and GND to the laser module, along with PWM output from the above circuit.
The circuit uses surface mount components, so bear that in mind if you get a board made. If recreating the circuit with e.g. Veroboard, remember to buy the through-hole version of the applicable components.
Circuit operational theory
This circuit is based around the 74HCT02 Quad NOR Gate. The PWM heater output on the Duet acts on the negative side, to pull it low, rather than pulling it high, which is the inverse to what the Laser expects.
NOR truth table
A simple approach would be to connect the heater PWM to two input pins of the 74HCT02. According to the truth table above, when both inputs are low, output is high, and when both inputs are high, output is low. This gives us both an inverted signal, and a signal that is pulled high, rather than pulled low, which is what the laser wants. This also functions as a level converter, as the output from the 74HCT02 is based on the voltage you feed it (5V in this case).
In the above circuit, this is augmented with 3v3 short detection. This simply feeds the 3v3 lines into inputs
1B, such that when 3.3v is present,
1Y (output) is low, and when not present, it is high. This means that if for some reason, the Duets 3v3 is shorted to ground,
1Y will output high. As
1Y is tied to
2A, this will present at least 1 high input meaning that NOR gate 2 cannot output high (as seen in the table above).
Connecting laser to Duet 3
Connect the laser GND, 5V and PWM wires to the appropriate pins on the Duet 3. The 3-pin 5V PWM output on the Duet 3 Mainboard is behind the MicroSD card holder. Connect the PWM wire to the 'out9' pin.
For Duet 2, in your config.g file, you'll need to add the following:
M452 C"exp.heater3" R255 F200 ; Enable Laser mode, on exp.heater3, with max intensity being 255, and a PWM frequency of 200
For Duet 3, add the following to your config.g file:
M452 C"out9" R255 F200 ; Enable Laser mode, on out9, with max intensity being 255, and a PWM frequency of 200
In your config.g file, you'll need to add the following:
M307 H3 A-1 C-1 D-1 ; Disable Heater output on H3 M452 P3 R255 F200 ; Enable Laser mode, on output 3 (heater 3), with max intensity being 255, and a PWM frequency of 200
Controlling the laser
The recommended way to control a laser is to use S parameters on G1 commands to set the laser power. Most programs that generate GCode for laser devices have this option.
You can control the laser based on E values in G1, though this is no longer recommended. If you want to use this method, set the following:
ALL THE BELOW ARE NOT TESTED!
Duet 3, RRF 3.x: M571 P"out9" F200 S255
Duet 2, RRF 3.x: M571 P"exp.heater3" F200 S255``
Duet 2, RRF 2.x: M571 P3 F200 S255
The M307 command is used to set heating parameters. In this case, we use it to disable all applicable parameters as we'll be using it for PWM, not heating. See the notes here. Not needed if your are using RepRapFirmware 3.x.
The M452 command is used to select the laser mode in RRF, such as PWM that relates to max power, and the PWM frequency. See notes here.
If you're using any fans, be sure to remember that as you're not using any heaters, you should probably disable thermostatic control on any fans with the M106 H-1 command. See notes here.