Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] No PWM on Pins 5, 6 and 44 (LED RGBW) ATmega2560 on MKS Gen L V2.0 #25018

Closed
1 task done
aviatorhh opened this issue Nov 25, 2022 · 7 comments
Closed
1 task done

Comments

@aviatorhh
Copy link

Did you test the latest bugfix-2.1.x code?

Yes, and the problem still exists.

Bug Description

Dear Development Team,

I have connected a LED RGBW strip via a transistor board to the Pins 5 (R), 4(G), 6(B) and 44 (W) and enabled RGBW_LED. When setting the values for LED lighting via M150 to S255 the corresponding LED illuminates. Setting a value of 254 or less the light switches off (0V at the pin). This does not affect pin 4 (G). This pin works as expected.
Even using M43 does not change the behaviour.
From past versions (v2.0.x) I can remember having pin 44 running on PWM before so I have seen PWM working on that board.

Bug Timeline

Seems to be from version 2.1 on

Expected behavior

I expected to dim all leds on pins 4, 5, 6 and 44 not on 4 alone.

Actual behavior

Only pin 4 dims and the others do not react to PWM values lower 255

Steps to Reproduce

e.g.

  1. M150 R255 (red led is on)
  2. M150 R254 (red led is off)

Version of Marlin Firmware

Marlin bugfix-2.1.x (Nov 25 2022 20:28:19)

Printer model

Anet A8

Electronics

MKS GEN L V2.0

Add-ons

No response

Bed Leveling

ABL Bilinear mesh

Your Slicer

Other (explain below)

Host Software

OctoPrint

Don't forget to include

  • A ZIP file containing your Configuration.h and Configuration_adv.h.

Additional information & file uploads

Using Slicer from Autodesk Fusion 360 (n/a to this issue)
Configs.zip

@ellensp
Copy link
Contributor

ellensp commented Nov 28, 2022

Most of your pins are in conflict

R is on pin 5
as is SPINDLE_DIR_PIN

G is on pin 4
as is FAN_PIN, FIL_RUNOUT_PIN and SPINDLE_LASER_ENA_PIN

B is on pin 6
as is SPINDLE_LASER_PWM_PIN and CASE_LIGHT_PIN

W is on 44
no conflicts

But even removing these pin conflicts, the PWM still fails to function.

@ellensp
Copy link
Contributor

ellensp commented Nov 28, 2022

A git bisect says e3e0735 is the commit that broke it

@ellensp
Copy link
Contributor

ellensp commented Nov 28, 2022

This fixes it.

diff --git a/Marlin/src/HAL/AVR/fast_pwm.cpp b/Marlin/src/HAL/AVR/fast_pwm.cpp
index e440315e00..3f17de5095 100644
--- a/Marlin/src/HAL/AVR/fast_pwm.cpp
+++ b/Marlin/src/HAL/AVR/fast_pwm.cpp
@@ -146,7 +146,7 @@ void MarlinHAL::set_pwm_frequency(const pin_t pin, const uint16_t f_desired) {
       LIMIT(res_pc_temp, 1U, maxtop);
 
       // Calculate frequencies of test prescaler and resolution values
-      const int f_diff = ABS(f - int(f_desired)),
+      const uint32_t f_diff = ABS(f - int(f_desired)),
                 f_fast_temp = (F_CPU) / (p * (1 + res_fast_temp)),
                 f_fast_diff = ABS(f_fast_temp - int(f_desired)),
                 f_pc_temp = (F_CPU) / (2 * p * res_pc_temp),

@aviatorhh
Copy link
Author

FYI my Pin debug. It may was confusing because I did not send in the changed pin definition files (MKS/RAMPS).

Recv: PIN: 4 Port: G5 RGB_LED_G_PIN Output = 0 TIMER0B PWM: 1 WGM: 3 COM0B: 3 CS: 3 TCCR0A: 3 TCCR0B: 3 TIMSK0: 3 overflow interrupt enabled

Recv: PIN: 5 Port: E3 RGB_LED_R_PIN Output = 0 TIMER3A PWM: 1 WGM: 1 COM3A: 1 CS: 0 TCCR3A: 1 TCCR3B: 0 TIMSK3: 0

Recv: PIN: 6 Port: H3 RGB_LED_B_PIN Output = 0 TIMER4A PWM: 1 WGM: 1 COM4A: 1 CS: 0 TCCR4A: 1 TCCR4B: 0 TIMSK4: 0

Recv: PIN: 44 Port: L5 RGB_LED_W_PIN Output = 1 TIMER5C PWM: 1 WGM: 1 COM5C: 0 CS: 0 TCCR5A: 1 TCCR5B: 0 TIMSK5: 0

ellensp added a commit to ellensp/Marlin that referenced this issue Nov 28, 2022
@ellensp
Copy link
Contributor

ellensp commented Nov 28, 2022

A PR to fix this issue has been created. Closing this issue.

@ellensp ellensp closed this as completed Nov 28, 2022
@aviatorhh
Copy link
Author

I can confirm the fix did it (at least on my side). All works as expected now. I tested manually with M150 and can also see the startup test going thru "all" colors. Great work! Thanks!

InsanityAutomation pushed a commit to InsanityAutomation/Marlin that referenced this issue Dec 4, 2022
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants