Skip to content

Liberary doesn't work when generating a PWM signal (when pins 15 and 16 split the PWM and encoder) #112

@TheCorruptedEngineer

Description

@TheCorruptedEngineer

this is the code. if i remove the "ledcWrite(ledChannel, counter);" and "ledcAttachPin(ledPin, ledChannel);" everything works and the encoder position is kept track of. If the line is present 90% of the encoder rotations are not detected. I tried to change the ledChannel,frequency and resolution. it did nothing
I used a regular ESP32 Dev Module

#include <ESP32Encoder.h> // https://github.com/madhephaestus/ESP32Encoder.git
#define CLK 4 // CLK ENCODER
#define DT 15 // DT ENCODER
ESP32Encoder encoder;

const int ledPin = 16; // 16 corresponds to GPIO16
const int freq = 25000;
const int ledChannel = 0;
const int resolution = 8;
int counter = 50;
void setup () {
encoder.attachHalfQuad ( DT, CLK );
encoder.setCount ( 0 );
ledcSetup(ledChannel, freq, resolution);
ledcAttachPin(ledPin, ledChannel);
ledcWrite(ledChannel, counter);
Serial.begin ( 115200 );
}

void loop () {
long newPosition = encoder.getCount() / 2;
Serial.println(newPosition);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions