Hello!
I have been working with an ESP32-S2 board to create a pretty simple, very low duty cycle (1kHz 0.1% duty or less) pulser. The application for this is to drive a circuit that creates very short high current pulses for testing laser diodes.
The LEDC peripheral works great for creating these pulses, even down to 500ns or less, and the pulse width is easily adjustable on the fly. My issue is that I need something like an interrupt on the falling edge of the pulse to trigger an ADC reading from a current sensor in the circuit (that part of the circuit works fine). I’m having trouble determining if this is possible with the LEDC peripheral.
Anyone able to help me with this? Or is a better solution to implement this using the general purpose timers? My experience is pretty limited when it comes to C and ESP-IDF, so I have not been able to determine for myself what the best path to follow is.
Thanks for any insight.
Use of either LEDC or general timers for very short (<2us) pulses
-
- Posts: 8
- Joined: Fri Apr 01, 2022 3:06 pm
Re: Use of either LEDC or general timers for very short (<2us) pulses
You might be able to utilize what I've done here to configure the pin as an input-and-output. At that point maybe you can configure a falling-edge interrupt as you would on any GPIO input?
viewtopic.php?f=19&t=13347#p122786
Edit: Funny enough, I just had to cross this bridge. After following what I proposed in the linked post, you can set set up an interrupt on the pin:
Define your callback function in your header file:
And then finally the callback function itself:
edit: It occurred to me that this is the Arduino flavor of the forum. The above example is written for the ESP-IDF, but the concept is all the same.
viewtopic.php?f=19&t=13347#p122786
Edit: Funny enough, I just had to cross this bridge. After following what I proposed in the linked post, you can set set up an interrupt on the pin:
Code: Select all
gpio_install_isr_service(0); // no error check so we don't assert if the service is already running
ESP_ERROR_CHECK(gpio_isr_handler_add(GPIO_NUM_33, (gpio_isr_t)pin_change, this));
ESP_ERROR_CHECK(gpio_set_intr_type(GPIO_NUM_33, GPIO_INTR_NEGEDGE));
ESP_ERROR_CHECK(gpio_intr_enable(GPIO_NUM_33));
Code: Select all
static void IRAM_ATTR pin_change(void * pData);
Code: Select all
void IRAM_ATTR pin_change(void * pData) {
ets_printf("Pin change!\n");
}
Re: Use of either LEDC or general timers for very short (<2us) pulses
This is really helpful, and works! Thank you! The Arduino-world attachInterrupt() works just as well for falling edge on the LEDC output pin. Even on a <500ns pulse width.
Thanks again.
Thanks again.
Who is online
Users browsing this forum: No registered users and 121 guests