Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapping of exposure time to register exposure value is wrong for ov5647. #20

Open
GustavEngdahl opened this issue Oct 8, 2018 · 2 comments

Comments

@GustavEngdahl
Copy link

The following lines in raspiraw.c:
if (cfg.exposure_us != -1)
{
cfg.exposure = ((int64_t)cfg.exposure_us * 1000) / sensor_mode->line_time_ns;
vcos_log_error("Setting exposure to %d from time %dus", cfg.exposure, cfg.exposure_us);
}

Does not work well for the ov5647 since the register need scanlines of 1/16.
The following works ok.
if (cfg.exposure_us != -1)
{
cfg.exposure = 16*((int64_t)cfg.exposure_us * 1000) / sensor_mode->line_time_ns;
vcos_log_error("Setting exposure to %d from time %dus", cfg.exposure, cfg.exposure_us);
}
The documentation of the ov5647 does not clearly state so, but ov5648 does and when testing the ov5647 it was clear that the set exposure time was not correct.

I'm not sure how the other supported camera-modules work but I guess the configuration structs need some sort of new factor integer to enable a correct time-to-scanline conversion.

Any thoughts on this?

/Gustav

@iHD992
Copy link

iHD992 commented Sep 9, 2019

I am quite confused. picamera and https://github.com/GustavEngdahl/raspiraw seem to behave differently:
raspiraw -hd -md 3 -f 1 -t 6000 -eus 6000000 -g 1023 -sr 1 -o out6_1023.%03d.raw

RaspiRaw: Probing sensor ov5647 on addr 36
RaspiRaw: Found sensor ov5647 at address 36
RaspiRaw: Setting exposure to 32646 from time 6000000us
RaspiRaw: Set exposure 3500 to 00
RaspiRaw: Set exposure 3501 to 7F
RaspiRaw: Set exposure 3502 to 86
RaspiRaw: Set vts 380E to 7F
RaspiRaw: Set vts 380F to 86
RaspiRaw: Set gain 350A to 03
RaspiRaw: Set gain 350B to FF

picamera:
camera.resolution = (2592, 1944)
sleep(2)
camera.framerate = Fraction(1, 6)
camera.shutter_speed = 6000000 # 0.1 secs
sleep(15)
print(camera.exposure_speed)
camera.analog_gain = 63
camera.digital_gain = 1

11710447-11710447 I²C: Address/Data: Start
11710468-11710470 I²C: Address/Data: Write
11710451-11710468 I²C: Address/Data: Address write: 36
11710471-11710473 I²C: Address/Data: ACK
11710473-11710494 I²C: Address/Data: Data write: 38
11710493-11710496 I²C: Address/Data: ACK
11710496-11710515 I²C: Address/Data: Data write: 0E
11710516-11710518 I²C: Address/Data: ACK
11710518-11710539 I²C: Address/Data: Data write: 81
11710538-11710541 I²C: Address/Data: ACK
11710541-11710560 I²C: Address/Data: Data write: 8D
11710561-11710563 I²C: Address/Data: ACK
11710564-11710564 I²C: Address/Data: Stop
[...]
11711056-11711056 I²C: Address/Data: Start
11711077-11711079 I²C: Address/Data: Write
11711060-11711077 I²C: Address/Data: Address write: 36
11711080-11711082 I²C: Address/Data: ACK
11711082-11711103 I²C: Address/Data: Data write: 35
11711102-11711105 I²C: Address/Data: ACK
11711105-11711124 I²C: Address/Data: Data write: 0A
11711125-11711127 I²C: Address/Data: ACK
11711127-11711148 I²C: Address/Data: Data write: 03
11711147-11711150 I²C: Address/Data: ACK
11711151-11711151 I²C: Address/Data: Stop
11711153-11711153 I²C: Address/Data: Start
11711175-11711178 I²C: Address/Data: Write
11711157-11711175 I²C: Address/Data: Address write: 36
11711177-11711180 I²C: Address/Data: ACK
11711180-11711199 I²C: Address/Data: Data write: 35
11711200-11711202 I²C: Address/Data: ACK
11711202-11711223 I²C: Address/Data: Data write: 0B
11711222-11711225 I²C: Address/Data: ACK
11711225-11711244 I²C: Address/Data: Data write: F0
11711245-11711247 I²C: Address/Data: ACK
11711248-11711248 I²C: Address/Data: Stop
11711820-11711820 I²C: Address/Data: Start
11711841-11711843 I²C: Address/Data: Write
11711824-11711841 I²C: Address/Data: Address write: 36
11711844-11711846 I²C: Address/Data: ACK
11711846-11711867 I²C: Address/Data: Data write: 35
11711866-11711869 I²C: Address/Data: ACK
11711869-11711888 I²C: Address/Data: Data write: 0A
11711889-11711891 I²C: Address/Data: ACK
11711891-11711912 I²C: Address/Data: Data write: 03
11711911-11711914 I²C: Address/Data: ACK
11711915-11711915 I²C: Address/Data: Stop
11711917-11711917 I²C: Address/Data: Start
11711939-11711942 I²C: Address/Data: Write
11711921-11711939 I²C: Address/Data: Address write: 36
11711941-11711944 I²C: Address/Data: ACK
11711944-11711963 I²C: Address/Data: Data write: 35
11711964-11711966 I²C: Address/Data: ACK
11711966-11711987 I²C: Address/Data: Data write: 0B
11711986-11711989 I²C: Address/Data: ACK
11711989-11712008 I²C: Address/Data: Data write: F0
11712009-11712011 I²C: Address/Data: ACK
11712012-11712012 I²C: Address/Data: Stop
11712016-11712016 I²C: Address/Data: Start
11712037-11712039 I²C: Address/Data: Write
11712020-11712037 I²C: Address/Data: Address write: 36
11712040-11712042 I²C: Address/Data: ACK
11712042-11712063 I²C: Address/Data: Data write: 32
11712062-11712065 I²C: Address/Data: ACK
11712065-11712084 I²C: Address/Data: Data write: 12
11712085-11712087 I²C: Address/Data: ACK
11712087-11712108 I²C: Address/Data: Data write: 00
11712107-11712110 I²C: Address/Data: ACK
11712111-11712111 I²C: Address/Data: Stop
11712115-11712115 I²C: Address/Data: Start
11712136-11712138 I²C: Address/Data: Write
11712119-11712136 I²C: Address/Data: Address write: 36
11712139-11712141 I²C: Address/Data: ACK
11712141-11712162 I²C: Address/Data: Data write: 35
11712161-11712164 I²C: Address/Data: ACK
11712164-11712183 I²C: Address/Data: Data write: 00
11712184-11712186 I²C: Address/Data: ACK
11712186-11712207 I²C: Address/Data: Data write: 07
11712206-11712209 I²C: Address/Data: ACK
11712210-11712210 I²C: Address/Data: Stop
11712212-11712212 I²C: Address/Data: Start
11712234-11712237 I²C: Address/Data: Write
11712216-11712234 I²C: Address/Data: Address write: 36
11712236-11712239 I²C: Address/Data: ACK
11712239-11712258 I²C: Address/Data: Data write: 35
11712259-11712261 I²C: Address/Data: ACK
11712261-11712282 I²C: Address/Data: Data write: 01
11712281-11712284 I²C: Address/Data: ACK
11712284-11712303 I²C: Address/Data: Data write: F8
11712304-11712306 I²C: Address/Data: ACK
11712307-11712307 I²C: Address/Data: Stop
11712310-11712310 I²C: Address/Data: Start
11712331-11712333 I²C: Address/Data: Write
11712314-11712331 I²C: Address/Data: Address write: 36
11712334-11712336 I²C: Address/Data: ACK
11712336-11712357 I²C: Address/Data: Data write: 35
11712356-11712359 I²C: Address/Data: ACK
11712359-11712378 I²C: Address/Data: Data write: 02
11712379-11712381 I²C: Address/Data: ACK
11712381-11712402 I²C: Address/Data: Data write: 60
11712401-11712404 I²C: Address/Data: ACK
11712405-11712405 I²C: Address/Data: Stop
11712407-11712407 I²C: Address/Data: Start
11712429-11712432 I²C: Address/Data: Write
11712411-11712429 I²C: Address/Data: Address write: 36
11712431-11712434 I²C: Address/Data: ACK
11712434-11712453 I²C: Address/Data: Data write: 32
11712454-11712456 I²C: Address/Data: ACK
11712456-11712477 I²C: Address/Data: Data write: 12
11712476-11712479 I²C: Address/Data: ACK
11712479-11712498 I²C: Address/Data: Data write: 10
11712499-11712501 I²C: Address/Data: ACK
11712502-11712502 I²C: Address/Data: Stop
11712505-11712505 I²C: Address/Data: Start
11712526-11712528 I²C: Address/Data: Write
11712509-11712526 I²C: Address/Data: Address write: 36
11712529-11712531 I²C: Address/Data: ACK
11712531-11712552 I²C: Address/Data: Data write: 32
11712551-11712554 I²C: Address/Data: ACK
11712554-11712573 I²C: Address/Data: Data write: 12
11712574-11712576 I²C: Address/Data: ACK
11712576-11712597 I²C: Address/Data: Data write: A0
11712596-11712599 I²C: Address/Data: ACK
11712600-11712600 I²C: Address/Data: Stop

I think its especially weird that raspiraw writes the same data to 3500/3501/3502 than to 380E/380F.

@iHD992
Copy link

iHD992 commented Sep 13, 2019

I did some testing. The correction above is not included in Gustav Engdahls raspiraw. When I patch Gustavs fork of raspiraw with his suggestion the results are better but I encountered 2 problems:

  • The first frame is completely black.
  • I contrast to 1 s exposure (raspiraw -hd -md 3 -f 1 -t 2800 -eus 1000000 -g 80 -sr 1 -o outnew1_80.%03d.raw) 6 s exposure (raspiraw -hd -md 3 -f 0.16666 -t 18800 -eus 6000000 -g 20 -sr 1 -o outnew6_20.%03d.raw) lead to completely black frames. Is "-f 0.16666" the correct way to set a framerate of 1/6?

Edit: 6 s work. I do not now why not in the first place. More than 6s does not lead to longer exposures. Maybe 0x380A<<8+0x380B has a maximum of 0x7FFF?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants