# Shortest pulse for triggering a digital input

**URL:** <https://forum.arduino.cc/t/shortest-pulse-for-triggering-a-digital-input/1304979>\
**Category:** Programming\
**Created:** [September 25, 2024, 11:54am UTC](https://forum.arduino.cc/t/shortest-pulse-for-triggering-a-digital-input/1304979 "2024-09-25T11:54:02Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pimpom](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pimpom](https://forum.arduino.cc/u/Pimpom)\
**Post date:** [September 25, 2024, 11:54am UTC](https://forum.arduino.cc/t/shortest-pulse-for-triggering-a-digital-input/1304979/1 "2024-09-25T11:54:03Z")

</div>

I want to start a simple code with a negative going (high-to-low) pulse at a digital input. The Arduino will be an Uno or a Nano running at stock clock with a 5V supply. The code works as intended with a push-button switch but, in the actual application, it will be triggered by a pulse from another circuit.

What is the shortest pulse that will reliably trigger the action?

I don't think the pulse will be anywhere close to the shortest duration limit but it will be nice to know - for this and for future applications.

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [September 25, 2024, 11:59am UTC](https://forum.arduino.cc/t/shortest-pulse-for-triggering-a-digital-input/1304979/2 "2024-09-25T11:59:33Z")

</div>

> [@Pimpom](#):
>
> What is the shortest pulse that will reliably trigger the action?

If you use interrupts to detect the pulse, then it need to be greater than 2 clocks long.  
So 2/16MHz

---

<div class="post-metadata">

**Author:** ![Pimpom](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pimpom](https://forum.arduino.cc/u/Pimpom)\
**Post date:** [September 25, 2024, 12:09pm UTC](https://forum.arduino.cc/t/shortest-pulse-for-triggering-a-digital-input/1304979/3 "2024-09-25T12:09:58Z")

</div>

That's 125nS. My pulse will be several µS long. Thanks.

---

<div class="post-metadata">

**Author:** ![GoForSmoke](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/goforsmoke/32/1127097_2.png) [@GoForSmoke](https://forum.arduino.cc/u/GoForSmoke)\
**Post date:** [September 25, 2024, 12:22pm UTC](https://forum.arduino.cc/t/shortest-pulse-for-triggering-a-digital-input/1304979/4 "2024-09-25T12:22:49Z")

</div>

The interrupt will catch the pulse but there will be a few microsecs before it will be processed. Interrupts have 5 micros overhead plus the code in the IRQ. Reaction only begins in the IRQ but you can grab micros() which steps by 4.

If you are waiting for a return pulse you can poll with a 1 usec count loop and get a closer read.

---

<div class="post-metadata">

**Author:** ![Pimpom](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pimpom](https://forum.arduino.cc/u/Pimpom)\
**Post date:** [September 25, 2024, 12:57pm UTC](https://forum.arduino.cc/t/shortest-pulse-for-triggering-a-digital-input/1304979/5 "2024-09-25T12:57:04Z")

</div>

Thanks for the further clarification. This is a simple operation that doesn't require high timing precision. Some milliseconds of delay or uncertainty will not make any difference. The starting signal is not even a sharp pulse. It's the exponential decay of an R-C network.

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [September 25, 2024, 1:03pm UTC](https://forum.arduino.cc/t/shortest-pulse-for-triggering-a-digital-input/1304979/6 "2024-09-25T13:03:06Z")

</div>

> [@Pimpom](#):
>
> It's the exponential decay of an R-C network.

Different story.  
Then you need to make sure it is 125ns wide at a level of 3V or higher

---

<div class="post-metadata">

**Author:** ![Pimpom](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pimpom](https://forum.arduino.cc/u/Pimpom)\
**Post date:** [September 25, 2024, 1:36pm UTC](https://forum.arduino.cc/t/shortest-pulse-for-triggering-a-digital-input/1304979/7 "2024-09-25T13:36:29Z")

</div>

I know. As I said before, the signal is several microseconds long at the Schmitt hysteresis threshold of an ATMega328P.

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [September 25, 2024, 1:39pm UTC](https://forum.arduino.cc/t/shortest-pulse-for-triggering-a-digital-input/1304979/8 "2024-09-25T13:39:55Z")

</div>

No problem then.

---

<div class="post-metadata">

**Author:** ![JohnLincoln](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@JohnLincoln](https://forum.arduino.cc/u/JohnLincoln)\
**Post date:** [September 25, 2024, 5:20pm UTC](https://forum.arduino.cc/t/shortest-pulse-for-triggering-a-digital-input/1304979/9 "2024-09-25T17:20:20Z")

</div>

I did a test using two Uno R3s to verify what the shortest pulse an interrupt could detect was.

I used one Uno to generate a low going pulse every 100ms.  
I used direct port manipulation, so that I could vary the pulse width in steps of 62.5ns.  
I varied the pulse width by adding/removing NOPs and recompiling.  
Here is the code that I used:

> ****
>
> ```arduino
> // https://docs.arduino.cc/hacking/software/PortManipulation
> 
> #define NOP __asm__ ("nop\n\t")
> 
> void setup() {
> DDRB = B00111111; // D8-D13 all outputs
> Serial.begin(115200);
> }
> 
> void loop() {
> PORTB = B00000000;
> NOP;
> PORTB = B00000001;
> delay(100);
> }
> 
> ```

I used the second Uno to detect the pulses using an interrupt.  
In the ISR, I generated a pulse on pin 12.  
Here is the code I used:

> ****
>
> ```arduino
> const byte outputPin = 12;
> const byte interruptPin = 2;
> unsigned long pulseWidth = 5;
> 
> void setup() { 
> pinMode(outputPin, OUTPUT);
> pinMode(interruptPin, INPUT);
> attachInterrupt(digitalPinToInterrupt(interruptPin), generatePulse, FALLING);
> }
> 
> void loop() {
> }
> 
> void generatePulse() {  
> PORTB = B00010000; // turn pin 12 high
> delayMicroseconds(pulseWidth);
> PORTB = B00000000; // turn pin 12 low
> }
> 
> ```

I used an oscilloscope to view the results:

- Chanel 1 - yellow trace - Pulse going to interrupt pin 2 of Uno.
- Channel 3 - blue trace - Pulse output from pin 12.

 ![62.5ns](https://europe1.discourse-cdn.com/arduino/original/4X/b/f/8/bf8954b9e514478c74f13b25c233a1bf22090cf6.png)  
The interrupt would detect a pulse right down to one clock cycle wide (62.5ns).

---

<div class="post-metadata">

**Author:** ![Pimpom](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pimpom](https://forum.arduino.cc/u/Pimpom)\
**Post date:** [September 25, 2024, 8:21pm UTC](https://forum.arduino.cc/t/shortest-pulse-for-triggering-a-digital-input/1304979/10 "2024-09-25T20:21:31Z")

</div>

Thanks. That info will come in handy when I move up to more advanced applications. I'm just a novice with MCUs although I do have some designing experience with analog and fixed logic devices.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 24, 2025, 8:21pm UTC](https://forum.arduino.cc/t/shortest-pulse-for-triggering-a-digital-input/1304979/11 "2025-03-24T20:21:57Z")

</div>

Closed on March 24, 2025, 8:21pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
