Pages: [1]   Go Down
Author Topic: How to do exact time blinking for a Led  (Read 525 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 219
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 545
Posts: 27352
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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.
  }
}
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 209
Posts: 13023
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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...

Quote
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.
Logged

Offline Offline
Edison Member
*
Karma: 36
Posts: leet
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The crystal-clock in your camera is probably MORE accurate than the Arduino resonator-clock. smiley-wink

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.
« Last Edit: February 05, 2013, 02:13:25 pm by DVDdoug » Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 219
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1468
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 219
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 33
Posts: 1468
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, thought you were using a DSLR!

Logged

Pages: [1]   Go Up
Jump to: