40640 and Creality 4.2.7 Ender5 Pro PWM Freq too low

I am currently trying to build new firmware for my ender5 (F1rstLayer 4.2.7) based on STM32F1 series I believe. I have the source for building from F1rstlayer and use Visual Studio/PlatformIO.

Found a fix involving changing from “Soft PWM” to “Hardware PWM” and increasing the frequency from 1k Hz to 31k Hz.

Do you know of a fix?
P.S. I have built a circuit to provide 5v PWM signal from FAN#2 (PA0) as the stock is 24v at the fan.

My current setup: (Found this fix on Github)
/////// ////////
P.S. For anyone who’s interested here’s the full list of changes to the firmware:

Set {&gpioa, &timer5, &adc1, 0, 1, 0}, /* PA0 */ in /Users/%USERPROFILE%/.platformio/packages/framework-arduinoststm32-maple/STM32F1/variants/generic_stm32f103r/boards.cpp
Commented #define FAN_SOFT_PWM in Marlin/src/pins/stm32f1/pins_CREALITY_V4.h
Uncommented #define FAST_PWM_FAN in Marlin/Configuration.h
Commented #define FAN_SOFT_PWM in Marlin/Configuration.h (DO NOT comment out #define SOFT_PWM_SCALE 0)
Set #define STEP_TIMER_NUM 4 // for other boards, five is fine. in Marlin/src/HAL/STM32F1/timers.h

This change after building sorta works with LightBurn, in that will not engrave below power setting 15 and will not go above 40 power. Also the power from laser seems to change with the speed setting also???

As is I do not think this is workable. I also tried max power setting in LightBurn 1024 instead of 255. I believe the STM32 is using 10bits for PWM but this did not help.

Okay, think we have SOLVED, still need to do some more testing with power and speed settings.

Remembering that the Neje 40640 likes 20kHz pwm or below, the hardware fix above did not work with 31kHz.

So, I went the other way, and commented out the FAST_PWM_FAN and uncommented the FAN_SOFT_PWM, and changed the SOFT_PWM_SCALE to 3, also uncommented SOFT_PWM_DITHER.

That build is working very well now, except the low end 5% or less will not FIRE in LightBurn. Will experiment with the lowest setting that will fire, cause I like the FRAME with laser to see your alignment.

Not fixed, laser worked okay, but when I switched to 3D printing (quick change mount) the bed did not heat up. Had to flash the 3D printer again without the PWM changes for the Laser.

Yes, PWM below 20kHz is recommended, but 30kHz will not damage your laser, but PWM is not linear with power increase
see also:

Thanks for the links.

With my last flash (Creality 4.2.7 board) the laser is working really good (power supply is only 2amps tho) but my heated bed did not work when I tried to print 3D, so I need to tweak the build.

No problem tho, I am planning on building a LASER dedicated only machine similar to the Neje Master 2 plus.
Thanks for the support,
David Hanson