Skip to content

Multiple analogWrites reset the PWM period on each write #4905

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

Closed
earlephilhower opened this issue Jul 8, 2018 · 0 comments
Closed

Multiple analogWrites reset the PWM period on each write #4905

earlephilhower opened this issue Jul 8, 2018 · 0 comments

Comments

@earlephilhower
Copy link
Collaborator

The following test shows on a logic analyzer that the PWM period is reset from the beginning on a pin which is used with analogWrite().

const int pin = D3;
void setup() {
  pinMode(pin,OUTPUT);
  analogWriteFreq(1000);
  analogWriteRange(1000);
}
void loop() {
  analogWrite(pin, 1);
}

This results in an improper 1-PWM-cycle ratio, and if called in a loop as shown can give a significantly different PWM result that desired.

earlephilhower added a commit to earlephilhower/Arduino that referenced this issue Jul 8, 2018
Setting a pin direction would cause a waveform generator attached to it to stop.
This could cause PWM to stop if pinMode() is called while running (as it was
called in __analogWrite()).

Remove the stopWaveform call from pinMode, the Tone, analogWrite, or Servo
that initiated the waveform has responsibility for stopping it (and it does)
when complete, irrespective of the pinMode.

Fixes esp8266#4905
earlephilhower added a commit that referenced this issue Jul 9, 2018
Setting a pin direction would cause a waveform generator attached to it to stop.
This could cause PWM to stop if pinMode() is called while running (as it was
called in __analogWrite()).

Remove the stopWaveform call from pinMode, the Tone, analogWrite, or Servo
that initiated the waveform has responsibility for stopping it (and it does)
when complete, irrespective of the pinMode.

Fixes #4905
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

1 participant