From the task, we understand that,
Hardware Interrupt Detection
So we are going to use an interrupt to detect the high-frequency pulse < 100 nsec. Below are the solutions to the given task using different microcontrollers
We’re using an STM32 NUCLEO-F103RB board, which runs at a 3.3 V logic level.
Key Peripherals Used:
Circuit Diagram

Project Setup in STM32CubeIDE:
GPIO_EXTI on the RISING edge.HAL_Init() → Initializes the HAL library.SystemClock_Config() → Configures system clock.MX_GPIO_Init() → Configures GPIO pins.Behavior Summary
// In MX_GPIO_Init()
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin : PC0 */
GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pin : LD2_Pin (PA5) */
GPIO_InitStruct.Pin = LD2_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);This configuration initializes PC0 as an external interrupt input, and LD2 (PA5) is configured as a push-pull digital output.
These are generated by Cube and available via main.h for the NUCLEO board:
// From CubeMX-generated headers
// LD2 GPIO on PA5
#define LD2_Pin GPIO_PIN_5
#define LD2_GPIO_Port GPIOAUsing these symbolic names makes the code portable and clear.
// Triggered when PC0 detects a rising edge (button press)
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if (GPIO_Pin == GPIO_PIN_0)
{
HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);
}
}When the pulse is detected, LD2 toggles immediately inside the EXTI ISR.
int main(void)
{
HAL_Init(); // HAL + SysTick
SystemClock_Config(); // HSI + PLL
MX_GPIO_Init(); // PC0 (EXTI), PA5 (LD2)
MX_USART2_UART_Init(); // Optional debugging UART @115200
while (1)
{
// Interrupt-driven demo: nothing to do here
}
}The complete STM32CubeIDE project (including .ioc configuration, main.c, and HAL drivers) is available here:
📥 Download Project
We are using the ESP32 DevKitC v4 development board and programming it using the Arduino IDE.
digitalRead() takes about 2–3 µs, while the pulse is <100 ns, is too short to detect by polling.
Time consumed by the interrupt:
A rising or falling edge GPIO interrupt should be used for reliable detection of <100 ns pulse.
Circuit Connection

Note: Avoid using GPIOs 34–39 for push-buttons while using ESP32 because they do not support pull-up/down resistors internally.
#define PULSE_PIN 4 // Input pin for incoming pulse (GPIO 4)
#define LED_PIN 2 // Output pin driving the LED (GPIO 2)
volatile bool state = false;
// Interrupt Service Routine (runs on each RISING edge on PULSE_PIN)
void IRAM_ATTR handlePulse() {
state = !state;
digitalWrite(LED_PIN, state); // Toggle LED
}
void setup() {
// Configure pins
pinMode(PULSE_PIN, INPUT); // Configure as Input
pinMode(LED_PIN, OUTPUT); // LED pin as output
// Attach interrupt on GPIO4, trigger on RISING edge
attachInterrupt(digitalPinToInterrupt(PULSE_PIN), handlePulse, RISING);
}
void loop() {
//controller doing important task here
}
This code uses a GPIO interrupt on pin 4 of the ESP32 to detect a rising edge signal and toggle an LED on pin 2.
Pin Setup:
pinMode(4, INPUT); → Configures GPIO 4 as an input.pinMode(2, OUTPUT); → Configures GPIO 2 as an output to drive the LED.Interrupt Attachment:
attachInterrupt(digitalPinToInterrupt(4), handlePulse, RISING);ISR Functionality:
handlePulse() executes immediately when a rising edge is detected.state = !state; → toggles the LED state.digitalWrite(2, state); → updates the LED output accordingly.Main Loop:
loop() is empty because the program is interrupt-driven, responding instantly to external rising-edge pulses without pollingWe are using the Arduino UNO development board and programming it using the Arduino IDE.
Detecting the pulse using an interrupt in Arduino UNO
Circuit Connection

The firmware
// Interrupt Service Routine for INT0 (pin 2)
void ISR_INT0() {
digitalWrite(13,!digitalRead(13)); //toggles the LED when pulse detected
}
void setup() {
pinMode(2, INPUT); // Configure interrupt INT0 (pin 2) as input
pinMode(13, OUTPUT); //onboard LED is connected to pin 13
// Attach external interrupts
attachInterrupt(digitalPinToInterrupt(2), ISR_INT0, RISING); // Trigger on rising edge for INT0
}
void loop() {
}This code uses an external interrupt (INT0) on pin 2 of an Arduino to detect a rising edge signal and toggle an LED on pin 13.
Pin Setup
pinMode(2, INPUT): Configures pin 2 as an input.pinMode(13, OUTPUT): Configures pin 13 as an output to control the onboard LED.Interrupt Attachment:
attachInterrupt(digitalPinToInterrupt(2), ISR_INT0, RISING): Sets up an interrupt on pin 2 to trigger on a rising edge.ISR Functionality:
ISR_INT0() is executed:digitalWrite(13, !digitalRead(13)).Main Loop
loop() function is empty since the program is interrupt-driven and responds instantly to external events.