Skip to content

Calls to digitalWrite() don't work after a previous analogWrite() #58

Open
@technoblogy

Description

@technoblogy

Once you've generated PWM on a pin with analogWrite(), a subsequent digitalWrite() doesn't work.

Here is a sequence of calls and the resulting voltage on the pin (on core 0.8.7), compared to the same sequence on an original Arduino Uno R3:

Command Arduino R4 Arduino R3
pinMode(3, OUTPUT) 0V 0V
digitalWrite(3, HIGH) 4.7V 5V
analogWrite(3, 200) 3.68V 3.9V
digitalWrite(3, LOW) 3.68V 0V
digitalWrite(3, HIGH) 3.68V 5V

The R3 behaviour is what I'd expect.

Here's a visual demonstration of the problem. This program first blinks the builtin LED, and then pulsates it smoothly on and off:

void blink () {
  for (int i=0; i<5; i++) {
    digitalWrite(13, HIGH); delay(1000);
    digitalWrite(13, LOW); delay(1000);
  }
}

void pulse () {
  for (int i=0; i<5; i++) {
    for (int x=0; x<=255; x++) { analogWrite(13, x); delay(5); }
    for (int x=255; x>=0; x--) { analogWrite(13, x); delay(5); }
  }
}

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

void loop() {
  blink();
  delay(1000);
  pulse();
  delay(1000);
}

The call to blink() only works the first time around loop().

The same problem occurs on the Uno R4 WiFi.

Note: Originally posted on the Early Access Program forum, but still an issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: imperfectionPerceived defect in any part of project

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions