Perfectly Sync Framerate

Hi everyone, I'm a little new to Arduino and I was hoping I could get opinions on the best way to approach a project. I'm building a lighting rig for video with multiple LED lights. The goal is to shoot footage at a high framerate (120 fps probably) and have a different light turned on for each frame. Getting it perfectly synced is crucial for the project to work. I have a first version of the rig built, but it needs some work.

I did some lower speed tests (30fps) using the delay function and was having too much drift on the timing. I actually had better results at 50fps because I could set the timer to an even 20ms instead of 16.6667ms. Even then it would only stay in sync for a bit before I'd hit a frame or two where two lights would fire, or even a frame where no lights would fire. From a code standpoint, I have some ideas to tighten things up. Currently I'm only measuring the time since the last event, so any small discrepancies in timing would compound on each other, slowly getting more and more off. If I store the time at the start of the application I can compare current time to total time and correct for any slide. Do you think that would be enough or do I need to look into some sort of time crystal? I'm concerned that this method still won't be accurate enough to switch every 8.3333ms. If a time crystal or other hardware addition would help I'd really appreciate recommendations. I'm currently using an UNO, but would switch if another board would be better for this.

My other problem is that I don't have enough light. My current LEDs are powered directly off the pins of my UNO, but I'm looking to upgrade to 12v LED strips which will require an external power source. It seems like relays will be too slow for my needs, so I was thinking I could use a transistor like the TIP120 or TIP102 which I would wire like the schematic posted by CrossRoads at the bottom of this thread http://forum.arduino.cc/index.php?PHPSESSID=9vevlsv5c4pkmdqegscfsmjoo3&topic=128938.15. Any issue there?

I have a lot of background coding complex things in javascript and actionscript, so I think I should be able to hang with any code suggestions. BUT I'm pretty much a n00b on the electronics side of things, so please bare with me if I need a little more explanation on that stuff. Thanks for your help!

One additional thing that might be worth mentioning. If there is enough light produced then the lights won't need to stay lit for every long, just a quick flash to expose the frame. In fact there should be some time between lights firing to allow for light in the room to dissipate, and to make sure that only one light is fired per frame. This empty time between light allows for a margin of error up to a few milliseconds for each individual frame as long as those little 1-2ms errors don't compound.

Unless you have some sort of feedback between the shutter and the arduino then you will always get drift.

No amount of twiddling with the software will fix it. This is because the arduino has a fixed clock period so time is only adjustable in 62.5nS lumps. Even then the 62.5nS has a tolerance on it.

Thanks for the reply! I wasn't aware of the 62.5ns lumps which may be very helpful. I know that I can't ever be sure that the camera and light rig start in sync to each other, so that part will be trial and error. Apart from syncing their start times, I'm hoping that I can trust the camera's timing to not drift, but that's an unknown. If I can remove as much drift from the light rig as possible, and keep individual drifts from compounding then I think that's as good as I can do.

I'm assuming that this system will never result in a 100% perfect sync, but hopefully I can get close enough that I'll only have to fix a frame every few seconds in post. My last test at 50fps was promising.

I'm hoping that I can trust the camera's timing to not drift, but that's an unknown.

That is the point I am making, you can never get a system that does not drift over time.

Agreed. Do you have any advice on how I can reduce the drift on the arduino side?

strobed58:
Agreed. Do you have any advice on how I can reduce the drift on the arduino side?

Unless you provide a way to maintain sync, you will never be more accurate than the Arduino's clock. That varies depending what sort of Arduino you're using and specifically what clock source it is using. However, if you code it badly you can introduce a lot of additional drift, so if your drift is significantly worse that the clock's accuracy then I suggest you post your code.

The lower you can keep the duty cycle on the light the further the clock can drift before a given flash crosses a frame boundary, so brighter lighting and shorter flashes will work in your favour. But ultimately, unless you provide a mechanism to keep the lighting in sync, it's inevitably going to drift.

It seems that the best thing I can do is to tighten up my code and get my duty cycle as low as possible so that it allows for a higher margin of error. Regarding the lights power supply, would a transistor work to switch them on instead of a relay? I've seen the TIP120 or TIP102 transistors suggested for this, but I've also seen people say that you need a logic level transistor which I don't think those are. Can anyone elaborate on that? This transistor also seems like a good choice: N-Channel MOSFET 60V 30A - COM-10213 - SparkFun Electronics

Ordering parts can take a few days so I'd just like to be sure that I order the right parts the first time. Thanks for all of your help so far!

I would suggest you learn how to use interrupts.
Bring in your 120fps clock signal, create an interrupt with it, and go from there.
I am doing the same with 195 outputs using shift registers. The pattern is pre-loaded, then moved to the output of the shift regsisters with the interrupt - at 20,000 fps. So 120 fps would be pretty slow in comparison.

How many independent light outputs do you need to control, and how much current is each light output drawing? Using a mechanical relay is a terrible solution for these frequencies and you should be aiming to use an electronic switch. If you're only switching a few amps at low voltage then a motor driver would give a convenient solution.

CrossRoads:
I would suggest you learn how to use interrupts.
Bring in your 120fps clock signal, create an interrupt with it, and go from there.
I am doing the same with 195 outputs using shift registers. The pattern is pre-loaded, then moved to the output of the shift regsisters with the interrupt - at 20,000 fps. So 120 fps would be pretty slow in comparison.

Unfortunately my camera does not accept or output a clock signal. It is not capable of "genlock". It seems like that would really be the best option for a sync, but without spending a lot of money on a new camera that isn't going to be an option. I did find this tool though which seems like it will help me get an exact frame rate out of my camera: [EOS] TimerGen Tool – g3gg0.de

When considering 120fps I was going to borrow a RED Epic, which is capable of genlock, but I can't get it for more than a couple hours, so working out a system for that isn't feasible. :confused: For now I think I should focus on getting 60fps working with my canon t2i... if I find that is impossible then I'll consider buying a new camera.

PeterH:
How many independent light outputs do you need to control, and how much current is each light output drawing? Using a mechanical relay is a terrible solution for these frequencies and you should be aiming to use an electronic switch. If you're only switching a few amps at low voltage then a motor driver would give a convenient solution.

I'm going to be controlling 4-5 lights. They are standard 12v LED strips bought off of ebay, it says they pull about 0.5A per meter. I have 15 meters which I was going to use to create all of my lights, though I might not need to use it all. My current power supply is 2A so I would plan on using no more than 4 meters per light, and only one light should be on at a time. Would a motor driver be a better choice than MOSFET transistors?

Thanks again for your help. It really is great to have people to bounce ideas off of.

Hopefully these strips include all the current control circuitry and can be hooked straight up to 12V, but do check.

If you only need to control 12V at 2A per output then any of the common L298 based motor drivers would be fine. They conveniently give you a dual h-bridge i.e. four independently controllable outputs each capable of supplying 2A. Maximum current for the whole thing is only 4A but if you're only turning on one at a time that wouldn't be an issue.

Nothing wrong with using any other drive circuit if you prefer and it would certainly be possible to make your own drive circuit cheaper, but there isn't a lot of money at stake and a product off the shelf saves you a lot of hassle.

During testing of the timing accuracy I would advise you to test using a much lower power output for simplicity.

By the way, are you really concerned about allowing time for "light in the room to dissipate"? I would have thought that would happen at about the speed of light and if that's a concern you aren't working in Arduino timing territory!

PeterH:
Hopefully these strips include all the current control circuitry and can be hooked straight up to 12V, but do check.

I'll see if I can find anything else about this. As far as I know they are just a bunch of LEDs wired in a strip, but no special circuitry.

