Skip to content

PWM channels of ESP32 #2660

Closed
Closed
@mimansamaheshwari

Description

@mimansamaheshwari

Hardware:

Board: ESP32 Dev Module
Core Installation/update date: 11/jul/2017
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 921600
Computer OS: Windows 8.1

Description:

I want to use 10 PWM channels of ESP32 for certain a task. I found no issue in working with 8 PWM channels at a time but as soon as I configure the 9th channel it does not work correctly. I am sharing a code that should change PWM of 10 channels after small delays. Is there anything wrong done by me in configuring channels?

Sketch:

int pin1 = 2;
int pin2 = 4;
int pin3 = 5;
int pin4 = 12;
int pin5 = 13;
int pin6 = 14;
int pin7 = 15;
int pin8 = 18;
int pin9 = 19;
int pin10 = 21;
void setup() {
  // put your setup code here, to run once:
  for (int i = 0 ; i < 10; i++)
  {
    ledcSetup(i, 50, 8);                      //50Hz , 8 bit
  }
  ledcAttachPin(pin1, 0);
  ledcAttachPin(pin2, 1);
  ledcAttachPin(pin3, 2);
  ledcAttachPin(pin4, 3);
  ledcAttachPin(pin5, 4);
  ledcAttachPin(pin6, 5);
  ledcAttachPin(pin7, 6);
  ledcAttachPin(pin8, 7);
  ledcAttachPin(pin9, 8);
  ledcAttachPin(pin10, 9);

}

void loop() {
  // put your main code here, to run repeatedly:
  for (int i = 0; i < 10; i++)
  {
    ledcWrite(i, 255);
  }
  delay(2000);
  for (int i = 0; i < 10; i++)
  {
    ledcWrite(i, 128);
  }
  delay(2000);
  
  for (int i = 0; i < 10; i++)
  {
    ledcWrite(i, 0);
  }
  delay(2000);
  
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions