Go Down

### Topic: Measuring tiny intervals (Read 2967 times)previous topic - next topic

#### Shashinka

##### Feb 21, 2012, 10:57 am
Hi,

Sorry for my first post in this forum being stupid questions ;-)
I also hope that there is not already a thread covering this topic. I searched but the results seemed not to suit my intentions.

My problem is as follows.

I want to check the shutter speed of my 'analog' cameras. Therefore I decided to use a photo diode as sensor together with a pull down resistor. The circuit seems to work well.

The corresponding program checks whether the status of a digital input pin has changed. When it has changed to HIGH, it stores the value returned by micros(). When it falls back to LOW, it calculates the diference between the current result of micros() and the previous value.

The time in micro seconds is then output via serial console.

At first I was very happy as everything worked as planned. However, when intervals get shorter there is no more linear correlation and the values returned seem to level off around 3000-4000 microseconds. That corresponds to a shutter speed of 1/250s.

First I thought that this might account to that fact that for focal plane shutters the time the "slit" is moving across the film plane is usually longer than the exposure time. However, I observed the same result for central shutters.

My questions:

Is it possible that the time the code needs to run is too long to measure intervals shorter than 4000 microseconds? How can I improve this?

Is it possibile that my circuit is too slow. e.g. not producing steep signals? Maybe I need a photo sensor which automatically integrates the light intensity like those used in light meters?

#### PeterH

#1
##### Feb 21, 2012, 01:49 pm

Is it possible that the time the code needs to run is too long to measure intervals shorter than 4000 microseconds? How can I improve this?

Is it possibile that my circuit is too slow. e.g. not producing steep signals? Maybe I need a photo sensor which automatically integrates the light intensity like those used in light meters?

Both possibilities seem feasible. It's impossible to tell whether your code is capable of measuring short intervals without seeing the code, though.

Do you know what the response characteristics of the photodiode are? Is it actually capable of responding to changes fast enough to detect the shutter opening and closing at your required speeds?
I only provide help via the forum - please do not contact me for private consultancy.

#### DuaneB

#2
##### Feb 21, 2012, 04:52 pmLast Edit: Feb 21, 2012, 04:57 pm by DuaneB Reason: 1
Hi,
With regards to the smallest interval that Arduino can measure, I saw that at the hardware level timer1 has an 'input capture' facility that I would expect to be much faster and more accurate than calling micros().

I have not used it myself but I have had it at the back of my mind to experiment with it, so if no-one else comes up with anything, I will have a go at using this to measure very short intervals and post my code/experience over the weekend.

If you want to have a go for yourself, its in the ATMega328 datasheet in the 16 bit timer section and I am sure there are examples for using it if you search around.

Duane B

rcarduino.blogspot.com
http://rcarduino.blogspot.com/2012/04/servo-problems-with-arduino-part-1.html
then watch this
http://rcarduino.blogspot.com/2012/04/servo-problems-part-2-demonstration.html

Rcarduino.blogspot.com

#### Shashinka

#3
##### Feb 22, 2012, 10:18 am

Both possibilities seem feasible. It's impossible to tell whether your code is capable of measuring short intervals without seeing the code, though.

I will provide the code later today when I have access to my other PC. However it seems really simple to me only consisting of a digitalread() and some if/else branches.

Quote

Do you know what the response characteristics of the photodiode are? Is it actually capable of responding to changes fast enough to detect the shutter opening and closing at your required speeds?

It is a BPW40 type if I am not mistaken. In the meantime, I figured out that the circuit used is probably limited to a frequency of about 8000 Hz which could be too slow.
For higher frequencies people use the photodiode in a quasi short circuit and use a transimpedance amplifier to convert the current into a proportional voltage.
The latter would take a little longer to test because I do not have a circuit diagram or the necessary parts at hand.

#### Grumpy_Mike

#4
##### Feb 22, 2012, 10:56 am
Quote
I will provide the code later today

Good, can you provide a schematic as well.

The point is that depending on how long it is between looks at the sensor, you might miss some time. It could be that you need to use the interrupts to do the timing.

#### Shashinka

#5
##### Feb 23, 2012, 12:01 am
Here is the code