PeterH:
If you only need to control 12V at 2A per output then any of the common L298 based motor drivers would be fine. They conveniently give you a dual h-bridge i.e. four independently controllable outputs each capable of supplying 2A. Maximum current for the whole thing is only 4A but if you're only turning on one at a time that wouldn't be an issue.

I just ordered two of these! If I read your note correctly I only need one, but an extra couldn't hurt. I think testing the timing accuracy with lower power does make sense. I can work on the timing with my current rig.

PeterH:
By the way, are you really concerned about allowing time for "light in the room to dissipate"? I would have thought that would happen at about the speed of light and if that's a concern you aren't working in Arduino timing territory!

Haha, you got me there. I'm sure it's not an issue.

strobed58:
I'll see if I can find anything else about this. As far as I know they are just a bunch of LEDs wired in a strip, but no special circuitry.

Each LED or chain of LEDs in series should have some form of current limiting device - perhaps just a series resistor.

What I've noticed during shooting video (with Canon DSLRs, you too seem to be using) short flashes of light don't look nice in video.
CMOS sensor in the camera doesn't actually take instantaneous pictures but rather scans gradually through the sensor, so one part of the picture always shows an earlier image than some other part.
The effect is that with short flashes the frame tends to be partially exposed showing horizontal lines.

This is what I mean (around 1:45).

The flashing light in this case were too LED strips controlled by a DMX thingy.

Good news! I set up a simplified timing test with 4 LEDs mounted on a breadboard. With a bit of tinkering I was able to shoot a 30 second video at 60fps that stayed in sync the whole time. I brought the footage into after effects and wrote an expression to only show every 4th frame. The video looks as though a single LED is constantly lit.

My first attempts were off based on the assumption that the camera was shooting at 59.94fps, but it was slightly off, I lost a frame approx every 16 seconds. I removed 17 microseconds from each switch and it seemed to line up great.

PeterH:
Each LED or chain of LEDs in series should have some form of current limiting device - perhaps just a series resistor.

That makes sense. What would a good value for that resistor be? Or if I need to calculate it, what would the calculation be? I apologize for being such a n00b when it comes to electrical circuits!

Shpaget:
CMOS sensor in the camera doesn't actually take instantaneous pictures but rather scans gradually through the sensor, so one part of the picture always shows an earlier image than some other part.

The rolling shutter is a concern. As long as I can get enough light my plan to account for this is to turn up my shutter speed and leave the lights on for the full frame duration. So the light changes every 1/60s, but each frame only exposes for 1/500s or however fast my lighting will allow... my test this morning was 1/1000th of a second, but I saw some rolling shutter problems when I was at lower shutter speeds.

strobed58:
Or if I need to calculate it, what would the calculation be?

Maybe the manufacturer of that LED strip has already got a solution in mind to control the current. If not, then you will need to provide that yourself and how you do it will depend on the characteristics of the LEDs and how they are connected. Here's an explanation of the calculation for a single LED:

https://www.sparkfun.com/tutorials/219

Why not just leave the LEDs on all the time?

PeterH:
Maybe the manufacturer of that LED strip has already got a solution in mind to control the current. If not, then you will need to provide that yourself and how you do it will depend on the characteristics of the LEDs and how they are connected. Here's an explanation of the calculation for a single LED:

LED Current Limiting Resistors - SparkFun Electronics

I'll see if I can find any info on the manufacturers site... if not I may just cut open a short piece and see what's in there. The ebay store I ordered from doesn't sell anything seperately that would fill that function, just standard power supplies, which leads me to believe it would have that stuff built into the strip.

CrossRoads:
Why not just leave the LEDs on all the time?

I'm trying to shoot a single video with multiple light conditions that can be combined to create a fake normal map. Basically a video version of this Normal Map Photography

strobed58:
if not I may just cut open a short piece and see what's in there.

It seems a bit strange to sell you an electrical component without any instructions about how it should be used, and I would be astonished if it was necessary to dismantle it to find out how to use it.