Skip to content

[ESP8266 - core 2.5.0]: BUGS in analogWrite functions #5957

Closed
@hasenradball

Description

@hasenradball

----------------------------- Delete above -----------------------------

Basic Infos

  • This issue complies with the issue POLICY doc.
  • [x ] I have read the documentation at readthedocs and the issue is not addressed there.
  • [x ] I have tested that the issue is present in current master branch (aka latest git).
  • [x ] I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • [x ] I have filled out all fields below.

Platform

  • Hardware: ESP12E
  • Core Version: 2.5.0
  • Development Env: Arduino IDE 1.88
  • Operating System: Windows 10

Settings in IDE

  • Module: NodeMCU1.0 (ESP12E)
  • Flash Mode:
  • Flash Size: 4MB
  • lwip Variant:
  • Reset Method:
  • Flash Frequency:
  • CPU Frequency:
  • Upload Using: Serial
  • Upload Speed:

Problem Description

If you use the function analogWrite(PIN, PWM) the you will find the following issues:

1.) the change of PWMRANGE via analogWriteRange(new_range) is not possible!
-> if you set 1000 or 255 for example there ist no change -> only 1023.

2.) if you write analogWrite(PIN, 0) the voltage is not zero -> an LED will not go off
-> if you write digitalWrite(PIN, LOW) the LED goes off.
-> for my understanding digitalWrite(PIN, LOW) and analogWrite(PIN, 0) should have the same effect on the Pin!
-> checked via Oszi

MCVE Sketch

#include <Arduino.h>
// #include <ESP8266WiFi.h>
#define LED 2
#define LED2 4

int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by

//=======================================================================
// Power on setup
//=======================================================================
void setup() {
Serial.begin(115200);
pinMode(LED, OUTPUT);
pinMode(LED2, OUTPUT);
analogWriteRange(1023);
delay(100);
Serial.println();
Serial.println(PWMRANGE);
}

//=======================================================================
// Main Program Loop
//=======================================================================
void loop() {
delay(5000);

for(int i = 0; i < PWMRANGE; i = i + PWMRANGE/10) {
analogWrite(LED, constrain(i, 0, PWMRANGE));
analogWrite(LED2, constrain(PWMRANGE - i, 0, PWMRANGE));
Serial.print("PWM: ");
Serial.print(i);
Serial.print(" \n\n");
delay(2000);
}

digitalWrite(LED2, HIGH);
delay(10000);

digitalWrite(LED2, LOW);
delay(10000);

//Continuous Fading
Serial.println("Fadding Started");
while(1)
{
// set the brightness of pin 9:
analogWrite(LED, brightness);
analogWrite(LED2, PWMRANGE - brightness);

// change the brightness for next time through the loop:
brightness = constrain(brightness + fadeAmount, 0, PWMRANGE);
//Serial.println(brightness);

// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= PWMRANGE) {
  fadeAmount = -fadeAmount;
  delay(4000);
}
// wait for 30 milliseconds to see the dimming effect
delay(20);

}
}
//=======================================================================

Debug Messages

Debug messages go here

Metadata

Metadata

Labels

waiting for feedbackWaiting on additional info. If it's not received, the issue may be closed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions