gordon77
Posts: 4179
Joined: Sun Aug 05, 2012 3:12 pm

Re: Hardware camera sync pulses

Sun Apr 28, 2019 3:16 pm

I thought the idea was you redirect the output to a gpio you do have access to, eg one of the GPIO pins on the pi.

To use pin 18 I changed... (note not a zero)

Lines 1226 to 1228 to

[email protected]_0_LED {
type = "internal";
number = <18>;

and LIne 1193 to

[email protected] { function = "output"; termination = "no_pulling"; }; // Camera LED
whether you use 2 or 3 depends which way you want the pulse to go

If 2, the camera LED GPIO will go low on a frame start, and high on frame end.
If 3, the camera LED GPIO will go high on a frame start, and low on frame end.
Last edited by gordon77 on Tue Jun 04, 2019 8:29 am, edited 1 time in total.

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

Re: Hardware camera sync pulses

Tue Jun 04, 2019 6:55 am

In my 4 months ago posting in this thread I was finally able to get the hardware sync pulses show up on GPIO18. But until yesterday I had no real application making use of that firmware feature.

Because of "Raspberry v1 camera global external shutter" tool "shots" missing synchronization of generating strobe pulses and camera frame capturing I had to go back to pigpio C library yesterday. If the total length of the "shots" waveform is less than 0.5s, then getting all pulses recorded onto a single "-fps 1" raspivid frame is not really a problem (just try several times). But I had to try 15 times to get two 9µs strobe pulses 0.9s apart onto a same frame.

I remembered this thread and used the frame end signal to start the waveform just in time for the new frame to be recorded. The passed argument N states how many frames with (this time 0.925s apart) double exposure should be taken. I tried with 20 and each and every frame got its double exposure correctly. I learned about gpioSetAlertFunc() function, and with that function the code is simple.

More details in "Hardware camera sync pulses" section on "Raspberry v1 camera global external shutter" github repo:
https://github.com/Hermann-SW/Raspberry ... ync-pulses


I did try with double exposure pulses 0.95s apart and got two strange frames instead of one. Because the length between both pulses can be specified with microsecond resolution, it seems that arbitrary length partial frames can be generated (I see no use of that for now, and that was exactly what I wanted to avoid). Anyway it is nice to see that these exact timings are possible thanks to the 2017 firmware change in this thread.

This is the 1st strange frame (as I said this never happens with strobe pulses 0.925s apart). The 2nd strobe pulse happens while nearly half of the frame got transmitted to Pi already, and thefore only the lower left part of the blade shows up on 1st frame:
Image


And this is the 2nd:
Image



These are samples for 0.925s apart strobe pulses, captured on a single frame thanks hardware camera sync pulses. The relative blade positions in each frame differ because of slight changes of propeller speed:
Image


Image


Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

Kinn
Posts: 1
Joined: Fri Jul 12, 2019 5:53 am

Re: Hardware camera sync pulses

Fri Jul 12, 2019 5:55 am

The dts has no entry for the pi4b, any way to get this working?

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

Re: Hardware camera sync pulses

Fri Jul 12, 2019 9:08 am

Kinn wrote:
Fri Jul 12, 2019 5:55 am
The dts has no entry for the pi4b, any way to get this working?
You've already raised it as https://github.com/raspberrypi/firmware/issues/1186, so no point in posting here as well.
In turn you didn't do even a brief search there, as the question is a duplicate of https://github.com/raspberrypi/firmware/issues/1176
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.

techmasterjoe
Posts: 11
Joined: Thu Nov 02, 2017 2:40 pm

Re: Hardware camera sync pulses

Fri Aug 02, 2019 1:50 am

hey 6by9 been a while
i have this running on a CMIO v3 board using GPIO41
i find i can't get a clean signal without adding a 10k pull down and the dt-blob.bin pull down not doing anything
if you have any ideas it be really helpful
i will need to redo about Lots of pcb's if i can't find a software solution.
Last edited by techmasterjoe on Fri Aug 02, 2019 9:57 am, edited 1 time in total.

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

Re: Hardware camera sync pulses

Fri Aug 02, 2019 8:13 am

techmasterjoe wrote:
Fri Aug 02, 2019 1:50 am
hey 6by9 been a while
i have this running on a CMIO v3 board using GPIO41
i find i can't get a clean signal without adding a 10k pull down and the dt-blob.bin pull down not doing anything
if you have any ideas it be really helpful
i will need to redo about 1,000 pcb's if i can't find a software solution.
Use "raspi-gpio get" to confirm that you genuinely are activating the internal pull down. You can dynamically enable it by running "raspi-gpio set 41 pd", or add "gpio=41=op,pd,dl" to config.txt.

Define how your signal is unclean. Ringing, overdamped, noisy? What are you driving it into? Very few things in software can change the electrical behaviour of a hardware line.
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.

techmasterjoe
Posts: 11
Joined: Thu Nov 02, 2017 2:40 pm

Re: Hardware camera sync pulses

Fri Aug 02, 2019 9:32 am

6by9 wrote:
Fri Aug 02, 2019 8:13 am
techmasterjoe wrote:
Fri Aug 02, 2019 1:50 am
hey 6by9 been a while
i have this running on a CMIO v3 board using GPIO41
i find i can't get a clean signal without adding a 10k pull down and the dt-blob.bin pull down not doing anything
if you have any ideas it be really helpful
i will need to redo about Lots of pcb's if i can't find a software solution.
Use "raspi-gpio get" to confirm that you genuinely are activating the internal pull down. You can dynamically enable it by running "raspi-gpio set 41 pd", or add "gpio=41=op,pd,dl" to config.txt.

Define how your signal is unclean. Ringing, overdamped, noisy? What are you driving it into? Very few things in software can change the electrical behaviour of a hardware line.
i have a pin tied to PB06 on a SAMD21 a hardware interrupt on the micro controls a few things for power management and a PWM output to a LM3409 led driver
while the signal is good on a scope with the samd21 disconnected but with the samd21 the line floats 1.0~1.3v and thus randomly triggers the interrupt.
i tested the pin on the samd21 pin wire is over 4meg and the pi pin drives high but floats low with with also around 3.6meg just kinda odd
so based on that i guess overdamped but not by design

I will test adding the gpio's to config i was thinking of testing that but was not sure if it has an effect with the pins under rtos control
i will update soon

update :
no change adding to config.
custom img raspi-gpio command has been removed

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

Re: Hardware camera sync pulses

Fri Aug 02, 2019 11:30 am

techmasterjoe wrote:
Fri Aug 02, 2019 9:32 am
i have a pin tied to PB06 on a SAMD21 a hardware interrupt on the micro controls a few things for power management and a PWM output to a LM3409 led driver
while the signal is good on a scope with the samd21 disconnected but with the samd21 the line floats 1.0~1.3v and thus randomly triggers the interrupt.
i tested the pin on the samd21 pin wire is over 4meg and the pi pin drives high but floats low with with also around 3.6meg just kinda odd
so based on that i guess overdamped but not by design

I will test adding the gpio's to config i was thinking of testing that but was not sure if it has an effect with the pins under rtos control
i will update soon

update :
no change adding to config.
custom img raspi-gpio command has been removed
Sorry, I wasn't thinking earlier. If configured as an output, then the pull up/down will do next to nothing as the line is being actively driven high or low.

Download and build raspigpio from https://github.com/RPi-Distro/raspi-gpio

What does "raspigpio get | grep 41" actually report? The line should be an output.
If you've got an output drifting up to 1.0-1.3V with your circuit connected, then something very funny is going on. I'd query whether you'd managed to blow up part of the GPIO driver circuitry. Does it go wrong on a different CM module?
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.

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

Re: Hardware camera sync pulses

Fri Aug 02, 2019 3:36 pm

6by9 wrote:
Fri Aug 02, 2019 11:30 am
Download and build raspigpio from https://github.com/RPi-Distro/raspi-gpio
Thanks, seems to be a really useful tool.
This is output for Pi3A+ with DPMI display attached:

Code: Select all

[code][email protected]:~/raspi-gpio $ ./raspi-gpio get
BANK0 (GPIO 0 to 27):
GPIO 0: level=1 fsel=6 alt=2 func=PCLK
GPIO 1: level=0 fsel=6 alt=2 func=DE
GPIO 2: level=0 fsel=6 alt=2 func=LCD_VSYNC
GPIO 3: level=0 fsel=6 alt=2 func=LCD_HSYNC
GPIO 4: level=0 fsel=6 alt=2 func=DPI_D0
GPIO 5: level=0 fsel=6 alt=2 func=DPI_D1
GPIO 6: level=1 fsel=6 alt=2 func=DPI_D2
GPIO 7: level=0 fsel=6 alt=2 func=DPI_D3
GPIO 8: level=1 fsel=6 alt=2 func=DPI_D4
GPIO 9: level=0 fsel=6 alt=2 func=DPI_D5
GPIO 10: level=0 fsel=6 alt=2 func=DPI_D6
GPIO 11: level=0 fsel=6 alt=2 func=DPI_D7
GPIO 12: level=1 fsel=6 alt=2 func=DPI_D8
GPIO 13: level=1 fsel=6 alt=2 func=DPI_D9
GPIO 14: level=0 fsel=6 alt=2 func=DPI_D10
GPIO 15: level=0 fsel=6 alt=2 func=DPI_D11
GPIO 16: level=0 fsel=6 alt=2 func=DPI_D12
GPIO 17: level=1 fsel=6 alt=2 func=DPI_D13
GPIO 18: level=0 fsel=6 alt=2 func=DPI_D14
GPIO 19: level=1 fsel=6 alt=2 func=DPI_D15
GPIO 20: level=0 fsel=6 alt=2 func=DPI_D16
GPIO 21: level=1 fsel=6 alt=2 func=DPI_D17
GPIO 22: level=0 fsel=6 alt=2 func=DPI_D18
GPIO 23: level=0 fsel=6 alt=2 func=DPI_D19
GPIO 24: level=0 fsel=6 alt=2 func=DPI_D20
GPIO 25: level=0 fsel=6 alt=2 func=DPI_D21
GPIO 26: level=0 fsel=6 alt=2 func=DPI_D22
GPIO 27: level=0 fsel=6 alt=2 func=DPI_D23
BANK1 (GPIO 28 to 45):
GPIO 28: level=1 fsel=0 func=INPUT
GPIO 29: level=0 fsel=1 func=OUTPUT
GPIO 30: level=0 fsel=7 alt=3 func=CTS0
GPIO 31: level=0 fsel=7 alt=3 func=RTS0
GPIO 32: level=1 fsel=7 alt=3 func=TXD0
GPIO 33: level=1 fsel=7 alt=3 func=RXD0
GPIO 34: level=0 fsel=7 alt=3 func=SD1_CLK
GPIO 35: level=1 fsel=7 alt=3 func=SD1_CMD
GPIO 36: level=1 fsel=7 alt=3 func=SD1_DAT0
GPIO 37: level=1 fsel=7 alt=3 func=SD1_DAT1
GPIO 38: level=1 fsel=7 alt=3 func=SD1_DAT2
GPIO 39: level=1 fsel=7 alt=3 func=SD1_DAT3
GPIO 40: level=0 fsel=4 alt=0 func=PWM0
GPIO 41: level=0 fsel=4 alt=0 func=PWM1
GPIO 42: level=0 fsel=0 func=INPUT
GPIO 43: level=1 fsel=4 alt=0 func=GPCLK2
GPIO 44: level=1 fsel=5 alt=1 func=SDA0
GPIO 45: level=1 fsel=5 alt=1 func=SCL0
BANK2 (GPIO 46 to 53):
GPIO 46: level=1 fsel=0 func=INPUT
GPIO 47: level=1 fsel=1 func=OUTPUT
GPIO 48: level=0 fsel=4 alt=0 func=SD0_CLK
GPIO 49: level=1 fsel=4 alt=0 func=SD0_CMD
GPIO 50: level=1 fsel=4 alt=0 func=SD0_DAT0
GPIO 51: level=1 fsel=4 alt=0 func=SD0_DAT1
GPIO 52: level=1 fsel=4 alt=0 func=SD0_DAT2
GPIO 53: level=1 fsel=4 alt=0 func=SD0_DAT3
[email protected]:~/raspi-gpio $ 
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

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

Re: Hardware camera sync pulses

Fri Aug 02, 2019 4:00 pm

HermannSW wrote:
Fri Aug 02, 2019 3:36 pm
6by9 wrote:
Fri Aug 02, 2019 11:30 am
Download and build raspigpio from https://github.com/RPi-Distro/raspi-gpio
Thanks, seems to be a really useful tool.
It's available as a Raspbian package - I only linked to the repo as techmasterjoe had said "custom img raspi-gpio command has been removed".

raspi-gpio is maintained by Pi Towers, therefore it will always be updated should hardware change, hence commits to support the Pi4 on June 20th (launch day).
HermannSW wrote:This is output for Pi3A+ with DPMI display attached:

Code: Select all

[code][email protected]:~/raspi-gpio $ ./raspi-gpio get
BANK0 (GPIO 0 to 27):
GPIO 0: level=1 fsel=6 alt=2 func=PCLK
GPIO 1: level=0 fsel=6 alt=2 func=DE
GPIO 2: level=0 fsel=6 alt=2 func=LCD_VSYNC
GPIO 3: level=0 fsel=6 alt=2 func=LCD_HSYNC
GPIO 4: level=0 fsel=6 alt=2 func=DPI_D0
GPIO 5: level=0 fsel=6 alt=2 func=DPI_D1
GPIO 6: level=1 fsel=6 alt=2 func=DPI_D2
GPIO 7: level=0 fsel=6 alt=2 func=DPI_D3
GPIO 8: level=1 fsel=6 alt=2 func=DPI_D4
GPIO 9: level=0 fsel=6 alt=2 func=DPI_D5
GPIO 10: level=0 fsel=6 alt=2 func=DPI_D6
GPIO 11: level=0 fsel=6 alt=2 func=DPI_D7
GPIO 12: level=1 fsel=6 alt=2 func=DPI_D8
GPIO 13: level=1 fsel=6 alt=2 func=DPI_D9
GPIO 14: level=0 fsel=6 alt=2 func=DPI_D10
GPIO 15: level=0 fsel=6 alt=2 func=DPI_D11
GPIO 16: level=0 fsel=6 alt=2 func=DPI_D12
GPIO 17: level=1 fsel=6 alt=2 func=DPI_D13
GPIO 18: level=0 fsel=6 alt=2 func=DPI_D14
GPIO 19: level=1 fsel=6 alt=2 func=DPI_D15
GPIO 20: level=0 fsel=6 alt=2 func=DPI_D16
GPIO 21: level=1 fsel=6 alt=2 func=DPI_D17
GPIO 22: level=0 fsel=6 alt=2 func=DPI_D18
GPIO 23: level=0 fsel=6 alt=2 func=DPI_D19
GPIO 24: level=0 fsel=6 alt=2 func=DPI_D20
GPIO 25: level=0 fsel=6 alt=2 func=DPI_D21
GPIO 26: level=0 fsel=6 alt=2 func=DPI_D22
GPIO 27: level=0 fsel=6 alt=2 func=DPI_D23
BANK1 (GPIO 28 to 45):
GPIO 28: level=1 fsel=0 func=INPUT
GPIO 29: level=0 fsel=1 func=OUTPUT
GPIO 30: level=0 fsel=7 alt=3 func=CTS0
GPIO 31: level=0 fsel=7 alt=3 func=RTS0
GPIO 32: level=1 fsel=7 alt=3 func=TXD0
GPIO 33: level=1 fsel=7 alt=3 func=RXD0
GPIO 34: level=0 fsel=7 alt=3 func=SD1_CLK
GPIO 35: level=1 fsel=7 alt=3 func=SD1_CMD
GPIO 36: level=1 fsel=7 alt=3 func=SD1_DAT0
GPIO 37: level=1 fsel=7 alt=3 func=SD1_DAT1
GPIO 38: level=1 fsel=7 alt=3 func=SD1_DAT2
GPIO 39: level=1 fsel=7 alt=3 func=SD1_DAT3
GPIO 40: level=0 fsel=4 alt=0 func=PWM0
GPIO 41: level=0 fsel=4 alt=0 func=PWM1
GPIO 42: level=0 fsel=0 func=INPUT
GPIO 43: level=1 fsel=4 alt=0 func=GPCLK2
GPIO 44: level=1 fsel=5 alt=1 func=SDA0
GPIO 45: level=1 fsel=5 alt=1 func=SCL0
BANK2 (GPIO 46 to 53):
GPIO 46: level=1 fsel=0 func=INPUT
GPIO 47: level=1 fsel=1 func=OUTPUT
GPIO 48: level=0 fsel=4 alt=0 func=SD0_CLK
GPIO 49: level=1 fsel=4 alt=0 func=SD0_CMD
GPIO 50: level=1 fsel=4 alt=0 func=SD0_DAT0
GPIO 51: level=1 fsel=4 alt=0 func=SD0_DAT1
GPIO 52: level=1 fsel=4 alt=0 func=SD0_DAT2
GPIO 53: level=1 fsel=4 alt=0 func=SD0_DAT3
[email protected]:~/raspi-gpio $ 
I'm not sure what you're expecting us to do with that. The question is what techmasterjoe has done to GPIO41 on his CM.
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.

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

Re: Hardware camera sync pulses

Sat Aug 03, 2019 1:26 pm

6by9 wrote:
Fri Aug 02, 2019 4:00 pm
I'm not sure what you're expecting us to do with that. The question is what techmasterjoe has done to GPIO41 on his CM.
I was just surprised that all BANK0 GPIOs are used by DPMI interface -- unrelated to CM question.
So none of the GPIOs could be used for sending HW sync pulses to the outside to trigger something.

I used logic analyzer to see that HW sync pulses get overlayed to DPMI signals on same pin.
But even with 90fps recording they occur too seldom to have any visible effect on 7" DPMI LCD:
Image

"raspi-gpio get" did not show 32 as used, and that is default in dt-blob.dts for CAMERA led:
https://github.com/raspberrypi/firmware ... t-blob.dts

I dtc compiled that file unchanged and got what is needed with DPMI display in use:
  • "while true; do gpio -g read 32; done" showed always 0
  • started "raspivid -md 7 -t 0 &" in background
  • now "while true; do gpio -g read 32; done" showed 0s and 1s
  • stopped background raspivid
  • now "while true; do gpio -g read 32; done" showed always 0, again
Summary:
With DPMI LCD in use, hardware camera sync pulses cannot be signalled on one of the 40 pins.
But hardware camera sync pulses can be utilized by software eg. on GPIO32 (dt-blob.dts default for camera led).
This allows for example camera synchronization when doing global external shutter capturing with v1 camera with DPMI in use:
https://github.com/Hermann-SW/Raspberry ... ync-pulses
("#define gpioHWsync 18" has to be changed to "#define gpioHWsync 32" in gpio_alert.c#L21)
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

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

Re: Hardware camera sync pulses

Sat Aug 03, 2019 8:02 pm

What I reported was for a Raspberry Pi 2B.

Since I more often work with Pi 3A+ I wanted to enable hardware camera sync pulses with DPMI lcd for that Pi as well.
This diff provides the pulses on GPIO42 for software use as described in previous posting:

Code: Select all

[email protected]:~ $ diff dt-blob.dts dt-blob.42.dts 
1531c1531
<             [email protected] { function = "output"; termination = "no_pulling"; }; // Camera LED
---
>             [email protected] { function = "output"; termination = "no_pulling"; }; // Camera LED
1564,1565c1564,1565
<                type = "external";
<                number = <6>;
---
>                type = "internal";
>                number = <42>;
[email protected]:~ $ 
P.S:
Pi 3A+ with DPMI 7" lcd will make a good equipment basis when moving Raspberry v1 global external shutter setup to gun club for capturing much higher speed pellets than 109m/s airgun pellet at home (no laptop needed):
https://github.com/Hermann-SW/Raspberry ... setup2leds
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

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

Re: Hardware camera sync pulses

Fri Aug 09, 2019 10:27 am

There might be easier ways to determine the the time it takes to capture a single line with v1 or v2 camera.
I used logic analyzer and measured the hardware camera sync pulses.
The length of high signal for mode 7 640x480 is constant, regardless of framerate (the framerate affects only the signal low length between two frames),
v2 camera takes 4.7ms for 480 lines, v1 camera 10.21ms for 480 lines:
Image

Therefore a single line is captured for v2 camera in 4.7ms/480=9.8us, and for v1 camera in 10.21ms/480=21.3us.

Shooting an 36m/s airsoft pellet horizontally through camera view, the pellet will move 0.35mm/0.77mm from one of the 480 lines to the next for v2/v1 camera. During the whole frame (480 lines) the pellet will have moved 169mm/367mm for v2/v1 camera.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://gitlab.freedesktop.org/HermannSW/gst-template
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

Return to “Camera board”