Creating two different Clocks with different Frequencies and Different Duty Cycles with LEDC

mehdi.na94rm
Posts: 10
Joined: Mon Jun 17, 2019 4:04 pm

Creating two different Clocks with different Frequencies and Different Duty Cycles with LEDC

Postby mehdi.na94rm » Mon Jun 17, 2019 4:16 pm

Hi Everyone,

I am trying to use LEDC command to create two different clock signals to switch two sensors at different times to measure them the voltage. To make it simple I am just writing a code to turn on the LED at two different ports with different frequencies and duty cycles. Unfortunately I cannot separate them and both ports always work at the same frequency and the same duty cycles. Here is my simple code, I would be happy if you can help me on that:

// the number of the LED pin
const int ledPin = 16; // 16 corresponds to GPIO16
const int ledPin2 = 17; // 17 corresponds to GPIO17
//const int ledPin2 = 18; // 18 corresponds to GPIO18

// setting PWM properties
const int freq = 1000;
const int freq2 = 5000;

const int ledChannel = 0;
const int ledChannel2 = 0;
//const int ledChannel2 = 0;

const int resolution = 10;

void setup(){
// configure LED PWM functionalitites
ledcSetup(ledChannel2, freq2, resolution);
ledcSetup(ledChannel, freq, resolution);

// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
ledcAttachPin(ledPin2, ledChannel2);
//ledcAttachPin(ledPin2, ledChannel2);

}

void loop(){

const int dutyCycle = 1024;
ledcWrite(ledChannel, dutyCycle);


const int dutyCycle2 = 64;
ledcWrite(ledChannel2, dutyCycle2);


// const int dutyCycle2 = 256;
// ledcWrite(ledChannel2, dutyCycle2);
// delay(20);


}

Who is online

Users browsing this forum: ramier and 85 guests