Argus camera gives wrong gain range?

Hi,
I’m using JP4.5.1 and it looks like argus_camera application (or Argus::ISensorMode::getAnalogGainRange()) gives wrong gain range.

Here is gain config in device tree:

root@test:/proc/device-tree/cam_i2cmux/i2c@0/imx485_a@1a/mode3# for f in *gain*; do echo -n "$f "; cat $f; echo ""; done
default_gain 0
gain_factor 10
inherent_gain 1
max_gain_val 720
min_gain_val 0
step_gain_val 3
root@test:/proc/device-tree/cam_i2cmux/i2c@0/imx485_a@1a# for f in *gain*; do echo -n "$f "; cat $f; echo ""; done
delayed_gain false
use_decibel_gain true

So, in theory, the gain range in argus_camera should be 0 - 72.0 (db)

But actually, the max gain range in argus_camera is so high: 3981

Can anybody help me explaining this?

The v4l2-ctrl shows correct range 0 - 720

PS: I’m using v4l2 driver version 2 (similar to imx185.c)

hello nvl1109,

it’s device tree properties to define the gain range is DB.
and… there’s fixed point scaling (to use 64-bit) to translate the gain values.

you may examine the settings to see if they’re configure correctly through sensor driver.
thanks

Hi @JerryChang ,

If I set min & max gain in argus_camera, the gain in v4l2 driver show ~720 ==> it is correct.
I just wonder how 0 - 720 gain range in driver can translate into 0 - 3981 in argus? And the map between v4l2 gain range and argus gain range is not linear. Is there any formula to translate between argus’s gain range and v4l2 gain range?
0-16 in argus = 0 - 240 in v4l2 driver.
16-3981 in argus = 241 - 720 in v4l2 driver.

Thank you.

hello nvl1109,

you may also disable ISP digital gain to dig into this.

Hi @JerryChang ,

I have tried to with ISP digital gain range set to 1-1.
The behavior with gain range is still the same. range is 0-3981 and not linear.

Am I correct in disabling ISP digital gain? Or need to do in another way?

Thank you.

hello nvl1109,

please follow below to enable Argus daemon LOGs,
there’s commands, enableCamCoreLogs=5 to enable the debug logs of camera stack, you should expect lots of messages will populate to your terminal, please gather all of them as single text file and attach them to the forum thread for reference,
thanks

$ sudo su 
# pkill nvargus-daemon
# export enableCamCoreLogs=5
# nvargus-daemon

Hi @JerryChang ,

Here is nvargus-daemon log with core level = 5.
I just start argus_camera, then change cam mode from 0 → 3, then set ISP digital gain range to 1-1, and finally close the argus_camera app.

argus-daemon.log (4.5 MB)

hello nvl1109,

BTW, did you configure use_decibel_gain="true" in the device tree property?
if yes, the driver returns analog gain in decibels (dB), according to the formula, dB = 20 * log (Analog Gain)

Hi @JerryChang ,

Yes, I used use_decibel_gain=“true” as in the first post.

The max gain val = 720, and factor = 10, so that it is 72db.

even with “dB = 20 * log(gain)” the gain range from Argus::ISensorMode::getAnalogGainRange() can’t not be 0 - 3981?

hello nvl1109,

the gain range shown in argus_camera isn’t represent with decibels (dB).
there’s debug messages, you may check log2(Gain) for confirmation.
for example,
NvIspAeGetEVTableIndex: Gain = 1.206781, log2(Gain) = 0.271163

it looks correct to me you’re having 0dB (20 * log(1)) ~ 72dB (20 * log(3981)) gain range.
thanks

Hi @JerryChang ,

It is still not correct, I think.
The max gain in nvargus-daemon log:

NvIspAeGetEVTableIndex: log2(GainThresholds) = {-1.000000, 0.000000, 1.000000, 2.000000, 3.000000, 4.000000, 5.000000}
NvIspAeGetEVTableIndex: Gain = 3981.001465, log2(Gain) = 11.958916
NvIspAeGetEVTableIndex: log2(GainThresholds[6]) = 5.000000 (0.000000)

and v4l2-ctrl:

gain 0x009a2009 (int64)  : min=0 max=720 step=3 default=0 value=720 flags=slider

So, with gain = 3981 the log2(gain) = 11.95 ==> db = 20 * 11.95 = 239
It is not 72dB as we expected.

Another example, with argus log:

NvIspAeGetEVTableIndex: Gain = 16.000000, log2(Gain) = 4.000000

the v4l2-ctl shows gain:

gain 0x009a2009 (int64)  : min=0 max=720 step=3 default=0 value=240 flags=slider

==> with Argus Gain = 16.0, the actual gain applied in sensor is 24dB.

Any thoughts?

Thanks.

hello nvl1109,

low-level camera driver side use AnalogGain for calculation.
here’s formula of the debug messages, Log2Gain = log(Gain) / log(2.f);
it’s covert as log2 scale is for better readability of debug logs.
for example,
NvIspAeGetEVTableIndex: Gain = 100.999985, log2(Gain) = 6.658211
it means… when sensor analog gain = 100.999985; log2(Gain) = (log100.999985/log2) = 6.658211

BTW,
did you see any unexpected gain settings behaviors in the use-case?

Hi @JerryChang ,

No unexpected gain behavior happened.

I just don’t know the argus stack is using “Voltage Ratio Gain” instead of analog gain.
Now I knew the fomular:
argus gain value = 10^(gain_dB / 20)
which gain_dB is the actual analog gain in sensor.