LED cycling

I read somewhere that LEDs can toggle on/off several million times a second :o. I’m assuming that your average ATMega can’t command it to do so, but does anyone have any idea how often it can toggle something on/off?

Does it have to do with the Clock? If you’re running at 16MHz, does that mean the Arduino can switch something 16,000,000 a second? :stuck_out_tongue:

Did you try searching the forum? This has been discussed a few times.

Here’s an excellent thread with experimental results (and explanations) of how quickly an Arduino can toggle a pin.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230286016

Of course the answer depends on how you toggle it - using arduino-native digitalWrite() commands is much lower than using assembly code.

If fact you could get it to toggle millions of times per second - 4 million times if you use a 16MHz clock and assembly code. Using digitalWrite() would get you one hundred thousand or so per second.

Even if an LED could toggle this fast, your eye wouldn’t be able to see it :slight_smile:

Did you try searching the forum? This has been discussed a few times.

I did, but the search isn’t too great lately :P. I’ll use Google next time.

Here’s an excellent thread with experimental results

Thanks for the link.

Yes you can switch it very fast. And yes, how fast relates to the clock speed of the processor and what code instructions you use. However after about 16 blinks a second your eye can’t detect that it is in fact blinking, just a steady glow.

Lefty

16,000,000 a second

While any LED can blink fast (hundreds of thousand per second) this is a bit too fast for some LEDs, it depends on the construction so check the data sheet.

Sometimes LEDs are made to blink fast to modulate data on the light like the optical digital audio output on some hi-fi systems. Others can drive fibre optic systems and can modulate video speed digital signals. These have to go even faster from the millions of times a second to the thousands of millions times a second in the Giga Hertz regions.

@retrolefty, I would like to disagree. Although it is true that >16 blinks per seconds are harder to notice it is not to hard to actually differentiate a 100 Hz blink from a continuous light. This is especially true for LEDs in the dark. And it is the reason why cars with LED tail lights are so annoying to me. I can definitely see blinks up to 100 Hz although the mainstream theory tells me otherwise. And this is true for other people as well. At least one vendor of LED flashlights increased the PWM frequency due to sufficient customer complaints about this issue.

Cheers, Udo

@retrolefty, I would like to disagree. Although it is true that >16 blinks per seconds are harder to notice it is not to hard to actually differentiate a 100 Hz blink from a continuous light. This is especially true for LEDs in the dark. And it is the reason why cars with LED tail lights are so annoying to me. I can definitely see blinks up to 100 Hz although the mainstream theory tells me otherwise. And this is true for other people as well. At least one vendor of LED flashlights increased the PWM frequency due to sufficient customer complaints about this issue.

I’m always have to adjust my monitors to their highest refresh rate due to the annoying bars I see progressing along the screen :P. I guess some people are more sensitive to that than others?

Definitely. In doubt I would recommend to be above 1 kHz, just to be on the really safe side :wink:

With regard to your original question. The absolute maximum speed that you can achieve is 1 toggle per cycle. However this implies you have to directly manipulate the timers. To be more precise you have to set timer1 in fast PWM mode, no prescaling (N=1) and TOP = 1. Then it will toggle each cycle. Of course if you cheat as mentioned in the cited thread you can get the system clock on an output pin thus toggling at the clock spped 16 Mhz. And to push it furhter you could switch to a 20Mhz crystal.

Humans aren’t digital, and they have a fairly wide variation on things like persistence.

The “normal” human can’t see things that “flicker” faster than around 60Hz with light backgrounds. Most of us are a bit more sensitive with dark backgrounds.

If you are able to see 100 hz flicker, you are pretty far out on the tail (maybe 1/2% or farther), but not really weird.

Maybe the point is that definition of “seeing flicker” is currently such that <0.5% can “see it” but actually more can perceive it although most to do not really notice or understand the point.

The point is: if something flickers at say 100 Hz in a dark environment and you move your head and/or eye then you see separate images instead of a blur. The question is if this is anoying and if you get the root cause for the anoyance. For me it is anyoing and the root cause is typically the low PWM frequency. This kind of “seeing flicker” does not depend on your nerves transmission speed but on angular velocity of the flicker source. Hence this can be seen even way beyond 100Hz.

The most anyoing source of this kind of flicker are LED based car tail lights.

The most anyoing source of this kind of flicker are LED based car tail lights.

Hmm are those PWM’d or something? I’ve never noticed anything with them.

Even more annoying when you’re driving are active LED cat’s-eyes.
The PWM frequency seems to be deliberately chosen to cause flicker in peripheral vision, so as you pass them, you look around when you really, really ought to be looking ahead…

I am driving highways most of the time. So bicycle tail lights are not an issue for me. However the car tail lights are.

Anyway: I can see the difference between 80 and 100 Hz CRT, so maybe I am far out the tail and easily annoyed by it. Anyway I will hail any engineer who will PWM beyond 1KHz, especially if care would be taken to ensure that the flicker is not removed by making the circuit “whistle” :wink:

The other consideration to flashing LEDs on and off REALLY fast is the way you drive the LEDs. My semiconductor physics is a bit rusty. But I vaguely recall that typical LEDs have charge trapped by junction capacitance – that needs to be pulled out to really switch an LED. Unless you do this correctly, even if you have a square wave coming out of the Atmega at a couple megahertz, you’re not going to see the LED switching on and off at these higher frequencies.

LED tail lights bug me too due to the PWM. The regular ‘on’ brightness is something less than when the brakes are on, at which time the PWM goes to 100% and there’s no longer any flicker. But my in-laws just bought a little Toyota truck that has LED tail lights and they are not PWM driven, or they are being driven at an EXTREMELY high frequency. They have zero flicker at any brightness, no matter how quickly I look from side to side (in fact I made myself dizzy trying to find the flicker) :smiley:

I am working with power LEDs right now and even at 3900Hz PWM freq, I can still see flicker when my eyes dart from side to side. I’m a little worried that I’ll be able to see that when the project is done and mounted on the handlebars of my bicycle. But unless I do an analog conversion, 3900Hz is the highest I can go due to the limitations of the LED driver’s PWM input line.

To address the OP, I’m pretty sure you can’t cycle LEDs faster than they can handle in any practical application. The main limitation you’ll run into is the LED driver’s maximum PWM input frequency. That can’t be any faster than about 1/10th the regulator switching frequency of the driver or you get aliasing in the output and unstable regulation. If you’re talking small LEDs (up to 50 mA), I found some text that indicates the nanosecond range, although it was not a very thorough document.

Why do you need analog conversion? An LC low pass filter should already help a lot.

I understand that this increases part cost and design efforts somewhat. However I would like to learn you opinion on this. Since you already figured about aliasing you sound like you know very well what you are doing.

Cheers, Udo