ESP32-C3-Wroom-02 VSC - PlatformIO - Problem generating 4 PWM signals with the same starting front.
Posted: Tue Apr 25, 2023 6:37 am
Hi,
He looked a little in the forum before posting. I didn’t know how to find what I was looking for, so I came here to find out.
My specifications:
- I need to generate 4 PWM signals 25 kHz.
- They must start at the same time.
So I started by doing a search. I found indications with "ledc". Ok I started a code.
I can’t generate the 4 signals. One is frozen at 1 logic and doesn’t go down.
They are stripped using this method.
I’m looking for a way to keep the ledcSetup() and ledcAttachPin() configuration working. But I would have to write a solution to replace the 4 ledcWrite() that do not do the job properly.
At the limit, I have a test code to show you what I did, a copy of the statement I made with scanastudio. Maybe someone can help me recode a little in order to generate the 4 signals correctly.
platformio.ini
main.cpp
Thank you so much for your help.
He looked a little in the forum before posting. I didn’t know how to find what I was looking for, so I came here to find out.
My specifications:
- I need to generate 4 PWM signals 25 kHz.
- They must start at the same time.
So I started by doing a search. I found indications with "ledc". Ok I started a code.
I can’t generate the 4 signals. One is frozen at 1 logic and doesn’t go down.
They are stripped using this method.
I’m looking for a way to keep the ledcSetup() and ledcAttachPin() configuration working. But I would have to write a solution to replace the 4 ledcWrite() that do not do the job properly.
At the limit, I have a test code to show you what I did, a copy of the statement I made with scanastudio. Maybe someone can help me recode a little in order to generate the 4 signals correctly.
platformio.ini
Code: Select all
[env:esp32-c3-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino
upload_port = COM[3]
;Used here to enable the use of the serial link: Serial.print("")
build_flags =
-DARDUINO_USB_MODE=1
-DARDUINO_USB_CDC_ON_BOOT=1
Code: Select all
#include <Arduino.h>
// GPIO REEL
#define IO0 0
#define IO1 1
#define IO2 2
#define IO3 3
#define IO4 4
#define IO5 5
#define IO6 6
#define IO7 7
#define IO8 8
#define IO9 9 // Boot / Led for default
#define IO10 10
// PWM DECLARATION CHANNEL
#define IO0_PWM_CH0 0
#define IO1_PWM_CH1 1
#define IO2_PWM_CH2 2
#define IO3_PWM_CH3 3
#define IO4_PWM_CH4 4
#define IO5_PWM_CH0 0
// Variables
const uint16_t frequency = 25000; // Hz - 25 kHz
const uint8_t resolution = 8;
const int dutyCycle = 150;
void setup() {
// put your setup code here, to run once:
// PWM 1
ledcSetup(IO0_PWM_CH0, frequency, resolution);
ledcAttachPin(IO0, IO0_PWM_CH0);
// PWM 2
ledcSetup(IO1_PWM_CH1, frequency, resolution);
ledcAttachPin(IO1, IO1_PWM_CH1);
// PWM 3
ledcSetup(IO2_PWM_CH2, frequency, resolution);
ledcAttachPin(IO2, IO2_PWM_CH2);
// PWM 4
ledcSetup(IO3_PWM_CH3, frequency, resolution);
ledcAttachPin(IO3, IO3_PWM_CH3);
}
void loop() {
// put your main code here, to run repeatedly:
/**
* @brief We are looking to generate 4 identical signals starting at the same time.
* */
ledcWrite(IO0_PWM_CH0, 50);
ledcWrite(IO1_PWM_CH1, 50);
ledcWrite(IO2_PWM_CH2, 50);
ledcWrite(IO3_PWM_CH3, 50);
delay(100); // For measurement
ledcWrite(IO0_PWM_CH0, 0);
ledcWrite(IO1_PWM_CH1, 0);
ledcWrite(IO2_PWM_CH2, 0);
ledcWrite(IO3_PWM_CH3, 0);
/* At this place, I’d like to do this */
// Same PWM started at the same time
//write(IO0_PWM_CH0, 50, IO1_PWM_CH1, 50, IO2_PWM_CH2, 50, IO3_PWM_CH3, 50);
// PWM started at the same time with a different frequency
// write(IO0_PWM_CH0, 50, IO1_PWM_CH1, 100, IO2_PWM_CH2, 150, IO3_PWM_CH3, 200);
while(1); // Stop generating signal
}