FlyingDutch
Advanced Member level 1
- Joined
- Dec 16, 2017
- Messages
- 458
- Helped
- 45
- Reputation
- 92
- Reaction score
- 55
- Trophy points
- 28
- Location
- Bydgoszcz - Poland
- Activity points
- 5,029
#include "ledc.h"
void setup() { //---------------------------------------------------------------------------------------
Serial.begin(115200); // use the serial port
ledc_timer_config_t ledc_timer;
ledc_channel_config_t ledc_channel;
//params ledc_timer
ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE;//LEDC_HIGH_SPEED_MODE;
ledc_timer.timer_num = LEDC_TIMER_0;
ledc_timer.bit_num = (ledc_timer_bit_t) LEDC_TIMER_1_BIT; //LEDC_TIMER_2_BIT;
ledc_timer.freq_hz = 1000000;
ledc_timer.clk_cfg = LEDC_USE_APB_CLK;
//params ledc_channel
ledc_channel.channel = LEDC_CHANNEL_0;
ledc_channel.gpio_num = 18; //WAS 18
ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE;
ledc_channel.timer_sel = LEDC_TIMER_0;
ledc_channel.duty = 1;
//Generacja zegara dla PCM1808
ledc_timer_config(&ledc_timer);
ledc_channel_config(&ledc_channel);
Serial.println("Program Started");
}//---------------------------------------------------------------------------------------
void loop() {
}
Hello @FvM,The timer is clocked by 80 MHz APB clock and not suited to generate 11.29 MHz. ESP32 has however a fractional audio clock for the I2S interface which is supporting 44.1 kS/s audio with usual frame formats. Review the I2S paragraphs in hardware and API reference.
I want to use external I2S ADC (the main reason is resolution of ADC) based on PCM1808 IC - see datasheet:The LEDC can be used for generating signals at much higher frequencies that are sufficient enough to clock other devices, e.g., a digital camera module. In this case, the maximum available frequency is 40 MHz with duty resolution of 1 bit. This means that the duty cycle is fixed at 50% and cannot be adjusted.
Lets assume that on this step I want to generate exactly 11 MHz square waveform (duty 50%).Hello @FvM,
so what clock I have to use: REF_TICK has only 1MHz frequency and RTC8M_CLK has f=8 MHz. See screenshot:
with documentation (Expressif). And here is citation from documentation:
I want to use external I2S ADC (the main reason is resolution of ADC) based on PCM1808 IC - see datasheet:
https://www.ti.com/lit/ds/symlink/pcm1808-q1.pdf?ts=1647175592223&ref_url=https%3A%2F%2Fwww.ti.com%2Fproduct%2FPCM1808-Q1
and this IC requires this external clock waveform on it's SCKI input (256*Fs) - where Fs is sampling audio signal frequency
Do you have any suspicions what can to cause such low amplitude (Below 1V) of generated waveform on I/O pin of ESP32 (even for low frequencies about few KHz)?
In worst case I am able to generate such frequency on small FPGA, but it result in unnecessary complexity of hardware for this project.
Thanks for your answer and regards
#include "ledc.h"
#define CLK_PIN (18)
void setup() { //---------------------------------------------------------------------------------------
Serial.begin(115200); // use the serial port
Serial.println("Starting ...");
gpio_reset_pin((gpio_num_t)CLK_PIN);
/* Set the GPIO as a push/pull output */
//gpio_set_direction((gpio_num_t)CLK_PIN, GPIO_MODE_OUTPUT);
gpio_set_drive_capability((gpio_num_t)CLK_PIN, GPIO_DRIVE_CAP_3);
ledc_timer_config_t ledc_timer;
ledc_channel_config_t ledc_channel;
//params ledc_timer
ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE;//LEDC_HIGH_SPEED_MODE;
ledc_timer.timer_num = LEDC_TIMER_0;
ledc_timer.bit_num = (ledc_timer_bit_t) LEDC_TIMER_14_BIT; //LEDC_TIMER_2_BIT;
ledc_timer.freq_hz = 4000;
ledc_timer.clk_cfg = LEDC_USE_APB_CLK;
//params ledc_channel
ledc_channel.channel = LEDC_CHANNEL_0;
ledc_channel.gpio_num = 18; //WAS 18
ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE;
ledc_channel.timer_sel = LEDC_TIMER_0;
ledc_channel.duty = 6000;
//Generacja zegara dla PCM1808
ledc_timer_config(&ledc_timer);
ledc_channel_config(&ledc_channel);
Serial.println("Program Started");
}//---------------------------------------------------------------------------------------
void loop() {
}
Hello,That looks very like the AC component only. Are you certain that you are looking at the pin directly (and not via some capacitor) and have the scope set up for DC?
What if you simply drive a GPIO pin up and down directly, perhaps with a bit of delay in the 'while' loop (without a delay you can certainly run into slew limitations)?
Personally I would not try to use the Arduino framework for the ESP32's - it takes a while to get used to it but the ESP-IDF framework does let you get closer to the hardware. (I use VS Code as the IDE with the PlatformIO framework that automatically brings in the ESP-IDF if you ask it to.)
Susan
#include "ledc.h"
#define CLK_PIN (18)
void setup() { //---------------------------------------------------------------------------------------
Serial.begin(115200); // use the serial port
Serial.println("Starting ...");
gpio_reset_pin((gpio_num_t)CLK_PIN);
/* Set the GPIO as a push/pull output */
gpio_set_direction((gpio_num_t)CLK_PIN, GPIO_MODE_OUTPUT);
gpio_set_drive_capability((gpio_num_t)CLK_PIN, GPIO_DRIVE_CAP_3);
ledc_timer_config_t ledc_timer;
ledc_channel_config_t ledc_channel;
//params ledc_timer
ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE;//LEDC_HIGH_SPEED_MODE;
ledc_timer.timer_num = LEDC_TIMER_0;
ledc_timer.bit_num = (ledc_timer_bit_t) LEDC_TIMER_1_BIT; //LEDC_TIMER_2_BIT;
ledc_timer.freq_hz = 11289600;
ledc_timer.clk_cfg = LEDC_USE_APB_CLK;
//params ledc_channel
ledc_channel.channel = LEDC_CHANNEL_0;
ledc_channel.gpio_num = 18; //WAS 18
ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE;
ledc_channel.timer_sel = LEDC_TIMER_0;
ledc_channel.duty = 1;
//Generacja zegara dla PCM1808
ledc_timer_config(&ledc_timer);
ledc_channel_config(&ledc_channel);
Serial.println("Program Started");
}//---------------------------------------------------------------------------------------
void loop() {
}
BTW: how to mark thread as "Solved"?Hello,
@Aussie Susan and @KlausST you two have right, I made big mistake. I connect scope one pin too far (not pin 18 but next). I am ashamed, because I should first check if i am connected to proper pin. On this 4KHz waveform now is ideal square. For square wave of frequency 11 289 600 Hz also everything is OK. I put the final version of program (working OK on Arduino IDE) for square wave f=11289600 Hz. Maybe someone esle would like to generate square wave of big frequency on ESP32:
C++:#include "ledc.h" #define CLK_PIN (18) void setup() { //--------------------------------------------------------------------------------------- Serial.begin(115200); // use the serial port Serial.println("Starting ..."); gpio_reset_pin((gpio_num_t)CLK_PIN); /* Set the GPIO as a push/pull output */ gpio_set_direction((gpio_num_t)CLK_PIN, GPIO_MODE_OUTPUT); gpio_set_drive_capability((gpio_num_t)CLK_PIN, GPIO_DRIVE_CAP_3); ledc_timer_config_t ledc_timer; ledc_channel_config_t ledc_channel; //params ledc_timer ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE;//LEDC_HIGH_SPEED_MODE; ledc_timer.timer_num = LEDC_TIMER_0; ledc_timer.bit_num = (ledc_timer_bit_t) LEDC_TIMER_1_BIT; //LEDC_TIMER_2_BIT; ledc_timer.freq_hz = 11289600; ledc_timer.clk_cfg = LEDC_USE_APB_CLK; //params ledc_channel ledc_channel.channel = LEDC_CHANNEL_0; ledc_channel.gpio_num = 18; //WAS 18 ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE; ledc_channel.timer_sel = LEDC_TIMER_0; ledc_channel.duty = 1; //Generacja zegara dla PCM1808 ledc_timer_config(&ledc_timer); ledc_channel_config(&ledc_channel); Serial.println("Program Started"); }//--------------------------------------------------------------------------------------- void loop() { }
In zip archive is full project for "Arduino IDE" with needed header files.
Best Regards
every one makes mistakes. Almost the same happened to me a couple days ago.I am ashamed, because I should first check if i am connected to proper pin.
BTW: how to mark thread as "Solved"?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?