Stroboscopes: why smartphone LED can't blink fast?

Other Computers and Game Systems

Moderator: Moderators

Post Reply
User avatar
highinfidelity
Vic 20 Nerd
Posts: 644
Joined: Thu Jul 28, 2011 2:34 am
Website: http://www.hirtel.it
Location: Torino, Italy.

Stroboscopes: why smartphone LED can't blink fast?

Post by highinfidelity »

I recently changed my smartphone and bought a model that also has the flash for the camera (my previous one was simple and pretty old and didn't) so I went on Google Play Store to see if there was anything interesting that I could do with it beyond taking pictures. There are apps that turn the flash unit into a stroboscopic light, which is useful to me in order to adjust the speed of record players and gramophones. As usual most of these apps don't even do the job for which they were programmed, however one looks pretty good and reliable and it is named "Strobily".

What amazes me is that these apps can have the LED blinking only at very low cycles per second rates. As far as I see Strobily offers a maximum of 100 Hz, but also has a built-in diagnostic feature that reads how many cycles per second are effectively reached, an in my case the theoretical maximum would be just above 68 Hz. Other apps don't even go that far, one in particular halts at 20 Hz (!!!) and it got many negative reviews.

Strobily can also have the front display blinking as a stroboscope, but (perhaps with no surprise, in this case) it is even slower that the LED flash unit.

I'm really surprised by all this. I had previously assumed that LEDs, being cold solid state components, could blink very very fast. Aren't they also used in optic fibers' technology as light emitters at very high frequency? On the other hand, although I ignore the current average speed of smartphones' processors, I would assume that their clock is many orders of magnitude faster than 100 Hz and should be able to easily deal with frequencies *well* above this limit.

Does anyone know where the "bottle neck" that set such ridicolously low limit is situated inside a smartphone?
Last edited by highinfidelity on Wed Feb 21, 2018 11:06 am, edited 1 time in total.
GOD is REAL. Unless declared DOUBLE PRECISION.
User avatar
beamrider
Vic 20 Scientist
Posts: 1447
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: Stroboscopes: why smartphone LED can't blink fast?

Post by beamrider »

Just guessing here but...

I would imagine that flash is performed by an abstracted service in the phone OS and that this service runs on a scheduler and that this scheduler is servicing the requests too slowly.

In fairness I doubt the designers of the OS had your use-case in mind and also increasing the responsiveness would probably add to battery drain.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Stroboscopes: why smartphone LED can't blink fast?

Post by Mike »

highinfidelity,

LEDs used for lighting purposes are not anymore those "cold solid state components" you think of - rather, cooling efforts are necessary to dissipate excess heat: their efficiency is still less than 100%, and we're dealing with >1 W of electrical power already.

Furthermore, their supply couldn't afford to burn most of the electrical power over a series current regulating resistor like it's done with most signal LEDs. Rather, a switching regulator provides a current source, which is ramped up and down carefully to limit the inrush current from 'normal' on/off actions. When used as flash, the regulator supplies the maximum allowed current for the duration of the flash, and then the excess heat needs to be dissipated over the course of several seconds. Otherwise, the lifespan of the power LED would be significantly reduced.

Take your own conclusions, whether using a high power LED as stroboscope is such a good idea afterall. The speed of a record player can also be adjusted with a standard (signal) LED modulated by a small calibrated circuit.

Greetings,

Michael
User avatar
highinfidelity
Vic 20 Nerd
Posts: 644
Joined: Thu Jul 28, 2011 2:34 am
Website: http://www.hirtel.it
Location: Torino, Italy.

Re: Stroboscopes: why smartphone LED can't blink fast?

Post by highinfidelity »

Mike, of course when the LED is used as a stroboscope it's not driven at high power as when used as a flash unit. By the way, the smartphone also has a factory built-in facility with which the LED can be turned on and used as a torch. I never made a test to see if there is a time limit after which it is turned off automatically due to overheating limits, however it can definitely stay on for few minutes without all the terrifying effects that you describe happening.

Yesterday evening I gave the app a try with a turntable and unfortunately it's just terrible, to the point of being useless. Very unsteady, and so many bursts are skipped that the strobe dots are very hard to be seen, while you seriously risk seizures. Much inferior to a common incandescent light. (Of course it may behave differently on other smartphones).

While trying it I've found out that Strobily's author provides an e-mail address within the app. I will try and drop him few lines, and see if he will have patience and time enough to reply.
GOD is REAL. Unless declared DOUBLE PRECISION.
User avatar
beamrider
Vic 20 Scientist
Posts: 1447
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: Stroboscopes: why smartphone LED can't blink fast?

Post by beamrider »

If you look at the stock driver source code for LED devices under Android, you can see at lines 65-80 that it tries to obtain an execution context and if not available schedules the work for some time later.

As mentioned earlier, I would suggest this could be the reason for your issues rather than anything to do with the hardware itself.

Remember that in a multitasking OS, you don't have direct control over the LEDs from your program code, you ask the operating system to turn it on/off which it does when it gets around to it.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Stroboscopes: why smartphone LED can't blink fast?

Post by Mike »

Mike, of course when the LED is used as a stroboscope it's not driven at high power as when used as a flash unit.
"Of course"? Can you really be sure that the app isn't misusing the presumably faster response of the LED when it is triggered as flash?
highinfidelity wrote:[...] the smartphone also has a factory built-in facility with which the LED can be turned on and used as a torch.
That's exactly what I described as 'normal on/off action' in my preceding post, with the slow ramp up/down facility of the regulator.
I never made a test to see if there is a time limit after which it is turned off automatically due to overheating limits, however it can definitely stay on for few minutes without all the terrifying effects that you describe happening.
What terrifying effects? The manufactorer enforces the heat management anyway. Worst that could happen is it drains your smartphone accu. Second worst, the shell of your smartphone becomes slightly warmer than expected. That what you want as application (stroboscope) is not delivered is caused in part by the OS (though, for the application as flash light it's surely a bad idea to leave the timing to a standard non-real-time multitasking environment :P ), and in other part by the regulator hardware.
While trying it I've found out that Strobily's author provides an e-mail address within the app. I will try and drop him few lines, and see if he will have patience and time enough to reply.
Let's see if he adds something as explanation that hasn't been covered before here. :wink:
User avatar
highinfidelity
Vic 20 Nerd
Posts: 644
Joined: Thu Jul 28, 2011 2:34 am
Website: http://www.hirtel.it
Location: Torino, Italy.

Re: Stroboscopes: why smartphone LED can't blink fast?

Post by highinfidelity »

beamrider wrote:If you look at the stock driver source code for LED devices under Android, you can see at lines 65-80 that it tries to obtain an execution context and if not available schedules the work for some time later.

As mentioned earlier, I would suggest this could be the reason for your issues rather than anything to do with the hardware itself.

Remember that in a multitasking OS, you don't have direct control over the LEDs from your program code, you ask the operating system to turn it on/off which it does when it gets around to it.
That's interesting and might very well be the cause. I'm still surprised, though, that this scheduled timing is slower than 50 cycles per second, when the OS runs on a hex-core 64bit CPU at 2 GHz (I checked the data in the menwhile). I suppose the VIC20 could possibly do better. There is also a in-app switch with which maximum OS priority can be given to Strobily, but eventually even this feature doesn't improve the LED behaviour significantly. The author also suggests in the notes to switch the phone to airplane mode and to shut the screen off in order to avoid screen refreshes, but again to no avail.
GOD is REAL. Unless declared DOUBLE PRECISION.
User avatar
Mike
Herr VC
Posts: 4816
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: Stroboscopes: why smartphone LED can't blink fast?

Post by Mike »

highinfidelity wrote:[...] the OS runs on a hex-core 64bit CPU at 2 GHz [...]
The CPU could even run at infinite speed: when a resource is locked it can't do anything about this. And then it waits... and waits... and waits... until the resource is available, and then the locked thread/process can continue.

That's a problem with all non-real-time OS'es nowadays. The timing behaviour just can't be guaranteed in the presence of hundreds of processes, threads, file handles, locks, cache misses and what else.

Of course a VIC-20 will fare far better with a single real-time application. Witness my Paddlescope. Or anything else simply running in IRQ or NMI.

My bet still is on a combination on both software and hardware reasons (those already laid in my preceding two posts).
User avatar
beamrider
Vic 20 Scientist
Posts: 1447
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: Stroboscopes: why smartphone LED can't blink fast?

Post by beamrider »

Expanding on this consider what would happen if you had multiple programs all trying to switch the led on and off rapidly running at the same time. What should the behaviour be?

It makes sense for the OS to allocate a minimum time granularity for the LED especially taking into account possible hardware restrictions mentioned by Mike.
User avatar
highinfidelity
Vic 20 Nerd
Posts: 644
Joined: Thu Jul 28, 2011 2:34 am
Website: http://www.hirtel.it
Location: Torino, Italy.

Re: Stroboscopes: why smartphone LED can't blink fast?

Post by highinfidelity »

Although all you say is possibly (probably) correct, still there are only three apps that may require access to the flash LED:

1) camera
2) torch
3) strobily

