Nevercast,
Thanks for your comments. I did so and used almost the same method to generate the pulses. By the way, I am using these six pulses to turn on 6 switches in different periods to measure 3 sensors differently with the same hardware and also discharge the output during three different switches.
Regards,
Mehdi
Using LEDC for generating two pulses
-
- Posts: 10
- Joined: Mon Jun 17, 2019 4:04 pm
Re: Using LEDC for generating two pulses
Hi, i need to generate two different PWM signals on two different pins on the ESP32
However im not getting it, i have tried different codes but i guess my problem is when im configurating the channels, i read they need to have different channel numbers but still the multimeter is not showing different PWM freq
#include <driver/ledc.h>
//the number of the LED pin
const int ledPin = 15; // 16 corresponds to GPIO16
const int ledPin2 = 18; // 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 = 5;
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 = 1024;
ledcWrite(ledChannel2, dutyCycle2);
}
However im not getting it, i have tried different codes but i guess my problem is when im configurating the channels, i read they need to have different channel numbers but still the multimeter is not showing different PWM freq
#include <driver/ledc.h>
//the number of the LED pin
const int ledPin = 15; // 16 corresponds to GPIO16
const int ledPin2 = 18; // 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 = 5;
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 = 1024;
ledcWrite(ledChannel2, dutyCycle2);
}
Who is online
Users browsing this forum: No registered users and 36 guests