The custom driver worked perfectly. The laser power is now the B axis. B0 is off and B0.0255 is full power. I used a arduino nano to build the driver. The code is very simple:
const byte laserPin = 3;
const byte stepPin = 2;
const byte dirPin = 4;
volatile int brightness = 0;
volatile int dir = 0;
void setup() {
pinMode(laserPin, OUTPUT);
pinMode(stepPin, INPUT);
pinMode(dirPin, INPUT);
attachInterrupt(digitalPinToInterrupt(stepPin), step, RISING);
}
void loop() {
analogWrite(laserPin, brightness);
}
void step() {
dir = digitalRead(dirPin);
if (dir == LOW) {
if (brightness < 255) brightness++;
}
else if (brightness > 0) brightness--;
}
I ran a few jobs last night that were a couple hours long and it didn't lose a single step... but if you needed to re-zero the axis for a missed step you can just drive it to B1 and back to 0 since it ignores steps beyond the limits. The machine changes speed ever so slightly while changing the power since it's still doing coordinated motions, but it's way better than the spindle commands where it would literally stop for a half second and burn a hole.