Welcome! Log In Create A New Profile


Laser driver TTL with MKS Base

Posted by chantling 
Laser driver TTL with MKS Base
December 04, 2017 07:17PM
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?
Re: Laser driver TTL with MKS Base
December 05, 2017 03:21AM
I also use the fan M106 command with RAMPS to trigger the TTL input, but I rerouted the signal to a different PWM-capable pin in pins.h, since the fan output is 12V not 5V.

Another safety related thing I do: I test new laser drivers with a common 3W LED. It acts the same as a Laser diode, but doesn't harm your eyes.
Re: Laser driver TTL with MKS Base
December 05, 2017 08:36AM
I didn't think about re-routing the M106 command to a logic-level pin; I wonder if that would fix the issue with the PWM low not going to 0V. Still can't figure out what's going on there; do all MKS Base control boards have that issue? Both of my BIQU ones do. I was hoping to get everything set up in such a way that I didn't change or remove any existing functionality, which is why I was trying to get my unused X+ pin set up for the PWM signal. I'm using an X-carriage with swappable plates and plug-in connections for the hotends/laser diode/whatever, so it just takes a couple of seconds to switch from my J-head to an E3Dv6 to a laser. Was hoping not to have to upload a different firmware for each one, as I envision swapping back and forth fairly regularly. The only reason I don't switch more frequently now is that it's a pain changing the offsets for each tool every time. I'm lazy as hell; there's essentially no amount of effort I won't put in to save myself a bit of work eye rolling smiley. Though I'm mostly worried about setting the machine aside for a few months and then trying to remember which firmware goes with which toolhead and where I stored it, what settings have to be changed, etc. But switching the fan pin would also get me 256 levels of control, too. May have to play with the spare controller to see how that works.

I got the laser driver working. I tested the TTL with a battery and a voltage divider and found that its HIGH threshold is 0.59V, which seems ridiculously low. My PWM signal from the MKS Base never went below 0.89V, so was always seen as high. I dropped the voltage through a couple of diodes to a low of around 0.23V; still didn't work. Added an LED and resistor in parallel to the laser driver, which dropped my signal to a range from 0V->4.1V. Didn't work. Built a high pass filter with a cap and a resistor, which basically gave me an AC signal centered around 0V with the HIGH going to ~2V and the LOW going to -2V. I figured that would surely work, because to date the only way I'd been able to turn off the drivers was by accidentally reversing the TTL polarity. It didn't work. I beat my head against a wall for a while. Pulled out some hair. Cried a little.

Finally found a simple circuit with a transistor and a few resistors that was designed to remove DC bias from a square wave without inverting it. The circuit gave me a range from 0V to 2.5V instead of the 0V-5V range the circuit simulation showed, but it worked! Soldered it up on a piece of perfboard using SMD resistors and it's only 12.5mm x 30mm, so I can shrink wrap it and leave it inline with the wiring harness.

I just wish I understood why none of the other solutions worked. I hate when electronics do something completely the opposite of what I expect and I can't figure out why.

Thanks for the tip about the 3W LED. I've got a few laying around; I'll have to dig one out and solder a connector onto it.
Re: Laser driver TTL with MKS Base
December 07, 2017 02:48AM
The MOSfets on the MKS board aren't fully switched open, that's where the 0.89V might come from. Same problem as on many RAMPS boards? The 5V onboard regulator is crap.
When the TTL input switches at 0.7V it looks like there is no resistor divider on board.
I hope your added circuit allows a fine tuneable and linear PWM?
Re: Laser driver TTL with MKS Base
December 10, 2017 09:05PM
It spits out the same waveform it takes in; just scaled from 0V to ~2.5V instead of 0.9V-5V. Several of the options I tried output a true 0-5V waveform matching the MKS' waveform except reaching 0V, but they didn't work and I've been unable to figure out why confused smiley. The input and output waveforms on the scope looked identical, but the driver wouldn't recognize them. Found a circuit using a resistor divider and a transistor online from somebody trying to remove DC bias from a square wave. Figured since that's what I'm trying to do as well I'd give it a shot, and it worked. Its output also looks identical to the ones that didn't work, albeit that it only reaches 2.5V on high, but both laser drivers accept it and modulate their brightness accordingly, so I made a cable for each laser.

The PWM response is linear on the scope. Can't say if the laser output is linear or not, as I haven't got a way to test the output. Thought about aiming it at a solar panel and monitoring the voltage change as I changed the PWM, but haven't gotten around to it yet. I can see the brightness change with the naked eye (well, the safety-goggled naked eye) for every step for maybe the first 20-25 steps. After that it's a bit harder to make out unless you go in 5 step increments. Above maybe 85-90 I can't see an increase in brightness.
Re: Laser driver TTL with MKS Base
December 11, 2017 03:09AM

The PWM response is linear on the scope. Can't say if the laser output is linear or not, as I haven't got a way to test the output. Thought about aiming it at a solar panel and monitoring the voltage change as I changed the PWM, but haven't gotten around to it yet. I can see the brightness change with the naked eye (well, the safety-goggled naked eye) for every step for maybe the first 20-25 steps. After that it's a bit harder to make out unless you go in 5 step increments. Above maybe 85-90 I can't see an increase in brightness.

Sounds familiar to me. It'll allow you to do gray scale engraving. The only problem still is, there is no adaption between XY-spped/acceleration and laser-PWM. You'll see slightly darker pixels at the turningpoint of a move from deceleration/acceleration.
You can try to increase the yerk setting above engraving speed ( at your own risk ).
I always add a white frame around the pics I want to engrave. That way the laser is off at the turningpoints.
Sorry, only registered users may post in this forum.

Click here to login