Sensor fixed gain/exposure not working

Hmm, I see what you mean.

I apologize, I’ve never tested the code by removing all light. It appears the sensor does something else and modifies the behavior.

Since the OV7725 doesn’t really have any more doucmentation than the datasheet which isn’t that detailed I don’t know what’s going on. I’ve tried to turn off the AGC/AWB gains and set them to zero and this doesn’t seem to matter. I’ve also tried turning off night mode (settings register 0x0e to zero and this doesn’t help either).

It appears that these registers 0x35 to 0x3c change their values. I’m not sure why. They aren’t documented in an auto mode.

I’ve also tried dumping all regs, then writing them again and seeing if that forces the sensor to the settings I want - but, it does not.

We sell the MT9V034 sensor for this reason. The OV7725 is made for taking pictures. It’s auto control is not well documented. The MT9V034 has a complete datasheet and does actually obey when commanded.

If you still want to use the OV7725 I would just continuously modify the register settings until it stabilizes at a value you want. You can use read the AGC gain at register 0, AWB gains at registers 1,2,3, the Y_AVG at register 2F.

To be clear, I have no idea what’s causing it to not accept the values provided… our C code sets all registers to the commanded values as we expect. We turn off the auto methods and then set the registers that are required to be set.

I’m thinking though the sensor probably has some hidden register state that is not writable directly unless the auto control modes are on. When the senor turns on from power off the auto methods are enabled by default. The short time window before you turn them off is probably enough for them to change some internal registers that cannot easily be cleared.

I’m guessing this is happening because I noticed that some of the registers controlling dummy line insertion which night mode controls changed when I was doing a dump register diff.

Can you describe how your application with the OV7725 works? Maybe there’s a way to use the auto functions to do what you want. For example, you can control the AEC/AGC exposure target which will allow you to make the camera auto functions hit a particular Y_AVG value.

Thanks very much Nyamekye.

I’ll keep playing with it and see if I can figure out which registers have to be set in which order to get full manual control.

For what its worth I reached out to Omnivision tech support for assistance.

For what its worth I reached out to Omnivision tech support for assistance.

Good luck… they don’t provide help support. On product path for us is moving to OnSemi products for us. They cost more, but, are better and we have access to all documentation currently.

You just do this to dump all regs:

reg_list = []
for i in range(256): # I don't think registers after 0xad are implemented
    reg_list.append(sensor.__read_reg(i))

And then to write them back:

for i in range(256): # I don't think registers after 0xad are implemented
    sensor.__write_reg(reg_list[i])

… Then you can diff the reg list to see what changed.

SOLVED:
For full manual control of the OV7725 sensor, you need to disable auto gain, auto white balance, auto exposure, night mode (auto frame rate) and black level calibration (BLC). Only AFTER all of these auto modes are disabled, restore a bunch of offset registers back to their default values, because these get changed based on the initial images by the various auto modes before they are disabled.

Also manually set white balance.

Setup Image Sensor format

sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)

Setup for manual gain, exposure, and white balance

sensor.set_auto_gain(False, gain_db=3) # gain in db
sensor.set_auto_whitebal(False)
sensor.set_auto_exposure(False, exposure_us=10000) # exposure in us

Setup contrast, brightness and saturation

sensor.set_contrast(3) # range -3 to +3
sensor.set_brightness(0) # range -3 to +3
sensor.set_saturation(0) # range -3 to +3

Disable night mode (auto frame rate) and black level calibration (BLC)

sensor.__write_reg(0x0E, 0b00000000) # Disable night mode
sensor.__write_reg(0x3E, 0b00000000) # Disable BLC

Set White Balance values manually

sensor.__write_reg(0x01, 0b01111100) # Blue Gain for White Balance
sensor.__write_reg(0x02, 0b01000000) # Red Gain for White Balance
sensor.__write_reg(0x03, 0b01111100) # Green Gain for White Balance

Restore to default values (these are changed before manual mode takes effect)

sensor.__write_reg(0x2D, 0b00000000) # LSB Insert Dummy Rows (Set to Default 0x00)
sensor.__write_reg(0x2E, 0b00000000) # MSB Insert Dummy Rows (Set to Default 0x00)

sensor.__write_reg(0x35, 0b10000000) # AD Offset B Chan (Set to Default 0x80)
sensor.__write_reg(0x36, 0b10000000) # AD Offset R Chan (Set to Default 0x80)
sensor.__write_reg(0x37, 0b10000000) # AD Offset Gb Chan (Set to Default 0x80)
sensor.__write_reg(0x38, 0b10000000) # AD Offset Gr Chan (Set to Default 0x80)

sensor.__write_reg(0x39, 0b10000000) # B channel offset (Set to Default 0x80)
sensor.__write_reg(0x3A, 0b10000000) # R channel offset (Set to Default 0x80)
sensor.__write_reg(0x3B, 0b10000000) # Gb channel offset (Set to Default 0x80)
sensor.__write_reg(0x3C, 0b10000000) # Gr channel offset (Set to Default 0x80)

Thanks again for all your help :slight_smile:

Glad you were able to solve it. Sounds like we should add a method that forces manual mode. Can you create a GitHub feature request for this?

Glad you were able to solve it. Sounds like we should add a method that forces manual mode. Can you create a GitHub feature request for this?

Sure. Github feature request posted.

I’ve run into a sticky problem and need help. I turned off the camera’s automatic exposure time control, automatic white balance control, automatic gain control, and night mode, BLC control and other automatic algorithm controls that may affect the shooting effect, and manually set the brightness, contrast, and saturation. After the above efforts, the captured image brightness still shows uncontrollable periodic changes, there is one with obvious brighter images for about every 3 images. As shown in the figure below, the ordinate is the image brightness, and the abscissa is the image order. If it is correct, the curve should show a smooth downward trend, but in fact, the captured results from the series of images in the figure do not. After every two images, an image with a sudden increase in brightness will be captured, and the brightness data is almost a constant value. This is obviously an abnormal result, but I can’t figure out why this happens, and I hope to get anyone’s help.
微信图片_20221207151943

This is the OV7725? The above post doesn’t handle the issue?

I figured I’d just hijack this thread because it seems to be a similar problem.

Are you aware of this being an issue on the MT9M114 sensor? Because it seems like it’s an issue on that sensor. I mimicked the whole light to dark, then dark to light kind of thing and the gain setting is whatever the camera decides despite any manual or ceiling I have. I haven’t done all of the register editing yet because I wasn’t sure if those registers were the same between cameras.

Edit: the gain value DOES work if I start it with my light on. Sorry for the confusion. But it DOES NOT work when starting in the dark then turning the light on. Weird stuff.

It shouldn’t be. We used the register settings recommended by OnSemi. We have access to their ImageSensor Portal. As such our driver actually does exactly what they recommend to do in order to setup the camera.

As for the auto functions on the camera. Yeah… I can’t say exactly. I implemented everything for their controls to the best of my ability and what was available. If it’s not configurable then it’s likely not possible. The register setups for these cameras don’t always allow that much tunning without having expert knowledge.

Got ya. For my setup I can work around so it’s not a huge deal at all. I just noticed the issue, and saw this was the only thread for it so wanted to bring it up incase you weren’t aware.