How fast can you blink an LED (Theoretical fastest speed)

I need to blink an LED's at 1ms intervals so I can test camera synchronization down to 1ms (1000fps).

According to this post on stack exchange, the theoretical time it takes to turn on/off an LED is on the order of nano seconds.

Using an Arduino Uno, what is the fastest I can reasonably expect to blink an LED?

What would be the bottleneck? Is there an easier/better solution than using an Arduino?

you did not mention which Arduino.

1ms is peanuts compared to that though, look at the blink without delay sketch and use micros() instead of millis() so that you get a better grasp at what's going on. using pin registers will be faster than digitalWrite()

On a typical 328P you can use the PIND register to flip a pin. if you put that in a while(true) loop, it will give high frequency (almost 8 MHz)

Hi @npsantini
The arduino UNO, nano, mini, (ATMEGA328) when connected to 5V, has a clock of 16 Mhz (16,000,000 Hz).
It has a cycle of 62.5 peak seconds or 0.0625 microseconds.
As, in simple terms, it executes one instruction per clock cycle, so theoretically it would have a pulse every 2 cycles.
1 cycle turns the LED on and one cycle turns the LED off.
In other words, we would have the LED blinking every 0.125 microseconds.
But as when writing the program other instructions are added, I would say you can get 1 pulse on the LED every microsecond. Or 1MHz.

RV mineirim

PS:
Pretty much any LED available can be operated at far higher blink frequencies than 1 KHz: White LEDs or others which use a secondary phosphor would be the slowest, often topping off in the 1 to 5 MHz region, while standard off-the-shelf primary LEDs (red, blue, green, IR, UV etc) are typically rated at a cut-off frequency of 10 to 50 MHz (sine wave).

1 Like

Depends...
What kind of LED, particularly how much power?
Not a white LED I hope/assume, because then all bets are off - most white LEDs rely on phosphor coatings that are way slower than what you need.

The higher the power, the more critical the driver circuitry would become.

That's slooooooow for an Arduino and semiconductors. Don't worry about it. Especially if you can get away with using some kind of linear current limiter circuit (e.g. a simple resistor).

How about a PCA9685. That's something like 1.4kHz@ 12 bits, hence something like 0.71ms / 4095 = ca. 173ns shortest pulse width.

1 Like

You can use one of the timers to generate an 8 MHz square wave on an output pin.

As others have indicated, 1 ms is slow in Arduino land.

However if you want to power and LED that requires a driver you have to pay attention to the Arduino output drive limitations. But you can still approach 100's of ns with a larger LED.

Most of the Arduinos will do about 100kHz to 200kHz with digitalWrite() in a loop:

while (1) {
  digitalWrite(pin, HIGH);
  digitalWrite(pin, LOW);
}

(and there isn't as much variation between "fast" arduino boards (like Due) and slower boards (like Uno) as you might think, because "reasons.")

They'll go significantly faster using one of the (usually CPU-specific) digitalWriteFast() libraries or user written "direct port access" code (also CPU specific.)
An Uno can toggle a pin at 2+ MHz: Maximum pin toggle speed
a SAMD21 at 48MHz will do about 12MHz, and one of Adafruit's 120MHz SAMD51 boards about 30MHz: Increasing the speed of execution of the adafruit feather - adafruit industries
Recent SAMD discussion: What is the fastest way to read/write GPIOs on SAMD21 boards? - #9 by westfw

Using the hardware timers, you can get even shorter pulses; usually down to about 2 CPU clock cycles. On faster CPUs, such fast signals may not "survive" being output to pins and traveling along wires...

With PIN register probably faster. One instruction for the register, one branch to jump back to the previous instruction, probably worth checking how fast this runs

while(true)  PIND = 0b10000 ; // toggle D4

It was mentioned in the linked discussion. 2.6667 MHz. Remember that toggling a pin is only half a cycle; you have to do it twice... 2 cycles of OUT, 4 cycles of jumps, 2.6667 MHz.

Right. Of course

Two PIND and one Jump ? (But then it’s not balanced)

If you want something done fast, do it in hardware. :slight_smile:

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