Skip to content

ESP32-S2 PWM for a Servo pulse #5050

Closed
@StuartsProjects

Description

@StuartsProjects

ESP32-S2 PWM settings do not work as expected.

The code bellow when run on an ESP32 WROOM Development board, generates 1ms and 2ms pulses at 50hz, works as intended. It correctly produces a pulse to control a servo that shifts between 1m2 and 2mS.

/*
On ESP32 generates a sweeping pulse of 1mS to 2mS at 50hz
*/

const int servoPin = 17;

int dutyCycle = 0;

const int PWMFreq = 50;                                //50hz
const int PWMChannel = 0;
const int PWMResolution = 12;                       //12 bits 0-4095
 
void setup()
{  
  ledcSetup(PWMChannel, PWMFreq, PWMResolution);
  ledcAttachPin(servoPin, PWMChannel);
  ledcWrite(PWMChannel, dutyCycle);
}

void loop()
{
    ledcWrite(PWMChannel, 200);                     //approx 1ms
    delay(2000);    
  
    ledcWrite(PWMChannel, 400);                     //approx 2mS
    delay(2000);    
}

When the above code is run on a ESP32-S2 Saola board the pulse produced is not correct, it has a period of circa 1500mS and periods of 80mS and 160mS.

If in the code I change PWMFreq from 50 to 4096, I end up with a pulse that is 1ms to 2ms @ 50hz on the ESP32-S2.

Metadata

Metadata

Assignees

Labels

Status: StaleIssue is stale stage (outdated/stuck)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions