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

analogWrite on Atmel SAMD behaves differently than described by official Arduino documentation #304

Open
pauljurczak opened this issue Jun 27, 2021 · 3 comments

Comments

@pauljurczak
Copy link

I’m working with Atmel SAMD microcontroller on Adafruit Feather M0 board. Looking at the documentation here: https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/, I read that PWM will be stopped or changed by next call to analogWrite() (or a call to digitalRead() or digitalWrite()) on the same pin. In my tests, only analogWrite() affects the PWM on given pin, e.g.:

analogWrite(1, 128);
analogWrite(1, 0);

will leave pin 1 in low state, but

analogWrite(1, 128);
digitalWrite(1, 0);

will leave it producing 50% duty cycle PWM. Forum post https://community.platformio.org/t/analogwrite-on-atmel-samd-behaves-differently-than-documented/22202 has a detailed explanation why it's happening.

@pauljurczak pauljurczak changed the title analogWrite on Atmel SAMD behaves differently than described by official ASrduino documentation analogWrite on Atmel SAMD behaves differently than described by official Arduino documentation Jun 27, 2021
@ladyada
Copy link
Member

ladyada commented Jun 27, 2021

could be! want to submit a PR to tweak the behavior of digitalwrite to disable pwm output?

@pauljurczak
Copy link
Author

Sure, why not. Before I do, are there any performance reasons, which would make adding an extra conditional instruction

if (timer != NOT_ON_TIMER) turnOffPWM(timer);

not acceptable, e.g. bit banging on I/O port?

@ladyada
Copy link
Member

ladyada commented Jun 27, 2021

arduino isnt very performant - if it works on a variety of tests thats ok!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants