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

Only first call to analogWrite() working on ATtiny817 #1109

Open
caternuson opened this issue Jun 7, 2024 · 3 comments
Open

Only first call to analogWrite() working on ATtiny817 #1109

caternuson opened this issue Jun 7, 2024 · 3 comments
Labels
bug Something isn't working critical High priority issue or bug

Comments

@caternuson
Copy link

This may affect other variants, but was discovered and tested using an ATtiny817.
megaTinyCore release 2.6.10

Example sketch to demonstrate issue:

// attiny817 PWM pins: 0, 1, 9, 10, 11, 12, 13, 20
// works: 0, 1, 9, 10, 20
// issue: 12, 13

#define PWM_PIN 13

void setup() {
  pinMode(PWM_PIN, OUTPUT);
}

void loop() {
  analogWrite(PWM_PIN, 255);
  delay(2000);
  analogWrite(PWM_PIN, 0);
  delay(2000);
}

and an LED attached to the output pin.

For pins 0, 1, 9, 10, and 20, the sketch works as expected. The LED blinks.
For pins 12 and 13, only the first call to analogWrite() works. Changing 255 to 127 has the expected effect on brightnesls. But the LED never turns off.

@hmeijdam
Copy link

hmeijdam commented Jun 8, 2024

I can confirm your findings for pin 12 and 13 (PC0 and PC1). With a 3217 it also seems that analogWrite(PWM_PIN, 0) blocks further analogwrite to that pin. Changing it into analogWrite(PWM_PIN,1) gives no problems, so it seems that only setting it to "0" breaks the function.
13 (PC1) can only have PWM from TimerD (WOD), so I suspect that timer is used for analogWrite on these two pins. TimerD is also notoriously difficult to set up,

@SpenceKonde
Copy link
Owner

SpenceKonde commented Aug 30, 2024

Yes, it's related to a feature designed to improve analogWrite performance I'm surprised that this has gone unnoticed for this long,..

@SpenceKonde SpenceKonde added bug Something isn't working critical High priority issue or bug labels Aug 30, 2024
@caternuson
Copy link
Author

caternuson commented Sep 25, 2024

@SpenceKonde Is there an older BSP release version you could recommend as a temporary work around?

Thanks for checking and tagging this issue!

EDIT: Ran the above test walking thru previous release versions (just re-installing BSP via ard board man), based on that seems like the issue was introduced with 2.6.8. The 2.6.5 release works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working critical High priority issue or bug
Projects
None yet
Development

No branches or pull requests

3 participants