61. Short Pulse Detection

From the task, we understand that,

  • We have to detect the pulse of width 100 or <100 nanoseconds.
  • The code for Pulse generation is already given.
  • The LED is toggled once the pulse is detected.
  • Pulse detection can be done using two approaches
    • Polling: Continuously checks the GPIO pin in the main loop to detect a pulse.
    • Interrupt: Automatically detects a pulse when the pin state changes, without blocking the main task.
  • But as per our task requirement, the polling method is not possible to implement, so we are going to use an interrupt to detect the pulse.

 Hardware Interrupt Detection

  • The GPIO hardware detects rising/falling edges automatically.
  • Detection occurs within a single or a few CPU cycles, typically in the nanosecond range.
  • Best suited for very short pulse detection (<100 ns) where polling is not feasible.

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

  1. STM32
  2. ESP32
  3. Arduino UNO

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!