I don't understand the frequency I am measuring

Hi
I have this circuit

Laser2 shine its light on the photodiode D1, it activates Laser1 that shine its light to D3 that turn off Laser2 and so I have a on-off cycle for the lasers.

I want to measure the frequency at witch they operate with an arduino board.

From datasheets I know that the time to switch for the transistor is about 300ns and the rise time for both the photo diode and laser should be less than 100ns(Unfortunately I don’t have them), so I would expect a frequency of the order of 1MHz.

But what I am measuring is at most 80KHz, and the measurement is inconsistent(it ranges from 30-70KHz). Looking at the laser I can see that Laser2 has a lower intensity than Laser1.

Using analogRead I saw that Arduino read value from 300 to 800 .

I thought that Arduino is unable to count some measurement because it does not reach a threshold for a digital 1.

Or maybe there are significant parasitic capacitance on the breadboard.

What do you think I should change on the circuit?

Thanks for the help!

Without current limiting on the laser diodes you may be damaging them, note.

Also this can mean the 2N2222's are heavily into saturation so will switch off slowly. The charge storage
time is 220ns at 150mA, it will increase with current as more charge is in the base when the saturation current
is higher. The 2N2222 has very low storage times, but it will still get worse with higher current.

Also the 2N2222 datasheet lists the switching times at 30V load, not 5V (which will be slower).

We also don't know the photo-diode's capacitance, which forms a time-constant with the 2k2 resistors.
Photodiode capacitance will be highest when the voltage across it is low - normally for fast operation you'd
keep the photodiodes reverse biased (lower capacitance) and drive a transconductance amplifier from it.

You've drawn the photodiodes backwards.

Another issue is we don't know if the lasers are strong enough to cause enough photo current to fully
extinguish the conduction in the transistors - an oscilloscope on the various nodes in the circuit would
be really useful diagnostic.

alebossi96:
Using analogRead I saw that Arduino read value from 300 to 800 .

I thought that Arduino is unable to count some measurement because it does not reach a threshold for a digital 1.

MarkT did a great job of covering the core of your issue [far better than I could have–my strengths are more in the Digital/Firmware arena), but he missed the question I quoted, above…so here goes:

First, I’m going to assume you mean Arduino Uno, when you say “Arduino”.

So, it sounds like you’re confusing the characteristics of Digital Inputs, with those of Analog Inputs.

An Analog Input, feeds a 10-bit ADC. As such the resulting values range from 0-1023, for an input voltage range of 0.00 to “+5V” ["+5V", in this case, is a substitute for whatever the actual “VCC” voltage is – something between 4.95V and 5.10V]. Assuming the Uno’s Regulator is holding the “+5V” rail at exactly 5.00V, a conversion value of 300, would be induced by the following input voltage:

[b](300/1023)*5.00 = [u]1.47 Volts[/u][/b]

and 800:

[b](800/1023)*5.00 = [u]3.91 Volts[/u][/b]

An input configured as Digital, has the following thresholds, where a “1” or a “0” is guaranteed:

0” same as VIL: [b]0.3 * V[/b][sub][b]CC[/b][/sub] or [b]0.3 * 5.00 = [/b][u][b]1.5V[/b][/u]
"
</sub>[/u] [u]<sub>1</sub>[/u] [u]<sub>
" same as VIH: [b]0.7 * V[/b][sub][b]CC[/b][/sub] or [b]0.7 * 5.00 = [u]3[/u][/b][u][b].5V[/b][/u]

Plus there’s, at minimum, 50mV of Hysteresis, so lets have a look at that [hopefully I get this right :o ]:

Any input voltage below 1.5V + hysteresis, is guaranteed to be interpreted as a “0” or “LOW”. And, an input voltage above 3.5V + hysteresis is guaranteed to be interpreted as a “1” or “HIGH”. Any voltage inbetween those two values, might be interpreted as a “0” or might be interpreted as a “1”. It will be one, or the other, and, because this is a Schmitt Trigger input, that nebulous area between 1.45V and 3.55V will behave like this: if it was a “0” before, it won’t become a “1” until the input voltage rises above the upper threshold + hysteresis [3.55V]. And, if it was a “1” before, it won’t become a “0” until the input voltage falls below the lower threshold + hysteresis [1.45V] – and, remember, we’re assuming the regulator is holding “+5V” at 5.00V, so the 3.55V and 1.45V levels are only valid for 5.00V.

In terms of the lower of your two Analog “reads”, 300 results in 1.47V, which is not below the 1.45V threshold, so it will stay a “0” if it was a “0”, and will stay a “1” if it was a “1”.

BUT, remember, we assumed perfect regulation at 5.00V. If it’s regulating at more than 50mV above the nominal 5.00V, then 1.47V would be a solid “0” – e.g: 5.10V * 0.3 - 0.05V = a lower threshold of 1.48V, thus 1.47V becomes a solid “0”.

Then, in the case of your 800 read, that’s a voltage of 3.91V, which is well above the upper threshold, even if we consider hysteresis AND even if the “+5V” voltage is 5.10V, so that’s a solid “1”.

So, I’m guessing the regulator, on your UNO, is running a little high – which is fine, as long as it isn’t above 5.10V. If it is, then it’s out-of-spec!

Thanks for the help!

It was really helpful!

alebossi96:
Thanks for the help!

It was really helpful!

"Help" usually is :wink:

alebossi96:
From datasheets I know that the time to switch for the transistor is about 300ns and the rise time for both the photo diode and laser should be less than 100ns(Unfortunately I don’t have them), so I would expect a frequency of the order of 1MHz.

That’s indeed without any real life parasitics.
A breadboard is a great source of those, the transistor can be as well. Maybe use a MOSFET, should be faster in switching.

Looking at the laser I can see that Laser2 has a lower intensity than Laser1.

Sounds scary.
Remember: don’t look in laser with remaining eye!

The values you read suggest you get sufficient swing for proper detection, but a comparator may help here to shore up this signal more.

1 MHz is no problem for an Arduino as such but you must have a sketch that’s written for it. It’s not trivial.