Code: [Select]
`int receiverPin = 12; // input from the ir receiver.int value = 0 ; // status of digital inputint prevvalue = 0; // previous state of the digital inputunsigned long duration = 0; // time shutter is openunsigned long starttime = 0; // for counting the timeunsigned long endtime = 0; void setup(){  pinMode(receiverPin, INPUT);  Serial.begin(9600);}void loop(){    value = digitalRead(receiverPin);  if (value != prevvalue)  {      if(value==LOW)      {       // Serial.println("LOW");        starttime = micros();       }      else     {      // Serial.println("HIGH");       endtime = micros();       if( endtime > starttime)        {      duration = endtime - starttime;      Serial.println(duration);       }     }      prevvalue = value;  }} `

Now that I think of it, the circuit must actually have been using a pull-up resistor. Otherwise it would not work with a LOW signal when light hits the photo diode.

The circuit was similar to this one. Only the resistor was different.

#### Nick Gammon

#6
##### Feb 23, 2012, 07:28 am
I tried your exact code, feeding in a 50 kHz signal (20 uS period) which would give 10 uS as the interval between low and high. It output:

Code: [Select]
`81281212`

So, slightly out for 20 uS (10 would be the correct answer as there are two pulses per interval).

So your code is OK - interrupts might improve it slightly, but probably not by much. Indeed, interrupts take 3.5 uS or so to service, and the error amount is less than that.

Therefore the problem is hardware, probably the time taken for the sensor to react.
Please post technical questions on the forum, not by personal message. Thanks!

http://www.gammon.com.au/electronics

#### GoForSmoke

#7
##### Feb 23, 2012, 08:20 am
You -could- use the light detector to charge a small R-C and time the bleed over a much longer period than the shutter open and close. It would need to be calibrated, say keep the shutter open while you blink the light source (a led for instance) for a known time (1/100th of a second?). After all, what does the film get? Light and duration.

2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

#### Shashinka

#8
##### Feb 23, 2012, 10:06 am

Therefore the problem is hardware, probably the time taken for the sensor to react.

Thank you very much for testing.

After reading a little bit about the mode of operation of photo diodes I am pretty sure, that the circuit is too simple.

I think I will try the method using a transimpedance amplifier.

I also thought that a photo transistor which has an additional base connector might work better. But that would be my second choice.

#### Shashinka

#9
##### Feb 23, 2012, 10:20 am

You -could- use the light detector to charge a small R-C and time the bleed over a much longer period than the shutter open and close.

Just for my understanding:

When light hits the photo diode, the current flowing is used to charge a condensator.
The condensator then discharges through a resistor which takes longer due to the lower current.
For me it seems that I still need something like an IU-converter because Arduino measures voltages and not currents, am I mistaken?

#### Shashinka

#10
##### Feb 23, 2012, 05:57 pm
Me stupid...

The BPW40 is a photo transistor, not a photo diode. I think I should get myself a real photo diode before I think about improving the circuit.

#### GoForSmoke

#11
##### Feb 24, 2012, 01:09 am

You -could- use the light detector to charge a small R-C and time the bleed over a much longer period than the shutter open and close.

Just for my understanding:

When light hits the photo diode, the current flowing is used to charge a condensator.
The condensator then discharges through a resistor which takes longer due to the lower current.
For me it seems that I still need something like an IU-converter because Arduino measures voltages and not currents, am I mistaken?

You are close. While the discharge is happening, the circuit is read digital in a loop that only increments a counter (how many cycles, read-branch?) and when the voltage drops below, I think, 1.1V the loop is terminated and the count says how long.

Normally I see it used with very small R-C values leading to very short intervals, the ability to time < 4 usecs in some topics. Always for short and precise the interrupts are turned off while measuring.

The thing is that you don't need to match the interval of shutter operation in the process of digitizing. You can use an R-C combination that takes longer to bleed than the shutter took to blink. The capacitor is going to take as long to bleed as it does. The charge came controlled by how much light got through. You can to a large degree create your own precision by controlling how much current goes to the R-C (transistor circuit) and what you used in the R-C. The thing there is you don't want interrupts off so long and still rely on counters and some other things, it's frowned on but I think possible.
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

#### Shashinka

#12
##### Apr 04, 2012, 11:41 am
Hi

I just want you let you know that I tried using a real photo diode (BPW 34) instead of the photo transistor.
It really makes a difference! Measuring down to about 500 µs opening time is possible. That's more than sufficient for my purposes.

Go Up

Please enter a valid email to subscribe