1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00

LimeSDR input: Added methods to control directly LNA, TIA and PGA

This commit is contained in:
f4exb 2017-04-21 16:46:39 +02:00
parent bef210d97f
commit a07403d942
2 changed files with 110 additions and 0 deletions

View File

@ -67,4 +67,108 @@ bool DeviceLimeSDR::setNCOFrequency(lms_device_t *device, bool dir_tx, std::size
}
}
bool DeviceLimeSDR::SetRFELNA_dB(lms_device_t *device, std::size_t chan, int value)
{
if (LMS_WriteParam(device, LMS7param(MAC), chan+1) < 0)
{
fprintf(stderr, "DeviceLimeSDR::SetRFELNA_dB: cannot set channel to #%lu\n", chan);
return false;
}
if (value > 30) {
value = 30;
}
int val = value - 30;
int g_lna_rfe = 0;
if (val >= 0) g_lna_rfe = 15;
else if (val >= -1) g_lna_rfe = 14;
else if (val >= -2) g_lna_rfe = 13;
else if (val >= -3) g_lna_rfe = 12;
else if (val >= -4) g_lna_rfe = 11;
else if (val >= -5) g_lna_rfe = 10;
else if (val >= -6) g_lna_rfe = 9;
else if (val >= -9) g_lna_rfe = 8;
else if (val >= -12) g_lna_rfe = 7;
else if (val >= -15) g_lna_rfe = 6;
else if (val >= -18) g_lna_rfe = 5;
else if (val >= -21) g_lna_rfe = 4;
else if (val >= -24) g_lna_rfe = 3;
else if (val >= -27) g_lna_rfe = 2;
else g_lna_rfe = 1;
if (LMS_WriteParam(device, LMS7param(G_LNA_RFE), g_lna_rfe) < 0)
{
fprintf(stderr, "DeviceLimeSDR::SetRFELNA_dB: cannot set LNA gain to %d (%d)\n", value, g_lna_rfe);
return false;
}
return true;
}
bool DeviceLimeSDR::SetRFETIA_dB(lms_device_t *device, std::size_t chan, int value)
{
if (LMS_WriteParam(device, LMS7param(MAC), chan+1) < 0)
{
fprintf(stderr, "DeviceLimeSDR::SetRFETIA_dB: cannot set channel to #%lu\n", chan);
return false;
}
if (value > 3) {
value = 3;
} else if (value < 1) {
value = 1;
}
int g_tia_rfe = value;
if (LMS_WriteParam(device, LMS7param(G_TIA_RFE), g_tia_rfe) < 0)
{
fprintf(stderr, "DeviceLimeSDR::SetRFELNA_dB: cannot set TIA gain to %d (%d)\n", value, g_tia_rfe);
return false;
}
return true;
}
bool DeviceLimeSDR::SetRBBPGA_dB(lms_device_t *device, std::size_t chan, float value)
{
if (LMS_WriteParam(device, LMS7param(MAC), chan+1) < 0)
{
fprintf(stderr, "DeviceLimeSDR::SetRBBPGA_dB: cannot set channel to #%lu\n", chan);
return false;
}
int g_pga_rbb = (int)(value + 12.5);
if (g_pga_rbb > 0x1f) g_pga_rbb = 0x1f;
if (g_pga_rbb < 0) g_pga_rbb = 0;
if (LMS_WriteParam(device, LMS7param(G_PGA_RBB), g_pga_rbb) < 0)
{
fprintf(stderr, "DeviceLimeSDR::SetRBBPGA_dB: cannot set G_PGA_RBB to %d\n", g_pga_rbb);
return false;
}
int rcc_ctl_pga_rbb = (430.0*pow(0.65, (g_pga_rbb/10.0))-110.35)/20.4516 + 16;
int c_ctl_pga_rbb = 0;
if (0 <= g_pga_rbb && g_pga_rbb < 8) c_ctl_pga_rbb = 3;
if (8 <= g_pga_rbb && g_pga_rbb < 13) c_ctl_pga_rbb = 2;
if (13 <= g_pga_rbb && g_pga_rbb < 21) c_ctl_pga_rbb = 1;
if (21 <= g_pga_rbb) c_ctl_pga_rbb = 0;
if (LMS_WriteParam(device, LMS7param(RCC_CTL_PGA_RBB), rcc_ctl_pga_rbb) < 0)
{
fprintf(stderr, "DeviceLimeSDR::SetRBBPGA_dB: cannot set RCC_CTL_PGA_RBB to %d\n", rcc_ctl_pga_rbb);
return false;
}
if (LMS_WriteParam(device, LMS7param(C_CTL_PGA_RBB), c_ctl_pga_rbb) < 0)
{
fprintf(stderr, "DeviceLimeSDR::SetRBBPGA_dB: cannot set C_CTL_PGA_RBB to %d\n", c_ctl_pga_rbb);
return false;
}
return true;
}

View File

@ -24,6 +24,12 @@ class DeviceLimeSDR
public:
/** set NCO frequency with positive or negative frequency (deals with up/down convert). Enables or disables NCO */
static bool setNCOFrequency(lms_device_t *device, bool dir_tx, std::size_t chan, bool enable, float frequency);
/** set LNA gain Range: [1-30] (dB) **/
static bool SetRFELNA_dB(lms_device_t *device, std::size_t chan, int value);
/** set TIA gain Range: [1-3] **/
static bool SetRFETIA_dB(lms_device_t *device, std::size_t chan, int value);
/** set PGA gain Range: [0-32] (dB) **/
static bool SetRBBPGA_dB(lms_device_t *device, std::size_t chan, float value);
};
#endif /* DEVICES_LIMESDR_DEVICELIMESDR_H_ */