1 and 2 are deactivated, so as a matter of fact we end with only one application requesting access.

And even though I can understand how complicated multi-tasking is, once again we're talking about a hex-processor with 2000000000 cycles of clock per second being asked to flash a LED 50 times per second and it miserably fails, while on the other hand it can display a 4K movie as a breeze. However you put it and whatever the reason, you must admit that it's "a bit strange" and quite disconcerting, isn't it?
GOD is REAL. Unless declared DOUBLE PRECISION.
User avatar
beamrider
Vic 20 Scientist
Posts: 1447
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: Stroboscopes: why smartphone LED can't blink fast?

Post by beamrider »

Other than debugging your own custom build of Android and writing your own high performance LED driver, I don't think there is an easy way to answer your query. Perhaps try the XDA developers forum.

But looks like your are using the wrong tool for the job, an Arduino solution would be more suited...
User avatar
beamrider
Vic 20 Scientist
Posts: 1447
Joined: Sun Oct 17, 2010 2:28 pm
Location: UK

Re: Stroboscopes: why smartphone LED can't blink fast?

Post by beamrider »

Mike wrote:That what you want as application (stroboscope) is not delivered is caused in part by the OS (though, for the application as flash light it's surely a bad idea to leave the timing to a standard non-real-time multitasking environment :P ), and in other part by the regulator hardware.
Interesting you should mention this. If you look at the Android HIDL for LEDs, you can see that it supports hardware assisted flashing (i.e. the light flashes itself).

Whether strobily uses this or the OPs phone supports it is anyone's guess. If it is used it may also enforce minimum durations over and above those of the phone OS.
User avatar
highinfidelity
Vic 20 Nerd
Posts: 644
Joined: Thu Jul 28, 2011 2:34 am
Website: http://www.hirtel.it
Location: Torino, Italy.

Re: Stroboscopes: why smartphone LED can't blink fast?

Post by highinfidelity »

The author took care to reply, and it was a very detailed and committed reply, which took me somewhat by surprise as the few times that I've tried to get in contact with an app developer in the past, I never got any kind of answer by anyone. Here are some of his notes about the routine that turns the LED on and off:
The first step is to open the Camera. Once you have the Camera, you're supposed to enable a video preview (the Preview Hack), I've found this step isn't necessary however. The third step is to read the camera parameters (which include things like pixel density, auto focus, white balance) and to set the flash state to FLASH_MODE_TORCH. Finally one writes the camera parameters to the camera and it sets its state. (I've tried to strip everything out of the parameters except the flash state which is what the Performance Hack is. When it works it helps.)

To make matters worse, not only are you setting camera parameters, but the camera runs in a different process. This is why the Full CPU option exists. It maxes out the processor with low priority threads, which increases the cpu frequency, and therefore makes the other process run faster.

Right before I had to stop working on the app (and right after I added diagnostic mode), I was running a profiler on the whole phone to figure out why I wasn't getting better performance. Now this is not the greatest analysis, but from what I could tell, there was some polling service that was running ~200 times per second. One would set the camera parameters (which blocks the calling function), wait for the next poll, see cpu activity in another process for maybe 8 polling intervals, and then the original process would unblock.

So in summary, I'd say the two problems are asynchronous commands and too high-level of control.
Concerning hardware assisted flashing as per your last post, he commented that this kind of interface didn't exist when he worked at the app (2011-2014).

He also has in mind to release his code as open source in the near future and see if someone may pick it up and improve performance.
GOD is REAL. Unless declared DOUBLE PRECISION.
Post Reply