Hi, I had problem to convert 12v PWM output for fan(M106) to 5V TTL for Diode laser for Marlin control board. I found the documentation for optocoupler circuit to convert CMOS to TTL circuit.
https://www.bristolwatch.com/ele3/ele6.htm
Based on that, I fabricated the circuit on the image.
I used SKR v1.4 board and PC817 optocoupler. It worked quite well for Lightburn software.
PC817 optocoupler has in quite cheap price and fast switching speed enough for this application.
I used 470ohm resistor for 12v fan output. If you use 24v, you may increase the resistor to 1k.
Best Regards