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,022
Hello,
I am trying to generate square wave of frequency 11.2896 MHz (this is external clock for IC PCM1608 (256*44.1KHz) on ESP32 board. I haven't big experience with using ESP32 MCU (I have bigger experience with ARM-CortexMx MCUs). I am trying to program ESP32-Wrover board in "Arduino-IDE". I wouldn't like to install "ESP-IDF" because of many dependences in my Windows OS (for example installed Python version) and this is "command-line" environment (quite complex). I was studying Expressif documentation, and found that "LEDC" module API can be used for generating square wave up to 40 MHz (using internal timers) - see link:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html
https://www.esp32.com/viewtopic.php?t=1037
I altered this code a bit in order to compile it in "Arduino IDE" (with boards package for ESP32). I had to add few headers files (from Github with ESP32 drivers). Here is code of main program "Arduino sketch":
This code is compiling without any errors in "Arduino IDE" and runs on ESP32 board without runtime errors.
First, I tried to generate 11 MHz square wave, but such frequency is very close to frequency limit for my cheap digital scope and I saw series of impulses of low amplitude (below 0.5 Volt). When I change the generated signal waveform to 1 MHz (see in given code above) I was observing 1 MHz sinusoidal wave of amplitude lower then 1 Volt. I tried to see generated waveform on logic analyzer (which has much bigger bandwith - 200 Mhz), but from the cause amplitude had to low to trigger sampling on it. I also made further experiments - lower the generated signal frequency to 4 Khz (in program code) and had seen it on scope. In this case I saw 4 KHz square waveform, but amplitude was only 1 Volt. In tis case timer resolution was 13-bit, and when I was changing the waveform duty, I was able to see it on scope properly. I also tried to find different example of code in C language, but all be very similar to code in link I attached.
As I told I haven't big experience with ESP32 MCU. Could somebody help me with this problem and give me any clue what I am doing wrong? In zip package is full program for "Arduino IDE" (with needed header files).
BTW: when I tried to generate lower frequencies the resolution of timer wasn't 1-bit, it was 13-bit: LEDC_TIMER_13_BIT
Thanks in advance and Regards
I am trying to generate square wave of frequency 11.2896 MHz (this is external clock for IC PCM1608 (256*44.1KHz) on ESP32 board. I haven't big experience with using ESP32 MCU (I have bigger experience with ARM-CortexMx MCUs). I am trying to program ESP32-Wrover board in "Arduino-IDE". I wouldn't like to install "ESP-IDF" because of many dependences in my Windows OS (for example installed Python version) and this is "command-line" environment (quite complex). I was studying Expressif documentation, and found that "LEDC" module API can be used for generating square wave up to 40 MHz (using internal timers) - see link:
https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/ledc.html
https://www.esp32.com/viewtopic.php?t=1037
I altered this code a bit in order to compile it in "Arduino IDE" (with boards package for ESP32). I had to add few headers files (from Github with ESP32 drivers). Here is code of main program "Arduino sketch":
Code:
#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() {
}
--- Updated ---
First, I tried to generate 11 MHz square wave, but such frequency is very close to frequency limit for my cheap digital scope and I saw series of impulses of low amplitude (below 0.5 Volt). When I change the generated signal waveform to 1 MHz (see in given code above) I was observing 1 MHz sinusoidal wave of amplitude lower then 1 Volt. I tried to see generated waveform on logic analyzer (which has much bigger bandwith - 200 Mhz), but from the cause amplitude had to low to trigger sampling on it. I also made further experiments - lower the generated signal frequency to 4 Khz (in program code) and had seen it on scope. In this case I saw 4 KHz square waveform, but amplitude was only 1 Volt. In tis case timer resolution was 13-bit, and when I was changing the waveform duty, I was able to see it on scope properly. I also tried to find different example of code in C language, but all be very similar to code in link I attached.
As I told I haven't big experience with ESP32 MCU. Could somebody help me with this problem and give me any clue what I am doing wrong? In zip package is full program for "Arduino IDE" (with needed header files).
BTW: when I tried to generate lower frequencies the resolution of timer wasn't 1-bit, it was 13-bit: LEDC_TIMER_13_BIT
Thanks in advance and Regards
Attachments
Last edited: