I recently bought a
"500mW" laser diode from Aliexpress, planning to mount it to my printer and use it to expose UV sensitive film on PCBs for etching. About a month ago I finally got around to actually mounting it and testing. It worked great on full power; better than I expected, as I was able to etch through paint, albeit at an incredibly slow feed rate. So I could bypass the whole finicky process of trying to get the UV film attached to the boards and then developing it after exposing. Great!
But then I was trying to vary the laser's output power so I could try my hand at greyscale engraving. I've read a few posts where people just hooked their laser's power to their fan PWM and controlled the output via M106 Sxx. That didn't work for me. I got nothing from S1-S7, a faint spot that didn't vary in apparent brightness from S8 to about S16, and then full power from S17 on through S255. So that was a wash, plus I read that cycling the power input on a laser driver that was built for TTL brightness control would kill the diode in short order. So I started looking into getting a TTL signal from my printer control board.
I'm using an MKS Base v1.4 control board running Marlin for my printer. I'm not using the X+ endstop (D2), so I set that in Marlin's configuration as my laser/spindle speed pin. Hooked up a multimeter, and I could see my average voltage vary as I changed the duty cycle of the PWM signal via M3 Sxx. Although the lowest voltage I could get was around 0.89V at S1, not close to 0V as I'd expect. Also found that I hit the full 5V at S100, not S255, so apparently the laser power range is 1-100, not 1-255 as with the fan PWM. But I was getting a PWM signal from D2, so I hooked it up to the TTL input on the laser driver.
The laser wouldn't power on. Disconnecting the TTL input caused the laser to come on. After some head-scratching, I realized that my seller's pinout for the TTL input was reversed. They're using the same exact picture of the control board as every other seller on Aliexpress, but they switched the polarity on the TTL for some reason. After switching the pins, I found the laser came on at full brightness no matter what the PWM duty cycle was set for. M3 S1 all the way to S100 gave full brightness on the laser. Verified with my multimeter that my average voltage was indeed swinging between ~0.89V-5V as the PWM changed. Laser driver didn't care.
I thought perhaps there was something wrong with the PWM output of D2, expecially since it didn't go all the way to 0V. Plus I'd like finer control over the power than 100 steps when outputting greyscale. So I built a 12V->5V voltage divider and hooked up the fan's PWM (D9) to the TTL input so I could control it with M106 Sxx. This gave me a range of 0V-4.9V, as the divider values weren't perfect. Same thing; full power all the time.
I was starting to suspect maybe I damaged the TTL input of the driver by reversing the polarity originally. I have a component tester that can output a PWM signal, so I hooked the laser up to that. To my surprise, it worked perfectly. A 1% duty cycle gave me a nice dim spot and I could smoothly ramp up the brightness as I worked my way up to 100%. I checked the frequency of the component tester's PWM, which was around 7KHz IIRC. Checked D2 on the MKS Base, and it was around 490Hz. Couldn't get a good reading on the fan PWM. But I thought maybe the PWM frequency from the MKS Base was too low for the laser driver. Tried changing every setting in Marlin pertaining to PWM. Soft PWM with varying multipliers, fast fan pwm, everything I could find. Nothing worked.
I set the laser aside for the time being. About a week later, I melted the main power terminal on the MKS while experimenting with PETG, as I don't currently power the bed through a MOSFET and apparently that would be a bright idea. I had a spare MKS Base, so I swapped the control boards and decided to try the laser again to see if the new board acted any differently. No change.
I decided to try varying PWM frequencies to see what frequency range the laser driver would work with. I modified the "Fading" sketch that comes with the Arduino IDE to allow me to change the PWM divisor, and thus the frequency. Hooked the laser driver up to D9 on an Arduino Uno and tried every allowable divisor. The frequency varied from 30Hz to around 30.5KHz, and every one of them worked. Even the 30Hz allowed brightness control, although it was so slow I could see the laser flickering on and off. A divisor of 128 gave me a frequency of 490Hz, the same as D2 on the MKS Base, and it controlled the laser brightness perfectly.
In the meantime, I had ordered another laser, this time
an EleksMaker "3.5W" diode from Banggood. The first laser worked but required such a low feed rate that a decent sized board would take hours, even if only doing isolation cuts. So I wanted a more powerful laser to speed it up, plus I was hoping the TTL on the new laser would work with my MKS Base out of the box. Got that laser in today. Hooked it up, and had the same results as the first one. My component tester and my Arduino can control the brightness just fine. The printer's control board just gives full power all the time.
Out of desperation, I dragged my oscilloscope out to the printer to see what was going on. Hooked it up to the fan PWM on D9 and was surprised to find that it wasn't actually PWM on the fan pin. I had assumed the MOSFET on D9 would pass on the PWM signal, but apparently it just varies the voltage it allows through based on the PWM, so no wonder it didn't work when I tried to use it with the voltage divider. Checking D2, I found exactly what I expected based on my multimeter's measurements; a PWM signal varying from 0.89V to 5V. Tried the spare MKS Base board and got the same 0.89V to 5V. Hooked up my Arduino, and got an identical signal except that the range was from 0V to 5V. Other than that they literally look identical. Same frequency, same peak.
The only thing I can think of is that the TTL driver on the lasers sees the 0.89V as a logic HIGH instead of a LOW, so no matter what the duty cycle is it's always HIGH and thus driving the diode. Which seems strange; even if it were 3.3V logic, 0.89V should be LOW. Even moreso for 5V.
So is there a way to get the low output of D2 down closer to 0V without additional hardware? I'm about to throw together a high-pass filter to try to remove that DC offset, but I'd prefer a software solution if possible. Is that offset maybe not the problem? Anybody else have issues driving the TTL from an MKS Base or similar board? Is there something obvious that I'm missing here?