Go Down

Topic: How to do exact time blinking for a Led (Read 1 time) previous topic - next topic


Well i would like to check the frequency of my camera, to checkout if it really does 30fps  or 29.5 fps  or 32fpsb...  etc
While thinking about this, it isnt difficult for me to blink a led, but how would one do accurate timing?
Since each instruction also does cost time


Well, 29.5, 30, 32 frames/second is not all that fast - 1/32 is the fastest, at 31,250 microseconds per frame.
Pretty sure you use micros( ) and control when your LED gets turned on & off to within a few microseconds.
Code: [Select]

void loop(){
currentTime = micros();
if ( (currentTime - previousTime)>= duration){
previousTime = previousTime + duration;
  toggle = 1 - toggle; // results in 1-0-1-0
  digitalWrite(ledPin, (toggle); // and use direct port manipulation to do this even faster.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Coding Badly

Since each instruction also does cost time

As @CrossRoads mentioned, the instruction time is so much faster as to be irrelevant.  Blink-without-delay will get you what you need except...

While thinking about this, it isnt difficult for me to blink a led, but how would one do accurate timing?

You need to provide a definition for "accurate".  It is possible the board you are using is not "accurate" enough for what you want to do.  The only way to know is if you better state the goal.


Feb 05, 2013, 08:08 pm Last Edit: Feb 05, 2013, 08:13 pm by DVDdoug Reason: 1
The crystal-clock in your camera is probably MORE accurate than the Arduino resonator-clock. ;)

But nothing is perfect, and if you shoot with multiple cameras they will drift apart after several minutes (or maybe an hour) of continuous shooting.  And if the audio is recorded separately, you can start to see "lip-sync" problems after a period of time.

With professional audio/video they use a very-accurate master clock linked to all of the equipment to keep multiple cameras and multiple audio recorders in sync. 

And of course, the playback system is equally important...  If you have two copies of a DVD and two DVD players, and if there were a way to start both players at exactly the same time, but the end of the movie, they would probably be out-of-sync by at least a couple of frames.


Dough you gave an interesting answer, since i didn't knew how usb camera's get triggered.

I wanted to make a long movie using a strobe scope but was worried that the strobe scope might get out of sync.   (and so i wanted to test it how precise its timing was)


Use a video camera and record the shutter opening and closing.

Rmember, that the strobe has to fire when the curtains are fully opened, which is the maximum "sync speed" of the camera, usually 1/200 - 1/250 of a second.


Ehm why 1/200   1/250 ?
Wouldnt it be roling shutters on a usb webcam ?


Sorry, thought you were using a DSLR!

Go Up