SPEED_POWER_SLOPE is divider. In additional to 0 min and 255 max it should be 1.0. And this means you can’t use same firmware for milling (with pwm controlled spindle and “real” rpm in S) and for laser (where 0-255 is usual). Or have to use M3 O128 like commands for laser.

Formula is

int16_t ocr_val = (spindle_laser_power - (SPEED_POWER_INTERCEPT)) * (1.0f / (SPEED_POWER_SLOPE)); // convert RPM to PWM duty cycle

NOMORE(ocr_val, 255); // limit to max the Atmel PWM will support

if (spindle_laser_power <= SPEED_POWER_MIN)

ocr_val = (SPEED_POWER_MIN - (SPEED_POWER_INTERCEPT)) * (1.0f / (SPEED_POWER_SLOPE)); // minimum setting

if (spindle_laser_power >= SPEED_POWER_MAX)

ocr_val = (SPEED_POWER_MAX - (SPEED_POWER_INTERCEPT)) * (1.0f / (SPEED_POWER_SLOPE)); // limit to max RPM

if (SPINDLE_LASER_PWM_INVERT) ocr_val = 255 - ocr_val;

WRITE(SPINDLE_LASER_ENABLE_PIN, SPINDLE_LASER_ENABLE_INVERT); // turn spindle on (active low)

analogWrite(SPINDLE_LASER_PWM_PIN