|
|
@ -43,7 +43,7 @@ cutter_power_t SpindleLaser::menuPower, // Power s
|
|
|
|
#if ENABLED(MARLIN_DEV_MODE)
|
|
|
|
#if ENABLED(MARLIN_DEV_MODE)
|
|
|
|
cutter_frequency_t SpindleLaser::frequency; // PWM frequency setting; range: 2K - 50K
|
|
|
|
cutter_frequency_t SpindleLaser::frequency; // PWM frequency setting; range: 2K - 50K
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#define SPINDLE_LASER_PWM_OFF ((SPINDLE_LASER_PWM_INVERT) ? 255 : 0)
|
|
|
|
#define SPINDLE_LASER_PWM_OFF TERN(SPINDLE_LASER_PWM_INVERT, 255, 0)
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Init the cutter to a safe OFF state
|
|
|
|
// Init the cutter to a safe OFF state
|
|
|
@ -71,16 +71,23 @@ void SpindleLaser::init() {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Set the cutter PWM directly to the given ocr value
|
|
|
|
* Set the cutter PWM directly to the given ocr value
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void SpindleLaser::set_ocr(const uint8_t ocr) {
|
|
|
|
void SpindleLaser::_set_ocr(const uint8_t ocr) {
|
|
|
|
WRITE(SPINDLE_LASER_ENA_PIN, SPINDLE_LASER_ACTIVE_STATE); // Turn spindle on
|
|
|
|
|
|
|
|
analogWrite(pin_t(SPINDLE_LASER_PWM_PIN), ocr ^ SPINDLE_LASER_PWM_OFF);
|
|
|
|
|
|
|
|
#if NEEDS_HARDWARE_PWM && SPINDLE_LASER_FREQUENCY
|
|
|
|
#if NEEDS_HARDWARE_PWM && SPINDLE_LASER_FREQUENCY
|
|
|
|
|
|
|
|
set_pwm_frequency(pin_t(SPINDLE_LASER_PWM_PIN), TERN(MARLIN_DEV_MODE, frequency, SPINDLE_LASER_FREQUENCY));
|
|
|
|
set_pwm_duty(pin_t(SPINDLE_LASER_PWM_PIN), ocr ^ SPINDLE_LASER_PWM_OFF);
|
|
|
|
set_pwm_duty(pin_t(SPINDLE_LASER_PWM_PIN), ocr ^ SPINDLE_LASER_PWM_OFF);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
analogWrite(pin_t(SPINDLE_LASER_PWM_PIN), ocr ^ SPINDLE_LASER_PWM_OFF);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SpindleLaser::set_ocr(const uint8_t ocr) {
|
|
|
|
|
|
|
|
WRITE(SPINDLE_LASER_ENA_PIN, SPINDLE_LASER_ACTIVE_STATE); // Cutter ON
|
|
|
|
|
|
|
|
_set_ocr(ocr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SpindleLaser::ocr_off() {
|
|
|
|
void SpindleLaser::ocr_off() {
|
|
|
|
WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_STATE); // Turn spindle off
|
|
|
|
WRITE(SPINDLE_LASER_ENA_PIN, !SPINDLE_LASER_ACTIVE_STATE); // Cutter OFF
|
|
|
|
analogWrite(pin_t(SPINDLE_LASER_PWM_PIN), SPINDLE_LASER_PWM_OFF); // Only write low byte
|
|
|
|
_set_ocr(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
@ -97,7 +104,7 @@ void SpindleLaser::apply_power(const uint8_t opwr) {
|
|
|
|
ocr_off();
|
|
|
|
ocr_off();
|
|
|
|
isReady = false;
|
|
|
|
isReady = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (enabled() || ENABLED(CUTTER_POWER_RELATIVE)) {
|
|
|
|
else if (ENABLED(CUTTER_POWER_RELATIVE) || enabled()) {
|
|
|
|
set_ocr(power);
|
|
|
|
set_ocr(power);
|
|
|
|
isReady = true;
|
|
|
|
isReady = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|