libpg2sdr
Host library for the ProStick Gen 2 SDR
Loading...
Searching...
No Matches
Tuner gain control

Functions

int pg2sdr_set_lna_gain (pg2sdr_device *dev, unsigned gain)
 Set LNA stage gain step.
 
int pg2sdr_set_mix_gain (pg2sdr_device *dev, unsigned gain)
 Set MIX stage gain step.
 
int pg2sdr_set_vga_gain (pg2sdr_device *dev, unsigned gain)
 Set VGA stage gain step.
 
int pg2sdr_get_stage_gains (pg2sdr_device *dev, unsigned *lna, unsigned *mix, unsigned *vga)
 Get per-stage gain step settings.
 
int pg2sdr_set_lna_gain_db (pg2sdr_device *dev, double gain_db)
 Set LNA stage gain in dB.
 
int pg2sdr_set_mix_gain_db (pg2sdr_device *dev, double gain_db)
 Set MIX stage gain in dB.
 
int pg2sdr_set_vga_gain_db (pg2sdr_device *dev, double gain_db)
 Set VGA stage gain in dB.
 
int pg2sdr_get_stage_gains_db (pg2sdr_device *dev, double *lna_db, double *mix_db, double *vga_db)
 Get per-stage gain settings in dB.
 
int pg2sdr_set_total_gain_db (pg2sdr_device *dev, double gain_db)
 Set total gain, in dB.
 
int pg2sdr_get_total_gain_db (pg2sdr_device *dev, double *gain_db)
 Get total gain setting, in dB.
 

Detailed Description

The tuner on PG2SDR hardware has three controllable gain-stages. In order, starting from the RF input, these stages are LNA, MIX, and VGA. Each stage has a configurable gain setting that can be set to one of 16 possible gain steps.

libpg2sdr provides three types of API for setting the gain of these stages, and matching getters to retrieve gain:

The gain APIs that deal in terms of dB rely on a set of gain tables, which provide conversions between hardware gain steps and values in dB. libpg2sdr provides a built-in set of tables by default. The conversion tables can be inspected or updated via pg2sdr_get_gain_tables() and pg2sdr_set_gain_tables().

All of the gain APIs can be called while streaming data, and take effect immediately when called.

Function Documentation

◆ pg2sdr_get_stage_gains()

int pg2sdr_get_stage_gains ( pg2sdr_device dev,
unsigned *  lna,
unsigned *  mix,
unsigned *  vga 
)

Get per-stage gain step settings.

This retrieves current hardware gain settings, in terms of the low-level hardware gain step for each stage.

Parameters
[in]devthe device to query
[out]lnaif not NULL, location to store the current LNA gain step
[out]mixif not NULL, location to store the current MIX gain step
[out]vgaif not NULL, location to store the current VGA gain step
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTif all of lna, mix, vga are NULL
<0negative error code on failure
See also
pg2sdr_set_lna_gain()
pg2sdr_set_mix_gain()
pg2sdr_set_vga_gain()

◆ pg2sdr_get_stage_gains_db()

int pg2sdr_get_stage_gains_db ( pg2sdr_device dev,
double *  lna_db,
double *  mix_db,
double *  vga_db 
)

Get per-stage gain settings in dB.

This retrieves current hardware gain settings, converting hardware gain step settings to a gain in dB using the currently set gain table.

Parameters
[in]devthe device to query
[out]lna_dbif not NULL, location to store the current LNA gain
[out]mix_dbif not NULL, location to store the current MIX gain
[out]vga_dbif not NULL, location to store the current VGA gain
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTif all of lna_db, mix_db, vga_db are NULL
<0negative error code on failure
See also
pg2sdr_set_lna_gain_db()
pg2sdr_set_mix_gain_db()
pg2sdr_set_vga_gain_db()
pg2sdr_get_gain_tables()

◆ pg2sdr_get_total_gain_db()

int pg2sdr_get_total_gain_db ( pg2sdr_device dev,
double *  gain_db 
)

Get total gain setting, in dB.

This retrieves current hardware gain settings, and converts them to a total gain value in dB using the currently set gain table.

