// Set the LEDC peripheral configuration
ledc_init();
// Set duty to 50%
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
// Update duty to apply the new value
//ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
adc1_config_width(ADC_WIDTH_BIT_12); // 12-bit ADC resolution
adc1_config_channel_atten(ADC1_CHANNEL, ADC_ATTEN_DB_0); // No attenuation
while (1)
{
// Read the ADC value
int adc_value = adc1_get_raw(ADC1_CHANNEL);
ESP_LOGI("ADC", "ADC Value: %d", adc_value);
// Delay for 100 ms
vTaskDelay(pdMS_TO_TICKS(100));
}
}
Debug Logs.
No response
More Information.
Trying to make a low power moisture sensor using the esp32-h2, however I cannot produce a 200KHz square wave using this board. I was able to using the dev kit + Arduino but for some reason my board is only giving me 13Hz. Could it be that the LEDC timer is defaulting to a one of the RTC timers somehow? Any help would be appreciated. Thank you
Answers checklist.
IDF version.
5.3.2
Espressif SoC revision.
ESP32-H2
Operating System used.
Windows
How did you build your project?
Command line with idf.py
If you are using Windows, please specify command line type.
CMD
Development Kit.
Custom ESP32-H2
Power Supply used.
USB
What is the expected behavior?
Output 200KHz Square Wave
What is the actual behavior?
Outputs a 13Hz Square Wave, verified by my oscilloscope
Steps to reproduce.
include
include "freertos/FreeRTOS.h"
include "freertos/task.h"
include "esp_log.h"
include "driver/adc.h"
include "driver/ledc.h"
include "driver/gpio.h"
include "esp_err.h"
define LEDC_TIMER LEDC_TIMER_0
define LEDC_MODE LEDC_LOW_SPEED_MODE
define LEDC_OUTPUT_IO (5) // Define the output GPIO
define LEDC_CHANNEL LEDC_CHANNEL_3
define LEDC_DUTY_RES LEDC_TIMER_1_BIT // Set duty resolution to 13 bits
define LEDC_DUTY (1 << (LEDC_DUTY_RES - 1))
define LEDC_FREQUENCY (200000)
define ADC1_CHANNEL (ADC1_CHANNEL_3) // GPIO 4 corresponds to ADC1_CHANNEL_3
static void ledc_init(void) { // Prepare and then apply the LEDC PWM timer configuration ledc_timer_config_t ledc_timer = { .speed_mode = LEDC_MODE, .duty_resolution = LEDC_DUTY_RES, .timer_num = LEDC_TIMER, .freq_hz = LEDC_FREQUENCY,
.clk_cfg = LEDC_USE_XTAL_CLK }; ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
}
void app_main(void) {
}
Debug Logs.
No response
More Information.
Trying to make a low power moisture sensor using the esp32-h2, however I cannot produce a 200KHz square wave using this board. I was able to using the dev kit + Arduino but for some reason my board is only giving me 13Hz. Could it be that the LEDC timer is defaulting to a one of the RTC timers somehow? Any help would be appreciated. Thank you