⚗️ Use pwm_set_duty over analogWrite to set PWM (#23048)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
@ -70,7 +70,7 @@ void CaseLight::update(const bool sflag) {
|
||||
|
||||
#if CASELIGHT_USES_BRIGHTNESS
|
||||
if (pin_is_pwm())
|
||||
analogWrite(pin_t(CASE_LIGHT_PIN), (
|
||||
set_pwm_duty(pin_t(CASE_LIGHT_PIN), (
|
||||
#if CASE_LIGHT_MAX_PWM == 255
|
||||
n10ct
|
||||
#else
|
||||
|
@ -72,9 +72,10 @@ void ControllerFan::update() {
|
||||
? settings.active_speed : settings.idle_speed
|
||||
);
|
||||
|
||||
// Allow digital or PWM fan output (see M42 handling)
|
||||
WRITE(CONTROLLER_FAN_PIN, speed);
|
||||
analogWrite(pin_t(CONTROLLER_FAN_PIN), speed);
|
||||
if (PWM_PIN(CONTROLLER_FAN_PIN))
|
||||
set_pwm_duty(pin_t(CONTROLLER_FAN_PIN), speed);
|
||||
else
|
||||
WRITE(CONTROLLER_FAN_PIN, speed);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,11 +121,11 @@ void LEDLights::set_color(const LEDColor &incol
|
||||
|
||||
// This variant uses 3-4 separate pins for the RGB(W) components.
|
||||
// If the pins can do PWM then their intensity will be set.
|
||||
#define _UPDATE_RGBW(C,c) do { \
|
||||
if (PWM_PIN(RGB_LED_##C##_PIN)) \
|
||||
analogWrite(pin_t(RGB_LED_##C##_PIN), c); \
|
||||
else \
|
||||
WRITE(RGB_LED_##C##_PIN, c ? HIGH : LOW); \
|
||||
#define _UPDATE_RGBW(C,c) do { \
|
||||
if (PWM_PIN(RGB_LED_##C##_PIN)) \
|
||||
set_pwm_duty(pin_t(RGB_LED_##C##_PIN), c); \
|
||||
else \
|
||||
WRITE(RGB_LED_##C##_PIN, c ? HIGH : LOW); \
|
||||
}while(0)
|
||||
#define UPDATE_RGBW(C,c) _UPDATE_RGBW(C, TERN1(CASE_LIGHT_USE_RGB_LED, caselight.on) ? incol.c : 0)
|
||||
UPDATE_RGBW(R,r); UPDATE_RGBW(G,g); UPDATE_RGBW(B,b);
|
||||
|
@ -66,7 +66,7 @@ void SpindleLaser::init() {
|
||||
#endif
|
||||
#if ENABLED(SPINDLE_LASER_USE_PWM)
|
||||
SET_PWM(SPINDLE_LASER_PWM_PIN);
|
||||
analogWrite(pin_t(SPINDLE_LASER_PWM_PIN), SPINDLE_LASER_PWM_OFF); // Set to lowest speed
|
||||
set_pwm_duty(pin_t(SPINDLE_LASER_PWM_PIN), SPINDLE_LASER_PWM_OFF); // Set to lowest speed
|
||||
#endif
|
||||
#if ENABLED(HAL_CAN_SET_PWM_FREQ) && defined(SPINDLE_LASER_FREQUENCY)
|
||||
set_pwm_frequency(pin_t(SPINDLE_LASER_PWM_PIN), SPINDLE_LASER_FREQUENCY);
|
||||
@ -92,10 +92,8 @@ void SpindleLaser::init() {
|
||||
void SpindleLaser::_set_ocr(const uint8_t ocr) {
|
||||
#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);
|
||||
#else
|
||||
analogWrite(pin_t(SPINDLE_LASER_PWM_PIN), ocr ^ SPINDLE_LASER_PWM_OFF);
|
||||
#endif
|
||||
set_pwm_duty(pin_t(SPINDLE_LASER_PWM_PIN), ocr ^ SPINDLE_LASER_PWM_OFF);
|
||||
}
|
||||
|
||||
void SpindleLaser::set_ocr(const uint8_t ocr) {
|
||||
|
Reference in New Issue
Block a user