If the current gain was set by calling pg2sdr_set_total_gain_db() then the returned gain reflects the recorded gain setting for the entry in the gain table that was used. If the current gain was set by setting individual gain stages, then an estimated total gain is returned by looking at the gain table for each stage individually; this estimated total may not exactly match the total gain measurements in the gain table.

Parameters
[in]devthe device to query
[out]gain_dblocation to store the current total gain, in dB
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTif gain_db is NULL
<0negative error code on failure
See also
pg2sdr_set_total_gain_db()
pg2sdr_get_gain_tables()

◆ pg2sdr_set_lna_gain()

int pg2sdr_set_lna_gain ( pg2sdr_device dev,
unsigned  gain 
)

Set LNA stage gain step.

Parameters
[in]devthe device to configure
[in]gainthe LNA gain step to set, in the range [0..15]
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTgain is out of range
<0negative error code on failure
See also
pg2sdr_get_stage_gains()

◆ pg2sdr_set_lna_gain_db()

int pg2sdr_set_lna_gain_db ( pg2sdr_device dev,
double  gain_db 
)

Set LNA stage gain in dB.

The requested dB value will be converted to a hardware gain step using the currently set gain table. The actual dB value may not exactly match the requested value.

Parameters
[in]devthe device to configure
[in]gain_dbthe LNA gain to set, in dB
Return values
PG2SDR_SUCCESSsuccess
<0negative error code on failure
See also
pg2sdr_get_stage_gains_db()
pg2sdr_set_gain_tables()

◆ pg2sdr_set_mix_gain()

int pg2sdr_set_mix_gain ( pg2sdr_device dev,
unsigned  gain 
)

Set MIX stage gain step.

Parameters
[in]devthe device to configure
[in]gainthe MIX gain step to set, in the range [0..15]
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTgain is out of range
<0negative error code on failure
See also
pg2sdr_get_stage_gains()

◆ pg2sdr_set_mix_gain_db()

int pg2sdr_set_mix_gain_db ( pg2sdr_device dev,
double  gain_db 
)

Set MIX stage gain in dB.

The requested dB value will be converted to a hardware gain step using the currently set gain table. The actual dB value may not exactly match the requested value.

Parameters
[in]devthe device to configure
[in]gain_dbthe MIX gain to set, in dB
Return values
PG2SDR_SUCCESSsuccess
<0negative error code on failure
See also
pg2sdr_get_stage_gains_db()
pg2sdr_set_gain_tables()

◆ pg2sdr_set_total_gain_db()

int pg2sdr_set_total_gain_db ( pg2sdr_device dev,
double  gain_db 
)

Set total gain, in dB.

The requested dB value is converted to a set of hardware gain steps for each stage, using the currently set gain table. The actual dB value may not exactly match the requested value.

Parameters
[in]devthe device to configure
[in]gain_dbthe total gain to set, in dB
Return values
PG2SDR_SUCCESSsuccess
<0negative error code on failure
See also
pg2sdr_get_total_gain_db()
pg2sdr_set_gain_tables()

◆ pg2sdr_set_vga_gain()

int pg2sdr_set_vga_gain ( pg2sdr_device dev,
unsigned  gain 
)

Set VGA stage gain step.

Parameters
[in]devthe device to configure
[in]gainthe VGA gain step to set, in the range [0..15]
Return values
PG2SDR_SUCCESSsuccess
PG2SDR_ERROR_BAD_ARGUMENTgain is out of range
<0negative error code on failure
See also
pg2sdr_get_stage_gains()

◆ pg2sdr_set_vga_gain_db()

int pg2sdr_set_vga_gain_db ( pg2sdr_device dev,
double  gain_db 
)

Set VGA stage gain in dB.

The requested dB value will be converted to a hardware gain step using the currently set gain table. The actual dB value may not exactly match the requested value.

Parameters
[in]devthe device to configure
[in]gain_dbthe VGA gain to set, in dB
Return values
PG2SDR_SUCCESSsuccess
<0negative error code on failure
See also
pg2sdr_get_stage_gains_db()
pg2sdr_set_gain_tables()