petttu
Posts: 2
Joined: Tue Jul 07, 2020 5:07 pm

Global shutter timing

Tue Jul 07, 2020 8:15 pm

Hello, basically doing another project where I found introduced to this UTOFIA ( https://www.utofia.eu/ ), In short it is an underwater camera system using a laser pulses and a range-gating camera. So there is a laser pulse that is synced to the camera, so that pulse is over around ( 20-80 ns) before the camera shutter opens.

Well it is an expensive system, so I had a thought that how close can one get by using cheaper parts. The aim would be to build a similar system (probably worse performing) but cheaper. I do understand there is a high probability that it does not work at all, but I would like to know how close can we go by using cheap parts. Theoretically it is just an timing issue, but since were are in the ns region it will be really hard.
So the idea that I have is to use Raspberry, ArduCam's OV9281 (monochrome global shutter) camera, and some kind of laser. I already have an raspberry and the camera (and well I will probably use a china laser, since I already have one of those to test). For the sync/timing there would be 3 options, using raspberry's GPIO pins (using flash function), using the camera boards strobe pin and using the cameras FSIN pin (external trigger).

The external trigger would probably be the easiest way, so I figured that theoretically if I would just make an signal for it and use some ultra high speed mosfet (or transitor) to control a laser module (probably no driver/ just an resistor for speed) and then use some delay chips to delay the signal that would go to FSIN. In theory as long as the signal (and the laser) will have consistence sync, one could just add delay for the FSIN, until the laser is somewhere near to the desired timing. For the delay I could use something like Maxim DS1100, of course some adjustable delay from Raspberry/ Arduino / stm32 would be useful, but with so small delay, I dont think that they are capable of providing it.

Problems are, that there is not much information how does the FSIN works in that camera, but in this there is an simple solution ( https://www.arducam.com/docs/usb-camera ... er-camera/ ) they have just connected an Arduino for the signal. I thing that maybe the signal generator will be the most problematic thing, because I have no idea how fast does the signal rise (so there could be a significant delays with it, depending of course by what device I am using). And the other thing is that I dont know what is the delay in the camera between receiving a signal in FSIN and start of the frame/open shutter. And off course the laser might not shut down fast enough for this.

I thing there would be a lot more hassling with trying to time the laser with either Raspberry's GPIO pins or the probe pin, because I really cant just and a little delay, but would be forced to create first a delay at the millisecond scale, and after that trying the get the ns delay to work.

Any ideas/comments to improve it or some reasons why it could not work at all?

cleverca22
Posts: 528
Joined: Sat Aug 18, 2012 2:33 pm

Re: Global shutter timing

Tue Jul 07, 2020 11:02 pm

there are options for hardware camera sync pulses

once you measure the timing from start to start, you can set a pi external timer (in a microcontroller) to trigger the laser before frame start

and this thread has some info on which cameras can do global shutter

User avatar
HermannSW
Posts: 2564
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Global shutter timing

Wed Jul 08, 2020 7:01 am

petttu wrote:
Tue Jul 07, 2020 8:15 pm
The external trigger would probably be the easiest way,
It is, there is a sample program in Arducam repo for ov9281 sensor, and I have tested that it works:
https://github.com/ArduCAM/MIPI_Camera/ ... _trigger.c
so I figured that theoretically if I would just make an signal for it and use some ultra high speed mosfet (or transitor) to control a laser module (probably no driver/ just an resistor for speed) and then use some delay chips to delay the signal that would go to FSIN. In theory as long as the signal (and the laser) will have consistence sync, one could just add delay for the FSIN, until the laser is somewhere near to the desired timing. For the delay I could use something like Maxim DS1100, of course some adjustable delay from Raspberry/ Arduino / stm32 would be useful, but with so small delay, I dont think that they are capable of providing it.
I used NOR gates in the past for fixed nanosecond delays, you can measure with 400Msps or higher resolution logic analyzer.

Pi can easily generate microsecond precision pulses with pigpio library. I used C interface as well as pigs command line tool for v1 camera global external shutter single digit microsecond duration 5000lm led flashes:
https://github.com/Hermann-SW/Raspberry ... al_shutter

Pi can even generate nanosecond length pulses:
viewtopic.php?f=33&t=270197&p=1640379#p1641091
Image

Although using a microcontroller like Arduino (16MHz Uno or 84MHz Due) might be better.

The experiments I did were recreatable in microsecond range, even if sound was involved:
https://github.com/Hermann-SW/Raspberry ... nd-trigger

So I would just setup everything and try out.

The ov9281 has FSYNC pulses as well.. Starting laser "after" having received FSYNC edge that frame has started could be good enough to start the laser then.
https://stamm-wilbrandt.de/en/Raspberry_camera.html
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/raspiraw
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 8715
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Global shutter timing

Wed Jul 08, 2020 8:28 am

I merged a V4L2 driver for OV9281 to the 5.4 kernel branch yesterday - https://github.com/raspberrypi/linux/pull/3709.
I don't have an Arducam module, but it works with the modules I do have ones from Innomaker and Vision Components.

It doesn't enable external trigger mode, but from the information I have available (I don't have a full datasheet), I believe changing register 0x3006 from 0x04 to 0x0c should do it.
If you need faster frame rates then I do have patches for 8bit readout, which increase the frame rate from 120fps to 144. The numbers don't quite work out when computing frame times from VBLANK, HBLANK, width, height, and PIXEL_RATE which is why I haven't pushed those as yet.

Without a datasheet it'll be somewhat guesswork as to exactly what FSIN triggers. One presumes that it'll be a sensor reset and start of exposure, potentially with a slight delay, but that's not guaranteed.
Similarly the behaviour of the strobe output could be start of exposure, or it could be start of readout. You'd need to experiment to work out which.

The Pi camera sync pulses probably aren't accurate enough for you as they are done in software from the ISR on CSI-2 frame start/end, so use those as a last resort.

HermannSW: I don't know if you noticed thread viewtopic.php?f=43&t=277885. I've made a PR for enabling the OV7251 (VGA global shutter sensor) module and dtoverlay, but I don't have one to test with. Any chance you could have a look as I think you got one from Arducam?
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

petttu
Posts: 2
Joined: Tue Jul 07, 2020 5:07 pm

Re: Global shutter timing

Wed Jul 08, 2020 2:42 pm

I used NOR gates in the past for fixed nanosecond delays, you can measure with 400Msps or higher resolution logic analyzer.
Yeah I probably will need to buy one of those DSLogic Analyzers from china (hoping that it would not cause too much delays). Currently I only have an 20kHz handheld china and an old 20MHz analog Phillips oscilloscopes. Not that good for the ns scale. There is almost dead hacklab near by, but I think that their scope is only 100MHz. For the NOR gates I had not thought about, if it goes to some single ns delays, one could always just use some extra wires (15cm extra length for 1 ns delay).
Pi can easily generate microsecond precision pulses with pigpio library. I used C interface as well as pigs command line tool for v1 camera global external shutter single digit microsecond duration 5000lm led flashes

Pi can even generate nanosecond length pulses:
Although using a microcontroller like Arduino (16MHz Uno or 84MHz Due) might be better.
Well yes, I know that raspberry can do it though I read that after something 100 microseconds the cpu load starts to get high (to use it for anything else), and some rumors that the pulses are maybe not that uniform, since the GPIO has some delays (since reading a signal and then applying the delay uses cpu cycles). But what I was trying to say, that I probably cant do that nanosecond delay at the same time when I am using the raspberry for filming. But otherwise haven't looked too deeply at it. That's why I haven't really locked the device/chip to do it. I have an STM32 discovery board but I think that minimum delay with it is some were 60ns. And because the Arduino Uno that I have has only 16MHz clock speed it would perform even worse. If the needed delay would be something like 100-500ns the chip would actually be quite easy to add.
But at the end of the day would probably have to measure it beforehand to get an idea how close is it.

For the sync pulse it is probably good enough to use some microsecond class, that could be build either Raspberry or Arduino, as the example had. Only thing with it is that if the rise time of the signal is some hundreds on ns, then it would affect the delay, but if the delay is consistent it would be fine.
The ov9281 has FSYNC pulses as well.. Starting laser "after" having received FSYNC edge that frame has started could be good enough to start the laser then.
Do you mean VSYNC? And the laser need to be off during the frame/gate open prediod, thats why the external trigger woulb be nice. I have seen some document involving PS3 camera that had Omnivision sensor, that they used to sync some cameras using the VSYNC. But there were 200ns delay between to the VSYNC pins on the synced cameras. Though if it stays consistent there would not be problems, but at that case the delay would have the same problem as the strobe pin, unless there is enough delay between VSYNC and the gate open.
So I would just setup everything and try out.
Probably, though I still need to figure out what delay system to use, but I dont know maybe I should wait for a analyzer/scope so that I could measure the scale off needed delay first. Basically I could borrow another raspberry from my 3d printer if I can get the adjustable ns delay working on it.



If you need faster frame rates then I do have patches for 8bit readout
Thanks, I dont really need a fast camera, 60 or even 30 fps is enough since this is only "strobe timing" not that much of capturing high speed stuff. The aim would be to use it only as an "regular" underwater camera, that has range-gating to "see" further and avoid backscatter.
Without a datasheet it'll be somewhat guesswork as to exactly what FSIN triggers. One presumes that it'll be a sensor reset and start of exposure, potentially with a slight delay, but that's not guaranteed.
Similarly the behaviour of the strobe output could be start of exposure, or it could be start of readout. You'd need to experiment to work out which.
Yes, without datasheet is basically only guessing, thought at the Arducam site stated that "Strobe generates a pulse with a reference starting point at the time when the pixel array starts integration. " So at least in theory I could just measure the delay between FSIN sync pulse and STROBE pulse to see how much delay there is. But I have this feeling that I will end up just trying different delays to find the right one.
The Pi camera sync pulses probably aren't accurate enough
I also heard about it, it is the last resort. And the cameras STROBE pin would actually do exactly the same thing, so there is basically no need for it, unless that it would be so accurate that the delay for the laser could be added straight there.

User avatar
HermannSW
Posts: 2564
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: Global shutter timing

Wed Jul 08, 2020 4:17 pm

HermannSW: I don't know if you noticed thread viewtopic.php?f=43&t=277885. I've made a PR for enabling the OV7251 (VGA global shutter sensor) module and dtoverlay, but I don't have one to test with. Any chance you could have a look as I think you got one from Arducam?
I got two ov7251 0.3MP monochrome global shutter modules from Lee from Arducam. One is built into my raspcatbot, so I will use the other:
https://www.uctronics.com/arducam-ov725 ... amera.html
6by9 wrote:
Wed Jul 08, 2020 8:28 am
I merged a V4L2 driver for OV9281 to the 5.4 kernel branch yesterday - https://github.com/raspberrypi/linux/pull/3709.
I don't have an Arducam module, but it works with the modules I do have ones from Innomaker and Vision Components.
How do I get your latest merges, just run "rpi-update" again?
And after reboot with ov7251 camera connected, will /dev/video0 allow to be used as v4l2 camera?
What should I test?
https://stamm-wilbrandt.de/en/Raspberry_camera.html
https://stamm-wilbrandt.de/en#raspcatbot
https://github.com/Hermann-SW/raspiraw
https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264

Return to “Camera board”